/* Lull design system — Apple Human Interface style.
 * System colors + system fills, 8-pt spacing scale, grouped-list rhythm, SF type scale.
 * Follows the OS light/dark. Class names are stable so markup/JS need no changes.
 *
 * Color roles (HIG review): every tint has a *text-safe* variant so all text meets WCAG AA
 * (≥4.5:1) in BOTH schemes — vivid system tints stay for decorative fills (dot, eq, slider),
 * the darker "accessible" variants (Apple's own accessible palette) carry text and filled
 * buttons with white labels. Keep that split when adding colors.
 */

:root {
  color-scheme: light dark;

  /* Backgrounds (light: systemGroupedBackground / secondary) */
  --bg: #f2f2f7;
  --surface: #ffffff;
  --border: rgba(60, 60, 67, 0.13);
  --border-strong: rgba(60, 60, 67, 0.22);

  /* iOS system fills (translucent — used for controls/chips over cards) */
  --fill-1: rgba(120, 120, 128, 0.12);
  --fill-2: rgba(120, 120, 128, 0.16);
  --surface-2: var(--fill-1);

  /* Labels */
  --text: #1c1c1e;
  --muted: rgba(60, 60, 67, 0.72); /* was 0.6 (≈3.5:1 on white) — 0.72 clears WCAG AA at 15px */
  --faint: #6d6d72; /* WCAG AA ≥4.5:1 on the light surfaces (was rgba(...,0.32), ~1.8:1) — finding #20 */

  /* Tints. Vivid system colors for FILLS; *-text/-deep are Apple's accessible variants for TEXT
   * and for fills that carry white labels (systemBlue/Green/Red fail AA under white text). */
  --accent: #0071e3;                       /* text + fills; 4.7:1 under white, AA as link on cards */
  --accent-fill: #0071e3;                  /* filled buttons / pressed chips (white label) */
  --accent-press: #005bb5;
  --play: #34c759;                         /* decorative fills only (status dot) */
  --play-text: #1d7a30;                    /* “playing” text, hub-online, eq — 5.0:1 on white */
  --play-deep: #1d7a30;                    /* Start button fill under white text (5.4:1) */
  --play-dim: rgba(52, 199, 89, 0.16);
  --warn: #c93400;                         /* accessible systemOrange — “needs tap”/“error” text */
  --danger: #d70015;                       /* accessible systemRed */
  --danger-text: #d70015;
  --danger-deep: #d70015;                  /* alarm banner fill — 5.4:1 under white text */
  --danger-bg: rgba(255, 59, 48, 0.12);

  /* Radii */
  --radius: 12px;
  --radius-lg: 18px;
  --radius-pill: 980px;

  /* 8-pt spacing scale */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 28px;

  --touch: 50px;
  --pad: 18px;
  --maxw: 540px;

  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 10px 30px rgba(0, 0, 0, 0.06);
  --ring: 0 0 0 4px rgba(0, 122, 255, 0.28);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui, "Segoe UI", sans-serif;

  /* Nav-bar chrome + "Now Playing" hero (native-feel pass). --bar-bg is the translucent wash
   * under the backdrop blur; browsers without blur fall back to solid --bg instead. */
  --bar-bg: rgba(242, 242, 247, 0.82);
  --hero-tint: rgba(0, 113, 227, 0.09);   /* accent wash at the top of the local-player hero */
  --hero-tint-0: rgba(0, 113, 227, 0);    /* same hue at 0 alpha — old WebKit greys "transparent" */
  --play-glow: rgba(29, 122, 48, 0.28);   /* soft elevation under the hero play button */

  /* iOS spring-ish easing for presses/entrances (fast out, gentle settle) */
  --ease-out: cubic-bezier(0.2, 0.7, 0.3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --border: rgba(84, 84, 88, 0.4);
    --border-strong: rgba(84, 84, 88, 0.65);

    --fill-1: rgba(120, 120, 128, 0.24);
    --fill-2: rgba(120, 120, 128, 0.32);

    --text: #ffffff;
    --muted: rgba(235, 235, 245, 0.6);
    --faint: #9a9aa2; /* WCAG AA on the dark surfaces — finding #20 */

    --accent: #0a84ff;                     /* dark links need the vivid blue (4.7:1 on surfaces) */
    --accent-fill: #0071e3;                /* deeper fill so white button labels stay ≥4.5:1 */
    --accent-press: #409cff;
    --play: #30d158;
    --play-text: #30d158;                  /* 8.8:1 on dark surfaces — no split needed */
    --play-deep: #1d7a30;
    --play-dim: rgba(48, 209, 88, 0.2);
    --warn: #ff9f0a;
    --danger: #ff453a;
    --danger-text: #ff6961;                /* accessible dark systemRed — Stop label ≥4.5:1 on its tint */
    --danger-deep: #e02418;                /* alarm banner fill — 4.7:1 under white text */
    --danger-bg: rgba(255, 69, 58, 0.18);

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 10px 30px rgba(0, 0, 0, 0.5);
    --ring: 0 0 0 4px rgba(10, 132, 255, 0.4);

    --bar-bg: rgba(18, 18, 20, 0.78);
    --hero-tint: rgba(10, 132, 255, 0.16);
    --hero-tint-0: rgba(10, 132, 255, 0);
    --play-glow: rgba(48, 209, 88, 0.16);
  }
}

/* touch-action: manipulation kills the double-tap-to-zoom gesture (and the 300ms tap delay) app-wide
   while KEEPING pinch-zoom for accessibility. Elements that need a different value (drag handles →
   touch-action:none) override this via their higher-specificity rule. */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
[hidden] { display: none !important; }

/* Apple-style inline SVG icons (web/icons.js). Sized in em so a mark scales with its text; the
 * baseline nudge aligns it with inline text, and flex:none keeps it crisp inside inline-flex
 * buttons (.btn/.iconbtn/.link-btn/.hub) where their `gap` handles spacing. currentColor ⇒ themes. */
.ico { width: 1.1em; height: 1.1em; flex: none; vertical-align: -0.18em; }
.ico-lg { width: 1.35em; height: 1.35em; }   /* .big buttons / hero */
.ico-dot { width: 0.62em; height: 0.62em; vertical-align: 0.02em; }  /* status dots (● / ○) */

/* Paint html too so iOS rubber-band overscroll shows the scheme background, not white/black.
 * overflow-x on the root clips any stray horizontal overflow at the viewport WITHOUT creating a
 * new scroll container on <body> (which would break position: sticky). */
html { background: var(--bg); overflow-x: hidden; }
html, body { height: 100%; }
/* Stop scroll chaining / accidental refresh gestures where supported; iOS keeps its native
 * rubber-band (old iOS simply ignores the property — @supports keeps the block harmless). */
@supports (overscroll-behavior-y: contain) { html { overscroll-behavior-y: contain; } }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px; line-height: 1.4; letter-spacing: -0.01em;
  color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; -webkit-text-size-adjust: 100%;
  -webkit-overflow-scrolling: touch; /* momentum/inertia on old-iOS scroll surfaces */
  padding:
    calc(env(safe-area-inset-top) + var(--s4))
    calc(env(safe-area-inset-right) + var(--s4))
    calc(env(safe-area-inset-bottom) + var(--s6))
    calc(env(safe-area-inset-left) + var(--s4));
}

.wrap { max-width: var(--maxw); margin: 0 auto; }

/* Type scale */
h1 { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.022em; margin: 0 0 var(--s1); }
h2 { font-size: 1.0625rem; font-weight: 600; letter-spacing: -0.01em; margin: 0; }
.sub { color: var(--muted); font-size: 0.98rem; margin: var(--s1) 0 var(--s6); line-height: 1.35; }
.muted { color: var(--muted); font-size: 0.9375rem; }
.faint { color: var(--faint); font-size: 0.8125rem; line-height: 1.35; }
.mono { font-variant-numeric: tabular-nums; }
.sec-label { font-size: 0.8125rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); margin: 0 0 var(--s2) 2px; }

.appbar { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s3); max-width: var(--maxw); margin: var(--s1) auto var(--s4); }
.appbar h1 { font-size: 1.5rem; margin: 0; } /* margin:0 so it truly centers against the right-side cluster */
.appbar-right { display: flex; align-items: center; gap: var(--s2); }
.iconbtn { -webkit-appearance: none; appearance: none; background: var(--fill-1); border: 0; border-radius: var(--radius-pill);
  width: 40px; height: 40px; font-size: 1.1rem; line-height: 1; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.iconbtn:active { opacity: 0.6; transform: scale(0.94); }
.iconbtn:focus-visible { outline: none; box-shadow: var(--ring); }
.tokenpanel { max-width: var(--maxw); margin: var(--s2) auto 0; padding: 12px 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.tokenrow { display: flex; gap: var(--s2); margin-top: 8px; }
.tokenrow .input { flex: 1; min-width: 0; }
.tokenrow .btn { flex: 0 0 auto; }
.tokendetails { margin-top: 14px; }
.tokendetails summary { cursor: pointer; padding: 4px 0; }

/* Sticky iOS navigation bar (controller). Full-bleed via negative margins that cancel the body's
 * safe-area padding, then re-pads itself so the title clears the notch/status bar. Translucent +
 * blurred where supported (iOS nav-bar material); solid scheme background everywhere else. */
.topbar {
  position: -webkit-sticky; position: sticky;
  top: 0; z-index: 10; /* below the alarm banner (z 20) — an alert outranks chrome */
  margin:
    calc(-1 * (env(safe-area-inset-top) + var(--s4)))
    calc(-1 * (env(safe-area-inset-right) + var(--s4)))
    var(--s3)
    calc(-1 * (env(safe-area-inset-left) + var(--s4)));
  padding:
    calc(env(safe-area-inset-top) + var(--s3))
    calc(env(safe-area-inset-right) + var(--s4))
    var(--s3)
    calc(env(safe-area-inset-left) + var(--s4));
  background: var(--bg);
  box-shadow: 0 0.5px 0 var(--border); /* hairline, like a scrolled UINavigationBar */
}
@supports ((-webkit-backdrop-filter: saturate(180%) blur(20px)) or (backdrop-filter: saturate(180%) blur(20px))) {
  .topbar {
    background: var(--bar-bg);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    backdrop-filter: saturate(180%) blur(20px);
  }
}
.topbar .appbar { margin: 0 auto; align-items: center; }
.topbar .hub { white-space: nowrap; }

/* Cards — inset grouped: soft shadow (light) / hairline (dark).
 * Subtle entrance (fade + 6px rise) so cards settle in like iOS grouped lists; the global
 * prefers-reduced-motion rule below disables it. */
.card { background: var(--surface); border-radius: var(--radius-lg); padding: var(--pad); box-shadow: var(--shadow); animation: card-in 0.32s var(--ease-out) both; }
@keyframes card-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-color-scheme: dark) { .card { box-shadow: none; border: 0.5px solid var(--border); } }
.card + .card { margin-top: var(--s4); }

/* Collapsible device cards (accordion, controller). Collapsed = only the title row shows; the
 * chevron is the toggle button and rotates when open. Header row is a large convenience tap target. */
.card.collapsed > :not(.cardhead) { display: none; }
.cardhead { cursor: pointer; -webkit-user-select: none; user-select: none; }
/* Keep a card's title on ONE line. When playback starts, the eq bars + "playing" chip widen the
 * right side; a wrapping title ("This device" → two lines) makes the whole card jump taller. Long
 * room names ellipsize instead of wrapping. (min-width:0 lets the flex item shrink for the ellipsis.) */
.cardhead > strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.chev { -webkit-appearance: none; appearance: none; background: transparent; border: 0; padding: 4px;
  margin: -4px -2px -4px 4px; color: var(--faint); cursor: pointer; display: inline-flex; align-items: center;
  min-width: 32px; min-height: 32px; justify-content: center; transition: transform 0.2s var(--ease-out); }
.chev:active { opacity: 0.5; }
.chev:focus-visible { outline: none; box-shadow: var(--ring); border-radius: 8px; }
.card:not(.collapsed) > .cardhead .chev { transform: rotate(180deg); }
/* Offline: recede the inert controls but keep the header row (name, “offline”, Forget) fully
 * legible — the only actionable thing on a dead card must not be dimmed with it. */
.card.offline > :not(.row) { opacity: 0.45; }
.card.attention { box-shadow: 0 0 0 1.5px var(--warn), var(--shadow); }

.row { display: flex; align-items: center; gap: var(--s2); }
.row.wrap { flex-wrap: wrap; }
.spacer { margin-left: auto; }
.stack { display: flex; flex-direction: column; gap: var(--s4); }
.sec { margin-top: var(--s5); }

/* Buttons */
.btn {
  -webkit-appearance: none; appearance: none;
  min-height: var(--touch);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  padding: 0 var(--s5);
  font: inherit; font-size: 1.0625rem; font-weight: 600; letter-spacing: -0.01em;
  color: var(--text); background: var(--fill-1);
  border: 0; border-radius: var(--radius);
  cursor: pointer; touch-action: manipulation;
  -webkit-touch-callout: none; -webkit-user-select: none; user-select: none;
  transition: opacity 0.15s ease, background 0.15s ease, transform 0.18s var(--ease-out);
}
.btn:active { opacity: 0.5; transform: scale(0.97); } /* iOS press: dim + slight squeeze */
.btn:disabled { opacity: 0.4; cursor: default; }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn.block { width: 100%; }
.btn.big { min-height: 54px; font-size: 1.1rem; border-radius: 14px; }
.btn-primary { background: var(--accent-fill); color: #fff; }
.btn-play { background: var(--play-deep); color: #fff; }
.btn-danger { background: var(--danger-bg); color: var(--danger-text); }
.btn-ghost { background: transparent; color: var(--accent); }
.btnrow { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }

/* Pills (timers, soundscapes) — 36px visual height (iOS pill scale) with an invisible
 * ±4px hit-area extension so the effective touch target is 44pt without bloating the look. */
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip {
  -webkit-appearance: none; appearance: none;
  position: relative;
  min-height: 36px; min-width: 44px; padding: 0 15px;
  font: inherit; font-size: 0.9375rem; font-weight: 500; letter-spacing: -0.01em;
  color: var(--text); background: var(--fill-1);
  border: 0; border-radius: var(--radius-pill);
  cursor: pointer; touch-action: manipulation;
  -webkit-touch-callout: none; -webkit-user-select: none; user-select: none;
  transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease, transform 0.18s var(--ease-out);
}
.chip::after { content: ""; position: absolute; top: -4px; bottom: -4px; left: 0; right: 0; }
.chip:active { opacity: 0.5; transform: scale(0.95); }
.chip:focus-visible { outline: none; box-shadow: var(--ring); }
.chip[aria-pressed="true"] { background: var(--accent-fill); color: #fff; font-weight: 600; }

/* Status dot / badge / state */
.dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; background: var(--faint); }
.dot.on { background: var(--play); }
.dot.off { background: var(--faint); }
.badge { font-size: 0.6875rem; letter-spacing: 0.03em; font-weight: 600; padding: 3px 8px; border-radius: var(--radius-pill); background: var(--fill-1); color: var(--muted); text-transform: uppercase; }
.statechip { font-size: 0.9375rem; font-weight: 500; color: var(--muted); }
.statechip.playing { color: var(--play-text); font-weight: 600; }
.statechip.bad { color: var(--warn); font-weight: 600; }

/* iOS slider — 44px input height for the touch target; track/thumb stay iOS-sized */
.slider-row { display: flex; align-items: center; gap: var(--s4); width: 100%; }
input[type="range"] { -webkit-appearance: none; appearance: none; flex: 1; height: 44px; background: transparent; margin: 0; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(var(--accent), var(--accent)) no-repeat, var(--fill-2); background-size: var(--fill, 40%) 100%; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 27px; height: 27px; margin-top: -11.5px; border-radius: 50%; background: #fff; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.24), 0 0 0 0.5px rgba(0, 0, 0, 0.04); }
input[type="range"]:focus-visible { outline: none; }
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: var(--ring); }

/* Text field */
.label { display: block; font-size: 0.9375rem; color: var(--muted); margin: 0 0 var(--s2); }
.input { width: 100%; min-height: var(--touch); padding: 0 var(--s4); font: inherit; font-size: 1.0625rem; color: var(--text); background: var(--surface); border: 0.5px solid var(--border-strong); border-radius: var(--radius); }
.input:focus-visible { outline: none; box-shadow: var(--ring); border-color: var(--accent); }
.input::placeholder { color: var(--faint); }
/* On a card, fields sit as filled iOS form rows (system fill, no outline) instead of white-on-white. */
.card .input { background: var(--fill-1); border-color: rgba(0, 0, 0, 0); }

/* Banners — solid systemRed alert, no pulsing */
.banner { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); border-radius: 14px; margin: 0 auto var(--s3); max-width: var(--maxw); }
.banner.alarm { position: -webkit-sticky; position: sticky; top: var(--s2); top: calc(env(safe-area-inset-top) + var(--s2)); z-index: 20; background: var(--danger-deep); color: #fff; box-shadow: var(--shadow); font-weight: 600; }
.banner.alarm .btn { margin-left: auto; min-height: 44px; padding: 0 var(--s4); background: rgba(255, 255, 255, 0.22); color: #fff; }
.hub { font-size: 0.9rem; display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.hub.online { color: var(--play-text); } .hub.offline { color: var(--danger-text); } .hub.connecting { color: var(--warn); }
.countdown { font-variant-numeric: tabular-nums; color: var(--muted); }

/* Now-playing waveform (decorative; symmetric bars) — matches the “playing” text color */
.eq { display: inline-flex; align-items: center; gap: 2.5px; height: 18px; }
.eq span { width: 3px; background: var(--play-text); border-radius: 2px; height: 30%; animation: eq 0.95s ease-in-out infinite; }
.eq span:nth-child(1) { animation-delay: 0s; }
.eq span:nth-child(2) { animation-delay: 0.12s; }
.eq span:nth-child(3) { animation-delay: 0.24s; }
.eq span:nth-child(4) { animation-delay: 0.36s; }
.eq span:nth-child(5) { animation-delay: 0.24s; }
.eq span:nth-child(6) { animation-delay: 0.12s; }
.eq span:nth-child(7) { animation-delay: 0s; }

/* Loading spinner — shown while a sound is fetching/decoding/starting, so a not-instant "play"
   never looks frozen. Inherits currentColor (theme-safe in both light/dark); sized in em so it
   scales with whatever text it sits beside. iOS 10.3-safe (border + transform rotate). */
.spinner { display: inline-block; width: 1em; height: 1em; border: 2px solid rgba(127,127,127,0.3); border-top-color: currentColor; border-radius: 50%; animation: spin 0.7s linear infinite; box-sizing: border-box; vertical-align: -0.15em; }
.spinner.sm { width: 0.85em; height: 0.85em; border-width: 2px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 1.8s; } }

/* Sound library rows (reorderable) + drop zone.
 * iOS table-cell rhythm on a 390px phone: the NAME gets the flexible space (no more "White …"
 * truncation), the secondary controls shrink visually but keep a ≥44pt EFFECTIVE touch target
 * via invisible ::after hit-area extensions (the same technique the chips use). */
.uprow { display: flex; align-items: center; gap: var(--s1); padding: 8px 0; border-top: 0.5px solid var(--border); }
.uprow:first-child { border-top: 0; }
.upname { flex: 1 1 auto; min-width: 0; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.uprow .faint { white-space: nowrap; } /* "built-in" tag never wraps to two lines */
.upedit { flex: 1; min-height: 44px; }
.uprow.dragging { opacity: 0.7; background: var(--fill-1); border-radius: 10px; border-top-color: transparent; }
.handle { position: relative; cursor: grab; color: var(--faint); font-size: 1.15rem; line-height: 1; min-width: 36px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center; margin-left: -6px; touch-action: none; user-select: none; -webkit-user-select: none; }
.handle::after { content: ""; position: absolute; top: 0; bottom: 0; left: -4px; right: -4px; }
.handle:active { cursor: grabbing; }
/* Favorite star — 44pt effective hit area; hollow (muted) off, systemYellow filled on. */
.fav { -webkit-appearance: none; appearance: none; background: transparent; border: 0; cursor: pointer;
  position: relative; min-width: 38px; min-height: 44px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.2rem; line-height: 1; color: var(--faint); border-radius: 8px;
  -webkit-user-select: none; user-select: none;
  transition: opacity 0.15s ease, transform 0.18s var(--ease-out); }
.fav::after { content: ""; position: absolute; top: 0; bottom: 0; left: -3px; right: -3px; }
.fav.on { color: #ffcc00; }
.fav:active { opacity: 0.5; transform: scale(0.9); }
.fav:focus-visible { outline: none; box-shadow: var(--ring); }
.card.dropping { outline: 2px dashed var(--accent); outline-offset: -6px; }
/* "This device" — the Now Playing hero. Reads like Apple Music's player card: an accent wash
 * settling into the surface, a headline title, and one prominent, softly-elevated play control. */
.card.local {
  background-color: var(--surface);
  background-image: linear-gradient(180deg, var(--hero-tint), var(--hero-tint-0) 60%);
  border-radius: 22px;
  padding-top: var(--s5);
}
.card.local:empty { display: none; }
/* Ambient health line in the nav bar (P3) — persistent "verified Ns ago" / "not responding". */
/* Same centered max-width column as .appbar / .tokenpanel so it lines up under the title instead of
 * drifting to the far-left edge on wide screens; a touch of top space separates it from the title. */
.healthline { max-width: var(--maxw); margin: var(--s2) auto 0; font-size: 0.8125rem; font-weight: 600; letter-spacing: -0.01em; }
.healthline:empty { display: none; }

/* Hearing-safety note (player setup + local player). Subtle grouped-note callout, not an alarm —
 * placement/volume/duration guidance from docs/RESEARCH-SOUND-SCIENCE.md §2. */
.note-safety {
  margin: 16px 0 0; padding: 12px 14px;
  font-size: 0.8125rem; line-height: 1.4; color: var(--faint);
  background: var(--fill-1); border: 1px solid var(--border); border-radius: var(--radius);
}
.note-safety strong { color: var(--text); font-weight: 600; }
.healthline.faint { color: var(--faint); font-weight: 400; }
.healthline.ok { color: var(--play-text); }
.healthline.bad { color: var(--danger-text); }
/* Pre-arm hardening checklist (P9) — table-cell rows with a comfortable 44pt tap height. */
.checkrow { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 6px 0; border-top: 0.5px solid var(--border); cursor: pointer; font-size: 0.95rem; }
.checkrow:first-child { border-top: 0; }
.checkrow input { width: 24px; height: 24px; flex: 0 0 auto; accent-color: var(--accent); }
/* Add-a-room setup link (P4) */
.addroom-link { display: block; width: 100%; word-break: break-all; font-size: 0.8125rem; background: var(--fill-1); border-radius: 10px; padding: 10px 12px; margin-top: var(--s2); }
/* Baby-monitor loudness meter (M8a) — green fill that turns red at the "possible crying" threshold. */
.meter { height: 12px; border-radius: 6px; background: var(--fill-1); overflow: hidden; }
.meter-fill { display: block; height: 100%; width: 0%; background: var(--play-text); border-radius: 6px; transition: width 0.25s linear, background 0.25s ease; }
.meter-fill.hot { background: var(--danger-text); }
#localPlayer > .row:first-child strong { font-size: 1.1875rem; letter-spacing: -0.02em; }
#localPlayer .local-play {
  min-height: 56px;
  font-size: 1.125rem;
  border-radius: 16px;
  box-shadow: 0 8px 20px var(--play-glow);
}
.chip-add { color: var(--accent); font-weight: 700; }
/* ≥44pt EFFECTIVE hit areas (finding #20) — visual size relaxes so a 390px row breathes, the
 * ::after extension keeps the touch target; VoiceOver / stressed one-handed use stays easy. */
.link-btn { -webkit-appearance: none; appearance: none; background: transparent; border: 0; padding: 6px 6px; min-height: 44px; min-width: 36px; position: relative; display: inline-flex; align-items: center; justify-content: center; font: inherit; font-size: 0.9rem; font-weight: 600; color: var(--accent); cursor: pointer; border-radius: 8px; transition: opacity 0.15s ease, transform 0.18s var(--ease-out); }
.link-btn::after { content: ""; position: absolute; top: 0; bottom: 0; left: -4px; right: -4px; }
.link-btn.danger { color: var(--danger-text); }
.link-btn:active { opacity: 0.5; transform: scale(0.94); }
.link-btn:focus-visible { outline: none; box-shadow: var(--ring); }

/* Full-screen tap-to-resume — deliberately dim (a lit screen in a dark nursery is a bug),
 * but still ≥4.5:1 on black. */
.overlay { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 60; display: none; align-items: center; justify-content: center; text-align: center; padding: 40px; background: #000; color: rgba(235, 235, 245, 0.5); cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
.overlay.show { display: flex; }
.overlay .big { font-size: 1.2rem; }
.overlay:focus-visible { outline: 2px solid rgba(235, 235, 245, 0.4); outline-offset: -8px; }

/* "Dim" — a full-black screen overlay (OLED = no light, less power) that keeps audio playing
 * underneath. Minor feedback: a faint breathing dot + one line so a glance confirms it's alive;
 * tap anywhere to restore brightness. Sits above everything but below a hard-failure overlay. */
.dim { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 55; display: none; align-items: center; justify-content: center; text-align: center; padding: var(--s6); background: #000; cursor: pointer; touch-action: manipulation; -webkit-user-select: none; user-select: none; }
.dim.show { display: flex; }
.dim-feedback { display: inline-flex; align-items: center; gap: var(--s2); color: rgba(235, 235, 245, 0.2); font-size: 0.9375rem; letter-spacing: 0.02em; max-width: 90%; }
.dim-dot { flex: 0 0 auto; width: 8px; height: 8px; border-radius: 50%; background: currentColor; animation: dim-breathe 3.6s ease-in-out infinite; }
@keyframes dim-breathe { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }
.dim:focus-visible { outline: 2px solid rgba(235, 235, 245, 0.25); outline-offset: -8px; }
@media (prefers-reduced-motion: reduce) { .dim-dot { animation: none; opacity: 0.6; } }

/* Empty state — centered guidance, placeholder outline instead of a bare paragraph */
#empty { text-align: center; padding: var(--s6) var(--s4); border: 1px dashed var(--border-strong); border-radius: var(--radius-lg); }

/* Controller information architecture (bedtime-first). Top → bottom mirrors how often a parent
 * touches each surface: the nightly zone (Bedtime scene + room cards) leads, "this phone" is the
 * secondary player, and the sound library sits last under MANAGE. Order is plain DOM order.
 *
 * #addRoomCard trades its card chrome for an iOS grouped-list SECTION HEADER row ("ROOMS" + the
 * ghost add button) sitting directly above the room list — the add affordance lives with the list
 * it adds to (Home-app pattern), and the empty state's "tap Add a room above" points one row up.
 * The expandable setup panel inherits the card treatment instead. */
#addRoomCard { background: none; box-shadow: none; border: 0; border-radius: 0; padding: 0 2px; margin-top: var(--s6); animation: none; }
#addRoomCard h2 { font-size: 0.8125rem; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
#addRoomPanel { background: var(--surface); border-radius: var(--radius-lg); padding: var(--pad); box-shadow: var(--shadow); margin-top: var(--s2); }
@media (prefers-color-scheme: dark) { #addRoomPanel { box-shadow: none; border: 0.5px solid var(--border); } }
/* "This phone" + MANAGE open new sections after the rooms list (no .card + .card adjacency there). */
#localPlayer { margin-top: var(--s6); }
.wrap > .sec-label { margin-top: var(--s6); }

/* First run (no rooms yet): the all-rooms scene can't do anything, so it recedes and the
 * Add-a-room path leads — and the add button steps up from ghost to a filled CTA. Guarded :has();
 * older engines simply keep today's always-visible layout. */
@supports selector(:has(*)) {
  .wrap:has(> #empty:not([hidden])) .bedtime { display: none; }
  .wrap:has(> #empty:not([hidden])) #addRoomCard { margin-top: var(--s2); }
  .wrap:has(> #empty:not([hidden])) #addRoomBtn { background: var(--accent-fill); color: #fff; }
}

/* Player (Speaker) screens — iOS-onboarding rhythm: large title outside, controls grouped on a
 * card, the "armed" status reading like a lock-screen now-playing summary. */
#setup { padding-top: var(--s4); }
#setup .card { margin-top: var(--s2); }
#setup #armError { margin: var(--s3) 0 0; }
#status { padding-top: var(--s4); }
#status .card { padding: var(--s5) var(--pad); }

/* Landing tiles */
a.tile { display: block; text-decoration: none; color: var(--text); transition: opacity 0.15s ease, transform 0.18s var(--ease-out); }
a.tile b { color: var(--accent); font-size: 1.1rem; }
a.tile:active { opacity: 0.6; transform: scale(0.98); }

@keyframes eq { 0%, 100% { height: 28%; } 50% { height: 100%; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
