/* ── Soft Pastel Pop ────────────────────────────────────────────────────
   One palette, two themes. Every colour is a token on :root so the dark
   block only has to restate the tokens, never the rules. */

:root {
  color-scheme: light dark;

  --bg: #FFF9F4;
  --surface: #FFE3D0;
  --surface-alt: #FFF1E6;
  --surface-grey: #F4EEE8;
  --ink: #2B2433;
  --ink-muted: #2B2433A6;
  --primary: #D9744F;
  --primary-pressed: #C4633F;
  --on-primary: #FFFFFF;
  --mint: #7FB69E;
  --mint-deep: #4E8A6F;
  --gold: #F4B860;
  --gold-soft: #FFECCC;
  --gold-deep: #B97F1F;
  --danger: #D14B3F;
  --outline: #F0DDD0;
  --grey: #8B96A7;
  --grey-soft: #C9CFD8;
  --sky: #A9D4EE;
  --slat: #E8C8B2;
  --scrim: #2B243380;
  --shadow: 0 8px 24px rgba(43, 36, 51, 0.08);

  --r-card: 24px;
  --r-pill: 999px;
  --tap: 44px;

  --font: "Plus Jakarta Sans", ui-rounded, -apple-system, BlinkMacSystemFont,
          "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --pad-top: max(12px, env(safe-area-inset-top));
  --pad-left: max(20px, env(safe-area-inset-left));
  --pad-right: max(20px, env(safe-area-inset-right));
  --pad-bottom: env(safe-area-inset-bottom);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #221C29;
    --surface: #3A2C2B;
    --surface-alt: #2C2434;
    --surface-grey: #2A2431;
    --ink: #F7EEE7;
    --ink-muted: #F7EEE7A6;
    --primary: #E8845E;
    --primary-pressed: #D9744F;
    --on-primary: #22161A;
    --mint: #8FC4AC;
    --mint-deep: #9FD3BB;
    --gold: #F4B860;
    --gold-soft: #4A3A22;
    --gold-deep: #EFC276;
    --danger: #E4695C;
    --outline: #3E3346;
    --grey: #9BA3B3;
    --grey-soft: #4C4557;
    --sky: #4E6E85;
    --slat: #C09572;
    --scrim: #120E16CC;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  }
}

/* ── Reset ─────────────────────────────────────────────────────────── */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
}

body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

.hidden { display: none !important; }

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

:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
  border-radius: 6px;
}

/* ── Buttons ───────────────────────────────────────────────────────── */

.btn {
  font-family: var(--font);
  font-weight: 700;
  font-size: 15px;
  min-height: var(--tap);
  padding: 12px 20px;
  border: 0;
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: transform 120ms ease, background-color 120ms ease, opacity 120ms ease;
  touch-action: manipulation;
}
.btn:active:not(:disabled) { transform: scale(0.975); }
.btn:disabled { opacity: 0.55; cursor: default; }

.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-pressed); }

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 2px solid var(--outline);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-alt); }

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 2px solid var(--danger);
}

.btn-block { display: block; width: 100%; }
.btn-inline { flex: 0 0 auto; padding: 12px 18px; }

.btn-chip {
  background: var(--surface-alt);
  color: var(--ink);
  border: 2px solid var(--outline);
  font-size: 14px;
  padding: 10px 16px;
}
.btn-chip:hover:not(:disabled) { background: var(--surface); }

.btn-cta {
  width: 100%;
  max-width: 340px;
  margin: 20px auto 0;
  display: block;
  font-size: 17px;
  font-weight: 700;
  min-height: 56px;
  box-shadow: var(--shadow);
}
.btn-cta[data-busy="true"] { opacity: 0.7; }

.btn-row { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 auto; }

/* ── Fields ────────────────────────────────────────────────────────── */

.field {
  font-family: var(--font);
  font-size: 16px; /* 16px keeps iOS from zooming on focus */
  color: var(--ink);
  background: var(--surface-alt);
  border: 2px solid var(--outline);
  border-radius: 14px;
  padding: 12px 14px;
  min-height: var(--tap);
  width: 100%;
  min-width: 0;
}
.field::placeholder { color: var(--ink-muted); }

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-muted);
  margin-bottom: 6px;
}

/* ── Full-screen states (boot, approval) ───────────────────────────── */

.fullscreen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--pad-top) var(--pad-right) calc(24px + var(--pad-bottom)) var(--pad-left);
  overflow-y: auto;
  z-index: 20;
}

.boot-inner { text-align: center; }
.boot-msg { color: var(--ink-muted); margin: 16px 0 12px; }

.spinner {
  width: 34px; height: 34px; margin: 0 auto;
  border: 3px solid var(--outline);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
}

.approval-inner { max-width: 420px; width: 100%; text-align: center; }
.approval-mark { color: var(--primary); margin-bottom: 12px; }
.approval-title { font-size: 24px; font-weight: 800; margin: 0 0 10px; line-height: 1.25; }
.approval-body { color: var(--ink-muted); margin: 0 0 24px; }
.code-form { text-align: left; }
.code-row { display: flex; gap: 10px; align-items: stretch; }
.approval-status { min-height: 20px; font-size: 14px; margin: 12px 0 0; }
.approval-status[data-tone="error"] { color: var(--danger); }
.approval-status[data-tone="ok"] { color: var(--mint-deep); }
.approval-status[data-tone="info"] { color: var(--ink-muted); }

.approval-divider {
  display: flex; align-items: center; gap: 12px;
  color: var(--ink-muted); font-size: 13px; margin: 24px 0 16px;
}
.approval-divider::before, .approval-divider::after {
  content: ""; flex: 1; height: 2px; background: var(--outline); border-radius: 1px;
}
.approval-hint { font-size: 13px; color: var(--ink-muted); margin: 10px 0 0; }

/* ── App shell ─────────────────────────────────────────────────────── */

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.chip-bar {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: var(--pad-top) var(--pad-right) 0 var(--pad-left);
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.chip {
  font-size: 12px;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: var(--r-pill);
  background: var(--surface-grey);
  color: var(--ink-muted);
}
.chip-offline { background: var(--gold-soft); color: var(--gold-deep); }

.panels {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.panel {
  max-width: 520px;
  margin: 0 auto;
  padding: 8px var(--pad-right) calc(96px + var(--pad-bottom)) var(--pad-left);
}

.screen-title { font-size: 26px; font-weight: 800; margin: 8px 0 16px; }

/* ── Gate hero ─────────────────────────────────────────────────────── */

.hero { display: flex; justify-content: center; margin-top: 4px; }

.gate-svg { width: min(300px, 78vw); height: auto; display: block; }

.ring-track { fill: none; stroke: var(--outline); stroke-width: 12; }
.ring-dashed {
  fill: none; stroke: var(--grey-soft); stroke-width: 12;
  stroke-linecap: round; stroke-dasharray: 22 18; opacity: 0;
}
.ring-fill {
  fill: none; stroke: var(--accent, var(--primary)); stroke-width: 12;
  stroke-linecap: round;
}
.hero-disc { fill: var(--surface); }
.door-sky { fill: var(--sky); }
.door-back { fill: var(--surface-alt); }
.slat { fill: var(--slat); }
.door-frame { fill: none; stroke: var(--accent, var(--primary)); stroke-width: 3.5; }
.ground { fill: var(--gold-deep); }
.hero-readout {
  fill: var(--accent, var(--primary));
  font-family: var(--font);
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.gate-svg[data-unknown="true"] .hero-disc { fill: var(--surface-grey); }
.gate-svg[data-unknown="true"] .ring-fill { opacity: 0; }
.gate-svg[data-unknown="true"] .ring-dashed { opacity: 1; }
.gate-svg[data-unknown="true"] .door-panel { opacity: 0.5; }
.gate-svg[data-unknown="true"] .ground { fill: var(--grey-soft); }

.state-caption {
  text-align: center;
  font-size: 22px;
  font-weight: 800;
  margin: 12px 0 2px;
  color: var(--accent, var(--ink));
}
.state-sub {
  text-align: center;
  font-size: 13px;
  color: var(--ink-muted);
  margin: 0;
  min-height: 19px;
}
.state-sub[data-tone="error"] { color: var(--danger); font-weight: 600; }

.reset-row {
  margin: 18px auto 0;
  max-width: 340px;
  background: var(--surface-grey);
  border-radius: var(--r-card);
  padding: 14px 16px;
  text-align: center;
}
.reset-label {
  display: block; font-size: 13px; font-weight: 600;
  color: var(--ink-muted); margin-bottom: 10px;
}
.reset-buttons { display: flex; gap: 10px; justify-content: center; }

/* ── Cards ─────────────────────────────────────────────────────────── */

.card {
  background: var(--surface-alt);
  border: 2px solid var(--outline);
  border-radius: var(--r-card);
  padding: 18px;
  margin-top: 18px;
}
.card-title { font-size: 17px; font-weight: 800; margin: 0 0 6px; }
.card-body { font-size: 14px; color: var(--ink-muted); margin: 0 0 14px; }
.card-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  background: var(--surface-grey);
  padding: 1px 5px;
  border-radius: 5px;
}
.card-status { font-size: 13px; margin: 10px 0 0; min-height: 18px; color: var(--ink-muted); }
.card-status[data-tone="error"] { color: var(--danger); font-weight: 600; }
.card-status[data-tone="ok"] { color: var(--mint-deep); font-weight: 600; }

.activity-preview { padding-bottom: 8px; }

.card-head {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; min-height: var(--tap);
  background: none; border: 0; padding: 0 0 4px;
  font-family: var(--font); color: var(--ink); cursor: pointer;
}
.card-head-title { font-size: 17px; font-weight: 800; }
.card-head-chevron { color: var(--ink-muted); display: flex; }

.name-form { display: flex; gap: 10px; align-items: stretch; }

/* ── Event list ────────────────────────────────────────────────────── */

.event-list { list-style: none; margin: 0; padding: 0; }

.event-row {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 0;
  border-top: 1.5px solid var(--outline);
}
.event-list > .event-row:first-child { border-top: 0; }

.event-list-full .event-row {
  background: var(--surface-alt);
  border: 2px solid var(--outline);
  border-radius: 16px;
  padding: 12px 14px;
  margin-bottom: 8px;
}

.event-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--dot, var(--grey));
  margin-top: 6px; flex: 0 0 auto;
}
.event-text { flex: 1 1 auto; min-width: 0; }
.event-title {
  font-size: 14px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.event-sub {
  font-size: 12px; color: var(--ink-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.event-ts {
  font-size: 12px; color: var(--ink-muted);
  flex: 0 0 auto; font-variant-numeric: tabular-nums; padding-top: 1px;
}

.event-row.is-new { animation: slide-in 320ms ease both; }
@keyframes slide-in {
  from { opacity: 0; transform: translateY(-10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .event-row.is-new { animation: none; }
}

.empty-note { font-size: 14px; color: var(--ink-muted); text-align: center; padding: 16px 0; }

/* ── Invite / pairing ──────────────────────────────────────────────── */

.invite-result { margin-top: 16px; }
.qr-wrap {
  display: flex; justify-content: center;
  background: #FFFFFF; padding: 12px; border-radius: 18px; margin-bottom: 12px;
}
.qr-wrap canvas { display: block; width: 220px; height: 220px; image-rendering: pixelated; }

.invite-link, .pair-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
  word-break: break-all;
  background: var(--surface-grey);
  border-radius: 12px;
  padding: 10px 12px;
  margin: 0;
  -webkit-user-select: all;
  user-select: all;
}
.pair-code { font-size: 13px; }

.countdown { font-size: 13px; color: var(--gold-deep); font-weight: 600; margin: 10px 0 0; }
.countdown[data-expired="true"] { color: var(--danger); }

.version-note {
  text-align: center; font-size: 12px; color: var(--ink-muted); margin: 24px 0 0;
}

/* ── Tab bar ───────────────────────────────────────────────────────── */

.tabbar {
  position: sticky;
  bottom: 0;
  display: flex;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 2px solid var(--outline);
  padding: 6px var(--pad-right) calc(6px + var(--pad-bottom)) var(--pad-left);
  z-index: 10;
}

.tab {
  flex: 1 1 0;
  min-height: var(--tap);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 4px;
  background: none;
  border: 0;
  border-radius: 14px;
  font-family: var(--font);
  font-size: 11px;
  font-weight: 700;
  color: var(--ink-muted);
  cursor: pointer;
}
.tab svg { width: 24px; height: 24px; }
.tab[aria-selected="true"] { color: var(--primary); }

/* ── Sheet + toast ─────────────────────────────────────────────────── */

.scrim {
  position: fixed; inset: 0; z-index: 30;
  background: var(--scrim);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 16px;
  padding-bottom: calc(16px + var(--pad-bottom));
}

.sheet {
  background: var(--bg);
  border-radius: var(--r-card);
  padding: 24px 20px 20px;
  width: 100%;
  max-width: 460px;
  box-shadow: var(--shadow);
  animation: sheet-up 200ms ease both;
}
@keyframes sheet-up { from { transform: translateY(16px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .sheet { animation: none; } }

.sheet-title { font-size: 20px; font-weight: 800; margin: 0 0 8px; }
.sheet-body { color: var(--ink-muted); margin: 0 0 20px; }
.sheet .btn-block + .btn-block { margin-top: 10px; }

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(84px + var(--pad-bottom));
  z-index: 40;
  max-width: min(420px, calc(100vw - 32px));
  background: var(--ink);
  color: var(--bg);
  font-size: 14px;
  font-weight: 600;
  padding: 12px 18px;
  border-radius: var(--r-pill);
  box-shadow: var(--shadow);
  text-align: center;
}
.toast[data-tone="error"] { background: var(--danger); color: #FFFFFF; }
