/* ── CSS Variables ── */
:root {
  --deep: #061020;
  --ocean: #0a1628;
  --foam: #e8f4f8;
  --tide: #4fc3f7;
  --kelp: #26a69a;
  --coral: #ff7043;
  --sand: #ffd54f;
  --mist: #b0bec5;
  --glass: rgba(255, 255, 255, 0.05);
  --gb: rgba(255, 255, 255, 0.09);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

/* ── Light theme ── */
:root.light {
  --deep: #dde5dd;
  --ocean: #f5f8f5;
  --foam: #0d2137;
  --tide: #0277bd;
  --kelp: #00695c;
  --coral: #d84315;
  --sand: #b8860b;
  --mist: #37474f;
  --glass: rgba(255, 255, 255, 0.7);
  --gb: rgba(0, 0, 0, 0.1);
}

/* ── Reset ── */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  scrollbar-width: thin;
  scrollbar-color: var(--gb) transparent;
}

*::-webkit-scrollbar {
  width: 3px;
  height: 3px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: var(--gb);
  border-radius: 3px;
}

*::-webkit-scrollbar-thumb:hover {
  background: var(--tide);
}

html,
body {
  height: 100%;
}

body {
  background: var(--deep);
  color: var(--foam);
  font-family: 'Bricolage Grotesque', sans-serif;
  min-height: 100vh;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background: radial-gradient(ellipse at 15% 60%, rgba(79, 195, 247, .07) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 15%, rgba(38, 166, 154, .05) 0%, transparent 50%),
    radial-gradient(ellipse at 55% 85%, rgba(26, 58, 92, .35) 0%, transparent 55%);
}

html.light body::before {
  background: radial-gradient(ellipse at 15% 60%, rgba(2, 136, 209, .07) 0%, transparent 55%),
    radial-gradient(ellipse at 85% 15%, rgba(0, 121, 107, .05) 0%, transparent 50%),
    radial-gradient(ellipse at 55% 85%, rgba(180, 215, 235, .4) 0%, transparent 55%);
}

/* ── App layout ── */
.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh; /* fallback */
  overflow: hidden;
  padding-top: calc(.9rem + var(--safe-top));
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  margin-bottom: 0;
  padding: 0 1.5rem .9rem;
  border-bottom: 1px solid var(--gb);
}

.logo {
  line-height: 1;
}

.logo img {
  height: 2rem;
  display: block;
}

/* ── Card ── */
.card {
  position: relative;
  background: var(--glass);
  border: 1px solid var(--gb);
  border-radius: 16px;
  padding: 1.4rem;
  margin-bottom: 1.2rem;
}

.card-title {
  font-family: 'DM Mono', monospace;
  font-size: .68rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .13em;
  color: var(--mist);
  margin-bottom: .9rem;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .45rem;
  padding: .58rem 1.1rem;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  font-family: 'Bricolage Grotesque', sans-serif;
  font-size: .84rem;
  font-weight: 600;
  transition: all .15s;
}

.btn:disabled {
  opacity: .35;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--tide), var(--kelp));
  color: var(--deep);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(79, 195, 247, .28);
}

.btn-ghost {
  background: var(--glass);
  border: 1px solid var(--gb);
  color: var(--foam);
}

.btn-ghost:hover {
  border-color: var(--tide);
  background: rgba(79, 195, 247, .07);
}

.btn-sand {
  background: rgba(255, 213, 79, .11);
  border: 1px solid rgba(255, 213, 79, .24);
  color: var(--sand);
}

.btn-sand:hover {
  background: rgba(255, 213, 79, .2);
}

.btn-coral {
  background: rgba(255, 112, 67, .13);
  border: 1px solid rgba(255, 112, 67, .28);
  color: var(--coral);
}

.btn-coral:hover {
  background: rgba(255, 112, 67, .22);
}

.btn-danger {
  background: rgba(255, 82, 82, .12);
  border: 1px solid rgba(255, 82, 82, .3);
  color: #ff5252;
}

.btn-danger:hover {
  background: rgba(255, 82, 82, .22);
}

.act-row {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
  margin-bottom: 1.2rem;
}

/* ── Modal shell ── */
/* Scoped to :not(.overlay-fixed) so TC picker overlays (.overlay-fixed) are unaffected */
.overlay:not(.overlay-fixed) {
  position: fixed;
  inset: 0;
  background: rgba(6, 16, 32, .9);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}

.overlay:not(.overlay-fixed).open {
  opacity: 1;
  pointer-events: all;
}

.overlay:not(.overlay-fixed) > .modal {
  position: relative;
  top: auto;      /* reset TC overlay.css: top:50% */
  left: auto;     /* reset TC overlay.css: left:50% */
  background: var(--ocean);
  border: 1px solid var(--gb);
  border-radius: 20px 20px 0 0;
  padding: 1.9rem 1.9rem calc(1.9rem + var(--safe-bot));
  width: 100%;
  max-width: 560px;
  transform: translateY(60px);
  transition: transform .25s cubic-bezier(.34, 1.2, .64, 1) .07s;
  max-height: 92vh;
  overflow-y: auto;
}

.overlay:not(.overlay-fixed).open > .modal {
  transform: translateY(0);
}

@media (min-width: 600px) {
  .overlay:not(.overlay-fixed) {
    align-items: center;
  }

  .overlay:not(.overlay-fixed) > .modal {
    border-radius: 20px;
    padding: 1.9rem;
    max-height: 88vh;
  }
}


.overlay:not(.overlay-fixed) .modal-title {
  font-family: 'Instrument Serif', serif;
  font-size: 1.5rem;
  color: var(--foam);
  margin-bottom: .3rem;
}

.overlay:not(.overlay-fixed) .modal-sub {
  font-size: .77rem;
  color: var(--mist);
  margin-bottom: 1.35rem;
  font-style: italic;
}

/* ── Shared form elements ── */
.fg {
  margin-bottom: .85rem;
}

.fl {
  display: block;
  font-family: 'DM Mono', monospace;
  font-size: .62rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--mist);
  margin-bottom: .32rem;
}

.fi,
.fs {
  width: 100%;
  background: rgba(255, 255, 255, .05);
  border: 1px solid var(--gb);
  border-radius: 8px;
  padding: .58rem .82rem;
  color: var(--foam);
  font-family: 'Bricolage Grotesque', sans-serif;
  font-size: .88rem;
  outline: none;
  transition: border-color .15s;
}

.fi:focus,
.fs:focus {
  border-color: var(--tide);
}

.fs option {
  background: var(--ocean);
}

.frow {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .68rem;
}

.frow3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: .68rem;
}

.m-actions {
  display: flex;
  gap: .68rem;
  margin-top: 1.35rem;
  flex-wrap: wrap;
}

.m-actions .btn {
  flex: 1;
  justify-content: center;
  min-width: 120px;
}

.section-divider {
  height: 1px;
  background: var(--gb);
  margin: 1.4rem 0;
}

.section-head {
  font-family: 'DM Mono', monospace;
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--mist);
  margin-bottom: .9rem;
}

/* ── Autocomplete ── */
.inp-wrap {
  position: relative;
}

.sug-list {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--ocean);
  border: 1px solid var(--tide);
  border-radius: 8px;
  z-index: 200;
  max-height: 165px;
  overflow-y: auto;
  margin-top: 2px;
}

.sug-item {
  padding: .48rem .82rem;
  font-size: .83rem;
  cursor: pointer;
  color: var(--foam);
  border-bottom: 1px solid var(--gb);
}

.sug-item:last-child {
  border-bottom: none;
}

.sug-item:hover,
.sug-item:active {
  background: rgba(79, 195, 247, .09);
  color: var(--tide);
}

/* ── Empty state ── */
.empty {
  text-align: center;
  padding: 2rem;
  color: var(--mist);
}

.empty .ei {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  margin: 0 auto .45rem;
  display: block;
}

.empty p {
  font-size: .82rem;
  font-style: italic;
}

/* ── Toast notification ── */
.notif {
  position: fixed;
  bottom: calc(1.5rem + var(--safe-bot));
  right: 1.5rem;
  background: var(--ocean);
  border: 1px solid var(--tide);
  border-radius: 10px;
  padding: .68rem 1.05rem;
  font-size: .79rem;
  color: var(--foam);
  z-index: 300;
  transform: translateY(120px);
  opacity: 0;
  transition: all .3s;
  max-width: 300px;
}

.notif.show {
  transform: translateY(0);
  opacity: 1;
}

.notif.ok {
  border-color: var(--kelp);
}

.notif.err {
  border-color: var(--coral);
  color: var(--coral);
}

/* ── Install / update banners ── */
.install-banner {
  position: fixed;
  top: calc(1rem + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  background: var(--ocean);
  border: 1px solid rgba(79, 195, 247, .3);
  border-radius: 12px;
  padding: .65rem 1.1rem;
  font-size: .78rem;
  color: var(--foam);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: .75rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, .4);
  white-space: nowrap;
}

.install-banner button {
  background: var(--tide);
  color: var(--deep);
  border: none;
  border-radius: 7px;
  padding: .3rem .75rem;
  font-size: .75rem;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}

.install-banner .ib-close {
  background: none;
  border: none;
  color: var(--mist);
  cursor: pointer;
  font-size: 1rem;
  padding: 0;
  line-height: 1;
}

/* ── App loading screen ── */
#app-loading {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
  transition: opacity .35s ease;
}

#app {
  opacity: 0;
  transition: opacity .4s ease;
}

#setup {
  opacity: 0;
  transition: opacity .4s ease;
}

#app-loading img {
  width: 80px;
  height: 80px;
  border-radius: 20px;
}

/* ── Profile chip ── */
.profile-chip {
  display: flex;
  align-items: center;
  gap: .6rem;
  background: var(--glass);
  border: 1px solid var(--gb);
  border-radius: 100px;
  padding: .35rem 1rem .35rem .35rem;
  cursor: pointer;
  transition: all .2s;
  font-size: .84rem;
  color: var(--mist);
}

.profile-chip:hover {
  border-color: var(--tide);
  color: var(--foam);
}

.avatar {
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--tide), var(--kelp));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .72rem;
  font-weight: 700;
  color: var(--deep);
  flex-shrink: 0;
}

/* ── Responsive ── */
@media (max-width: 580px) {
  .frow3 {
    grid-template-columns: 1fr 1fr;
  }
}


/* overlay backdrop */
html.light .overlay:not(.overlay-fixed) { background: rgba(180, 210, 230, .75); }

/* ── Light theme: component overrides ──
   All rgba(255,255,255,...) glass/background values need flipping
   to rgba(0,0,0,...) equivalents so they read correctly on light bg. */

/* activity-grid */
html.light .grid-tab          { background: rgba(0, 0, 0, .04); }
html.light .cell               { background: rgba(0, 0, 0, .06); }

/* session-log */
html.light .log-entry          { background: rgba(0, 0, 0, .03); }
html.light .log-tag.time       { border-color: rgba(0, 0, 0, .12); background: rgba(0, 0, 0, .04); }

/* journey */
html.light .tl-line            { background: rgba(0, 0, 0, .1); }
html.light .tl-dot             { border-color: rgba(0, 0, 0, .18); }
html.light .tl-km              { color: rgba(0, 0, 0, .4); }
html.light .pbar-wrap          { background: rgba(0, 0, 0, .08); }
html.light .stat-box           { background: rgba(0, 0, 0, .03); }

/* forms (log-activity / shared) */
html.light .fi,
html.light .fs                 { background: rgba(0, 0, 0, .05); }
html.light .sport-picker-trigger { background: rgba(0, 0, 0, .05); }
html.light .sport-pick-row     { background: rgba(0, 0, 0, .04); }
html.light .sport-pick-row:hover { background: rgba(0, 0, 0, .08); }

/* user */
html.light .strength-bar       { background: rgba(0, 0, 0, .08); }
html.light .btn-primary        { color: #ffffff; }
html.light .avatar             { color: #ffffff; }

/* settings */
html.light .set-item           { background: rgba(0, 0, 0, .03); }
html.light .tog-track          { background: rgba(0, 0, 0, .12); }

/* group */
html.light .lb-row             { background: rgba(0, 0, 0, .03); }

/* trends */
html.light .trends-tab         { background: rgba(0, 0, 0, .04); }
html.light .trends-stat        { background: rgba(0, 0, 0, .03); }

/* sync */
html.light .conflict-row       { background: rgba(0, 0, 0, .04); }
