/* ──────────────────────────────────────────────────────────────
   Reset, type scale and the app frame.

   One DOM, two shells: a phone shell with a top bar and bottom
   tabs, and a desktop shell with a side rail and full-width
   content. CSS picks, not JavaScript — so resizing the window
   never leaves the app in a half-state.

   Colour tokens all live in themes.css.
   ────────────────────────────────────────────────────────────── */

:root {
  --radius: 18px;
  --radius-sm: 12px;
  --gap: 14px;
  --rail-w: 244px;
  --tabbar-h: 62px;
  --pad: 16px;

  --font: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;
}

@media (min-width: 900px) {
  :root { --pad: 28px; --radius: 20px; }
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  background: var(--bg-0);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  /* Taps and scrolls, but no double-tap zoom — which, like pinch zoom,
     only drags a pinned layout off the edges of the screen. */
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body.is-locked { overflow: hidden; }

h1, h2, h3, p, dl, dd, figure, blockquote { margin: 0; }
ul { margin: 0; padding-left: 1.1em; }

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; padding: 0; }

:focus-visible {
  outline: 2px solid var(--accent-text);
  outline-offset: 2px;
  border-radius: 8px;
}

.icon { flex: none; }
.muted { color: var(--text-dim); }

.link {
  color: var(--accent-text);
  font-weight: 650;
  text-decoration: none;
  font-size: inherit;
}
.link:hover { text-decoration: underline; }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ══════════════════════════════════════════════════════════════
   Shell
   ══════════════════════════════════════════════════════════════ */

#app { min-height: 100%; }

/* Pinned to the viewport rather than sized with 100dvh. Added to an iOS
   home screen, dvh under-reports the screen height, which left a strip of
   background below the tab bar. Fixed insets always describe the real
   viewport, home indicator included. */
body[data-shell="app"] #app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  position: fixed;
  inset: 0;
}

/* ── phone: top bar ─────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) var(--pad) 10px;
  border-bottom: 1px solid var(--line);
  /* Deliberately not a backdrop-filter. A blurred layer pinned over a long
     scrolling list is one of the quickest ways to exhaust the GPU memory
     Safari allows a tab, which it answers by reloading the page. The rail
     on desktop can afford one; the phone bars cannot. */
  background: var(--surface-bar);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-brand { display: flex; align-items: center; gap: 10px; }

.brand-name {
  font-weight: 800;
  letter-spacing: -0.03em;
  font-size: 18px;
}

/* A two-peak ridge rather than a plain triangle — a lone triangle at this
   size reads as a play button. Drawn as a mask so the one class works
   anywhere, in the accent colour of whatever theme is on. */
.brand-mark {
  width: 25px;
  height: 25px;
  flex: none;
  background: var(--accent);
  -webkit-mask: var(--brand-glyph) center / contain no-repeat;
  mask: var(--brand-glyph) center / contain no-repeat;
}
.brand-mark--lg { width: 54px; height: 54px; }

:root {
  --brand-glyph: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M1.6 20.4 9.4 4.2l4.5 8.9 2.6-4.3 5.9 11.6Z'/%3E%3C/svg%3E");
}

.avatar-btn, .avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--surface-3);
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  flex: none;
}
.avatar--lg { width: 52px; height: 52px; font-size: 16px; }
.avatar-btn:hover { background: var(--accent); color: var(--accent-ink); }

/* ── phone: bottom tabs ─────────────────────────────────────── */

.tabbar {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  border-top: 1px solid var(--line);
  background: var(--surface-bar);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
  position: relative;
}

/* Carries the bar's colour on past its own bottom edge. If the viewport
   turns out to be a few pixels taller than the shell — which an installed
   iOS app does report, inconsistently — the strip underneath is the bar
   rather than the page background showing through. Invisible when there
   is nothing to cover. */
.tabbar::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  height: 120px;
  background: var(--surface-bar);
  pointer-events: none;
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 9px 2px 8px;
  color: var(--text-dim);
  font-size: 10px;
  font-weight: 650;
  letter-spacing: 0.02em;
  transition: color 0.15s;
  min-height: var(--tabbar-h);
}
.tab.is-on { color: var(--accent-text); }
.tab:active { transform: scale(0.94); }

/* ── phone: floating action button ──────────────────────────── */

.fab {
  position: fixed;
  right: var(--pad);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow);
  z-index: 9;
  transition: transform 0.15s;
}
.fab:active { transform: scale(0.9); }

/* ── the scrolling content area ─────────────────────────────── */

.view {
  overflow-y: auto;
  overscroll-behavior-y: contain;
  padding: 20px var(--pad) calc(96px + env(safe-area-inset-bottom));
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}
.view::-webkit-scrollbar { width: 10px; }
.view::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: 99px;
  border: 3px solid transparent;
  background-clip: content-box;
}

.stack { display: flex; flex-direction: column; gap: 18px; }

.view-title {
  font-size: clamp(26px, 5vw, 38px);
  font-weight: 800;
  letter-spacing: -0.035em;
  line-height: 1.1;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 11.5px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-dim);
  margin-bottom: 9px;
}

/* ── desktop: side rail, hidden on phones ───────────────────── */

.rail { display: none; }

@media (min-width: 900px) {
  body[data-shell="app"] #app {
    grid-template-columns: var(--rail-w) 1fr;
    grid-template-rows: 1fr;
  }

  .topbar, .tabbar, .fab { display: none; }

  .rail {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 22px 14px 18px;
    border-right: 1px solid var(--line);
    background: var(--surface-glass);
    backdrop-filter: blur(16px);
    overflow-y: auto;
  }

  .rail-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 0 10px 18px;
  }
  .rail-brand .brand-name { font-size: 21px; }

  .rail-nav { display: flex; flex-direction: column; gap: 3px; }

  .rail-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    border-radius: 12px;
    color: var(--text-dim);
    font-size: 14.5px;
    font-weight: 650;
    text-align: left;
    transition: background 0.14s, color 0.14s;
  }
  .rail-link:hover { background: var(--surface-2); color: var(--text); }
  .rail-link.is-on { background: var(--accent); color: var(--accent-ink); }
  .rail-cta { margin: 16px 0 0; }

  .rail-foot { margin-top: auto; padding-top: 16px; }

  .rail-user {
    display: flex;
    align-items: center;
    gap: 11px;
    width: 100%;
    padding: 9px 10px;
    border-radius: 12px;
    text-align: left;
    transition: background 0.14s;
  }
  .rail-user:hover { background: var(--surface-2); }
  .rail-user div { display: flex; flex-direction: column; min-width: 0; }
  .rail-user strong { font-size: 13.5px; }
  .rail-user span { font-size: 11.5px; color: var(--text-dim); }

  .view { padding: 32px var(--pad) 56px; }
  .stack { gap: 24px; }
}

/* ── wide-screen content grids ──────────────────────────────── */

.grid { display: grid; gap: 14px; }

/* Cards sit side by side as soon as there is room — this starts well
   before the desktop shell, so a tablet is not a tall phone. */
@media (min-width: 700px) {
  .grid { gap: 18px; }
  .grid--auto { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
}

@media (min-width: 900px) {
  .grid { gap: 20px; }
  .grid--auto { grid-template-columns: repeat(auto-fit, minmax(330px, 1fr)); }
}

@media (min-width: 1500px) {
  .grid--auto { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
}

/* ── boot splash ────────────────────────────────────────────── */

.boot {
  min-height: 100%;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  color: var(--text-dim);
  font-weight: 750;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 12px;
}
.boot .brand-mark { animation: rise 1.6s ease-in-out infinite; }

@keyframes rise {
  0%, 100% { transform: translateY(0); opacity: 0.75; }
  50% { transform: translateY(-7px); opacity: 1; }
}

/* Honour the system "reduce motion" setting: nothing moves, nothing loops.
   Switch transitions off outright rather than shortening them to ~0ms —
   a near-zero duration makes some engines freeze any property whose value
   comes from a custom property, which left the page background stale.
   The theme cross-fade in themes.css is a colour change rather than
   motion, and is deliberately kept. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
