/* Hand Me the Rule Book — shared design system.
   Theme: light by default, dark from the system setting, and either can be
   forced with <html data-theme="light|dark"> (set by the theme toggle).
   Always colour with the custom properties below so both themes work. */

:root {
  --bg: #f6f0e4;            /* cream table cloth */
  --surface: #fffdf9;       /* card stock */
  --surface-2: #f1e9d9;     /* inset areas */
  --text: #2b2420;
  --muted: #6a5d52;
  --border: #e2d7c3;
  --border-strong: #96887a; /* control outlines, 3:1 on surfaces */
  --accent: #1f6b54;        /* felt green */
  --accent-text: #ffffff;
  --accent-soft: #dcede5;
  --gold: #c97a1e;
  --online: #2c9a68;
  --logo-gold: #f3c06b;
  --danger: #b3261e;
  --danger-soft: #fbe6e3;
  --winner: #fde7a3;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(60 40 20 / 0.06), 0 6px 18px rgb(60 40 20 / 0.06);
  --dots: rgb(90 60 30 / 0.07);
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-display: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --nav-h: 64px;
  --ring: color-mix(in srgb, var(--accent) 32%, transparent);
  --glass: color-mix(in srgb, var(--surface) 86%, transparent);
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1b1816;
    --surface: #262220;
    --surface-2: #312c28;
    --text: #f2ece2;
    --muted: #b5a99b;
    --border: #3f3833;
    --border-strong: #84786c;
    --accent: #74d1b1;
    --accent-text: #0e2a21;
    --accent-soft: #1f3d33;
    --gold: #e9a54a;
    --online: #5fd39f;
    --logo-gold: #8a4a00;
    --danger: #ff9c90;
    --danger-soft: #4a2420;
    --winner: #5a4812;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 6px 18px rgb(0 0 0 / 0.25);
    --dots: rgb(255 240 220 / 0.045);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1b1816;
  --surface: #262220;
  --surface-2: #312c28;
  --text: #f2ece2;
  --muted: #b5a99b;
  --border: #3f3833;
  --border-strong: #84786c;
  --accent: #74d1b1;
  --accent-text: #0e2a21;
  --accent-soft: #1f3d33;
  --gold: #e9a54a;
  --online: #5fd39f;
  --logo-gold: #8a4a00;
  --danger: #ff9c90;
  --danger-soft: #4a2420;
  --winner: #5a4812;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 6px 18px rgb(0 0 0 / 0.25);
  --dots: rgb(255 240 220 / 0.045);
  color-scheme: dark;
}

/* ---- Base ---- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: 72px; }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font: 16px/1.55 var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  background-color: var(--bg);
  background-image: radial-gradient(var(--dots) 1.5px, transparent 1.5px);
  background-size: 22px 22px;
  color: var(--text);
  overflow-wrap: break-word;
}
a { color: var(--accent); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
h1, h2, h3 { font-family: var(--font-display); line-height: 1.2; letter-spacing: -0.01em; text-wrap: balance; }
p { margin: 0 0 12px; text-wrap: pretty; }
::selection { background: var(--ring); }
p:last-child { margin-bottom: 0; }
strong { font-weight: 650; }

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}
#view:focus { outline: none; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 30;
  padding: 10px 14px; border-radius: 10px;
  background: var(--accent); color: var(--accent-text); font-weight: 600;
}
.skip-link:focus { top: 8px; }

/* ---- Header and navigation ---- */
.app-header {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface); /* no backdrop-filter here on phones: it would trap the fixed tab bar */
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.app-header-inner {
  display: flex; align-items: center; gap: 8px 20px;
  max-width: 1080px; margin: 0 auto;
  padding: 8px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
}
.app-brand {
  display: flex; align-items: center; gap: 10px; min-width: 0;
  color: var(--text); text-decoration: none; border-radius: 10px;
}
.app-logo { flex: none; border-radius: 9px; box-shadow: 0 1px 2px rgb(0 0 0 / 0.18); }
.app-logo .logo-r { fill: var(--logo-gold); }
.app-title { font-size: 1.15rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.app-nav svg {
  width: 22px; height: 22px; fill: none; stroke: currentColor;
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.app-nav svg .fill { fill: currentColor; stroke: none; }
/* Mobile first: the nav is a bottom tab bar. */
.app-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr);
  padding: 6px max(4px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) max(4px, env(safe-area-inset-left));
  background: var(--glass);
  -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgb(0 0 0 / 0.06);
}
.app-nav :is(a, button) {
  display: grid; justify-items: center; gap: 2px;
  min-height: 52px; padding: 5px 2px 3px;
  border-radius: 12px;
  color: var(--muted); text-decoration: none;
  font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.01em;
  -webkit-tap-highlight-color: transparent;
}
.app-nav :is(a, button) svg {
  width: 46px; height: 28px; padding: 3px 12px; border-radius: 999px;
  transition: background-color 200ms var(--ease), color 200ms var(--ease), transform 200ms var(--ease);
}
.app-nav :is(a, button):active svg { transform: scale(0.92); }
.app-nav :is(a, button):hover { color: var(--text); }
.app-nav :is(a, button).active { color: var(--text); }
.app-nav :is(a, button).active svg { background: var(--accent); color: var(--accent-text); }

.app-main {
  max-width: 820px; margin: 0 auto;
  padding: 16px max(16px, env(safe-area-inset-right)) calc(var(--nav-h) + 32px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  display: grid; gap: 16px;
  grid-template-columns: minmax(0, 1fr);
}

@media (min-width: 900px) {
  .app-header {
    background: var(--glass);
    -webkit-backdrop-filter: saturate(1.4) blur(14px); backdrop-filter: saturate(1.4) blur(14px);
  }
  .app-title { font-size: 1.25rem; }
  .app-header-inner { padding-top: 10px; padding-bottom: 10px; }
  .app-nav {
    position: static; display: flex; gap: 2px; padding: 0; margin-left: auto;
    background: none; border: 0; box-shadow: none;
    -webkit-backdrop-filter: none; backdrop-filter: none;
  }
  .app-nav :is(a, button) {
    display: inline-flex; align-items: center; gap: 6px;
    min-height: 40px; padding: 6px 14px;
    border-radius: 999px; font-size: 0.9375rem;
    transition: background-color 150ms var(--ease), color 150ms var(--ease);
  }
  .app-nav :is(a, button) svg { display: none; width: 20px; height: 20px; padding: 0; border-radius: 0; }
  .app-nav :is(a, button):hover { background: var(--surface-2); }
  .app-nav :is(a, button).active { background: var(--accent); color: var(--accent-text); }
  .app-nav :is(a, button).active svg { background: none; color: inherit; }
  .app-main { padding-top: 28px; padding-bottom: 56px; gap: 20px; }
}
@media (min-width: 1080px) {
  .app-nav :is(a, button) { padding-left: 10px; }
  .app-nav :is(a, button) svg { display: block; }
}
/* Wide screens: the add form sits beside the list on Games and Players. */
@media (min-width: 1000px) {
  .app-main[data-route="games"], .app-main[data-route="players"] {
    max-width: 1080px; grid-template-columns: 340px minmax(0, 1fr); align-items: start;
  }
  .app-main[data-route="games"] > .steps, .app-main[data-route="players"] > .steps { grid-column: 1 / -1; }
  .app-main[data-route="games"] > .card:first-of-type,
  .app-main[data-route="players"] > .side-stack { position: sticky; top: 88px; }
  .app-main[data-route="games"] > .card:first-of-type .field-grid.game { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .app-main[data-route="games"] > .card:first-of-type .field-grid.game > .span-2 { grid-column: 1 / -1; }
  .app-main[data-route="players"] > .side-stack .row-form > * { flex-basis: 100%; }
}

/* ---- Cards ---- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card h2 { margin: 0 0 12px; font-size: 1.3rem; }
.card h3 { margin: 16px 0 8px; font-size: 1.05rem; }
.card-head {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px; margin-bottom: 12px;
}
.card-head h2 { margin: 0; }
.card-head .muted { font-size: 0.9rem; }
@media (min-width: 720px) { .card { padding: 22px 24px; } }

/* ---- Forms ---- */
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  min-height: 44px; padding: 9px 12px;
  border: 1px solid var(--border-strong); border-radius: 10px;
  background: var(--surface); color: var(--text); max-width: 100%;
  box-shadow: inset 0 1px 2px rgb(60 40 20 / 0.05);
  transition: border-color 150ms var(--ease), box-shadow 150ms var(--ease);
}
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
select {
  -webkit-appearance: none; appearance: none; padding-right: 38px; cursor: pointer; text-overflow: ellipsis;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a7d70' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 16px;
}
input[type="search"] {
  -webkit-appearance: none; appearance: none; padding-left: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a7d70' stroke-width='2.2' stroke-linecap='round'%3E%3Ccircle cx='11' cy='11' r='6.5'/%3E%3Cpath d='m16 16 4.5 4.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 12px center; background-size: 16px;
}
input[type="number"] { -moz-appearance: textfield; appearance: textfield; font-variant-numeric: tabular-nums; }
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="checkbox"], input[type="radio"] {
  min-height: 0; width: 20px; height: 20px; padding: 0; flex: none;
  accent-color: var(--accent); box-shadow: none; cursor: pointer;
}
input[type="color"] {
  -webkit-appearance: none; appearance: none;
  min-height: 0; width: 40px; height: 40px; padding: 0; border-radius: 50%;
  border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border-strong);
  background: none; cursor: pointer; overflow: hidden;
}
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 50%; }
input[type="color"]::-moz-color-swatch { border: 0; border-radius: 50%; }
input[type="color"][data-chosen] { box-shadow: 0 0 0 3px var(--text); }
input[type="file"] { border-style: dashed; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--ring); border-radius: 10px;
}
input[type="checkbox"]:focus-visible, input[type="radio"]:focus-visible { outline-offset: 2px; border-radius: 4px; box-shadow: none; }
input[type="color"]:focus-visible { border-radius: 50%; outline-offset: 3px; }
label { display: grid; gap: 5px; font-size: 0.875rem; color: var(--muted); font-weight: 600; letter-spacing: 0.005em; }
label.block { margin: 12px 0; }
label.block textarea, label.block input, label.block select { width: 100%; }
label.check {
  display: flex; align-items: center; gap: 8px; min-height: 36px;
  color: var(--text); font-size: 1rem; font-weight: 400; cursor: pointer;
}
.row-form { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; }
.row-form > label { flex: 1 1 150px; min-width: 0; }
.row-form > label.narrow { flex: 1 1 84px; }
.row-form > label > input:not([type="checkbox"]):not([type="radio"]):not([type="color"]),
.row-form > label > select { width: 100%; }
fieldset { min-width: 0; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px; cursor: pointer;
  border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface);
  color: var(--text); font-size: 1rem; font-weight: 600; line-height: 1.2;
  text-decoration: none; white-space: nowrap; user-select: none;
  box-shadow: 0 1px 1px rgb(60 40 20 / 0.06);
  -webkit-tap-highlight-color: transparent;
  transition: background-color 150ms var(--ease), border-color 150ms var(--ease), box-shadow 150ms var(--ease),
    filter 150ms var(--ease), transform 100ms var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn:active { transform: translateY(1px) scale(0.985); box-shadow: none; }
.btn.primary {
  background: var(--accent); border-color: var(--accent); color: var(--accent-text);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 0.16), 0 1px 2px rgb(20 60 45 / 0.25), 0 4px 12px -4px var(--ring);
}
.btn.primary:hover { filter: brightness(1.08); background: var(--accent); border-color: var(--accent); }
.btn.danger { color: var(--danger); border-color: currentColor; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: var(--surface); }
.btn.danger.solid:hover { filter: brightness(1.08); background: var(--danger); }
.btn.small { min-height: 36px; padding: 5px 12px; font-size: 0.875rem; border-radius: 8px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; filter: none; }

.error { color: var(--danger); margin: 8px 0 0; min-height: 1.5em; font-weight: 500; }
.error:empty { min-height: 0; margin: 0; }
.empty, .muted { color: var(--muted); }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; flex: none; }

.notice {
  padding: 12px 14px; border-radius: 10px;
  background: var(--accent-soft); color: var(--text);
  border-left: 4px solid var(--accent);
}
.notice[tabindex="-1"]:focus, .preview:focus { outline: none; }
.notice.warn { background: var(--winner); border-left-color: var(--gold); }
.notice.bad { background: var(--danger-soft); border-left-color: var(--danger); }
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--text); font-size: 0.8rem; font-weight: 600;
}
.toolbar { display: flex; flex-wrap: wrap; align-items: end; gap: 8px 12px; margin-bottom: 4px; }
.toolbar > label { flex: 1 1 140px; min-width: 0; }
.toolbar > label > input, .toolbar > label > select { width: 100%; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.actions .spacer { flex: 1; }

/* ---- Lists (games, players) ---- */
.item-list, .play-list { list-style: none; margin: 0; padding: 0; }
.item-list li {
  display: flex; align-items: center; gap: 12px; padding: 12px 0;
  border-top: 1px solid var(--border);
}
.item-list li:first-child { border-top: 0; }
.item-list li.editing {
  display: block; margin: 4px -8px; padding: 14px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2);
  box-shadow: inset 0 1px 3px rgb(60 40 20 / 0.06);
}
.item-list li.editing + li { border-top: 0; }
.item-main { flex: 1; min-width: 0; display: grid; gap: 1px; }
.item-name { flex: 1; font-weight: 600; }
.item-meta { font-size: 0.875rem; color: var(--muted); }
.item-stats { text-align: right; font-size: 0.875rem; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.item-stats strong { display: block; color: var(--text); font-size: 0.95rem; }
.avatar, .monogram {
  flex: none; display: inline-grid; place-items: center;
  width: 40px; height: 40px;
  font-weight: 700; font-size: 0.95rem; line-height: 1; user-select: none;
}
.avatar { border-radius: 50%; }
.monogram {
  border-radius: 9px; color: #fff;
  background: hsl(var(--hue, 160) 42% 34%);
  font-family: var(--font-display); font-size: 1.15rem;
  box-shadow: inset 0 -3px 0 rgb(0 0 0 / 0.18);
}
@media (max-width: 420px) {
  .item-list li { gap: 10px; }
  .item-list li:not(.editing) .btn.small { padding-left: 10px; padding-right: 10px; }
}

.edit-form { display: grid; gap: 12px; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field-grid > .span-2 { grid-column: 1 / -1; }
.field-grid input:not([type="checkbox"]):not([type="radio"]):not([type="color"]),
.field-grid select { width: 100%; }
@media (min-width: 560px) {
  .field-grid.game { grid-template-columns: 2fr 2fr 1fr 1fr; }
  .field-grid.game > .span-2 { grid-column: auto; }
}

.swatches { border: 0; margin: 0; padding: 0; }
.swatches legend { padding: 0; margin-bottom: 6px; font-size: 0.9rem; color: var(--muted); font-weight: 500; }
.swatch-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.swatch { position: relative; display: block; width: 40px; height: 40px; cursor: pointer; }
.swatch input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.swatch span {
  display: block; width: 100%; height: 100%; border-radius: 50%;
  background: var(--c); border: 2px solid var(--surface);
  box-shadow: 0 0 0 1px var(--border-strong);
  transition: transform 150ms var(--ease), box-shadow 150ms var(--ease);
}
.swatch:hover span { transform: scale(1.08); }
.swatch input:checked + span { box-shadow: 0 0 0 3px var(--text); }
.swatch input:focus-visible + span { outline: 3px solid var(--accent); outline-offset: 4px; }
.swatch-custom { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.9rem; }

/* ---- Empty states and first-run guide ---- */
.empty-state { display: grid; justify-items: center; gap: 6px; padding: 20px 8px 12px; text-align: center; }
.empty-state .empty-art {
  display: grid; place-items: center; width: 72px; height: 72px; margin-bottom: 4px;
  border-radius: 20px; background: var(--accent-soft); color: var(--accent); font-size: 2rem; transform: rotate(-5deg);
  box-shadow: inset 0 -4px 0 rgb(0 0 0 / 0.06);
}
.empty-art svg {
  width: 44px; height: 44px; fill: none; stroke: currentColor;
  stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}
.empty-art svg[viewBox="0 0 48 48"] { stroke-width: 2.6; }
.empty-art svg .fill { fill: currentColor; stroke: none; }
.empty-state h3 { margin: 0; font-size: 1.15rem; }
.empty-state p { margin: 0; color: var(--muted); max-width: 36ch; }
.empty-state .btn { margin-top: 8px; }

.steps {
  padding: 14px 16px; border-radius: var(--radius);
  background: var(--accent-soft); border: 1px solid var(--border);
}
.steps-title { margin: 0 0 10px; font-family: var(--font-display); font-weight: 700; font-size: 1.1rem; }
.steps ol { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.steps li a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  height: 100%; min-height: 44px; padding: 8px 4px;
  border-radius: 12px; background: var(--surface); border: 1px solid var(--border);
  color: var(--text); text-decoration: none; font-weight: 600; font-size: 0.85rem; text-align: center;
  transition: border-color 150ms var(--ease), transform 150ms var(--ease);
}
.steps li a:hover { border-color: var(--accent); transform: translateY(-1px); }
@media (min-width: 560px) {
  .steps li a { flex-direction: row; gap: 8px; padding: 6px 12px; border-radius: 999px; font-size: 0.95rem; }
}
.steps li a[aria-current="step"] { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.step-num {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; flex: none;
  background: var(--surface-2); color: var(--text); font-size: 0.85rem; font-weight: 700;
}
.steps li.done .step-num, .steps li.next .step-num { background: var(--accent); color: var(--accent-text); }
.steps li.done a { color: var(--muted); }
.steps-hint { margin: 10px 0 0; font-size: 0.95rem; }
.steps-hint:empty { display: none; }

/* ---- Data tab ---- */
.summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin: 12px 0; }
.summary > div {
  display: grid; padding: 10px 12px; border-radius: 10px;
  background: var(--surface-2); text-align: center;
}
.summary b { font-family: var(--font-display); font-size: 1.5rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.summary span { color: var(--muted); font-size: 0.85rem; }
.preview {
  margin-top: 14px; padding: 14px; border-radius: 12px;
  border: 1px dashed var(--border-strong); background: var(--bg);
}
.preview h3 { margin: 0 0 4px; font-size: 1.05rem; }
.preview .summary > div { background: var(--surface); }
.preview dl { margin: 0 0 12px; display: grid; gap: 4px; font-size: 0.95rem; }
.preview dt { color: var(--muted); font-size: 0.85rem; }
.preview dd { margin: 0 0 4px; }
.file-drop {
  position: relative; display: grid; justify-items: center; gap: 2px; padding: 22px 16px; text-align: center;
  border: 1.5px dashed var(--border-strong); border-radius: 12px; background: var(--bg);
  color: var(--text); font-size: 0.95rem; font-weight: 400; cursor: pointer;
  transition: border-color 150ms var(--ease), background-color 150ms var(--ease);
}
.file-drop:hover { border-color: var(--accent); background: var(--accent-soft); }
.file-drop svg {
  width: 28px; height: 28px; margin-bottom: 4px; fill: none; stroke: var(--accent);
  stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.file-drop .muted { font-size: 0.85rem; }
.file-drop input[type="file"] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.file-drop:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; box-shadow: 0 0 0 4px var(--ring); }
.segmented { display: inline-flex; padding: 3px; gap: 2px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--border); }
.segmented button {
  min-height: 40px; padding: 6px 16px; border: 0; border-radius: 9px;
  background: none; color: var(--muted); font-weight: 600; cursor: pointer;
  transition: background-color 150ms var(--ease), color 150ms var(--ease), box-shadow 150ms var(--ease);
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.danger-zone { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }

/* ---- Plays (base styles; css/plays.css refines) ---- */
.player-picker { border: 1px solid var(--border); border-radius: 10px; margin: 12px 0 0; padding: 8px 12px; }
.player-picker legend { font-size: 0.9rem; color: var(--muted); padding: 0 4px; }
.player-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 6px 0; }
.player-row > .check:first-child { flex: 1; min-width: 140px; }
.player-row input[type="number"] { width: 110px; }

.play-list li { padding: 12px 0; border-top: 1px solid var(--border); }
.play-list li:first-child { border-top: 0; }
.play-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.play-head .muted { flex: 1; }
.play-results { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
  display: inline-flex; align-items: center; padding: 2px 10px;
  border: 1px solid var(--border); border-radius: 999px; font-size: 0.9rem;
  background: var(--surface);
}
.chip.winner { background: var(--winner); border-color: var(--gold); font-weight: 600; }

/* ---- Stats (base styles; css/stats.css refines) ---- */
.stat-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; display: grid; box-shadow: var(--shadow);
}
.tile-value { font-family: var(--font-display); font-size: 1.9rem; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.tile-label { color: var(--muted); font-size: 0.9rem; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 6px; border-top: 1px solid var(--border); }
.table thead th { border-top: 0; color: var(--muted); font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ==== Shared-site shell: identity, presence, menus, dialogs, toasts ==== */

/* ---- Navigation extras ---- */
.app-nav button { border: 0; background: none; cursor: pointer; font-family: inherit; }
.app-nav :is(a, button) { position: relative; }
.app-nav .nav-wide { display: none; }
.nav-badge {
  position: absolute; top: 1px; left: calc(50% + 8px);
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  display: grid; place-items: center;
  background: var(--danger); color: var(--surface);
  font-size: 0.6875rem; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums;
  box-shadow: 0 0 0 2px var(--surface);
}
@media (max-width: 899.98px) {
  .app-nav .nav-more.active-narrow { color: var(--text); }
  .app-nav .nav-more.active-narrow svg { background: var(--accent); color: var(--accent-text); }
  /* A local copy has no Nights or Chat, so Stats takes a place in the bar. */
  :root[data-mode="local"] .app-nav .nav-wide { display: grid; }
  :root[data-mode="local"] .only-narrow { display: none; }
}
:root[data-mode="local"] .app-nav [data-shared] { display: none; }
@media (min-width: 900px) {
  .app-nav .nav-wide { display: inline-flex; }
  .app-nav { margin-left: auto; margin-right: 4px; }
  .nav-badge { position: static; box-shadow: none; margin-left: 2px; }
  .only-narrow { display: none !important; }
}

/* ---- Header: wordmark, status pill, you ---- */
.app-title span { display: block; }
@media (max-width: 1239.98px) {
  .app-title { font-size: 0.98rem; line-height: 1.08; white-space: normal; overflow: visible; }
}
@media (min-width: 1240px) {
  .app-header-inner { max-width: 1240px; }
  .app-title span { display: inline; }
}
.header-tools { flex: none; display: flex; align-items: center; gap: 8px; margin-left: auto; }
@media (min-width: 900px) { .header-tools { margin-left: 0; } }

.status-pill, .me-btn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface); color: var(--text); cursor: pointer;
  font-size: 0.875rem; font-weight: 600; white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 150ms var(--ease), border-color 150ms var(--ease), transform 100ms var(--ease);
}
.status-pill:hover, .me-btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.status-pill:active, .me-btn:active { transform: scale(0.97); }
.status-pill { padding: 0 12px 0 11px; }
.status-pill .avatar-stack { margin-right: 1px; }
.status-word { display: none; }
@media (min-width: 480px) { .status-word { display: inline; } }
.status-count { font-variant-numeric: tabular-nums; }

.status-dot {
  flex: none; width: 9px; height: 9px; border-radius: 50%;
  background: var(--online); box-shadow: 0 0 0 3px color-mix(in srgb, var(--online) 22%, transparent);
}
[data-tone="busy"] .status-dot { background: var(--gold); box-shadow: 0 0 0 3px color-mix(in srgb, var(--gold) 22%, transparent); }
[data-tone="off"] .status-dot { background: var(--border-strong); box-shadow: none; }
[data-tone="bad"] .status-dot { background: var(--danger); box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 22%, transparent); }
[data-tone="local"] .status-dot { background: none; box-shadow: inset 0 0 0 2px var(--border-strong); }
.status-pill[data-tone="bad"] { border-color: var(--danger); color: var(--danger); }
@media (prefers-reduced-motion: no-preference) {
  [data-tone="busy"] .status-dot { animation: pulse 1.2s var(--ease) infinite alternate; }
  @keyframes pulse { to { opacity: 0.35; } }
}

.me-btn { padding: 3px; }
.me-btn .avatar { width: 32px; height: 32px; font-size: 0.8rem; }
.me-name { display: none; max-width: 12ch; overflow: hidden; text-overflow: ellipsis; padding-right: 10px; }
.me-btn.anonymous { border-color: var(--accent); border-style: dashed; }
.me-btn.anonymous .me-name { display: inline; padding-left: 2px; }
@media (max-width: 419.98px) { .me-btn.anonymous .me-name { display: none; } }
@media (min-width: 1080px) { .me-name { display: inline; padding-left: 2px; } }
.me-unknown { background: var(--accent-soft); color: var(--accent); }
.me-unknown svg { width: 60%; height: 60%; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---- Avatars: sizes, online dot, stacks ---- */
.avatar { position: relative; }
.avatar.sm { width: 26px; height: 26px; font-size: 0.66rem; }
.avatar.lg { width: 56px; height: 56px; font-size: 1.25rem; }
.avatar.xl { width: 72px; height: 72px; font-size: 1.6rem; }
.avatar.is-online::after {
  content: ""; position: absolute; right: -2px; bottom: -2px;
  width: max(11px, 26%); height: max(11px, 26%); border-radius: 50%;
  background: var(--online); border: 2px solid var(--surface);
}
.avatar-stack { display: inline-flex; }
.avatar-stack .avatar { box-shadow: 0 0 0 2px var(--surface); }
.avatar-stack .avatar + .avatar { margin-left: -7px; }
.badge.you { background: var(--accent); color: var(--accent-text); }
.badge.online { background: color-mix(in srgb, var(--online) 18%, var(--surface)); }

/* ---- Menus (More, You, Online): bottom sheets on phones, dropdowns on wide screens ---- */
.scrim { position: fixed; inset: 0; z-index: 30; background: rgb(20 14 8 / 0.4); }
.menu {
  position: fixed; z-index: 40;
  left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right));
  bottom: calc(var(--nav-h) + 10px + env(safe-area-inset-bottom));
  max-height: min(70dvh, 520px); overflow-y: auto; overscroll-behavior: contain;
  padding: 8px; border-radius: 18px;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.1), 0 18px 48px rgb(0 0 0 / 0.22);
}
.menu:focus { outline: none; }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 6px; }
.menu-item {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px;
  padding: 7px 10px; border: 0; border-radius: 12px; background: none;
  color: var(--text); text-align: left; text-decoration: none; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color 120ms var(--ease);
}
.menu-item:hover { background: var(--surface-2); }
.menu-item > svg {
  flex: none; width: 38px; height: 38px; padding: 8px; border-radius: 11px;
  background: var(--surface-2); color: var(--text);
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.menu-item:hover > svg { background: var(--surface); }
.menu-item > span { display: grid; min-width: 0; }
.menu-item b { font-weight: 600; }
.menu-item small, .menu-head small { color: var(--muted); font-size: 0.8125rem; line-height: 1.3; }
.menu-item.active { background: var(--accent-soft); }
.menu-item.active > svg, .menu-item.primary > svg { background: var(--accent); color: var(--accent-text); }
.menu-head { display: flex; align-items: center; gap: 12px; padding: 10px 10px 12px; }
.menu-head > div { display: grid; min-width: 0; }
.menu-head b { font-family: var(--font-display); font-size: 1.15rem; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; }
.menu-title { margin: 10px 10px 6px; font-family: var(--font-body); font-size: 0.8rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); }
.status-menu { padding: 10px; }
.status-menu > .muted, .status-menu > .btn { margin: 0 10px 8px; }
.status-line { display: flex; gap: 10px; align-items: baseline; padding: 10px 12px; border-radius: 12px; background: var(--surface-2); font-size: 0.9rem; }
.status-line p { margin: 0; }
.status-line .status-dot { position: relative; top: -1px; }
.online-list { list-style: none; margin: 0; padding: 0 6px 4px; display: grid; }
.online-list li { display: flex; align-items: center; gap: 12px; padding: 6px 4px; font-weight: 600; }
.online-list li > span:nth-child(2) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
@media (min-width: 900px) {
  .scrim { background: none; }
  .menu { left: auto; bottom: auto; width: 320px; border-radius: 16px; max-height: min(80dvh, 560px); }
}
@media (prefers-reduced-motion: no-preference) {
  .menu { animation: menu-in 180ms var(--ease); }
  .scrim { animation: fade-in 180ms var(--ease); }
  @keyframes menu-in { from { opacity: 0; transform: translateY(10px); } }
  @keyframes fade-in { from { opacity: 0; } }
  @media (min-width: 900px) { @keyframes menu-in { from { opacity: 0; transform: translateY(-6px); } } }
}

/* ---- Notices under the header ---- */
.shell-notices { max-width: 820px; margin: 0 auto; padding: 0 max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left)); }
.shell-notice {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; margin-top: 14px;
  padding: 10px 14px; border-radius: 12px;
  background: var(--winner); border: 1px solid var(--gold); color: var(--text);
}
.shell-notice.bad { background: var(--danger-soft); border-color: var(--danger); }
.shell-notice.info { background: var(--accent-soft); border-color: var(--accent); }
.shell-notice p { flex: 1 1 220px; margin: 0; font-size: 0.95rem; }
.shell-notice .actions { flex: none; }

/* ---- Dialogs ---- */
dialog.dialog {
  width: min(480px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  padding: 0; border: 1px solid var(--border); border-radius: 20px;
  background: var(--surface); color: var(--text); overflow-y: auto;
  box-shadow: 0 4px 12px rgb(0 0 0 / 0.12), 0 28px 80px rgb(0 0 0 / 0.35);
}
dialog.dialog::backdrop { background: rgb(20 14 8 / 0.55); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.dialog-body { display: grid; gap: 12px; padding: 22px 20px 20px; }
.dialog-body h2 { margin: 0; font-size: 1.45rem; }
.dialog-body h2:focus { outline: none; }
.dialog-body p { margin: 0; }
.dialog-body label.block { margin: 0; }
.dialog-text { display: grid; gap: 10px; }
.confirm-word { color: var(--danger); letter-spacing: 0.04em; }
.btn-link {
  min-height: 44px; padding: 8px 12px; border: 0; border-radius: 8px; background: none;
  color: var(--muted); font-weight: 600; text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}
.btn-link:hover { color: var(--text); }
@media (prefers-reduced-motion: no-preference) {
  dialog.dialog[open] { animation: dialog-in 220ms var(--ease); }
  @keyframes dialog-in { from { opacity: 0; transform: translateY(12px) scale(0.98); } }
}

/* "Who are you?" */
.who-body { justify-items: center; text-align: center; gap: 10px; }
.who-kicker { color: var(--accent); font-size: 0.8rem; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; }
.who-lead { color: var(--muted); max-width: 44ch; }
.who-grid {
  list-style: none; margin: 10px 0 2px; padding: 0; width: 100%;
  display: flex; flex-wrap: wrap; justify-content: center; gap: 10px;
}
.who-grid li { flex: 0 0 calc((100% - 20px) / 3); max-width: 132px; min-width: 0; }
.who-person {
  display: grid; justify-items: center; align-content: start; gap: 8px; width: 100%; height: 100%;
  padding: 14px 6px 12px; border: 1px solid var(--border); border-radius: 18px;
  background: var(--surface); color: var(--text); cursor: pointer;
  font-weight: 600; line-height: 1.2; box-shadow: var(--shadow);
  -webkit-tap-highlight-color: transparent;
  transition: border-color 150ms var(--ease), transform 150ms var(--ease), box-shadow 150ms var(--ease);
}
.who-person:hover { border-color: var(--accent); transform: translateY(-2px); }
.who-person:active { transform: scale(0.97); }
.who-person.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow); }
.who-person .avatar.xl { width: 64px; height: 64px; font-size: 1.45rem; }
.who-name { max-width: 100%; overflow-wrap: anywhere; }
.who-new { border-style: dashed; border-color: var(--border-strong); background: none; box-shadow: none; }
.who-plus { background: var(--accent-soft); color: var(--accent); font-weight: 400; font-size: 2rem !important; }
.who-form { display: grid; gap: 14px; width: 100%; max-width: 380px; text-align: left; }
.who-form > .avatar { justify-self: center; }
.who-form .error { margin: 0; }
.who-form .actions .btn { flex: 1 1 auto; }
.who-foot { margin-top: 2px; }

dialog.who-full {
  width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0;
  border: 0; border-radius: 0; box-shadow: none;
  background-color: var(--bg);
  background-image: radial-gradient(var(--dots) 1.5px, transparent 1.5px); background-size: 22px 22px;
}
.who-full .who-body {
  max-width: 600px; min-height: 100%; margin: 0 auto; align-content: center;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
}
.who-full h2 { font-size: clamp(2rem, 1.4rem + 3vw, 2.8rem); }
.who-full .who-lead { font-size: 1.05rem; }
.who-art { width: min(78%, 340px); height: auto; margin-bottom: 4px; filter: drop-shadow(0 10px 16px rgb(0 0 0 / 0.16)); }
@media (max-height: 700px) { .who-art { width: min(56%, 230px); } }

/* ---- Toasts ---- */
.toasts {
  position: fixed; left: 0; right: 0; z-index: 60;
  bottom: calc(var(--nav-h) + 14px + env(safe-area-inset-bottom));
  display: grid; justify-items: center; gap: 8px; padding: 0 12px; pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; align-items: center; gap: 14px; max-width: min(520px, 100%);
  padding: 11px 16px; border-radius: 14px;
  background: var(--text); color: var(--bg); font-weight: 500; font-size: 0.95rem;
  box-shadow: 0 8px 28px rgb(0 0 0 / 0.28);
}
.toast.bad { background: var(--danger); color: var(--surface); }
.toast-action { flex: none; min-height: 32px; border: 0; background: none; color: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
@media (min-width: 900px) { .toasts { bottom: 28px; } }
@media (prefers-reduced-motion: no-preference) { .toast { animation: rise 220ms var(--ease); } }

/* ---- Players, Games and Data tab extras ---- */
.side-stack { display: grid; gap: 16px; min-width: 0; }
.item-name .lock { width: 14px; height: 14px; margin-left: 5px; vertical-align: -1px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.pin-input { width: 100%; padding-left: calc(12px + 0.3em); font-size: 1.35rem !important; letter-spacing: 0.3em; text-align: center; font-variant-numeric: tabular-nums; }
.pin-input::placeholder { font-size: 1rem; letter-spacing: 0; }
.who-hint { font-size: 0.85rem; text-align: center; }
.who-form .avatar + .block { margin-top: 0; }
.who-body > .avatar.xl { margin-bottom: 2px; }
.who-full .who-body:has(.who-grid li:nth-child(7)) .who-art, .who-full form.who-body .who-art { width: min(52%, 210px); }
.invite-card { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; background: linear-gradient(120deg, var(--accent-soft), var(--surface) 75%); }
.invite-card > div { flex: 1 1 220px; min-width: 0; }
.invite-card h2 { margin-bottom: 4px; }
.invite-card p { color: var(--muted); }
.item-name .badge { margin-left: 6px; vertical-align: 1px; font-size: 0.72rem; }
.item-list li.is-me { background: linear-gradient(90deg, var(--accent-soft), transparent 70%); margin: 0 -8px; padding-left: 8px; padding-right: 8px; border-radius: 12px; border-top-color: transparent; }
.item-list li.is-me + li { border-top-color: transparent; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn {
  min-height: 36px; padding: 4px 14px; border: 1px solid var(--border-strong); border-radius: 999px;
  background: var(--surface); color: var(--text); font-size: 0.9rem; font-weight: 600; cursor: pointer;
  transition: background-color 150ms var(--ease), border-color 150ms var(--ease);
}
.chip-btn:hover { background: var(--surface-2); }
.chip-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.kv { display: grid; gap: 2px; margin: 0; }
.kv dt { color: var(--muted); font-size: 0.85rem; }
.kv dd { margin: 0 0 8px; }
.device-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.device-row > div { flex: 1 1 160px; min-width: 0; display: grid; }
.device-row b { font-family: var(--font-display); font-size: 1.15rem; }
.mode-choice { display: grid; gap: 8px; border: 0; margin: 12px 0; padding: 0; }
.mode-choice label {
  display: flex; align-items: flex-start; gap: 10px; padding: 12px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface);
  color: var(--text); font-size: 1rem; font-weight: 400;
}
.mode-choice label:has(input:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.mode-choice label > span { display: grid; }
.mode-choice small { color: var(--muted); font-size: 0.875rem; }
.mode-choice input { margin-top: 2px; }

@media print {
  .header-tools, .menu, .scrim, .toasts, .shell-notices { display: none; }
}

/* ---- Motion ---- */
@media (prefers-reduced-motion: no-preference) {
  .item-list li.editing, .preview, .confirm, .notice[role="status"] { animation: rise 200ms var(--ease); }
  .app-main.view-enter > * { animation: rise 280ms var(--ease) both; }
  .app-main.view-enter > :nth-child(2) { animation-delay: 40ms; }
  .app-main.view-enter > :nth-child(3) { animation-delay: 80ms; }
  .app-main.view-enter > :nth-child(n + 4) { animation-delay: 120ms; }
  @keyframes rise { from { opacity: 0; transform: translateY(6px); } }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important; animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important; scroll-behavior: auto !important;
  }
}

@media print {
  .app-nav, .skip-link { display: none; }
  .app-header { position: static; }
  body { background: #fff; }
}

/* =====================================================================
   Polish layer: splash, skeletons, busy buttons, footer, scrollbars,
   game art, and the welcome page's quieter chrome.
   ===================================================================== */

html { scrollbar-color: var(--border-strong) transparent; scrollbar-width: thin; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 3px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }
::selection { background: var(--accent); color: var(--accent-text); }
a, button, summary { -webkit-tap-highlight-color: transparent; }
:focus-visible { box-shadow: 0 0 0 5px var(--ring); }
input:focus-visible, select:focus-visible, textarea:focus-visible { box-shadow: 0 0 0 4px var(--ring); }
img { max-width: 100%; }

/* Header: one tidy line on phones. */
.app-header-inner { min-height: 56px; }
.header-tools { margin-left: auto; }
.app-brand { flex: 0 1 auto; }
@media (max-width: 479.98px) {
  .app-title .t-lead { display: none; }
  .app-title { font-size: 1.2rem; }
}
@media (min-width: 900px) { .header-tools { margin-left: 0; } }

/* Loading splash (shown until the first view renders). */
.splash { display: grid; justify-items: center; align-content: center; gap: 14px; min-height: 55dvh; color: var(--muted); }
.splash p { margin: 0; font-size: 0.95rem; font-weight: 500; }
.splash-logo { border-radius: 16px; box-shadow: var(--shadow); }
@media (prefers-reduced-motion: no-preference) {
  .splash-logo { animation: splash-bob 1.4s ease-in-out infinite alternate; }
  @keyframes splash-bob { to { transform: translateY(-6px) rotate(-3deg); } }
}

/* Skeletons: <div class="skeleton" style="height:16px;width:60%"></div> */
.skeleton {
  display: block; min-height: 14px; border-radius: 8px;
  background: linear-gradient(100deg, var(--surface-2) 30%, color-mix(in srgb, var(--surface-2) 55%, var(--surface)) 50%, var(--surface-2) 70%);
  background-size: 220% 100%;
}
@media (prefers-reduced-motion: no-preference) {
  .skeleton { animation: shimmer 1.4s linear infinite; }
  @keyframes shimmer { from { background-position: 120% 0; } to { background-position: -120% 0; } }
}

/* Busy buttons: add .is-busy (or aria-busy="true") while a request is in flight. */
.btn.is-busy, .btn[aria-busy="true"] { position: relative; color: transparent !important; pointer-events: none; }
.btn.is-busy::after, .btn[aria-busy="true"]::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid color-mix(in srgb, var(--text) 25%, transparent); border-top-color: var(--text);
}
.btn.primary.is-busy::after, .btn.primary[aria-busy="true"]::after {
  border-color: color-mix(in srgb, var(--accent-text) 30%, transparent); border-top-color: var(--accent-text);
}
@media (prefers-reduced-motion: no-preference) {
  .btn.is-busy::after, .btn[aria-busy="true"]::after { animation: spin 700ms linear infinite; }
  @keyframes spin { to { transform: rotate(360deg); } }
}
.btn.is-busy svg, .btn[aria-busy="true"] svg { opacity: 0; }

/* Inline validation. */
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] { border-color: var(--danger); }
input[aria-invalid="true"]:focus-visible { box-shadow: 0 0 0 4px color-mix(in srgb, var(--danger) 30%, transparent); outline-color: var(--danger); }

/* List items settle in. */
@media (prefers-reduced-motion: no-preference) {
  .item-list > li, .play-list > li { animation: rise 240ms var(--ease) both; }
  .item-list > li:nth-child(n + 8), .play-list > li:nth-child(n + 8) { animation: none; }
}

/* Game art: the box art / photo when a game has one, else the monogram tile. */
.game-art { flex: none; border-radius: 10px; object-fit: cover; }
img.game-art { background: var(--surface-2); border: 1px solid color-mix(in srgb, var(--text) 14%, transparent); box-shadow: 0 1px 2px rgb(60 40 20 / 0.12); display: block; }
.hm-mono.is-big.game-art { border-radius: 16px; }

/* Footer. */
.app-footer {
  max-width: 820px; margin: 0 auto; text-align: center; color: var(--muted); font-size: 0.8125rem;
  padding: 8px 16px calc(var(--nav-h) + 28px + env(safe-area-inset-bottom));
}
.app-footer p { margin: 0; }
.app-footer b { color: var(--text); font-family: var(--font-display); font-weight: 700; }
.app-main { padding-bottom: 12px; }
@media (min-width: 900px) {
  .app-footer { padding-bottom: 36px; }
  .app-main { padding-bottom: 24px; }
}
body[data-route="chat"] .app-footer { display: none; }

/* Welcome page: the app's chrome steps back so the page leads; Sign in stays clear. */
body[data-route="welcome"] .app-nav, body[data-route="welcome"] .status-pill { display: none; }
body[data-route="welcome"] .app-header { position: static; background: transparent; border-bottom-color: transparent; box-shadow: none; }
body[data-route="welcome"] .me-btn.anonymous { padding: 3px 14px 3px 3px; }
body[data-route="welcome"] .me-btn.anonymous .me-name { display: inline; }
body[data-route="welcome"] .app-main { padding-bottom: 24px; max-width: 1080px; }
body[data-route="welcome"] .app-footer { padding-bottom: 32px; }
body[data-route="welcome"] .toasts { bottom: 20px; }
input[type="date"], input[type="time"], input[type="datetime-local"] { min-width: 0; }

/* The page container takes focus on route change for screen readers; it must not draw a ring. */
#view:focus, #view:focus-visible { outline: none; box-shadow: none; }

/* The welcome page has its own Sign in buttons, so the "have a look around" bar would repeat them. */
body:has(#view[data-route="welcome"]) #shell-notices { display: none; }

/* Owner role */
.badge.owner { background: var(--accent-soft); color: var(--text); }
.reset-code {
  font-size: 2.6rem; font-weight: 800; letter-spacing: 0.3em; text-align: center; margin: 4px 0;
  font-variant-numeric: tabular-nums; user-select: all; padding-left: 0.3em;
}
.item-list li .btn.small + .btn.small { margin-left: 6px; }

/* Notifications dialog */
.push-sub { margin: 14px 0 2px; font-size: 0.95rem; }
.push-switch { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 10px 0; cursor: pointer; position: relative; }
.push-switch-text { display: grid; gap: 2px; }
.push-switch-text small { color: var(--muted, inherit); opacity: 0.8; }
.push-switch input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.push-track { flex: none; width: 46px; height: 28px; border-radius: 14px; background: color-mix(in srgb, currentColor 25%, transparent); position: relative; transition: background 0.15s; }
.push-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4); transition: transform 0.15s; }
.push-switch input:checked + .push-track { background: var(--accent); }
.push-switch input:checked + .push-track::after { transform: translateX(18px); }
.push-switch input:focus-visible + .push-track { outline: 3px solid var(--accent); outline-offset: 2px; }
.push-switch input:disabled + .push-track { opacity: 0.5; }
@media (prefers-reduced-motion: reduce) { .push-track, .push-track::after { transition: none; } }

/* Signed out on the hosted site: only the welcome page. No tabs, no status, no unread badge. */
html[data-auth="out"] #nav,
html[data-auth="out"] #status-btn,
html[data-auth="out"] #more-btn { display: none !important; }

/* Long names, titles and places wrap (or get an ellipsis where a row already truncates) inside their card
   instead of pushing the whole page sideways on a phone. `anywhere` also lets flex and grid children shrink. */
#view .card, #view .card *:not(svg):not(path):not(button):not(input):not(select):not(textarea) { overflow-wrap: anywhere; }
#view { min-width: 0; max-width: 100%; }
.hm-night-facts, .hm-night-going, .hm-play, .hm-res, .item-list li, .next-week, .next-week > span, .night, .night-head { min-width: 0; }
.next-week > span { flex: 1; }
.who-name { overflow-wrap: anywhere; }
.hm-play, .hm-play > *, .hm-play-top, .hm-play-top strong, .hm-res, .hm-res > span { min-width: 0; }
.hm-play-top strong { flex: 0 1 auto; max-width: 100%; }
.next-week { max-width: 100%; overflow-wrap: anywhere; text-align: left; }
.next-week > span { min-width: 0; }
.hm-play-body, .hm-play-body > *, .hm-results, .hm-col > * { min-width: 0; }

/* Phone layout: tap targets of at least 44px (the small buttons, snack chips, "Details" links, chat controls). */
@media (max-width: 640px), (pointer: coarse) {
  .btn.small, .chip-btn, .hm-more, .chat-icon-btn, .icon-btn, [data-theme-choice], summary {
    min-height: 44px !important; /* beats the per-page rules that set 32-36px */
  }
  .chat-icon-btn, .icon-btn { min-width: 44px; }
  .btn.small { min-width: 44px; }
  .hm-more, summary { display: inline-flex; align-items: center; }
  .chip-btn { align-items: center; }
  [data-act="quote"] { position: relative; }
  [data-act="quote"]::after { content: ""; position: absolute; inset: -10px -4px; }
}

.invite-code { font-size: 1.6rem; font-weight: 800; letter-spacing: 0.25em; font-variant-numeric: tabular-nums; user-select: all; margin: 4px 0; }

/* "A new version is ready" bar (js/version.js): small, non-blocking, above the tab bar on phones. */
.update-bar {
  position: fixed; left: 12px; right: 12px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 60;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 14px; border-radius: 14px; background: var(--surface, #222); color: var(--text, #fff);
  border: 1px solid var(--accent, #6c9); box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}
@media (min-width: 900px) { .update-bar { left: auto; right: 24px; bottom: 24px; max-width: 360px; } }

/* "Turn on notifications" card (Home, Game nights): compact, 44px buttons, theme colours only. */
.notify-card { padding: 14px 16px; border-left: 4px solid var(--accent); }
.notify-card p { margin: 0 0 10px; }
.notify-card .actions { margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.notify-card .btn { min-height: 44px; }
.notify-card .error:empty { display: none; }
