/* Reversi (Othello) — on the 3D park table like Dame, against the phone or two on one phone (js/reversi.js).
   Theme-aware like the other game pages: tokens on :root, redefined under body.dark-theme. */
:root {
    --rv-accent: #15803d;
    --rv-accent-soft: #dcfce7;
    --rv-page-bg: #f5f8f4;
    --rv-card-bg: #ffffff;
    --rv-card-border: #dfe7dc;
    --rv-muted: #6b7280;
    --rv-shadow: 0 10px 30px rgba(20, 70, 40, .10);
    --rv-felt: #23804a;
    --rv-felt-dark: #1b6b3c;
    --rv-line: #0f3a22;
    --rv-frame: #5b3a22;
    --rv-hint: rgba(255, 216, 77, .95);
    --rv-last: rgba(250, 204, 21, .40);
}

body.dark-theme {
    --rv-accent: #4ade80;
    --rv-accent-soft: #14301f;
    --rv-page-bg: #111827;
    --rv-card-bg: #1f2937;
    --rv-card-border: #374151;
    --rv-muted: #9ca3af;
    --rv-shadow: 0 10px 30px rgba(0, 0, 0, .4);
    --rv-felt: #1d6e40;
    --rv-felt-dark: #175a34;
    --rv-line: #0a2716;
    --rv-frame: #2b1b10;
}

/* 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. */
.rv-body, body.rv-body#page-top {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    background: var(--rv-page-bg);
    color: var(--text-color);
    min-height: 100vh;
    overflow-x: clip;
}
.rv-main { padding-top: 100px; padding-bottom: 40px; }
.rv-game .container, .rv-hero .container { max-width: 600px; }

/* ---- hero ---- */
.rv-hero { text-align: center; padding: 4px 0 10px; }
.rv-hero h1 { font-weight: 800; font-size: clamp(1.6rem, 5vw, 2.3rem); margin: 0 0 6px; display: inline-flex; align-items: center; gap: 12px; }
.rv-hero-icon { width: 46px; height: 46px; border-radius: 14px; display: inline-grid; place-items: center; font-size: 22px; color: #fff; background: linear-gradient(135deg, #16a34a, #14532d); box-shadow: var(--rv-shadow); }
.rv-lead { max-width: 560px; margin: 0 auto; color: var(--rv-muted); font-size: 1rem; line-height: 1.55; }

/* ---- mode picker ---- */
.rv-modes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 5px; margin: 10px 0 8px; border-radius: 16px; background: var(--rv-card-bg); border: 1px solid var(--rv-card-border); }
.rv-mode { min-height: 52px; padding: 6px 8px; border: 0; border-radius: 12px; background: transparent; color: inherit; font-weight: 700; font-size: .95rem; line-height: 1.2; display: flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; touch-action: manipulation; text-align: left; }
.rv-mode small { display: block; font-weight: 500; font-size: .76rem; color: var(--rv-muted); }
.rv-mode[aria-checked="true"] { background: var(--rv-accent); color: #fff; }
.rv-mode[aria-checked="true"] small { color: rgba(255, 255, 255, .85); }
body.dark-theme .rv-mode[aria-checked="true"] { color: #0b2414; }
body.dark-theme .rv-mode[aria-checked="true"] small { color: rgba(11, 36, 20, .8); }
.rv-mode:focus-visible, .rv-chip:focus-visible { outline: 2px solid var(--rv-accent); outline-offset: 2px; }

/* ---- level and colour chips ---- */
.rv-opts { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; margin: 0 0 8px; }
.rv-opts[hidden] { display: none; }
.rv-chips { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; justify-content: center; }
.rv-chips-label { font-size: .85rem; font-weight: 600; color: var(--rv-muted); margin-right: 2px; }
.rv-chip { min-height: 40px; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--rv-card-border); background: var(--rv-card-bg); color: inherit; font-weight: 700; font-size: .9rem; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; touch-action: manipulation; }
.rv-chip[aria-checked="true"] { border-color: var(--rv-accent); background: var(--rv-accent-soft); color: var(--rv-accent); box-shadow: inset 0 0 0 1px var(--rv-accent); }

/* ---- turn ---- */
.rv-turn { display: flex; align-items: center; justify-content: center; gap: 12px; font-weight: 800; font-size: clamp(1.4rem, 6vw, 2rem); line-height: 1.15; text-align: center; margin: 4px 0 2px; min-height: 1.2em; }
.rv-turn-dot { width: .9em; height: .9em; border-radius: 50%; flex: none; box-shadow: 0 2px 4px rgba(0, 0, 0, .35); }
.rv-turn-dot.is-b, .rv-mini.is-b { background: radial-gradient(circle at 35% 30%, #5b5b62, #222226 55%, #0b0b0d); }
.rv-turn-dot.is-w, .rv-mini.is-w { background: radial-gradient(circle at 35% 30%, #ffffff, #f1eee4 55%, #cfc9b8); }
.rv-turn-dot.is-draw { background: linear-gradient(90deg, #222226 50%, #f1eee4 50%); }
.rv-turn.is-thinking #rv-turn-text::after { content: ""; display: inline-block; width: .9em; text-align: left; animation: rv-dots 1.2s steps(4) infinite; }
@keyframes rv-dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.rv-hint { min-height: 2.6em; margin: 0 0 6px; text-align: center; color: var(--rv-muted); font-size: .95rem; font-weight: 600; line-height: 1.3; display: flex; align-items: center; justify-content: center; }
.rv-hint.is-alert { color: #b45309; }
body.dark-theme .rv-hint.is-alert { color: #fbbf24; }

/* ---- 2D board (the fallback without WebGL) ---- */
.rv-board-wrap { position: relative; width: 100%; max-width: 560px; margin: 0 auto; }
.rv-board { position: relative; display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); grid-template-rows: repeat(8, minmax(0, 1fr)); gap: 2px; aspect-ratio: 1 / 1; width: 100%; padding: 2px; border: 8px solid var(--rv-frame); border-radius: 10px; box-shadow: var(--rv-shadow); background: var(--rv-line); user-select: none; -webkit-user-select: none; -webkit-tap-highlight-color: transparent; }
.rv-cell { position: relative; display: block; min-width: 0; min-height: 0; width: 100%; height: 100%; padding: 0; margin: 0; border: 0; border-radius: 0; background: radial-gradient(circle at 50% 40%, var(--rv-felt), var(--rv-felt-dark)); color: inherit; cursor: default; touch-action: manipulation; font: inherit; }
.rv-cell:focus { outline: none; }
.rv-cell:focus-visible { outline: 3px solid #38bdf8; outline-offset: -3px; z-index: 2; }
.rv-cell.is-last { background-image: linear-gradient(var(--rv-last), var(--rv-last)), radial-gradient(circle at 50% 40%, var(--rv-felt), var(--rv-felt-dark)); }
.rv-cell.is-legal { cursor: pointer; }
.rv-cell.is-hint::after { content: ""; position: absolute; left: 50%; top: 50%; width: 26%; height: 26%; transform: translate(-50%, -50%); border-radius: 50%; background: var(--rv-hint); box-shadow: 0 0 0 2px rgba(0, 0, 0, .18); pointer-events: none; }
@media (hover: hover) { .rv-cell.is-legal:hover::after { width: 70%; height: 70%; opacity: .45; } }
.rv-board.is-locked .rv-cell { cursor: default; }
.rv-dots4 { position: absolute; width: 7px; height: 7px; margin: -3.5px 0 0 -3.5px; border-radius: 50%; background: var(--rv-line); pointer-events: none; z-index: 1; }

/* discs */
.rv-disc { position: absolute; left: 8%; top: 8%; width: 84%; height: 84%; border-radius: 50%; pointer-events: none; will-change: transform; }
.rv-disc.is-b { background: radial-gradient(circle at 35% 30%, #63636b 0%, #2a2a2f 40%, #121214 75%, #050506 100%); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .4), 0 3px 5px rgba(0, 0, 0, .5); }
.rv-disc.is-w { background: radial-gradient(circle at 35% 30%, #ffffff 0%, #f5f2ea 45%, #d9d3c3 85%, #bfb8a5 100%); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, .12), 0 3px 5px rgba(0, 0, 0, .45); }
.rv-disc.is-new { animation: rv-land .26s ease-out; }
@keyframes rv-land { from { transform: scale(1.25); opacity: .4; } to { transform: scale(1); opacity: 1; } }
/* a disc turned over: shows its old colour until its turn, narrows to an edge, comes back the new colour */
.rv-disc.is-flip-b { animation: rv-to-b .36s ease-in-out both; }
.rv-disc.is-flip-w { animation: rv-to-w .36s ease-in-out both; }
@keyframes rv-to-b {
    0% { transform: scaleX(1); background: radial-gradient(circle at 35% 30%, #ffffff 0%, #f5f2ea 45%, #d9d3c3 85%, #bfb8a5 100%); }
    49.9% { transform: scaleX(.06) translateY(-6%); background: radial-gradient(circle at 35% 30%, #ffffff 0%, #f5f2ea 45%, #d9d3c3 85%, #bfb8a5 100%); }
    50% { transform: scaleX(.06) translateY(-6%); background: radial-gradient(circle at 35% 30%, #63636b 0%, #2a2a2f 40%, #121214 75%, #050506 100%); }
    100% { transform: scaleX(1); background: radial-gradient(circle at 35% 30%, #63636b 0%, #2a2a2f 40%, #121214 75%, #050506 100%); }
}
@keyframes rv-to-w {
    0% { transform: scaleX(1); background: radial-gradient(circle at 35% 30%, #63636b 0%, #2a2a2f 40%, #121214 75%, #050506 100%); }
    49.9% { transform: scaleX(.06) translateY(-6%); background: radial-gradient(circle at 35% 30%, #63636b 0%, #2a2a2f 40%, #121214 75%, #050506 100%); }
    50% { transform: scaleX(.06) translateY(-6%); background: radial-gradient(circle at 35% 30%, #ffffff 0%, #f5f2ea 45%, #d9d3c3 85%, #bfb8a5 100%); }
    100% { transform: scaleX(1); background: radial-gradient(circle at 35% 30%, #ffffff 0%, #f5f2ea 45%, #d9d3c3 85%, #bfb8a5 100%); }
}
@media (prefers-reduced-motion: reduce) { .rv-disc.is-new, .rv-disc.is-flip-b, .rv-disc.is-flip-w { animation-duration: .01s; } }

/* ---- game over ---- */
.rv-over { position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, .35); border-radius: 10px; z-index: 10; animation: rv-fade .25s ease-out; }
.rv-over[hidden] { display: none; }
@keyframes rv-fade { from { opacity: 0; } to { opacity: 1; } }
.rv-over-card { width: min(320px, 100%); padding: 20px 18px 18px; border-radius: 18px; background: var(--rv-card-bg); color: var(--text-color); text-align: center; box-shadow: 0 20px 50px rgba(0, 0, 0, .45); }
.rv-over-icon { width: 54px; height: 54px; margin: 0 auto 8px; border-radius: 50%; display: grid; place-items: center; font-size: 24px; color: #fff; background: linear-gradient(135deg, #22c55e, #166534); }
.rv-over-card h2 { font-size: 1.45rem; font-weight: 800; margin: 0 0 4px; }
.rv-over-card p { margin: 0 0 14px; color: var(--rv-muted); }
.rv-over-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }

/* ---- disc count ---- */
.rv-count { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 10px; max-width: 560px; margin: 12px auto 0; padding: 10px 12px; border-radius: 16px; background: var(--rv-card-bg); border: 1px solid var(--rv-card-border); box-shadow: var(--rv-shadow); }
.rv-count-side { display: flex; align-items: center; gap: 7px; font-weight: 700; }
.rv-count-side.is-turn .rv-count-name { color: var(--rv-accent); text-decoration: underline; text-underline-offset: 4px; }
.rv-mini { display: inline-block; width: 18px; height: 18px; border-radius: 50%; box-shadow: 0 1px 2px rgba(0, 0, 0, .4); flex: none; }
.rv-chip .rv-mini { width: 14px; height: 14px; }
.rv-count-num { font-size: 1.6rem; font-weight: 800; line-height: 1; min-width: 1.4em; text-align: center; font-variant-numeric: tabular-nums; }
.rv-count-bar { height: 10px; border-radius: 999px; background: #ece8dc; overflow: hidden; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12); }
body.dark-theme .rv-count-bar { background: #d6d1c4; }
.rv-count-fill { display: block; height: 100%; width: 50%; background: #1e1e22; transition: width .35s ease; }

/* ---- buttons ---- */
.rv-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px auto 10px; max-width: 560px; }
.rv-btn { min-height: 48px; padding: 8px 14px; border-radius: 12px; border: 1px solid var(--rv-card-border); background: var(--rv-card-bg); color: inherit; font-weight: 700; font-size: .98rem; display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; touch-action: manipulation; box-shadow: 0 2px 6px rgba(0, 0, 0, .05); }
.rv-btn:hover:not(:disabled) { border-color: var(--rv-accent); }
.rv-btn:disabled { opacity: .45; cursor: not-allowed; }
.rv-btn:focus-visible { outline: 2px solid var(--rv-accent); outline-offset: 2px; }
.rv-btn-primary { background: var(--rv-accent); border-color: var(--rv-accent); color: #fff; }
body.dark-theme .rv-btn-primary { color: #0b2414; }
.rv-link { border: 0; background: none; padding: 4px 6px; color: var(--rv-muted); font-size: .85rem; text-decoration: underline; cursor: pointer; }

/* ---- switches ---- */
.rv-switches { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 22px; margin: 0 auto 12px; }
.rv-switch { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 600; cursor: pointer; user-select: none; }
.rv-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.rv-switch-track { position: relative; width: 46px; height: 26px; flex: none; border-radius: 999px; background: var(--rv-card-border); transition: background .15s; }
.rv-switch-track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .15s; }
.rv-switch input:checked + .rv-switch-track { background: var(--rv-accent); }
.rv-switch input:checked + .rv-switch-track::after { transform: translateX(20px); }
.rv-switch input:focus-visible + .rv-switch-track { outline: 2px solid var(--rv-accent); outline-offset: 2px; }

/* ---- score ---- */
.rv-score { max-width: 560px; margin: 0 auto 12px; padding: 12px 12px 4px; border-radius: 16px; background: var(--rv-card-bg); border: 1px solid var(--rv-card-border); box-shadow: var(--rv-shadow); text-align: center; }
.rv-score-title { font-size: .85rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--rv-muted); margin: 0 0 6px; }
.rv-score-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.rv-score-cell { display: flex; flex-direction: column; align-items: center; }
.rv-score-cell strong { font-size: 1.9rem; font-weight: 800; line-height: 1.1; font-variant-numeric: tabular-nums; }
.rv-score-cell span { color: var(--rv-muted); font-size: .82rem; }
.rv-score-best { margin: 6px 0 0; color: var(--rv-muted); font-size: .85rem; min-height: 1.2em; }
.rv-reset-wrap { text-align: center; margin: 2px 0 4px; }

/* ---- help ---- */
.rv-help { max-width: 560px; margin: 0 auto; padding: 12px 14px; border-radius: 14px; background: var(--rv-card-bg); border: 1px solid var(--rv-card-border); }
.rv-help summary { font-weight: 700; cursor: pointer; min-height: 32px; display: list-item; }
.rv-help ul { margin: 10px 0 8px; padding-left: 20px; line-height: 1.55; }
.rv-help p { margin: 0; color: var(--rv-muted); font-size: .93rem; }
.rv-powered { text-align: center; color: var(--rv-muted); font-size: .85rem; margin: 22px 0 0; }
.rv-powered a { color: var(--rv-accent); }

@media (max-width: 420px) {
    .rv-main { padding-top: 92px; }
    .rv-mode { font-size: .88rem; gap: 6px; padding: 6px; }
    .rv-btn { font-size: .9rem; padding: 8px 10px; }
    .rv-board { border-width: 5px; gap: 1px; padding: 1px; }
    .rv-chip { padding: 4px 10px; }
}

/* ---- the 3D park table (shared with Șah and Dame): the players at a stone table, the discs by hand ---- */
.rv-board-wrap.is-3d { max-width: 980px; }
.rv-board-wrap.is-3d > .rv-board { display: none; }
.rv-board3d { position: relative; width: 100%; aspect-ratio: 16 / 10; border-radius: 10px; overflow: hidden; background: #bcd8ec; box-shadow: var(--rv-shadow); }
.rv-board3d[hidden] { display: none; }
@media (max-width: 575.98px) { .rv-board3d { aspect-ratio: 1 / 1; } }
.rv-view-btns { position: absolute; top: 6px; left: 6px; z-index: 6; display: flex; gap: 6px; }
.rv-view-btns[hidden] { display: none; }
.rv-view-btn { width: 40px; height: 40px; border: 0; border-radius: 8px; display: grid; place-items: center; background: rgba(0, 0, 0, .55); color: #fff; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.rv-view-btn.on { background: #1abc9c; color: #0d1f1a; }
.board-voice-btn { position: absolute; top: 6px; right: 6px; z-index: 5; width: 40px; height: 40px; border: 0; border-radius: 8px; display: grid; place-items: center;
    background: rgba(0, 0, 0, 0.55); color: #fff; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.board-voice-btn:active { transform: scale(0.92); }
.people-say { position: absolute; z-index: 4; transform: translateY(-50%); max-width: min(70%, 320px); padding: 0.35rem 0.75rem; border-radius: 14px;
    background: rgba(255, 255, 255, 0.95); color: #222; font-weight: 700; font-size: 0.95rem; line-height: 1.25; text-align: center; pointer-events: none;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25); }
.rv-board-wrap .people-say { z-index: 7; }   /* (over the view buttons: the words stay readable, taps pass through) */
.people-say[hidden] { display: none; }
.people-say::after { content: ''; position: absolute; right: 100%; top: 50%; transform: translateY(-50%); border: 7px solid transparent; border-right-color: rgba(255, 255, 255, 0.95); }
.people-say.flip::after { right: auto; left: 100%; border-right-color: transparent; border-left-color: rgba(255, 255, 255, 0.95); }
.people-say.me { top: auto; bottom: 62px; transform: translateX(-50%); background: rgba(20, 30, 20, 0.82); color: #fff; }
.people-say.me::after { display: none; }

/* full screen: the table fills the screen (a CSS fallback where the browser has no element full screen, as on iPhone) */
.rv-board-wrap.is-fs { position: fixed; inset: 0; z-index: 2000; max-width: none; width: 100vw; height: 100vh; height: 100dvh; margin: 0; background: #0d1117; }
.rv-board-wrap:fullscreen { max-width: none; width: 100vw; height: 100vh; background: #0d1117; }
.rv-board-wrap.is-fs > .rv-board3d, .rv-board-wrap:fullscreen > .rv-board3d { width: 100%; height: 100%; aspect-ratio: auto; border-radius: 0; }
.rv-board-wrap.is-fs > .rv-board, .rv-board-wrap:fullscreen > .rv-board { width: min(100vw, 100vh); margin: auto; }
body.rv-fs-lock { overflow: hidden; }
