:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #f4ead2;
  --muted: #b8b6aa;
  --night: #04100f;
  --forest: #071a18;
  --surface: rgba(8, 35, 30, 0.94);
  --surface-soft: rgba(10, 45, 38, 0.86);
  --gold: #d4b368;
  --gold-dark: #8a6a31;
  --emerald: #68ad82;
  --ruby: #d36562;
  --sapphire: #6591cf;
  --line: rgba(212, 179, 104, 0.42);
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.34);
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--night); }
body { margin: 0; min-width: 320px; background: var(--night); color: var(--ink); }
button, input, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
a { color: var(--gold); text-underline-offset: 0.2em; }
.app { min-height: 100dvh; display: grid; grid-template-rows: 1fr auto; }
#content { min-width: 0; }
h1, h2, p { margin-top: 0; }
h1, h2, .brand, .wordmark, .life-orbit strong { font-family: Georgia, "Times New Roman", serif; }

footer {
  position: relative;
  z-index: 3;
  padding: 0.9rem 1rem;
  background: #020a09;
  color: #92968f;
  border-top: 1px solid rgba(212, 179, 104, 0.14);
  font-size: 0.72rem;
  line-height: 1.5;
  text-align: center;
}
footer a { color: #bcb7a6; }

.primary-button, .secondary-button, .danger-button, .quiet-button, .text-button {
  min-height: 46px;
  border-radius: 999px;
  padding: 0.78rem 1.2rem;
  border: 1px solid transparent;
  font-weight: 750;
  letter-spacing: 0.01em;
  cursor: pointer;
}
.primary-button {
  color: #0a1815;
  border-color: #f0d88d;
  background: linear-gradient(180deg, #f1d789, #c69b45);
  box-shadow: 0 9px 26px rgba(212, 179, 104, 0.24), inset 0 1px rgba(255, 255, 255, 0.4);
}
.secondary-button { border-color: var(--line); background: rgba(18, 62, 52, 0.8); color: var(--ink); }
.danger-button { border-color: rgba(211, 101, 98, 0.65); background: rgba(116, 35, 38, 0.28); color: #ffd6d3; }
.quiet-button { min-height: 40px; padding: 0.55rem 1rem; border-color: var(--line); background: rgba(4, 16, 15, 0.5); }
.text-button { min-height: 0; display: inline-flex; align-items: center; justify-content: center; padding: 0.5rem; border: 0; background: transparent; color: var(--gold); }
button:disabled { cursor: not-allowed; opacity: 0.45; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 3px solid var(--sapphire);
  outline-offset: 3px;
}

/* Home */
.home-page { background: #061312; }
.hero {
  position: relative;
  min-height: min(780px, calc(100dvh - 44px));
  display: flex;
  align-items: center;
  padding: clamp(4rem, 9vw, 8rem) clamp(1.4rem, 8vw, 9rem);
  isolation: isolate;
  overflow: hidden;
  background-image: linear-gradient(90deg, rgba(1, 8, 10, 0.98) 0%, rgba(2, 11, 14, 0.82) 42%, rgba(2, 10, 13, 0.25) 100%), url("/public/assets/enchanted-forest.jpg");
  background-position: center 24%;
  background-size: cover;
}
.hero::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(circle at 27% 30%, rgba(58, 116, 164, 0.18), transparent 34%), linear-gradient(0deg, #061312 0%, transparent 20%);
}
.hero-copy { width: min(610px, 52vw); }
.brand { margin-bottom: 1.4rem; color: var(--gold); font-size: clamp(2rem, 4vw, 3.5rem); letter-spacing: -0.035em; }
.hero h1 { max-width: 11ch; margin-bottom: 1.25rem; font-size: clamp(3.4rem, 7vw, 7.3rem); font-weight: 500; line-height: 0.93; letter-spacing: -0.055em; text-wrap: balance; }
.hero-lede { max-width: 540px; margin-bottom: 2rem; color: #d0d2ca; font-size: clamp(1.08rem, 1.8vw, 1.35rem); line-height: 1.65; }
.create-button { min-width: 190px; min-height: 56px; font-size: 1.05rem; }
.hero-note { margin: 1rem 0 0; color: #9da69e; font-size: 0.85rem; }
.home-explainer { padding: clamp(4rem, 8vw, 7rem) clamp(1.4rem, 8vw, 9rem); background: #061312; }
.home-explainer h2 { max-width: 12ch; margin: 0 auto 3rem; color: var(--ink); font-size: clamp(2.2rem, 4vw, 4.4rem); font-weight: 500; line-height: 1; text-align: center; }
.steps { max-width: 900px; margin: auto; display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; border: 1px solid var(--line); background: var(--line); }
.steps p { min-height: 160px; margin: 0; padding: 1.6rem; display: flex; flex-direction: column; gap: 2rem; background: #081c19; }
.steps strong { color: var(--gold); font-family: Georgia, serif; font-size: 2rem; font-weight: 500; }
.steps span { color: #d5d4c8; line-height: 1.45; }

/* Shared forest and join */
.forest-page, .game-page {
  background-color: #03100e;
  background-image: linear-gradient(rgba(3, 16, 14, 0.2), rgba(3, 16, 14, 0.48)), url("/public/assets/enchanted-forest.jpg");
  background-position: center top;
  background-size: cover;
  background-attachment: fixed;
}
.join-page { min-height: calc(100dvh - 44px); display: grid; place-items: center; padding: 2rem 1rem; }
.join-panel {
  width: min(100%, 440px);
  padding: clamp(1.5rem, 6vw, 2.4rem);
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(5, 27, 23, 0.94);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}
.wordmark { color: var(--gold); font-family: Georgia, serif; font-size: 1.6rem; text-decoration: none; }
.wordmark.dark { color: #73561e; }
.status-line { display: flex; align-items: center; gap: 0.55rem; margin: 1.5rem 0 0.9rem; color: var(--muted); font-size: 0.82rem; }
.status-line span { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 50%; background: var(--emerald); box-shadow: 0 0 12px rgba(104, 173, 130, 0.72); }
.status-line span.paused { background: var(--gold); box-shadow: 0 0 12px rgba(212, 179, 104, 0.72); }
.status-line span.offline { background: var(--ruby); box-shadow: 0 0 12px rgba(211, 101, 98, 0.72); }
.join-panel h1 { margin-bottom: 0.7rem; font-size: 2.7rem; font-weight: 500; }
.join-panel > p { color: var(--muted); line-height: 1.55; }
.join-form { display: grid; gap: 0.8rem; margin-top: 2rem; }
.join-form label, .quick-note > span { font-size: 0.85rem; font-weight: 750; }
.join-form input, .quick-note textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0.95rem 1rem;
  background: rgba(1, 13, 12, 0.74);
  color: var(--ink);
}
.join-form input { min-height: 52px; }
.privacy-note { margin: 1.4rem 0 0; font-size: 0.75rem; }
.error-message { padding: 0.8rem; border: 1px solid rgba(211, 101, 98, 0.42); border-radius: 10px; background: rgba(107, 31, 34, 0.3); color: #ffd8d4 !important; }

/* Game */
.game-page { width: min(100%, 760px); min-height: 100dvh; margin: auto; padding: 0 12px 40px; box-shadow: 0 0 80px #000; }
.game-header {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 70px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.7rem;
  margin: 0 -12px;
  padding: 0.75rem 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(4, 25, 21, 0.92);
  backdrop-filter: blur(18px);
}
.game-header .status-line { margin: 0; justify-content: center; }
.game-header .quiet-button { justify-self: end; }
.players-strip { display: flex; gap: 0.55rem; overflow-x: auto; margin: 0 -12px; padding: 0.85rem 12px; scrollbar-width: none; }
.players-strip::-webkit-scrollbar { display: none; }
.player-chip { flex: 0 0 auto; min-width: 148px; display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto; align-items: center; gap: 0.12rem 0.5rem; padding: 0.5rem 0.75rem; border: 1px solid rgba(212, 179, 104, 0.24); border-radius: 18px; background: rgba(4, 23, 20, 0.86); color: #d5d7cf; font-size: 0.76rem; font-family: inherit; text-align: left; }
button.player-chip { cursor: pointer; }
.player-chip.you { border-color: rgba(212, 179, 104, 0.7); }
.player-chip .player-color-dot, .player-dot { width: 10px; height: 10px; grid-row: 1; flex: 0 0 auto; border-radius: 50%; background: var(--player-color); box-shadow: 0 0 10px var(--player-color); }
.player-chip strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-counter-summary { grid-column: 1 / -1; display: flex; gap: 0.5rem; overflow: hidden; color: var(--gold); font-size: 0.68rem; white-space: nowrap; }
.player-counter-summary b { color: var(--ink); font-size: inherit; }

.life-section { padding: 1rem 0 1.2rem; text-align: center; }
.life-heading-row { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-bottom: 0.5rem; }
.life-heading-row > p { margin: 0; color: var(--muted); font-size: 0.76rem; font-weight: 750; letter-spacing: 0.12em; text-transform: uppercase; }
.life-mode-picker { display: flex; gap: 2px; padding: 2px; border: 1px solid rgba(212, 179, 104, 0.28); border-radius: 999px; background: rgba(3, 18, 16, 0.82); }
.life-mode-picker button { min-height: 34px; padding: 0.35rem 0.7rem; border: 0; border-radius: 999px; background: transparent; color: var(--muted); font-size: 0.68rem; font-weight: 750; cursor: pointer; }
.life-mode-picker button[aria-pressed="true"] { background: rgba(212, 179, 104, 0.18); color: var(--ink); box-shadow: inset 0 0 0 1px rgba(212, 179, 104, 0.42); }
.life-control { min-height: 0; height: 100%; }
.life-mode { height: 100%; align-items: center; justify-content: center; }
.life-mode { display: none; }
.life-section[data-life-mode="abacus"] .life-mode,
.life-section[data-life-mode="dial"] .life-mode { display: none; }
.life-section[data-life-mode="abacus"] [data-life-view="abacus"],
.life-section[data-life-mode="dial"] [data-life-view="dial"] { display: grid; }
.life-total { font-family: Georgia, "Times New Roman", serif; font-size: clamp(4.2rem, 19vw, 8rem); font-weight: 400; line-height: 1; text-shadow: 0 2px 18px rgba(244, 234, 210, 0.14); }
.life-abacus {
  width: min(100%, 570px);
  grid-template-columns: minmax(92px, 0.7fr) minmax(250px, 2fr);
  grid-template-rows: 1fr auto;
  align-items: center;
  gap: 0.3rem 1rem;
  margin: auto;
}
.abacus-readout { align-self: stretch; display: flex; flex-direction: column; align-items: center; justify-content: center; border: 1px solid var(--line); border-radius: 16px; background: rgba(4, 26, 22, 0.9); }
.abacus-readout .life-total { font-size: clamp(3.8rem, 12vw, 6.6rem); }
.abacus-readout span { color: var(--muted); font-size: 0.65rem; font-weight: 750; letter-spacing: 0.12em; text-transform: uppercase; }
.abacus-frame { min-width: 0; display: grid; gap: 0.55rem; padding: 0.6rem 0.7rem; border: 5px solid #75562b; border-radius: 14px; background: linear-gradient(135deg, #3b2815, #916e38 47%, #3a2714 100%); box-shadow: inset 0 0 0 2px #c29856, inset 0 0 18px #180e08, 0 10px 28px rgba(0,0,0,.34); }
.abacus-row { min-width: 0; display: grid; grid-template-columns: 28px 1fr; align-items: center; gap: 0.45rem; touch-action: none; cursor: ew-resize; }
.abacus-label { color: #ead69d; font-size: 0.58rem; font-weight: 800; text-transform: uppercase; }
.abacus-wire { position: relative; height: 34px; border-radius: 10px; background: linear-gradient(180deg, transparent 43%, #5c646b 44%, #f3f6f7 48%, #aeb7bd 53%, #4b5359 57%, transparent 58%); box-shadow: inset 0 1px rgba(0,0,0,.62), 0 2px 3px rgba(0,0,0,.28); }
.abacus-wire i { position: absolute; top: 4px; width: 16px; height: 26px; border-radius: 48%; box-shadow: 0 5px 7px rgba(0,0,0,.82), 0 2px 2px #000, inset 1px 0 2px rgba(255,255,255,.72), inset -2px 0 3px rgba(0,0,0,.48); transition: left 140ms ease, filter 140ms ease; }
.abacus-row[data-abacus-place="10"] .abacus-wire i { border: 1px solid #f4f7f8; background: linear-gradient(90deg, #444b50 0%, #aab2b7 22%, #f7f9fa 48%, #949da3 72%, #343a3e 100%); }
.abacus-row[data-abacus-place="1"] .abacus-wire i { border: 1px solid #ffe49a; background: linear-gradient(90deg, #51320d 0%, #c58a28 22%, #ffe39a 48%, #b8751c 72%, #3d2509 100%); }
.abacus-wire i.counted { filter: saturate(1.18) brightness(1.12); }
.control-hint { grid-column: 1 / -1; color: var(--muted); font-size: 0.62rem; text-align: center; }
.life-dial { width: 100%; min-width: 0; grid-template-rows: minmax(0, 1fr) auto auto; align-items: center; justify-items: center; gap: 0.3rem; margin: auto; }
.mechanical-counters { width: 100%; min-height: 0; display: flex; align-items: center; gap: 0.8rem; overflow-x: auto; padding: 0.35rem 0.2rem 0.55rem; scrollbar-width: thin; scrollbar-color: rgba(212,179,104,.45) transparent; scroll-snap-type: x proximity; }
.mechanical-counter { position: relative; flex: 0 0 auto; display: flex; align-items: center; gap: 0.45rem; scroll-snap-align: center; }
.counter-emoji { min-width: 1.4em; font-size: clamp(1.5rem, 5vw, 2.1rem); filter: drop-shadow(0 3px 4px rgba(0,0,0,.55)); }
.counter-body { height: 102px; display: flex; align-items: stretch; perspective: 320px; filter: drop-shadow(0 8px 10px rgba(0,0,0,.58)); }
.counter-cap { width: 36px; min-height: 44px; padding: 0; border: 1px solid #ff856f; background: linear-gradient(145deg, #f45c43 0%, #bd2f24 55%, #7b160f 100%); color: #fff8e8; font-size: 0.8rem; text-shadow: 0 1px 2px #5f100a; box-shadow: inset 0 1px 4px rgba(255,255,255,.45), inset 0 -8px 12px rgba(83,8,5,.38); cursor: pointer; }
.counter-cap-left { border-radius: 19px 5px 5px 19px; transform: rotateY(8deg); transform-origin: right center; }
.counter-cap-right { border-radius: 5px 19px 19px 5px; transform: rotateY(-8deg); transform-origin: left center; }
.counter-cap:disabled { opacity: 0.62; }
.number-wheel-bank { display: flex; align-items: stretch; border-top: 3px solid #1d2021; border-bottom: 3px solid #050606; background: #090a0a; box-shadow: inset 0 0 14px #000; }
.number-wheel { width: 52px; display: grid; grid-template-rows: 1fr 1.35fr 1fr; overflow: hidden; border-left: 1px solid #303334; border-right: 1px solid #020303; background: linear-gradient(90deg, #050606, #191b1b 25%, #242626 50%, #111212 78%, #030404); transform: rotateX(-2deg); }
.number-wheel button, .number-wheel output { min-width: 0; display: grid; place-items: center; border: 0; border-radius: 0; padding: 0; font-family: Georgia, "Times New Roman", serif; line-height: 1; }
.number-wheel button { min-height: 28px; background: rgba(255,255,255,.025); color: rgba(246,246,240,.62); font-size: 1rem; cursor: pointer; }
.number-wheel button:first-child { border-bottom: 1px solid rgba(255,255,255,.08); }
.number-wheel button:last-child { border-top: 1px solid rgba(0,0,0,.8); }
.number-wheel button:active { background: rgba(255,255,255,.14); color: #fff; }
.number-wheel output { position: relative; color: #fff; background: linear-gradient(#151717, #050606 45%, #0c0d0d 55%, #171919); font-size: 2.25rem; font-weight: 700; text-shadow: 0 2px 1px #000; box-shadow: inset 0 5px 9px rgba(0,0,0,.7), inset 0 -5px 9px rgba(0,0,0,.7); }
.number-wheel output::before, .number-wheel output::after { content: ""; position: absolute; left: 0; right: 0; height: 1px; background: rgba(255,255,255,.12); }
.number-wheel output::before { top: 3px; }.number-wheel output::after { bottom: 3px; }
.remove-counter { position: absolute; top: -8px; right: -8px; width: 26px; height: 26px; padding: 0; border: 1px solid rgba(255,255,255,.28); border-radius: 50%; background: #4c1714; color: #ffd8d2; line-height: 1; }
.add-counter-button { min-height: 36px; padding: 0.35rem 0.85rem; border: 1px dashed rgba(212,179,104,.62); border-radius: 999px; background: rgba(3,18,16,.72); color: var(--gold); font-size: 0.68rem; font-weight: 750; }
.player-name-button { min-height: 40px; margin-top: 1rem; padding: 0.35rem 1rem; border: 0; border-bottom: 1px solid rgba(212, 179, 104, 0.42); background: transparent; color: var(--ink); font-weight: 700; cursor: pointer; }

.commander-panel, .notes-section, .log-section, .host-controls {
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}
.commander-panel summary { min-height: 56px; display: flex; align-items: center; justify-content: space-between; padding: 0.8rem 1rem; cursor: pointer; font-family: Georgia, serif; font-size: 1.15rem; list-style: none; }
.commander-panel summary::-webkit-details-marker { display: none; }
.commander-panel summary::after { content: "+"; width: 28px; color: var(--gold); font-family: system-ui; font-size: 1.45rem; text-align: center; }
.commander-panel[open] summary::after { content: "−"; }
.commander-panel summary span { margin-left: auto; margin-right: 0.7rem; color: var(--muted); font-family: system-ui; font-size: 0.75rem; }
.commander-list { padding: 0 1rem 1rem; }
.commander-row { min-height: 54px; display: grid; grid-template-columns: auto 1fr 44px 36px 44px; align-items: center; gap: 0.6rem; border-top: 1px solid rgba(212, 179, 104, 0.16); }
.commander-row button { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 50%; background: rgba(15, 57, 48, 0.7); font-size: 1.25rem; }
.commander-row b { text-align: center; font-size: 1.2rem; }
.empty-state { color: var(--muted); font-size: 0.85rem; }

.notes-section { padding: 1rem; }
.section-heading { text-align: center; }
.section-heading h1 { margin-bottom: 0.35rem; font-size: clamp(1.8rem, 7vw, 2.4rem); font-weight: 500; }
.section-heading p { margin-bottom: 1.2rem; color: var(--muted); font-size: 0.78rem; }
.notes-heading-row { display: flex; align-items: start; justify-content: space-between; gap: 1rem; text-align: left; }
.notes-heading-row > div { min-width: 0; }
.notes-heading-row .undo-button { flex: 0 0 auto; min-height: 44px; padding: 0.5rem 0.8rem; border: 1px solid rgba(212,179,104,.45); border-radius: 999px; background: rgba(3,20,17,.72); color: var(--gold); font-size: 0.72rem; font-weight: 750; }
.notes-heading-row .undo-button[hidden] { display: none; }
.action-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.65rem; }
.action-grid button { min-height: 96px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.5rem; padding: 0.7rem 0.4rem; border: 1px solid rgba(212, 179, 104, 0.5); border-radius: 14px; background: linear-gradient(160deg, rgba(15, 64, 52, 0.88), rgba(4, 23, 20, 0.94)); color: var(--ink); font-size: 0.78rem; font-weight: 720; cursor: pointer; }
.action-grid button span { color: var(--gold); font-family: Georgia, serif; font-size: 1.65rem; line-height: 1; }
.action-grid button.selected { border-color: #efcf7a; background: linear-gradient(160deg, rgba(36, 91, 72, 0.94), rgba(7, 35, 29, 0.96)); box-shadow: inset 0 0 0 2px rgba(239, 207, 122, 0.18), 0 0 20px rgba(212, 179, 104, 0.12); }
.prompt-options { min-height: 0; display: flex; gap: 0.5rem; overflow-x: auto; padding-top: 0; }
.prompt-options:not(:empty) { padding-top: 0.8rem; }
.prompt-options button { flex: 0 0 auto; min-height: 40px; padding: 0.5rem 0.8rem; border: 1px solid rgba(212, 179, 104, 0.34); border-radius: 999px; background: rgba(3, 20, 17, 0.7); color: #d9d6c9; font-size: 0.76rem; }
.prompt-options button.selected { border-color: var(--gold); background: rgba(33, 76, 62, 0.9); color: #fff6da; }
.note-details { display: grid; grid-template-columns: 2fr 1fr; gap: 0.6rem; margin-top: 0.8rem; }
.note-details label { min-width: 0; display: grid; gap: 0.35rem; color: var(--ink); font-size: 0.76rem; font-weight: 750; text-align: left; }
.note-details small { color: var(--muted); font-weight: 400; }
.note-details input { width: 100%; min-height: 46px; border: 1px solid var(--line); border-radius: 12px; padding: 0.7rem 0.8rem; background: rgba(1,13,12,.74); color: var(--ink); }
.quick-note { display: grid; gap: 0.5rem; margin-top: 1rem; }
.quick-note small { color: var(--muted); font-weight: 400; }
.quick-note textarea { min-height: 76px; resize: vertical; line-height: 1.45; }
.note-form-actions { display: flex; gap: 0.6rem; margin-top: 0.8rem; }
.note-form-actions .quiet-button { flex: 0 0 auto; }
.add-log-button { flex: 1; width: 100%; margin: 0; }
.form-message { min-height: 1.2em; margin: 0.6rem 0 0; color: var(--muted); font-size: 0.75rem; text-align: center; }

.log-section { padding: 1rem; }
.log-heading-row { display: flex; align-items: start; justify-content: space-between; gap: 1rem; }
.log-heading-row h2 { margin-bottom: 0.2rem; font-size: 1.25rem; font-weight: 500; }
.log-heading-row p { margin-bottom: 0.8rem; color: var(--muted); font-size: 0.72rem; }
.game-log { margin: 0; padding: 0; list-style: none; }
.game-log li { min-height: 64px; display: grid; grid-template-columns: auto 1fr auto; align-items: start; gap: 0.7rem; padding: 0.85rem 0; border-top: 1px solid rgba(212, 179, 104, 0.14); }
.game-log .player-dot { margin-top: 0.25rem; }
.game-log strong { display: block; margin-bottom: 0.22rem; color: #d6d3c4; font-size: 0.76rem; }
.game-log p { margin: 0; color: #f2ecde; font-family: Georgia, serif; font-size: 0.96rem; line-height: 1.35; }
.game-log time { color: var(--gold); font-size: 0.68rem; }
.log-entry-copy { min-width: 0; }
.log-entry-meta { display: grid; justify-items: end; gap: 0.35rem; }
.log-entry-actions { display: flex; gap: 0.3rem; }
.log-entry-actions button { min-width: 44px; min-height: 44px; padding: 0.2rem 0.45rem; border: 1px solid rgba(212,179,104,.28); border-radius: 999px; background: rgba(3,20,17,.75); color: var(--gold); font-size: 0.6rem; }
.log-entry-actions button:last-child { color: #f2aaa5; }
.host-controls { padding: 1rem; }
.host-controls > p { margin-bottom: 0.7rem; color: var(--muted); font-size: 0.75rem; font-weight: 750; text-transform: uppercase; letter-spacing: 0.08em; }
.host-controls > div { display: flex; gap: 0.7rem; }
.host-controls button { flex: 1; }

.share-dialog { width: min(calc(100% - 24px), 430px); padding: 1.5rem; border: 1px solid var(--line); border-radius: 22px; background: #08221d; color: var(--ink); box-shadow: 0 30px 90px #000; text-align: center; }
.share-dialog::backdrop { background: rgba(0, 5, 5, 0.8); backdrop-filter: blur(6px); }
.share-dialog h2 { margin-bottom: 0.4rem; font-size: 2rem; font-weight: 500; }
.share-dialog > p { color: var(--muted); }
.share-dialog img { width: min(280px, 78vw); height: auto; display: block; margin: 1rem auto; padding: 6px; border-radius: 12px; background: #fff; }
.dialog-close { position: absolute; top: 0.7rem; right: 0.7rem; width: 44px; height: 44px; border: 0; background: transparent; color: var(--muted); font-size: 1.7rem; }
.counter-dialog { width: min(calc(100% - 24px), 420px); padding: 0; border: 1px solid var(--line); border-radius: 22px; background: #08221d; color: var(--ink); box-shadow: 0 30px 90px #000; }
.counter-dialog::backdrop { background: rgba(0,5,5,.8); backdrop-filter: blur(6px); }
.counter-dialog form { position: relative; display: grid; gap: 0.9rem; padding: 1.5rem; }
.counter-dialog .legal-kicker { margin: 0; }
.counter-dialog h2 { margin: 0; font-size: 2rem; font-weight: 500; }
.counter-dialog-copy { margin: -0.45rem 0 0; color: var(--muted); font-size: 0.82rem; line-height: 1.45; }
.emoji-options { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.emoji-options button { min-width: 0; min-height: 42px; padding: 0; border: 1px solid rgba(212,179,104,.24); border-radius: 10px; background: rgba(2,15,13,.72); font-size: 1.2rem; }
.emoji-options button.selected { border-color: var(--gold); background: rgba(212,179,104,.16); box-shadow: inset 0 0 0 1px rgba(212,179,104,.3); }
.counter-field { display: grid; grid-template-columns: 1fr 1.3fr; align-items: center; gap: 0.75rem; font-size: 0.8rem; font-weight: 750; }
.counter-field input, .counter-field select { width: 100%; min-height: 46px; border: 1px solid var(--line); border-radius: 12px; padding: 0.6rem 0.75rem; background: #031310; color: var(--ink); }
.counter-field input { font-size: 1.35rem; }
.counter-example { min-height: 46px; display: grid; place-items: center; margin: 0; border: 1px solid rgba(212,179,104,.2); border-radius: 12px; background: rgba(2,12,10,.62); font-family: Georgia, serif; font-size: 1.4rem; }
.join-link { display: block; overflow-wrap: anywhere; margin-bottom: 0.8rem; font-size: 0.74rem; }
.toast { position: fixed; left: 50%; bottom: 1rem; z-index: 30; max-width: calc(100% - 2rem); padding: 0.8rem 1rem; border: 1px solid rgba(211, 101, 98, 0.5); border-radius: 999px; background: #36191b; color: #ffe2df; opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: 180ms ease; }
.toast.visible { opacity: 1; transform: translate(-50%, 0); }
.game-paused .notes-section, .game-paused .life-section, .game-paused .commander-panel { filter: saturate(0.68); }
.game-ended .notes-section, .game-ended .life-section, .game-ended .commander-panel { filter: grayscale(0.3); }

/* Legal */
body[data-page="legal"] { background: #f5f1e7; color: #201c17; }
body[data-page="legal"] footer { background: #e9e2d2; color: #625a4e; border-color: #d9cfbb; }
body[data-page="legal"] footer a { color: #55441d; }
.legal-page { min-height: calc(100dvh - 44px); padding: clamp(2rem, 8vw, 6rem) 1.25rem; background: #f5f1e7; color: #201c17; }
.legal-page article { max-width: 760px; margin: auto; }
.legal-kicker { margin: 3rem 0 0.6rem; color: #81642c; font-size: 0.75rem; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }
.legal-page h1 { margin-bottom: 1.4rem; font-size: clamp(2.6rem, 7vw, 5rem); font-weight: 500; line-height: 0.96; }
.legal-page p { color: #514b42; font-size: 1.02rem; line-height: 1.75; }
.legal-page a { color: #66501e; }
.legal-links { display: grid; margin: 2.5rem 0; border-top: 1px solid #d6ccb6; }
.legal-links a { display: flex; align-items: center; justify-content: space-between; min-height: 56px; border-bottom: 1px solid #d6ccb6; text-decoration: none; }
.legal-links a::after { content: "→"; }
.legal-draft { padding: 1rem; border-left: 3px solid #9e7a32; background: #ece5d5; font-size: 0.85rem !important; }

@media (max-width: 680px) {
  .hero { min-height: 760px; align-items: end; padding: 20rem 1.25rem 4rem; background-image: linear-gradient(0deg, #04100f 4%, rgba(3, 13, 15, 0.86) 38%, rgba(2, 11, 14, 0.12) 76%), url("/public/assets/enchanted-forest.jpg"); background-position: center top; }
  .hero-copy { width: 100%; }
  .hero h1 { font-size: clamp(3.2rem, 15vw, 5rem); }
  .hero-lede { font-size: 1rem; }
  .home-explainer { padding: 4rem 1.25rem; }
  .steps { grid-template-columns: 1fr; }
  .steps p { min-height: auto; flex-direction: row; align-items: center; gap: 1.4rem; }
  .game-header { grid-template-columns: 1fr auto; }
  .game-header .status-line { grid-row: 2; grid-column: 1 / -1; justify-content: start; }
  .game-header .quiet-button { grid-column: 2; grid-row: 1; }
  .action-grid button { min-height: 86px; }
}

@media (max-width: 390px) {
  .game-page { padding-left: 8px; padding-right: 8px; }
  .game-header { margin-left: -8px; margin-right: -8px; }
  .action-grid { gap: 0.45rem; }
  .action-grid button { min-height: 80px; font-size: 0.7rem; }
  .life-wheel { gap: 0.55rem; }
  .commander-row { grid-template-columns: auto minmax(70px, 1fr) 40px 30px 40px; gap: 0.35rem; }
  .host-controls > div { flex-direction: column; }
}

/* Portrait tabletop mode: the complete active game surface fits one viewport. */
@media (max-width: 760px) and (orientation: portrait) {
  body[data-page="game"] { height: 100dvh; overflow: hidden; }
  body[data-page="game"] .app { height: 100dvh; min-height: 0; grid-template-rows: 1fr; overflow: hidden; }
  body[data-page="game"] footer { display: none; }

  .game-page {
    width: min(100%, 520px);
    height: 100dvh;
    min-height: 0;
    display: grid;
    grid-template-rows: 52px 44px minmax(170px, 24dvh) 44px minmax(0, 1fr) 70px 48px;
    gap: 6px;
    overflow: hidden;
    padding: 0 8px 8px;
  }

  .game-header {
    position: relative;
    min-height: 0;
    height: 52px;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: 1fr;
    gap: 0.45rem;
    margin: 0 -8px;
    padding: 5px 10px;
  }
  .game-header .wordmark { font-size: 1.3rem; }
  .game-header .status-line {
    grid-column: 2;
    grid-row: 1;
    justify-content: center;
    margin: 0;
    font-size: 0.68rem;
    white-space: nowrap;
  }
  .game-header .quiet-button {
    grid-column: 3;
    grid-row: 1;
    min-height: 44px;
    height: 44px;
    padding: 0.35rem 0.75rem;
    font-size: 0.76rem;
  }

  .players-strip {
    height: 44px;
    min-height: 0;
    align-items: center;
    gap: 0.4rem;
    margin: 0;
    padding: 2px 0;
  }
  .player-chip {
    min-width: 118px;
    min-height: 44px;
    padding: 0.22rem 0.5rem;
    border-radius: 12px;
    font-size: 0.64rem;
  }
  .player-counter-summary { gap: 0.35rem; font-size: 0.58rem; }

  .life-section {
    min-height: 0;
    display: grid;
    grid-template-rows: 44px minmax(0, 1fr);
    align-items: center;
    padding: 0;
  }
  .life-heading-row { height: 44px; justify-content: flex-end; gap: 0.4rem; margin: 0; }
  .life-heading-row > p { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .life-mode-picker { height: 44px; padding: 0; }
  .life-mode-picker button { min-width: 44px; min-height: 44px; padding: 0.2rem 0.55rem; font-size: 0.56rem; }
  .life-control { min-height: 0; }
  .life-abacus { width: 100%; height: 100%; grid-template-columns: 72px minmax(0, 1fr); grid-template-rows: 1fr 12px; gap: 2px 6px; }
  .abacus-readout { border-radius: 10px; }
  .abacus-readout .life-total { font-size: clamp(2.8rem, 13vw, 4.3rem); }
  .abacus-readout span { display: none; }
  .abacus-frame { gap: 3px; padding: 4px 5px; border-width: 3px; border-radius: 9px; }
  .abacus-row { grid-template-columns: 22px 1fr; gap: 3px; }
  .abacus-wire { height: 30px; }
  .abacus-wire i { top: 4px; width: 15px; height: 22px; }
  .control-hint { font-size: 0.53rem; line-height: 1; }
  .life-dial { height: 100%; grid-template-rows: minmax(0, 1fr) 28px; gap: 2px; }
  .life-dial .control-hint { display: none; }
  .mechanical-counters { gap: 0.55rem; padding: 2px; }
  .mechanical-counter { gap: 0.3rem; }
  .counter-emoji { font-size: 1.25rem; }
  .counter-body { height: 76px; }
  .counter-cap { width: 28px; min-height: 44px; font-size: 0.62rem; }
  .number-wheel { width: 40px; }
  .number-wheel button { min-height: 22px; font-size: 0.72rem; }
  .number-wheel output { font-size: 1.65rem; }
  .add-counter-button { min-height: 28px; padding: 0.15rem 0.65rem; font-size: 0.56rem; }
  .remove-counter { top: -4px; right: -5px; width: 24px; height: 24px; }
  .player-name-button { display: none; }

  .commander-panel {
    position: relative;
    z-index: 6;
    min-height: 0;
    margin: 0;
    border-radius: 12px;
  }
  .commander-panel summary { min-height: 44px; height: 44px; padding: 0.4rem 0.75rem; font-size: 0.9rem; }
  .commander-panel[open] .commander-list {
    position: absolute;
    top: calc(100% + 4px);
    left: -1px;
    right: -1px;
    padding: 0 0.75rem 0.5rem;
    border: 1px solid var(--line);
    border-radius: 0 0 12px 12px;
    background: #08231e;
    box-shadow: var(--shadow);
  }
  .commander-panel summary span { font-size: 0.62rem; }
  .commander-row { min-height: 44px; grid-template-columns: auto 1fr 40px 30px 40px; }
  .commander-row button { width: 38px; height: 38px; }

  .notes-section {
    min-height: 0;
    display: grid;
    grid-template-rows: auto auto auto 44px minmax(0, 1fr) 44px 0;
    align-content: stretch;
    gap: 5px;
    margin: 0;
    padding: 7px;
    border-radius: 14px;
    overflow: hidden;
  }
  .notes-heading-row { align-items: center; gap: 0.4rem; }
  .section-heading h1 { margin: 0; font-size: 1.2rem; line-height: 1; }
  .section-heading p { max-width: 44ch; margin: 0.16rem 0 0; font-size: 0.52rem; line-height: 1.15; }
  .notes-heading-row .undo-button { min-height: 44px; padding: 0.25rem 0.55rem; font-size: 0.56rem; }
  .action-grid { grid-template-columns: repeat(3, 1fr); gap: 4px; }
  .action-grid button {
    min-height: 48px;
    gap: 0.18rem;
    padding: 0.25rem 0.2rem;
    border-radius: 9px;
    font-size: 0.62rem;
  }
  .action-grid button span { font-size: 1.05rem; }
  .prompt-options { gap: 4px; min-height: 0; padding: 0; }
  .prompt-options:not(:empty) { padding: 0; }
  .prompt-options button { min-height: 44px; padding: 0.2rem 0.55rem; font-size: 0.62rem; }
  .note-details { height: 44px; gap: 4px; margin: 0; }
  .note-details label { position: relative; display: block; font-size: 0; }
  .note-details label > span { position: absolute; z-index: 1; top: 3px; left: 8px; color: var(--muted); font-size: 0.48rem; pointer-events: none; }
  .note-details label > span small { display: none; }
  .note-details input { height: 44px; min-height: 44px; padding: 14px 8px 3px; border-radius: 8px; font-size: 0.68rem; }
  .quick-note { min-height: 0; grid-template-rows: 16px minmax(0, 1fr); gap: 2px; margin: 0; }
  .quick-note > span { font-size: 0.66rem; }
  .quick-note textarea { min-height: 0; height: 100%; padding: 0.45rem 0.55rem; border-radius: 8px; font-size: 0.72rem; resize: none; }
  .note-form-actions { height: 44px; gap: 4px; margin: 0; }
  .note-form-actions .quiet-button { min-height: 44px; height: 44px; padding: 0.2rem 0.55rem; font-size: 0.62rem; }
  .add-log-button { min-height: 44px; height: 44px; margin: 0; padding: 0.35rem 1rem; font-size: 0.76rem; }
  .form-message { min-height: 0; height: 0; margin: 0; overflow: visible; font-size: 0.62rem; transform: translateY(-30px); pointer-events: none; }

  .log-section {
    min-height: 0;
    margin: 0;
    padding: 7px 9px;
    border-radius: 12px;
    overflow: hidden;
  }
  .log-heading-row { align-items: center; }
  .log-heading-row h2 { margin: 0; font-size: 0.88rem; }
  .log-heading-row p { margin: 0; font-size: 0.58rem; }
  .log-heading-row .text-button { min-height: 44px; padding: 0.2rem; font-size: 0.66rem; }
  .game-log li { min-height: 43px; padding: 5px 0 0; gap: 0.45rem; }
  .game-log li:nth-child(n + 2) { display: none; }
  .game-log strong { margin: 0; font-size: 0.6rem; }
  .game-log p { overflow: hidden; font-size: 0.72rem; line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; }
  .game-log time { font-size: 0.58rem; }
  .log-entry-actions button { min-width: 44px; min-height: 44px; padding: 0.1rem 0.3rem; font-size: 0.52rem; }

  .host-controls {
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    padding: 1px 6px;
    border-radius: 12px;
  }
  .host-controls[hidden] { display: none; }
  .host-controls > p { display: none; }
  .host-controls > div { min-width: 0; display: flex; flex-direction: row; gap: 5px; }
  .host-controls button { min-height: 44px; padding: 0.25rem 0.5rem; font-size: 0.64rem; }
}

@media (max-width: 760px) and (orientation: portrait) and (max-height: 740px) {
  .game-page { grid-template-rows: 48px 44px 158px 44px minmax(0, 1fr) 64px 48px; gap: 4px; padding-bottom: 4px; }
  .game-header { height: 48px; }
  .players-strip { height: 44px; }
  .life-section { grid-template-rows: 44px minmax(0, 1fr); }
  .life-abacus { grid-template-columns: 66px minmax(0, 1fr); }
  .counter-body { height: 68px; }
  .counter-cap { width: 26px; }
  .number-wheel { width: 36px; }
  .number-wheel button { min-height: 20px; font-size: 0.65rem; }
  .number-wheel output { font-size: 1.45rem; }
  .commander-panel summary { min-height: 44px; height: 44px; }
  .notes-section { padding: 5px; gap: 3px; }
  .section-heading h1 { font-size: 1.1rem; }
  .action-grid button { min-height: 44px; }
  .quick-note { grid-template-rows: 13px minmax(0, 1fr); }
  .note-form-actions, .add-log-button { min-height: 44px; height: 44px; }
  .log-section { padding: 5px 8px; }
  .game-log li { min-height: 36px; padding-top: 3px; }
  .host-controls button { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
