:root {
    color-scheme: light;
    --ink: #1c1915;
    --muted: #5c564c;
    --paper: #f6f1e8;
    --panel: #fffdf8;
    --line: #e4dccf;
    --accent: #2f6b4f;
    --accent-ink: #f4fbf6;
    --warn: #8a3d2f;
    --light: #efe6d2;
    --dark: #6f8f5b;
    --shadow: 0 1px 0 rgba(28, 25, 21, 0.04);
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; touch-action: manipulation; }

body {
    margin: 0 auto;
    max-width: 880px;
    padding: calc(16px + env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
    color: var(--ink);
    background: var(--paper);
}

h1, h2, p { margin: 0; }

h1 {
    font-family: "Iowan Old Style", Palatino, Georgia, serif;
    font-size: 1.75rem;
    font-weight: 600;
    letter-spacing: -0.03em;
}

h2 {
    font-size: 1rem;
    font-weight: 650;
}

.eyebrow {
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.top {
    display: flex;
    justify-content: center;
    margin-bottom: 12px;
}

.logo {
    width: min(150px, 40vw);
    height: auto;
}

.bar, .section-head, .row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.panel {
    margin: 0 0 14px;
    padding: 16px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: var(--shadow);
}

label {
    display: block;
    margin: 12px 0 6px;
    font-size: 0.85rem;
    font-weight: 650;
}

.hint { color: var(--muted); font-weight: 500; }

input, select, button {
    font: inherit;
    color: inherit;
}

input, select {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
}

.switch {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    font-weight: 550;
    cursor: pointer;
}

.switch input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

.switch-ui {
    position: relative;
    flex: 0 0 auto;
    width: 51px;
    height: 31px;
    border-radius: 31px;
    background: #e5e5ea;
    transition: background 0.25s ease;
}

.switch-ui::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 27px;
    height: 27px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.28);
    transition: transform 0.25s ease;
}

.switch input:checked + .switch-ui { background: #34c759; }
.switch input:checked + .switch-ui::after { transform: translateX(20px); }
.switch input:focus-visible + .switch-ui { outline: 2px solid var(--accent); outline-offset: 2px; }

.switch-line {
    display: flex;
    align-items: center;
    gap: 4px;
}

.switch-line .switch { flex: 1; margin-bottom: 0; }

.help, .help-x {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    border-radius: 50%;
    font-weight: 750;
    line-height: 1;
}

.regions {
    border: 0;
    margin: 14px 0 0;
    padding: 0;
}

.regions legend {
    font-size: 0.85rem;
    font-weight: 650;
    margin-bottom: 8px;
}

.region-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}

.region {
    position: relative;
    margin: 0;
    font-weight: 600;
}

.region input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}

.region span {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: 52px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
}

.region small {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 650;
}

.region input:checked + span {
    background: #e7f5ee;
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.region input:focus-visible + span {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

body:has(#table[hidden]) {
    min-height: 100svh;
    display: grid;
    grid-template-rows: 1fr auto 1fr;
    justify-items: center;
    align-items: center;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

body:has(#table[hidden]) .top {
    grid-row: 1;
    align-self: end;
    margin-bottom: 18px;
}

body:has(#table[hidden]) #lobby {
    grid-row: 2;
    width: min(420px, 100%);
}

body:has(#table[hidden]) #resume {
    position: absolute;
    left: 50%;
    top: calc(50% + 155px);
    width: min(420px, calc(100vw - 32px));
    margin: 0;
    transform: translateX(-50%);
}

.menu-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}

.menu-actions button { width: 100%; }

.watch-label { margin: 16px 0 8px; }

dialog.sheet-modal {
    width: min(520px, calc(100vw - 32px));
    max-height: min(720px, calc(100vh - 32px));
    margin: auto;
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--panel);
    color: var(--ink);
    box-shadow: 0 16px 40px rgba(28, 25, 21, 0.24);
    overflow: auto;
}

dialog.sheet-modal::backdrop { background: rgba(28, 25, 21, 0.48); }

dialog.sheet-modal form { display: flex; flex-direction: column; gap: 14px; }

dialog.sheet-modal p { line-height: 1.45; }

.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

dialog.sheet-modal form > button { width: 100%; }

@media (min-width: 560px) {
    .region-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

button {
    min-height: 44px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    cursor: pointer;
}

button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
}

button.bot {
    width: 100%;
    background: #f0b429;
    border-color: #d9a11a;
    color: #1c1915;
    font-weight: 750;
}


.diff {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    border: 0;
    margin: 0;
    padding: 0;
}

.diff legend {
    grid-column: 1 / -1;
    font-size: 0.85rem;
    font-weight: 650;
}

button.quiet { background: transparent; }

button:disabled { opacity: 0.45; cursor: default; }

button:focus-visible, input:focus-visible, select:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.row { flex-wrap: wrap; margin-top: 12px; }
.row button { flex: 1 1 140px; }

.stack { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }

.room {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    text-align: left;
}

.room-wrap { display: flex; flex-direction: column; gap: 8px; }
.room small { display: block; color: var(--muted); font-size: 0.8rem; }

.empty { color: var(--muted); }

.who { font-weight: 700; }
.meta { color: var(--muted); font-size: 0.85rem; }

.clock {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    font-size: 1.25rem;
}

.clock.running { color: var(--accent); }

.taken {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    min-height: 8px;
    margin: 8px 0;
}

.taken img {
    width: 36px;
    height: 36px;
    object-fit: contain;
}

#board-wrap {
    width: min(calc(100vw - 32px), calc(100svh - 420px), 640px);
    margin: 0 auto;
    touch-action: none;
}

@media (max-width: 700px), (orientation: landscape) and (max-height: 500px) {
    #board-wrap {
        width: calc(100% + 32px);
        margin-left: -16px;
        margin-right: -16px;
    }

    #board { border-radius: 0; }
}

#board, .board-box { touch-action: none; }

#table { padding-bottom: 96px; }

.board-box { position: relative; width: 100%; }

.hints {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 6px);
    z-index: 4;
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(28, 25, 21, 0.94);
    color: #f6f1e8;
    box-shadow: 0 10px 28px rgba(28, 25, 21, 0.28);
    pointer-events: none;
}

.hints p { font-weight: 700; text-transform: capitalize; margin-bottom: 6px; }

.hint-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 6px; font-size: 0.75rem; }
.hint-row strong { margin-right: 4px; }

.chip {
    padding: 3px 7px;
    border-radius: 999px;
    color: #fff;
    text-transform: capitalize;
    font-weight: 650;
}

.cutscene {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    place-items: center;
    background: rgba(10, 16, 14, 0.62);
    pointer-events: none;
}

.cutscene[hidden] { display: none; }

.move-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    width: min(calc(100vw - 32px), calc(100svh - 420px), 640px);
    margin: 8px auto 0;
    min-height: 36px;
}

#move-line {
    flex: 1;
    min-height: 1.2em;
    color: var(--ink);
    font-size: 0.92rem;
    font-weight: 650;
}

#open-log { min-height: 36px; padding: 6px 12px; }

.move-bar:has(#open-log[hidden]):not(:has(#move-line:not(:empty))) { display: none; }

#dock {
    position: fixed;
    z-index: 20;
    left: 0;
    right: 0;
    bottom: 0;
    max-width: 880px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    padding: 0 14px calc(12px + env(safe-area-inset-bottom));
    pointer-events: none;
}

#dock[hidden] { display: none; }

.dock-left {
    position: relative;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    pointer-events: none;
}

.game-menu {
    position: absolute;
    left: 0;
    bottom: 60px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 168px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--panel);
    box-shadow: 0 10px 28px rgba(28, 25, 21, 0.18);
    pointer-events: auto;
}

.game-menu[hidden] { display: none; }

.game-menu button { width: 100%; min-height: 40px; }

.actions:not(:has(button:not([hidden]))) { display: none; }

.dock-btn, .dock-nav button {
    position: relative;
    width: 52px;
    height: 52px;
    padding: 0;
    border-radius: 16px;
    background: var(--panel);
    box-shadow: 0 8px 22px rgba(28, 25, 21, 0.18);
    pointer-events: auto;
    font-size: 1.7rem;
    line-height: 1;
}

.dock-btn svg { width: 26px; height: 26px; }

.dock-nav { display: flex; gap: 8px; pointer-events: auto; }

.dock-nav button:disabled {
    opacity: 1;
    color: #8b877f;
    background: #ece7df;
    border-color: #d9d0c2;
}

.chat-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: #d23b2e;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 750;
    line-height: 18px;
}

.chat-badge[hidden] { display: none; }

.log-list, .chat-log {
    margin: 0;
    padding: 0;
    max-height: min(420px, 50vh);
    overflow: auto;
}

.log-list { list-style: none; }

.log-list button {
    width: 100%;
    text-align: left;
    background: transparent;
}

.log-list button.current { background: #e7f5ee; }

.chat-log p { margin: 0 0 8px; line-height: 1.4; }
.chat-log strong { margin-right: 6px; }

.chat-form { display: flex; gap: 8px; margin-top: 12px; }
.chat-form input { flex: 1; }
.chat-form button { width: auto; }

.stage {
    position: relative;
    width: min(640px, calc(100vw - 28px));
    height: min(360px, 58vh);
    overflow: hidden;
    border-radius: 18px;
    background:
        radial-gradient(ellipse at 50% 78%, #8dcc74 0%, #3f8a4b 38%, #1f5a38 68%, #10281f 100%);
    box-shadow: 0 22px 60px rgba(0, 0, 0, 0.45);
}

.stage .ground {
    position: absolute;
    left: 7%;
    right: 7%;
    bottom: 16%;
    height: 30%;
    border-radius: 50%;
    background: rgba(16, 64, 36, 0.28);
    box-shadow: inset 0 0 0 10px rgba(255, 255, 255, 0.05);
}

#cut-back, #cut-front {
    position: absolute;
    z-index: 1;
    object-fit: contain;
    object-position: center bottom;
    filter: drop-shadow(0 10px 8px rgba(0, 0, 0, 0.35));
}

#cut-back {
    left: 4%;
    bottom: 16%;
    width: 40%;
    height: 48%;
    transform-origin: 70% 100%;
}

#cut-front {
    right: 6%;
    bottom: 28%;
    width: 32%;
    height: 38%;
    transform-origin: 30% 100%;
}

#cut-fx {
    position: absolute;
    z-index: 2;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
}

.ps-fx {
    position: absolute;
    z-index: 2;
    pointer-events: none;
    transform-origin: center center;
}

.ps-flash {
    position: absolute;
    z-index: 1;
    inset: 0;
    pointer-events: none;
}

#cut-line {
    position: absolute;
    z-index: 4;
    left: 12px;
    right: 12px;
    bottom: 10px;
    margin: 0;
    padding: 8px 12px;
    border-radius: 12px;
    background: rgba(255, 253, 248, 0.95);
    color: var(--ink);
    font-weight: 750;
    text-align: center;
}

#drag-ghost {
    position: fixed;
    z-index: 20;
    width: 72px;
    height: 72px;
    margin: -36px 0 0 -36px;
    pointer-events: none;
    filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.35));
}

#drag-ghost img { width: 72px; height: 72px; object-fit: contain; }

.ghost-chip {
    display: grid;
    place-items: center;
    width: 88px;
    height: 44px;
    margin-left: -8px;
    border-radius: 12px;
    color: #fff;
    font-weight: 750;
    text-transform: capitalize;
}

body.dragging { overflow: hidden; touch-action: none; }

#confetti {
    position: fixed;
    z-index: 40;
    inset: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    border-radius: 0;
    background: transparent;
}

#confetti[hidden] { display: none; }

canvas {
    display: block;
    width: 100%;
    height: auto;
    border-radius: 8px;
    touch-action: none;
    background: var(--light);
}

#fx {
    position: absolute;
    left: 50%;
    top: 46%;
    width: min(46%, 220px);
    transform: translate(-50%, -50%);
    pointer-events: none;
    border-radius: 12px;
}

.toast {
    margin: 10px 0;
    padding: 10px 12px;
    border-radius: 10px;
    background: #1c1915;
    color: #f6f1e8;
}

.tray {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
    gap: 8px;
    margin-top: 12px;
}

.tray button {
    position: relative;
    min-height: 48px;
    color: #fff;
    border: 0;
    text-transform: capitalize;
    touch-action: none;
}

.tray button.used::after {
    content: "✓";
    position: absolute;
    top: -7px;
    right: -5px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #1c1915;
    color: #fff;
    font-size: 15px;
    line-height: 24px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
}

.tray button[aria-pressed="true"] { outline: 2px solid var(--ink); }

.sheet {
    margin-top: 12px;
    padding: 12px;
    border-radius: 14px;
    background: var(--panel);
    border: 1px solid var(--line);
}

.actions { margin-top: 14px; }

@media (min-width: 720px) {
    h1 { font-size: 2.1rem; }
    .taken img { width: 44px; height: 44px; }
}
