/* Domino — real 3D tiles on the park's stone table (js/domino.js, js/domino3d.js).
   Theme-aware like the other game pages: tokens on :root, redefined under body.dark-theme. */
:root {
    --dn-accent: #1d4e89;
    --dn-accent-2: #1e40af;
    --dn-accent-soft: #e3ecf8;
    --dn-on-accent: #ffffff;
    --dn-page-bg: #f3f5f2;
    --dn-card-bg: #ffffff;
    --dn-card-border: #d9dfd6;
    --dn-muted: #5a6458;
    --dn-shadow: 0 10px 30px rgba(20, 40, 30, .10);
    --dn-stage-bg: #bcd8ec;
    --dn-ok: #15803d;
    --dn-ok-soft: #dcfce7;
    --dn-gold: #b45309;
    --dn-tile: #f8f2e4;
    --dn-tile-edge: #d8ccb2;
    --dn-overlay: rgba(10, 20, 30, .55);
    --dn-cur: #fff4d6;
    --dn-cur-border: #e8b64c;
    --dn-hud: rgba(255, 255, 255, .92);
    --dn-hud-button: #f3f5f2;
    --dn-hud-button-text: #263238;
}

body.dark-theme {
    --dn-accent: #7cb2f2;
    --dn-accent-2: #93c5fd;
    --dn-accent-soft: #172a42;
    --dn-on-accent: #071526;
    --dn-page-bg: #0f1312;
    --dn-card-bg: #181d1c;
    --dn-card-border: #2f3836;
    --dn-muted: #a9b5ad;
    --dn-shadow: 0 10px 30px rgba(0, 0, 0, .45);
    --dn-stage-bg: #22313b;
    --dn-ok: #4ade80;
    --dn-ok-soft: #12341f;
    --dn-gold: #fbbf24;
    --dn-tile: #efe7d6;
    --dn-tile-edge: #9c917c;
    --dn-overlay: rgba(0, 0, 0, .62);
    --dn-cur: #3a2e17;
    --dn-cur-border: #d9a441;
    --dn-hud: rgba(15, 19, 18, .9);
    --dn-hud-button: #252d2b;
    --dn-hud-button-text: #eef4f0;
}

/* clip, not hidden: the site-wide `body { overflow-x: hidden }` makes <body> a scroll
   container that never scrolls, which silently kills any position: sticky inside. */
.dn-body, body.dn-body#page-top {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--dn-page-bg);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: clip;
}
.dn-main { padding-top: 92px; padding-bottom: 40px; }
.dn-game .container, .dn-hero .container { max-width: 1080px; }

/* ---- hero ---- */
.dn-hero { text-align: center; padding: 4px 0 8px; }
.dn-hero h1 { font-weight: 800; font-size: clamp(1.6rem, 5vw, 2.2rem); margin-bottom: 4px; }
.dn-hero-icon { color: var(--dn-accent); }
.dn-lead { margin: 0 auto; max-width: 600px; color: var(--dn-muted); font-size: .98rem; line-height: 1.45; }
body.dn-playing .dn-hero { display: none; }
body.dn-playing .dn-main { padding-top: 14px; }

/* ---- buttons ---- */
.dn-btn { min-height: 48px; padding: 8px 16px; border-radius: 14px; border: 1px solid var(--dn-card-border); background: var(--dn-card-bg); color: inherit; font-weight: 700; font-size: 1rem; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; touch-action: manipulation; transition: background .15s, border-color .15s, transform .1s; }
.dn-btn:hover { border-color: var(--dn-accent); }
.dn-btn:active { transform: scale(.98); }
.dn-btn[hidden] { display: none; }
.dn-btn:disabled { opacity: .5; cursor: default; transform: none; }
.dn-btn-primary { background: var(--dn-accent); border-color: var(--dn-accent); color: var(--dn-on-accent); }
.dn-btn-primary:hover { background: var(--dn-accent-2); border-color: var(--dn-accent-2); }
.dn-btn-ghost { background: transparent; border-color: transparent; color: var(--dn-muted); }
.dn-wide { width: 100%; }
.dn-btn:focus-visible, .dn-chip:focus-visible, .dn-tile:focus-visible, .dn-round:focus-visible, .dn-seg button:focus-visible, .dn-endchip:focus-visible { outline: 3px solid var(--dn-accent); outline-offset: 2px; }

/* ---- setup ---- */
.dn-setup { max-width: 560px; margin: 6px auto 0; padding: 16px; border-radius: 18px; background: var(--dn-card-bg); border: 1px solid var(--dn-card-border); box-shadow: var(--dn-shadow); display: flex; flex-direction: column; gap: 12px; }
.dn-setup[hidden] { display: none; }
.dn-setup-title { margin: 0; font-size: 1.35rem; font-weight: 800; text-align: center; }
.dn-field { display: flex; flex-direction: column; gap: 6px; }
.dn-field[hidden] { display: none; }
.dn-label { font-weight: 700; font-size: .92rem; color: var(--dn-muted); }
.dn-note { color: var(--dn-muted); font-size: .84rem; line-height: 1.4; }
.dn-chips { display: flex; gap: 6px; }
.dn-chip { flex: 1; min-height: 46px; padding: 4px 6px; border-radius: 12px; border: 1px solid var(--dn-card-border); background: var(--dn-page-bg); color: inherit; font-weight: 800; font-size: 1rem; cursor: pointer; touch-action: manipulation; line-height: 1.15; }
.dn-chip[aria-checked="true"] { background: var(--dn-accent); border-color: var(--dn-accent); color: var(--dn-on-accent); }
.dn-seats { display: grid; gap: 8px; }
.dn-seat { display: grid; grid-template-columns: auto 1fr; gap: 6px 8px; align-items: center; padding: 8px; border-radius: 14px; background: var(--dn-page-bg); border: 1px solid var(--dn-card-border); }
.dn-seat .dn-dot { width: 18px; height: 18px; }
.dn-seat input { min-width: 0; width: 100%; min-height: 42px; padding: 6px 10px; border-radius: 10px; border: 1px solid var(--dn-card-border); background: var(--dn-card-bg); color: inherit; font-size: 1rem; }
.dn-seat input:focus { outline: 2px solid var(--dn-accent); outline-offset: 1px; }
.dn-seat small.dn-seat-team { grid-column: 1 / -1; color: var(--dn-muted); font-size: .78rem; margin-top: -2px; }
.dn-seg { grid-column: 1 / -1; display: grid; grid-template-columns: 1.15fr 1fr 1fr 1fr; gap: 4px; padding: 3px; border-radius: 12px; background: var(--dn-card-bg); border: 1px solid var(--dn-card-border); }
.dn-seg button { min-height: 40px; border: 0; border-radius: 9px; background: transparent; color: inherit; font-weight: 700; font-size: .9rem; cursor: pointer; touch-action: manipulation; display: inline-flex; align-items: center; justify-content: center; gap: 5px; padding: 0 4px; }
.dn-seg button[aria-checked="true"] { background: var(--dn-accent); color: var(--dn-on-accent); }

/* ---- the table ---- */
.dn-play { display: flex; flex-direction: column; gap: 8px; max-width: 980px; margin: 0 auto; }
.dn-play[hidden] { display: none; }
.dn-top { display: flex; align-items: center; gap: 8px; min-height: 46px; padding: 4px 6px 4px 12px; border-radius: 14px; background: var(--dn-card-bg); border: 1px solid var(--dn-card-border); }
.dn-dot { width: 16px; height: 16px; flex: none; border-radius: 50%; background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, .7), transparent 45%), var(--c, #1d4e89); box-shadow: 0 1px 3px rgba(0, 0, 0, .35); }
.dn-turn-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.15; }
.dn-turn-text strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 1rem; }
.dn-turn-text small { color: var(--dn-muted); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dn-round { width: 40px; height: 40px; flex: none; border-radius: 50%; border: 1px solid var(--dn-card-border); display: grid; place-items: center; background: var(--dn-page-bg); color: inherit; font-size: 15px; cursor: pointer; touch-action: manipulation; }
.dn-round[hidden], .dn-round span[hidden] { display: none; }

.dn-scores { display: grid; grid-template-columns: repeat(var(--n, 2), minmax(0, 1fr)); gap: 6px; }
.dn-score { position: relative; display: flex; align-items: center; gap: 6px; min-width: 0; min-height: 40px; padding: 4px 8px; border-radius: 12px; background: var(--dn-card-bg); border: 1px solid var(--dn-card-border); font-size: .86rem; }
.dn-score.is-turn { background: var(--dn-cur); border-color: var(--dn-cur-border); box-shadow: inset 0 0 0 1px var(--dn-cur-border); }
.dn-score .dn-dot { width: 12px; height: 12px; }
.dn-score-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; line-height: 1.1; }
.dn-score-name small { display: block; font-weight: 600; color: var(--dn-muted); font-size: .72rem; }
.dn-score-pts { font-weight: 900; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.dn-score-pts small { font-weight: 600; color: var(--dn-muted); font-size: .7rem; }

.dn-stage { position: relative; width: 100%; height: clamp(320px, calc(100vh - 360px), 600px); border-radius: 18px; overflow: hidden; background: var(--dn-stage-bg); box-shadow: var(--dn-shadow); touch-action: none; user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
.dn-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: pointer; }
.dn-canvas[hidden] { display: none; }
.dn-stage-hud { position: absolute; z-index: 4; top: 8px; left: 8px; right: 8px; pointer-events: none; }
.dn-stage-hud > * { pointer-events: auto; }
.dn-stage-hud .dn-top, .dn-stage-hud .dn-scores { background: var(--dn-hud); color: var(--text-color); backdrop-filter: blur(8px); }
.dn-stage-hud .dn-top { border-color: var(--dn-card-border); }
.dn-stage-hud .dn-scores { margin-top: 6px; }
.dn-stage-hud .dn-round { background: var(--dn-hud-button); color: var(--dn-hud-button-text); border-color: var(--dn-card-border); }
.dn-stage-hud .dn-round[aria-pressed="true"] { background: var(--dn-accent); color: var(--dn-on-accent); border-color: var(--dn-accent); }
.dn-menu-toggle { background: var(--dn-hud-button); color: var(--dn-hud-button-text); }
.dn-menu-panel { position: absolute; z-index: 7; top: 108px; right: 8px; width: min(320px, calc(100% - 16px)); max-height: calc(100% - 120px); overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; border: 1px solid var(--dn-card-border); border-radius: 14px; background: var(--dn-hud); color: var(--text-color); box-shadow: var(--dn-shadow); backdrop-filter: blur(10px); }
.dn-menu-panel[hidden] { display: none; }
.dn-menu-panel > strong { font-size: 1rem; }
.dn-menu-panel .dn-help { max-width: none; margin: 0; padding: 8px; background: transparent; }
.dn-menu-panel .dn-help[open] { max-height: 55vh; overflow: auto; }
.dn-menu-panel .dn-help ul { padding-left: 18px; }
.dn-stage-actions { position: absolute; z-index: 4; left: 12px; bottom: 12px; width: min(55%, 320px); min-height: 0; padding: 8px; border-radius: 16px; background: var(--dn-hud); backdrop-filter: blur(8px); }
.dn-stage-actions[hidden] { display: none; }
.dn-stage .dn-bar.dn-stage-actions .dn-btn { flex: 1 1 100%; max-width: none; }
.dn-stage-status { position: absolute; z-index: 3; left: auto; right: 12px; bottom: 14px; max-width: 52%; margin: 0; text-align: right; pointer-events: none; text-shadow: 0 1px 3px var(--dn-hud); }
.dn-hand[hidden] { display: none; }
.dn-stage:fullscreen { box-sizing: border-box; width: 100vw; height: 100vh; height: 100dvh; max-height: none; margin: 0; border-radius: 0; }
.dn-stage:fullscreen .dn-canvas { width: 100%; height: 100%; }
.dn-loading { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; padding: 12px; text-align: center; color: #1e2a36; font-weight: 700; }
.dn-loading[hidden] { display: none; }
.dn-banner { position: absolute; left: 50%; top: 40%; z-index: 2; transform: translate(-50%, -50%) scale(.9); margin: 0; padding: 10px 22px; border-radius: 18px; max-width: 92%; text-align: center; color: #fff; font-weight: 900; font-size: clamp(1.4rem, 7vw, 2.3rem); line-height: 1.15; text-shadow: 0 3px 12px rgba(0, 0, 0, .5); background: linear-gradient(135deg, rgba(29, 78, 137, .92), rgba(15, 118, 110, .92)); opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; }
.dn-banner.is-on { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.dn-banner small { display: block; font-size: .5em; font-weight: 700; opacity: .92; }
.dn-ends { position: absolute; left: 8px; top: 8px; z-index: 2; margin: 0; padding: 5px 10px; border-radius: 999px; background: rgba(15, 23, 32, .66); color: #fff; font-weight: 700; font-size: .84rem; pointer-events: none; display: inline-flex; gap: 6px; align-items: center; max-width: calc(100% - 16px); }
.dn-ends:empty { display: none; }
.dn-ends b { display: inline-grid; place-items: center; min-width: 22px; height: 22px; padding: 0 4px; border-radius: 6px; background: var(--dn-tile); color: #1c1917; font-weight: 900; }

/* the hand: real-looking tiles, standing */
.dn-hand { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; min-height: 84px; padding: 4px 2px 2px; }
.dn-hand:empty::before { content: attr(data-empty); align-self: center; color: var(--dn-muted); font-size: .9rem; }
.dn-tile { position: relative; flex: 0 0 auto; width: 40px; height: 78px; padding: 0; border-radius: 9px; border: 1.5px solid var(--dn-tile-edge); background: var(--dn-tile); box-shadow: 0 3px 0 var(--dn-tile-edge), 0 4px 8px rgba(0, 0, 0, .12); cursor: pointer; touch-action: manipulation; transition: transform .15s, box-shadow .15s, opacity .15s, border-color .15s; }
.dn-tile svg { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.dn-tile.is-playable { transform: translateY(-6px); border-color: var(--dn-ok); box-shadow: 0 3px 0 var(--dn-ok), 0 8px 14px rgba(0, 0, 0, .18); }
.dn-tile.is-dim { opacity: .55; }
.dn-tile.is-sel { transform: translateY(-10px); border-color: var(--dn-gold); box-shadow: 0 0 0 3px var(--dn-gold), 0 10px 16px rgba(0, 0, 0, .22); }
.dn-tile.is-new { animation: dn-new .6s ease-out; }
@keyframes dn-new { 0% { transform: translateY(-24px); opacity: 0; } 100% { opacity: 1; } }
.dn-tile:disabled { cursor: default; }
.dn-hand.is-many .dn-tile { width: 34px; height: 66px; }

.dn-bar { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; min-height: 52px; }
.dn-bar .dn-btn { flex: 1 1 160px; max-width: 360px; min-height: 52px; font-size: 1.05rem; }
.dn-endchips { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; width: 100%; }
.dn-endchips[hidden] { display: none; }
.dn-endchip { min-height: 48px; min-width: 96px; padding: 4px 12px; border-radius: 12px; border: 2px solid var(--dn-ok); background: var(--dn-ok-soft); color: inherit; font-weight: 800; font-size: .95rem; cursor: pointer; touch-action: manipulation; display: inline-flex; align-items: center; gap: 6px; }
.dn-endchip kbd { font-size: .7rem; padding: 1px 5px; border-radius: 4px; background: var(--dn-card-bg); color: var(--dn-muted); border: 1px solid var(--dn-card-border); }
.dn-status { margin: 0; min-height: 2.7em; text-align: center; color: var(--dn-muted); font-size: .9rem; line-height: 1.35; }

.dn-record { margin: 14px 0 0; text-align: center; color: var(--dn-muted); font-size: .9rem; }
.dn-record:empty { display: none; }
.dn-reset-wrap { text-align: center; margin: 2px 0 10px; }
.dn-reset-wrap[hidden] { display: none; }
.dn-link { border: 0; background: none; padding: 6px; color: var(--dn-muted); font-size: .85rem; text-decoration: underline; cursor: pointer; }

/* ---- help ---- */
.dn-help { max-width: 760px; margin: 12px auto 0; padding: 12px 14px; border-radius: 14px; background: var(--dn-card-bg); border: 1px solid var(--dn-card-border); }
.dn-help summary { font-weight: 700; cursor: pointer; min-height: 32px; }
.dn-help ul { margin: 10px 0 4px; padding-left: 20px; line-height: 1.55; }
.dn-help li { margin-bottom: 4px; }
.dn-credit { margin: 8px 0 0; font-size: .82rem; color: var(--dn-muted); }
.dn-credit a, .dn-powered a { color: var(--dn-accent); }
.dn-powered { text-align: center; color: var(--dn-muted); font-size: .85rem; margin: 22px 0 0; }

/* ---- dialogs ---- */
.dn-overlay { position: fixed; inset: 0; z-index: 1060; display: flex; align-items: center; justify-content: center; padding: 16px; background: var(--dn-overlay); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); overflow-y: auto; }
.dn-overlay[hidden] { display: none; }
.dn-stage > .dn-overlay { position: absolute; z-index: 20; }
#dn-cover { background: rgba(10, 20, 30, .94); }
.dn-dialog { width: 100%; max-width: 400px; margin: auto; display: flex; flex-direction: column; gap: 10px; padding: 20px 16px; border-radius: 20px; background: var(--dn-card-bg); border: 1px solid var(--dn-card-border); box-shadow: var(--dn-shadow); color: var(--text-color); text-align: center; }
.dn-cover-card { max-width: 340px; }
.dn-dialog h2 { margin: 0; font-weight: 800; font-size: 1.4rem; }
.dn-dialog-sub { margin: 0; color: var(--dn-muted); font-size: .93rem; line-height: 1.4; }
.dn-dialog-sub:empty { display: none; }
.dn-dialog-icon { width: 56px; height: 56px; margin: 0 auto; border-radius: 50%; display: grid; place-items: center; font-size: 24px; color: #fff; background: linear-gradient(135deg, #1d4e89, #0f766e); }
.dn-final { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.dn-final li { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 12px; background: var(--dn-page-bg); font-weight: 700; text-align: left; }
.dn-final li .dn-n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dn-final li .dn-n small { display: block; color: var(--dn-muted); font-weight: 600; font-size: .76rem; white-space: normal; }
.dn-final li strong { font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.dn-final li .dn-plus { color: var(--dn-ok); font-weight: 800; font-size: .9rem; min-width: 3.2em; text-align: right; }
.dn-final li.is-win { background: linear-gradient(135deg, rgba(29, 78, 137, .2), rgba(15, 118, 110, .2)); }
.dn-dialog-actions { display: grid; gap: 8px; }

/* the players' bubbles from people4-3d.js (voices are off here, kept for completeness) */
.dn-stage .people-say { position: absolute; z-index: 4; transform: translateY(-50%); max-width: min(60%, 300px); padding: .35rem .75rem; border-radius: 14px; background: rgba(255, 255, 255, .95); color: #222; font-weight: 700; font-size: .9rem; pointer-events: none; }
.dn-stage .people-say[hidden] { display: none; }

@media (min-width: 900px) {
    .dn-stage { height: clamp(360px, calc(100vh - 372px), 620px); }
    .dn-tile { width: 44px; height: 86px; }
}
@media (max-width: 899px) {
    .dn-main { padding-top: 84px; }
    body.dn-playing .dn-main { padding-top: 10px; }
    .dn-stage { height: clamp(280px, calc(100svh - 405px), 520px); }
}
@media (max-width: 420px) {
    .dn-setup { padding: 12px; }
    .dn-seg button { font-size: .84rem; }
    .dn-chip { font-size: .92rem; }
    .dn-score { padding: 4px 6px; font-size: .8rem; }
    .dn-tile { width: 36px; height: 70px; }
    .dn-hand.is-many .dn-tile { width: 30px; height: 58px; }
}
@media (prefers-reduced-motion: reduce) {
    .dn-banner, .dn-tile { transition: none; }
    .dn-tile.is-new { animation: none; }
}
