/*
 * The CMS's one stylesheet (Docs/CMS_BUILD.md 3, "Look"; CMS_DESIGN 9): the dark "Night" ground with the game's
 * own colours (I dislike pale UI: memory ui-not-too-white). Every colour is a token on :root, and every token is in
 * the declared palette (cms/test/palette.test.ts), cross-checked against app/lib/ui/tokens.dart: where the plan's
 * hex and the game's differ, the game's wins (the violet lip is the game's #5A3DD6, not #5B3FD6).
 *
 * No inline style exists anywhere (the CSP has no 'unsafe-inline'): components set classes, and the few numbers
 * they set go through CSSOM (h.ts).
 *
 * Layout: phone first, a bottom tab bar (five tabs and More); from 1024 px a left rail and a 420 px drawer for
 * sheets; from 1200 px Now and the player card stand in two columns. Signed out, there is no nav and the Unlock card
 * is centred. Nothing scrolls sideways from 320 px up: a grid track that holds text is `minmax(0, 1fr)` or
 * `minmax(min(Npx, 100%), 1fr)`, so a long word wraps instead of widening the page. Tap targets are 48 px or more.
 */

@font-face { font-family: 'Fredoka'; font-weight: 600; font-display: swap; src: url('fonts/Fredoka-SemiBold.ttf') format('truetype'); }
@font-face { font-family: 'Fredoka'; font-weight: 700; font-display: swap; src: url('fonts/Fredoka-Bold.ttf') format('truetype'); }
@font-face { font-family: 'Nunito'; font-weight: 600; font-display: swap; src: url('fonts/Nunito-SemiBold.ttf') format('truetype'); }
@font-face { font-family: 'Nunito'; font-weight: 700; font-display: swap; src: url('fonts/Nunito-Bold.ttf') format('truetype'); }
@font-face { font-family: 'Nunito'; font-weight: 800; font-display: swap; src: url('fonts/Nunito-ExtraBold.ttf') format('truetype'); }

:root {
  /* the Night ground and its glow */
  --ground-top: #1B2140;
  --ground-bottom: #2B2F4A;
  --violet: #5A3DD6;
  --violet-hi: #7C5CFF;
  --violet-max: #9A80FF;
  /* cards: a navy slab with the game's gold highlight edge */
  --card: #2E3560;
  --well: #1B2140;
  --gold: #F2A900;
  /* text: cream on the dark, ink on the bright fills */
  --cream: #FFF6E6;
  --cream-soft: rgba(255, 246, 230, 0.72);
  --cream-faint: rgba(255, 246, 230, 0.12);
  --ink: #2B2F4A;
  --muted: #7A7F9A;
  /* the game's buttons */
  --green: #45E06A;
  --green-2: #22B14C;
  --green-lip: #178A3A;
  --blue: #4C9BFF;
  --blue-2: #2F6FE0;
  --blue-lip: #1F4FB0;
  --danger: #FF5A5F;
  --danger-lip: #C43A3F;
  /* currencies and accents */
  --coin: #FFC93C;
  --coin-lip: #B07A00;
  --crystal: #4FD8FF;
  --crystal-lip: #127FA8;
  --amber: #FFB300;
  --pink: #FF7AD9;
  /* the game's popup (the letter preview): its blue rim and its light-blue well */
  --rim: #2F7CF0;
  --paper-well: #E4EDFB;
  --grass: #8BE06A;
  --grass-2: #5EC24A;
  --white: #FFFFFF;
  --shade: rgba(0, 0, 0, 0.45);
  --scrim: rgba(0, 0, 0, 0.6);

  --radius: 16px;
  --radius-small: 10px;
  --tap: 48px;
  --tabbar: 64px;
  --strip: 32px;
  --display: 'Fredoka', ui-rounded, system-ui, sans-serif;
  --body: 'Nunito', system-ui, sans-serif;
  --mono: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  --env: var(--violet);
  --env-2: var(--violet-hi);
  color-scheme: dark;
}
html.env-prod { --env: var(--danger); --env-2: var(--pink); }
html.env-dev { --env: var(--grass); --env-2: var(--grass-2); }
html.env-demo { --env: var(--violet); --env-2: var(--violet-hi); }

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  color: var(--cream);
  font: 600 16px/1.45 var(--body);
  background-color: var(--ground-top);
  background-image:
    radial-gradient(120% 60% at 85% -10%, rgba(124, 92, 255, 0.35), transparent 60%),
    radial-gradient(90% 50% at -10% 110%, rgba(90, 61, 214, 0.30), transparent 60%),
    linear-gradient(180deg, var(--ground-top), var(--ground-bottom));
  background-attachment: fixed;
}
h1, h2, h3, h4 { font-family: var(--display); font-weight: 700; margin: 0 0 8px; line-height: 1.15; }
h1 { font-size: 26px; }
h2 { font-size: 19px; }
h3 { font-size: 16px; }
p { margin: 0 0 8px; }
code, .mono { font-family: var(--mono); font-size: 0.9em; overflow-wrap: anywhere; }
a { color: var(--crystal); }
.muted { color: var(--cream-soft); }
.text-link { color: var(--crystal); font-weight: 700; text-decoration: none; }
.text-link:hover { text-decoration: underline; }
:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
.icon { width: 22px; height: 22px; fill: currentColor; flex: none; }
.icon-xl { width: 44px; height: 44px; }

/* ---- the boot paint and a refused host ---- */
.boot { min-height: 100dvh; display: grid; place-items: center; font: 700 22px var(--display); color: var(--cream-soft); }
.refused { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }

/* ---- the environment strip (every screen, the sign-in included) ---- */
.env-strip {
  position: sticky; top: 0; z-index: 30;
  height: var(--strip);
  display: flex; align-items: center; gap: 10px;
  padding: 0 14px;
  font: 700 13px/1 var(--display); letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--ink);
  background: linear-gradient(90deg, var(--env), var(--env-2));
  box-shadow: 0 2px 0 var(--shade);
}
.env-strip-prod {
  color: var(--white);
  background: repeating-linear-gradient(-45deg, var(--danger) 0 14px, var(--pink) 14px 28px);
  text-shadow: 0 1px 0 var(--danger-lip);
}
.env-strip-demo { color: var(--cream); }
.env-words { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.env-who { font-family: var(--body); text-transform: none; letter-spacing: 0; opacity: 0.9; }
.sync-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; background: var(--muted); box-shadow: 0 0 0 2px var(--shade); }
.sync-warm { background: var(--green); }
.sync-waking { background: var(--amber); animation: pulse 1.1s ease-in-out infinite; }
.sync-cached { background: var(--muted); }
@keyframes pulse { 50% { transform: scale(0.7); opacity: 0.55; } }

/* ---- the shell: phone first ---- */
.shell { min-height: calc(100dvh - var(--strip)); }
.screen { display: block; max-width: 980px; margin: 0 auto; padding: 16px 14px calc(var(--tabbar) + 24px + env(safe-area-inset-bottom)); outline: none; }
.screen-title { font-size: 28px; margin: 4px 0 14px; }
.shell.is-signed-out .nav { display: none; }
.shell.is-signed-out .screen { padding-bottom: 32px; }

.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around; align-items: stretch;
  height: calc(var(--tabbar) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--card);
  border-top: 2px solid var(--gold);
  box-shadow: 0 -4px 0 var(--shade);
}
.nav-brand { display: none; }
.nav-item {
  position: relative;
  flex: 1 1 0; min-width: var(--tap); min-height: var(--tap);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 6px 2px; border: 0; background: transparent;
  color: var(--cream-soft); text-decoration: none; cursor: pointer;
  font: 600 12px/1 var(--display);
}
.nav-item.is-active { color: var(--gold); }
.nav-item.is-active .icon { filter: drop-shadow(0 2px 0 var(--shade)); }
/* the phone's bar is the five tabs and More: the "more" screens are in the nav for the rail only (two classes, so
   this beats .nav-item's display) */
.nav-item.nav-more-only { display: none; }
/* a report group is open: an amber dot on More (and on the rail's and the More sheet's Reports) */
.nav-item.has-dot::after {
  content: ''; position: absolute; top: 7px; left: calc(50% + 6px);
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--amber); box-shadow: 0 0 0 2px var(--card);
}
.more-list .nav-item.has-dot::after { top: 8px; left: 32px; box-shadow: 0 0 0 2px var(--well); }
.more-list { display: grid; gap: 8px; }
.more-list .nav-item { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 12px 14px; font-size: 17px; color: var(--cream); background: var(--well); border-radius: var(--radius-small); }

/* ---- desktop: a left rail ---- */
@media (min-width: 1024px) {
  .shell { display: grid; grid-template-columns: 236px minmax(0, 1fr); }
  /* signed out there is no rail: the screen takes the whole width (the Unlock card is centred in it) */
  .shell.is-signed-out { grid-template-columns: minmax(0, 1fr); }
  .nav {
    position: sticky; top: var(--strip); bottom: auto; height: calc(100dvh - var(--strip));
    flex-direction: column; justify-content: flex-start; gap: 4px; padding: 16px 12px;
    border-top: 0; border-right: 2px solid var(--gold); box-shadow: 4px 0 0 var(--shade);
  }
  .nav-brand { display: flex; align-items: baseline; gap: 8px; padding: 4px 12px 18px; font: 700 24px var(--display); color: var(--gold); }
  .brand-word { color: var(--cream); font-size: 18px; }
  .nav-item.nav-more-only { display: flex; }
  .nav-more { display: none; }
  .nav-item.has-dot::after { top: 8px; left: 32px; }
  .nav-item { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 14px; font-size: 16px; border-radius: var(--radius-small); }
  .nav-item:hover { background: var(--cream-faint); color: var(--cream); }
  .nav-item.is-active { background: var(--well); }
  .screen { width: 100%; padding: 24px 28px 48px; }
}

/* ---- cards, tiles, notices ---- */
.card {
  background: var(--card);
  border: 2px solid var(--gold);
  border-radius: var(--radius);
  box-shadow: 0 5px 0 var(--shade);
  padding: 16px;
  margin: 0 0 16px;
}
.card-title { font-size: 18px; color: var(--gold); }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); gap: 12px; margin: 0 0 16px; }
.tiles > * { min-width: 0; }
.tile {
  min-height: 96px; padding: 12px 14px;
  background: var(--well); border-radius: var(--radius-small);
  border: 2px solid var(--cream-faint);
  display: flex; flex-direction: column; gap: 4px;
}
.tile-label { font: 600 13px var(--display); color: var(--cream-soft); text-transform: uppercase; letter-spacing: 0.04em; }
.tile-value { font: 700 26px/1.1 var(--display); color: var(--cream); }
.tile-foot { font-size: 13px; color: var(--cream-soft); }
.tile-label, .tile-value, .tile-foot { overflow-wrap: anywhere; }
.tile-ok { border-color: var(--green-2); }
.tile-warn { border-color: var(--amber); }
.tile-danger { border-color: var(--danger); }
.tile-coin .tile-value { color: var(--coin); }
.tile-crystal .tile-value { color: var(--crystal); }
.tile-violet { border-color: var(--violet-hi); } .tile-violet .tile-value { color: var(--violet-max); }

.notice { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; margin: 0 0 12px; border-radius: var(--radius-small); border: 2px solid; font-weight: 700; }
.notice .icon { margin-top: 1px; }
.notice-body { flex: 1; min-width: 0; }
.notice-info { border-color: var(--blue); background: rgba(76, 155, 255, 0.14); }
.notice-warn { border-color: var(--amber); background: rgba(255, 179, 0, 0.14); color: var(--cream); }
.notice-warn .icon, .toast-warn .icon, .tile-warn .tile-value { color: var(--amber); }
.notice-danger { border-color: var(--danger); background: rgba(255, 90, 95, 0.16); }
.notice-danger .icon, .toast-error .icon, .tile-danger .tile-value { color: var(--danger); }
.notice-ok { border-color: var(--green-2); background: rgba(69, 224, 106, 0.14); }
.notice-ok .icon, .toast-ok .icon, .tile-ok .tile-value { color: var(--green); }

/* ---- buttons (the game's slabs over a lip) ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: var(--tap); padding: 10px 22px; margin: 4px 0;
  border: 0; border-radius: 14px; cursor: pointer;
  font: 700 18px/1 var(--display); color: var(--white);
  text-shadow: 0 1px 0 var(--shade);
  transition: transform 80ms ease, box-shadow 80ms ease;
}
.btn:active:not(:disabled) { transform: translateY(3px); }
.btn-primary { background: linear-gradient(180deg, var(--green), var(--green-2)); box-shadow: 0 5px 0 var(--green-lip); }
.btn-primary:active:not(:disabled) { box-shadow: 0 2px 0 var(--green-lip); }
.btn-secondary { background: linear-gradient(180deg, var(--blue), var(--blue-2)); box-shadow: 0 5px 0 var(--blue-lip); }
.btn-secondary:active:not(:disabled) { box-shadow: 0 2px 0 var(--blue-lip); }
.btn-danger { background: var(--danger); box-shadow: 0 5px 0 var(--danger-lip); }
.btn-ghost { background: transparent; color: var(--cream); border: 2px solid var(--cream-faint); box-shadow: none; }
.btn:disabled { cursor: not-allowed; background: var(--muted); box-shadow: 0 5px 0 var(--ground-bottom); color: var(--cream-soft); text-shadow: none; }
.btn-small { min-height: 40px; padding: 6px 14px; font-size: 15px; }

/* ---- chips ---- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 28px; padding: 3px 10px; border-radius: 999px;
  font: 700 14px/1.2 var(--body);
  background: var(--well); color: var(--cream); border: 2px solid var(--cream-faint);
  overflow-wrap: anywhere;
}
.chip-before { background: rgba(255, 90, 95, 0.16); border-color: var(--danger); color: var(--danger); }
.chip-before s { text-decoration-thickness: 2px; }
.chip-after { background: rgba(69, 224, 106, 0.16); border-color: var(--green-2); color: var(--green); }
.chip-warn { border-color: var(--amber); color: var(--amber); }
.chip-ok { border-color: var(--green-2); color: var(--green); }
.chip-danger { border-color: var(--danger); color: var(--danger); }
.chip-coin { border-color: var(--coin-lip); color: var(--coin); }
.chip-crystal { border-color: var(--crystal-lip); color: var(--crystal); }
.chip-target { border-color: var(--gold); color: var(--gold); font-family: var(--mono); font-size: 13px; }
.chip-mono { font-family: var(--mono); font-size: 13px; }
.chip-choice { min-height: var(--tap); padding: 6px 16px; cursor: pointer; font-family: var(--display); font-size: 16px; }
.chip-choice.is-selected { background: var(--violet); border-color: var(--violet-hi); color: var(--white); }

/* ---- fields and switches ---- */
.field-label { display: block; margin: 12px 0 6px; font: 700 15px var(--display); color: var(--cream-soft); }
.field-input {
  width: 100%; min-height: var(--tap); padding: 10px 14px;
  font: 700 18px var(--body); color: var(--cream);
  background: var(--well); border: 2px solid var(--cream-faint); border-radius: var(--radius-small);
}
.field-input:focus { border-color: var(--gold); outline: none; }
.field-input.mono { font-family: var(--mono); letter-spacing: 0.12em; text-transform: uppercase; }
.field-hint { margin: 6px 0 10px; font-size: 14px; color: var(--cream-soft); }
.switch { display: flex; align-items: center; gap: 12px; min-height: var(--tap); cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { position: relative; width: 56px; height: 32px; border-radius: 999px; background: var(--muted); box-shadow: inset 0 2px 0 var(--shade); flex: none; transition: background 120ms; }
.switch-track::after { content: ''; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%; background: var(--white); box-shadow: 0 2px 0 var(--shade); transition: transform 120ms; }
.switch input:checked + .switch-track { background: var(--green-2); }
.switch input:checked + .switch-track::after { transform: translateX(24px); }
.switch input:focus-visible + .switch-track { outline: 3px solid var(--gold); outline-offset: 2px; }
.switch input:disabled + .switch-track { opacity: 0.5; }
.switch-label { font: 700 17px var(--display); }
.lever-row { display: grid; gap: 4px; }

/* ---- skeletons ---- */
.skeleton { display: grid; gap: 10px; padding: 4px 0; }
.skeleton-line { height: 16px; border-radius: 8px; background: linear-gradient(90deg, var(--cream-faint), rgba(255, 246, 230, 0.22), var(--cream-faint)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
.screen-skeleton { padding: 24px 0; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---- the sheet: a bottom sheet on the phone, a 420 px drawer on the desktop ---- */
.overlay { position: fixed; inset: 0; z-index: 40; }
.scrim { position: absolute; inset: 0; background: var(--scrim); opacity: 0; transition: opacity 180ms; }
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  max-height: 88dvh; display: flex; flex-direction: column;
  background: var(--card);
  border-top: 4px solid var(--env);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -6px 0 var(--shade);
  transform: translateY(100%); transition: transform 180ms ease-out;
}
.overlay.is-open .scrim { opacity: 1; }
.overlay.is-open .sheet { transform: none; }
.sheet-grip { width: 44px; height: 5px; border-radius: 3px; background: var(--cream-faint); margin: 8px auto 0; }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px 8px; }
.sheet-title { flex: 1; margin: 0; font-size: 20px; }
.sheet-prod .sheet-title { color: var(--danger); }
.sheet-dev .sheet-title { color: var(--grass); }
.sheet-demo .sheet-title { color: var(--violet-max); }
.sheet-close { width: var(--tap); height: var(--tap); border: 0; border-radius: 50%; background: var(--well); color: var(--cream); cursor: pointer; display: grid; place-items: center; }
.sheet-close:disabled { opacity: 0.4; cursor: not-allowed; }
.sheet-body { overflow-y: auto; padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); }
.sheet-body > .btn { width: 100%; margin-top: 12px; }
@media (min-width: 1024px) {
  .sheet { top: 0; left: auto; width: 420px; max-height: none; border-top: 0; border-left: 4px solid var(--env); border-radius: 0; box-shadow: -6px 0 0 var(--shade); transform: translateX(100%); }
  .sheet-grip { display: none; }
}

/* ---- the plan sheet ---- */
.plan-status { color: var(--cream-soft); }
.plan-lines { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 10px; }
.plan-lines.is-dim { opacity: 0.45; }
.plan-line { padding: 10px 12px; border-radius: var(--radius-small); background: var(--well); border: 2px solid transparent; }
.plan-line.is-moved { border-color: var(--amber); box-shadow: 0 0 0 3px rgba(255, 179, 0, 0.25); }
.plan-label { font: 700 16px var(--display); }
.plan-path { display: block; margin: 2px 0 8px; color: var(--cream-soft); font-size: 12px; }
.plan-values { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.plan-arrow { color: var(--cream-soft); font-weight: 800; }
.plan-effects { font-weight: 700; color: var(--crystal); }
.plan-tick { display: flex; gap: 12px; align-items: flex-start; min-height: var(--tap); padding: 10px 12px; margin: 0 0 8px; border-radius: var(--radius-small); border: 2px solid var(--amber); background: rgba(255, 179, 0, 0.1); cursor: pointer; }
.plan-tick input { width: 24px; height: 24px; margin: 0; flex: none; accent-color: var(--amber); }
.plan-tick.is-missing { box-shadow: 0 0 0 3px rgba(255, 179, 0, 0.3); }
.plan-meta { color: var(--cream-soft); font-size: 13px; }
.plan-problems { margin: 0 0 12px; padding-left: 20px; }

/* ---- toasts ---- */
.toasts { position: fixed; left: 12px; right: 12px; bottom: calc(var(--tabbar) + 12px + env(safe-area-inset-bottom)); z-index: 50; display: grid; gap: 8px; pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 14px; background: var(--card); border: 2px solid var(--green-2); box-shadow: 0 4px 0 var(--shade); font-weight: 700; animation: toast-in 180ms ease-out; }
.toast-info { border-color: var(--blue); }
.toast-warn { border-color: var(--amber); }
.toast-error { border-color: var(--danger); }
.toast-text { flex: 1; }
.toast-link { color: var(--gold); font-weight: 800; }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } }
/* signed out there is no tab bar to stay clear of */
.shell.is-signed-out ~ .toasts { bottom: calc(12px + env(safe-area-inset-bottom)); }
@media (min-width: 1024px) { .toasts, .shell.is-signed-out ~ .toasts { left: auto; width: 380px; bottom: 20px; right: 20px; } }

/* ---- unlock / add this device ---- */
.screen-unlock { width: 100%; max-width: 420px; margin: 6vh auto 0; text-align: center; }
.screen-unlock .card { padding: 24px 20px; }
.screen-unlock .btn { width: 100%; }
.screen-unlock .field-label, .screen-unlock .field-hint, .screen-unlock .notice { text-align: left; }
.unlock-mark { width: 76px; height: 76px; margin: 0 auto 12px; border-radius: 50%; display: grid; place-items: center; color: var(--ink); background: linear-gradient(180deg, var(--coin), var(--gold)); box-shadow: 0 5px 0 var(--coin-lip); }
.unlock-title { font-size: 24px; }
.unlock-body { margin: 16px 0 8px; }
.unlock-status { margin-top: 12px; }
.unlock-alt { margin: 16px 0 0; }

/* ---- the screens (stage 2) ---- */
.small { font-size: 13px; }
.screen-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.screen-head .screen-title { margin: 4px 0 10px; }
.tile-link, .pin, .needs-item, .row { color: inherit; text-decoration: none; }
a.btn { text-decoration: none; }
.tile-link { display: flex; } .tile-link .tile { flex: 1; }
.tile-link:hover .tile, .row:hover, .needs-item:hover { border-color: var(--gold); }
.pins { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(140px, 100%), 1fr)); gap: 10px; margin: 0 0 8px; }
.pin { display: flex; align-items: center; gap: 10px; min-width: 0; overflow-wrap: anywhere; min-height: 56px; padding: 10px 14px; border-radius: 14px; font: 700 16px var(--display); background: linear-gradient(180deg, var(--violet-hi), var(--violet)); box-shadow: 0 5px 0 var(--shade); }
.choices { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 6px 0 10px; }
.choices-label { min-width: 72px; font: 700 15px var(--display); color: var(--cream-soft); }
.tabs { margin-bottom: 16px; }
.needs { display: grid; gap: 10px; }
.needs-item { display: block; padding: 12px 14px; border-radius: var(--radius-small); background: var(--well); border: 2px solid var(--blue); }
.needs-act { border-color: var(--amber); } .needs-urgent { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(255, 90, 95, 0.25); }
.needs-title { display: flex; justify-content: space-between; gap: 8px; font: 700 17px var(--display); }
.needs-count { min-width: 32px; padding: 0 8px; border-radius: 999px; text-align: center; color: var(--ink); background: var(--amber); }
.rows { display: grid; gap: 8px; }
.row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; min-height: var(--tap); padding: 10px 12px; border-radius: var(--radius-small); background: var(--well); border: 2px solid transparent; }
.row-main { display: flex; flex-direction: column; min-width: 0; }
.row-sub { color: var(--cream-soft); font-size: 12px; }
.row-chips, .row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.row-actions { gap: 8px; margin: 4px 0; }
.log-row { margin: 0 0 8px; border-radius: var(--radius-small); background: var(--well); border: 2px solid transparent; }
.log-row.is-hit { border-color: var(--gold); }
/* the command, the time and the approval chip wrap; the mono target has a line of its own (a narrow phone used to
   shrink it to one character a line); from 720 px it sits between the command and the time when it fits */
.log-row > summary { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; min-height: var(--tap); padding: 8px 12px; cursor: pointer; }
.log-cmd { min-width: 0; overflow-wrap: anywhere; }
.log-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; min-width: 0; font-size: 13px; color: var(--cream-soft); }
.log-target { flex: 1 0 100%; min-width: 0; font-size: 13px; color: var(--cream-soft); overflow-wrap: anywhere; }
@media (min-width: 720px) {
  .log-target { flex: 1 1 18ch; order: 1; }
  .log-meta { order: 2; }
}
.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 6px 14px; margin: 0; padding: 4px 12px 12px; }
.kv dt { color: var(--cream-soft); font-size: 14px; } .kv dd { margin: 0; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.counter { float: right; font: 600 13px var(--body); color: var(--cream-soft); }
.field-num { width: 140px; min-height: var(--tap); } .field-date { width: auto; }
.mono-plain { font-family: var(--mono); font-size: 15px; }
textarea.field-input { resize: vertical; font-size: 16px; }
select.field-input { margin: 8px 0; }
.review-bar { position: sticky; bottom: calc(var(--tabbar) + 8px); z-index: 10; padding: 12px 14px; border-radius: var(--radius); background: var(--card); border: 2px solid var(--env); box-shadow: 0 5px 0 var(--shade); }
.bar-lines { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.bar-line { font-size: 14px; color: var(--cream-soft); }
.bar-buttons { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
.card-maint { border-color: var(--danger); }
.wall { margin: 12px 0 4px; padding: 18px; border-radius: 18px; text-align: center; background: linear-gradient(180deg, var(--violet), var(--ground-top)); border: 3px solid var(--cream-faint); }
.wall-label { font-size: 12px; color: var(--cream-soft); text-transform: uppercase; }
.wall-title { margin: 6px 0; font: 700 24px var(--display); color: var(--coin); text-shadow: 0 2px 0 var(--coin-lip); }
.wall-until { display: inline-block; margin-top: 4px; padding: 4px 12px; border-radius: 999px; background: var(--shade); }
.twin { display: flex; align-items: center; gap: 6px; }
.previews { display: grid; gap: 12px; }
/* the MAIL row: a Night card with the gold edge. The letter: the game's popup (letter_card.ts), its CLAIM the
   primary button */
.phone-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 16px; color: var(--cream); background: var(--card); border: 2px solid var(--gold); position: relative; }
.phone-row > span:last-child { display: flex; flex-direction: column; } .phone-row small { color: var(--cream-soft); }
.disc { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; flex: none; color: var(--white); background: var(--blue); box-shadow: inset 0 0 0 5px var(--well); }
.disc-gold { background: var(--gold); }
.dot { position: absolute; left: 46px; top: 8px; width: 12px; height: 12px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 2px var(--card); }
.lp { padding: 18px 18px 22px; border-radius: 22px; text-align: center; color: var(--ink); background: var(--cream); border: 4px solid var(--rim); box-shadow: 0 5px 0 var(--blue-lip); }
.lp-disc, .lp-disc > span { display: grid; place-items: center; margin: 0 auto 10px; width: 64px; height: 64px; border-radius: 50%; background: var(--paper-well); }
.lp-disc > span { margin: 0; width: 44px; height: 44px; color: var(--white); background: var(--rim); }
.lp-disc.is-gold > span { background: var(--coin); }
.clip, .lp-title { display: -webkit-box; -webkit-line-clamp: 3; line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; margin: 4px 0; white-space: pre-wrap; }
.lp-title { margin: 0 0 8px; font-size: 21px; text-transform: uppercase; overflow-wrap: anywhere; -webkit-line-clamp: 2; line-clamp: 2; }
.lp-body { margin: 0 0 14px; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 17.4em; overflow-y: auto; }
.lp-body.is-long { text-align: left; }
.lp-gift { display: grid; justify-content: center; gap: 2px; margin: 0 0 12px; padding: 8px 12px; border-radius: 12px; background: var(--paper-well); }
.lp-row { display: flex; align-items: center; gap: 10px; min-height: 30px; font: 700 16px var(--display); text-align: left; overflow-wrap: anywhere; }
.lp-art { width: 26px; height: 26px; flex: none; border-radius: 50%; }
.lp-art img { display: block; width: 100%; height: 100%; }
.lp-art.is-missing { background: var(--muted); opacity: 0.4; }
.lp-ends, .events-card small { display: block; color: var(--cream-soft); }
.lp-ends { margin: 0 0 12px; font-weight: 800; color: var(--muted); }
.lp .btn { display: flex; font-size: 20px; cursor: default; }
.lp .btn .icon { color: var(--coin); }
.events-card { margin: 12px 0; padding: 14px; border-radius: 16px; color: var(--cream); background: var(--card); border: 2px solid var(--gold); }
/* the composer: the form, the preview, the review; from 1200 px the preview beside them, sticky (screens/inbox.ts) */
.compose { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 20px; }
.stepper, .item-row { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.stepper-n { min-width: 24px; font: 700 18px var(--display); text-align: center; }
.item-rows { display: grid; justify-items: start; gap: 8px; flex: 1 1 260px; min-width: 0; }
select.field-pick { width: auto; max-width: 100%; margin: 0; }
.sent-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 0; border-bottom: 2px solid var(--cream-faint); }
.sent-log { margin-bottom: 8px; }
.group { margin: 0 0 10px; padding: 0 12px 4px; border-radius: var(--radius-small); background: var(--well); border: 2px solid var(--cream-faint); }
.group-open { border-color: var(--amber); }
.group > summary { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; min-height: var(--tap); padding: 8px 0; cursor: pointer; }
.group-name { font: 700 20px var(--mono); color: var(--cream); }
.holder { padding: 6px; border-radius: var(--radius-small); border: 2px solid var(--cream-faint); }
.uid-line { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

/* two columns from 1200 px (ui.ts columns: Now, the player card). Below it the columns are `display: contents`,
   so the cards stack in the phone's order (each card's CSSOM `order`); only those two screens widen (from their
   first paint: the player card's skeleton is as wide as the card) */
.cols { display: flex; flex-direction: column; }
.cols-col { display: contents; }
@media (min-width: 1200px) {
  .screen:has(> .screen-now, > .screen-player, .compose) { max-width: 1240px; }
  .compose { grid-template-columns: minmax(0, 1fr) 400px; align-items: start; }
  .compose-side { grid-area: 1 / 2 / 3; position: sticky; top: calc(var(--strip) + 12px); }
  .compose-act { grid-area: 2 / 1; }
  .cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; align-items: start; }
  .cols-col { display: block; min-width: 0; }
}

/* a write landed (app.ts landed): the tile or row it changed glows once, and the propagation ring turns until the
   next read (CMS_DESIGN 10.9: writes are authoritative, never optimistic) */
.is-fresh { animation: fresh 1.4s ease-out 2; }
@keyframes fresh { from { box-shadow: 0 0 0 0 var(--gold); } to { box-shadow: 0 0 0 14px transparent; } }
.ring::before { content: ''; display: inline-block; width: 12px; height: 12px; margin-right: 8px; vertical-align: -1px; border-radius: 50%; border: 2px solid var(--green); border-right-color: transparent; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- the active players list (screens/players.ts; its header says the layout) ---- */
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.screen-players > .field-label { margin-top: 0; }
.counts, .ret-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 10px 0 6px; }
.count { display: flex; flex-direction: column; min-width: 0; min-height: 44px; padding: 4px 10px; text-align: left; color: var(--cream); font: inherit; border-radius: var(--radius-small); }
.count, .seg, .switch-chip { background: var(--well); border: 2px solid var(--cream-faint); }
.seg, .switch-chip { border-radius: 999px; }
.count-label { font: 600 11px var(--display); color: var(--cream-soft); text-transform: uppercase; letter-spacing: 0.04em; overflow-wrap: anywhere; }
.count-value { font: 700 17px/1.15 var(--display); overflow-wrap: anywhere; }
.counts .skeleton { grid-column: 1 / -1; }
.count-now { grid-column: 1 / -1; flex-direction: row; align-items: center; justify-content: space-between; min-height: 48px; padding: 2px 14px; border-color: var(--green-2); }
.count-now .count-label { font-size: 14px; color: var(--green); }
.count-now .count-value { font-size: 30px; color: var(--green); }
.count-new24h .count-value { color: var(--crystal); }
.count-tap { cursor: pointer; }
.count-tap:hover { border-color: var(--gold); }
.count-tap.is-on { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(242, 169, 0, 0.3); }
.count-now.is-live, .tile.is-live { animation: live 2.2s ease-out infinite; }
@keyframes live { 0% { box-shadow: 0 0 0 0 rgba(69, 224, 106, 0.5); } 70%, 100% { box-shadow: 0 0 0 12px rgba(69, 224, 106, 0); } }
.active-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 0 0 4px; }
.stamp { min-width: 0; margin: 0; }
.stamp .btn { margin: 0 0 0 6px; }
.stamp-err { color: var(--amber); }
.trend-link { flex: none; min-height: 40px; padding: 0 4px; border: 0; background: none; cursor: pointer; font: 700 14px var(--display); color: var(--crystal); }
.active-insights { scroll-margin-top: calc(var(--strip) + 8px); outline: none; }
.active-controls { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; margin: 0 0 10px; }
.active-controls .choices { flex-wrap: nowrap; gap: 8px; min-width: 0; max-width: 100%; margin: 0; }
.active-controls .choices-label { min-width: 34px; font-size: 14px; }
.seg { display: flex; gap: 2px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.seg .chip-choice { flex: none; min-height: 36px; padding: 2px 12px; font-size: 14px; border-color: transparent; }
.seg .chip-choice:focus-visible { outline-offset: -3px; }
.ctl-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }
.switch-chip { gap: 8px; min-height: 40px; padding: 0 12px 0 6px; }
.switch-chip .switch-track { width: 36px; height: 22px; }
.switch-chip .switch-track::after { top: 3px; left: 3px; width: 16px; height: 16px; }
.switch-chip input:checked + .switch-track::after { transform: translateX(14px); }
.switch-chip .switch-label { font-size: 14px; }
.list-card { padding: 8px; }
.arows { gap: 6px; transition: opacity 120ms; }
.arows.is-stale { opacity: 0.5; }
.arow-head { display: none; }
/* 2 lines: the dot, the name, the last seen; then the rest */
.row.arow { display: grid; grid-template-columns: 12px minmax(0, 1fr) auto; align-items: center; gap: 2px 10px; padding: 6px 12px; line-height: 1.3; }
.rdot { width: 12px; height: 12px; border-radius: 50%; background: var(--muted); }
.rdot-now { background: var(--green); box-shadow: 0 0 0 3px rgba(69, 224, 106, 0.3); }
.rdot-hour { background: var(--amber); }
.rdot-day { background: var(--blue); }
.arow-name { min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; font-size: 16px; }
.arow-noname { color: var(--cream-soft); font-style: italic; font-weight: 600; }
.arow-seen, .arow-sub { font-size: 13px; color: var(--cream-soft); }
.arow-seen { white-space: nowrap; }
.arow-sub { grid-column: 2 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; min-width: 0; }
.arow-stars::before, .arow-uid::before { content: '\00B7'; margin-right: 6px; }
.arow-made { display: none; }
.arow-flags { display: contents; }
.chip-small { min-height: 22px; padding: 1px 8px; font-size: 12px; }
.more-box { display: flex; justify-content: center; margin-top: 8px; }
.more-box:empty { display: none; }
.tcharts { display: grid; gap: 16px; }
.tchart-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.tchart-title { font: 700 15px var(--display); }
.tchart-plot { display: flex; align-items: flex-end; gap: 2px; height: 96px; border-bottom: 2px solid var(--cream-faint); }
.tcol { flex: 1 1 0; min-width: 0; height: 100%; display: flex; align-items: flex-end; border-radius: 4px 4px 0 0; }
.tcol:hover { background: var(--cream-faint); }
.tcol.is-missing { border-bottom: 2px dashed var(--danger); }
.tbar { width: 100%; border-radius: 4px 4px 0 0; background: var(--blue); }
.tchart-fresh .tbar { background: var(--green-2); }
.tcol:hover .tbar { background: var(--gold); }
.tchart-axis { display: flex; justify-content: space-between; margin-top: 4px; }
.ttable { margin-top: 12px; }
.ttable > summary { min-height: var(--tap); display: flex; align-items: center; cursor: pointer; color: var(--crystal); font-weight: 700; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--cream-faint); }
.tbl th:first-child, .tbl td:first-child { text-align: left; font-family: var(--mono); }
.ev-s{border:0;background:none;color:inherit;font:inherit}
.eco-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.eco-words { display: block; margin-bottom: 4px; font-weight: 700; }
.eco-track { display: block; height: 10px; border-radius: 5px; background: var(--well); overflow: hidden; }
.eco-fill { display: block; height: 100%; border-radius: 5px; background: linear-gradient(90deg, var(--violet), var(--violet-hi)); }
/* retention: three tiles across at every width; the heat map's six steps of one hue (dark text on the top two), its
   key days and newest 30 cohorts on the phone */
.ret-tile .count-value { font-size: 22px; color: var(--crystal); }
.ret-tile.is-few .count-value { color: var(--cream-soft); }
.ret-foot { font-size: 12px; color: var(--cream-soft); overflow-wrap: anywhere; }
.hm-box { overflow-x: auto; }
.hm { width: 100%; border-spacing: 2px; font-size: 13px; }
.hm th, .hm td { padding: 4px 3px; text-align: center; white-space: nowrap; border-radius: 4px; }
.hm thead th { font: 600 11px var(--display); color: var(--cream-soft); }
.hm tr > :first-child { text-align: left; }
.hm-few, .hm-na { color: var(--cream-soft); font-style: italic; }
.hm0 { background: rgba(79, 216, 255, 0.06); }
.hm1 { background: rgba(79, 216, 255, 0.16); }
.hm2 { background: rgba(79, 216, 255, 0.28); }
.hm3 { background: rgba(79, 216, 255, 0.4); }
.hm4 { background: rgba(79, 216, 255, 0.7); }
.hm5 { background: var(--crystal); }
.hm4, .hm5 { color: var(--ink); }
.hm-x, .hm-more { display: none; }
.hm.is-all .hm-more { display: table-row; }
/* a tablet: the counts in a line, the charts side by side */
@media (min-width: 720px) and (max-width: 1199.98px) {
  .counts { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .count-now { grid-column: auto; flex-direction: column; align-items: stretch; }
  .count-now .count-value { font-size: 26px; }
  .tcharts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
/* the desktop: a sticky left column; rows of columns (ROW_HEADS) */
@media (min-width: 1200px) {
  .screen:has(> .screen-players, > .screen-retention) { max-width: 1440px; }
  .screen-players > .field-input { max-width: 640px; }
  .cols-side { grid-template-columns: 300px minmax(0, 1fr); }
  /* the padding keeps the pulse and the focus ring inside */
  .cols-side > .cols-col:first-child { position: sticky; top: calc(var(--strip) + 12px); max-height: calc(100dvh - var(--strip) - 24px); overflow-y: auto; scrollbar-width: thin; margin: -12px; padding: 12px; }
  .cols-side .tchart-plot { height: 72px; }
  .trend-link { display: none; }
  .row.arow, .arow-head { grid-template-columns: 12px minmax(0, 1.3fr) 52px 84px 64px 64px minmax(0, 1fr) 84px; gap: 0 8px; }
  .arow-head { display: grid; padding: 0 14px 6px; font: 600 12px var(--display); color: var(--cream-soft); text-transform: uppercase; letter-spacing: 0.04em; }
  .row.arow > *, .arow-sub > * { grid-row: 1; }
  .arow-sub { display: contents; }
  .arow-word { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .arow-stars::before, .arow-uid::before { content: none; }
  .arow-league { grid-column: 3; } .arow-stars { grid-column: 4; } .arow-seen { grid-column: 5; }
  .arow-made { grid-column: 6; display: block; } .arow-flags { grid-column: 7; display: flex; flex-wrap: wrap; gap: 4px; } .arow-uid { grid-column: 8; }
  .hm-x { display: table-cell; } .hm-more { display: table-row; } .hm-all { display: none; }
  /* all 30 days fit the widened screen; the narrow column keeps the tiles' words in their title */
  .hm { border-spacing: 1px; } .hm th, .hm td { padding: 4px 2px; }
  .cols-side .ret-foot { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}
