/* Othello Variants - warm dark premium theme. Text contrast >= WCAG AA. */
:root {
  --bg: #16110d;
  --bg-2: #211a14;
  --surface: #2a221a;
  --surface-2: #362b21;
  --glass: linear-gradient(160deg, rgba(255, 238, 205, .075), rgba(255, 238, 205, .02));
  --line: #4b3f32;
  --line-soft: rgba(255, 232, 190, .12);
  --text: #f7eddc;
  --muted: #c9b79f;
  --accent: #f0b35a;
  --accent-2: #ffd48f;
  --accent-ink: #20140a;
  --accent-soft: rgba(240, 179, 90, .16);
  --danger: #ff9a86;
  --ok: #9fdc9a;
  --shadow: 0 10px 30px rgba(0, 0, 0, .38), 0 1px 0 rgba(255, 240, 210, .05) inset;
  --shadow-lg: 0 24px 70px rgba(0, 0, 0, .65);
  /* read by board-view.mjs */
  --board: #1f6b4a;
  --board-line: #0e3f2b;
  --disc-black: #17171b;
  --disc-white: #f3efe4;
  --hint: #7ee8fa;
  --wall: #5b5650;
  --radius: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  color-scheme: dark;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background:
    radial-gradient(900px 520px at 50% -8%, rgba(240, 179, 90, .17) 0%, transparent 70%),
    radial-gradient(700px 500px at 100% 100%, rgba(31, 107, 74, .16) 0%, transparent 70%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 400 16px/1.5 var(--font);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }
.skip { position: absolute; left: 8px; top: -60px; background: var(--accent); color: var(--accent-ink); padding: 10px 14px; border-radius: 8px; z-index: 100; }
.skip:focus { top: 8px; }
h1, h2, h3 { margin: 0; font-family: var(--serif); font-weight: 700; letter-spacing: .01em; }
p { margin: 0; }

:focus { outline: none; }
:focus-visible { outline: 3px solid var(--accent-2); outline-offset: 2px; border-radius: 10px; }

#app { min-height: 100%; }
.screen { min-height: 100vh; min-height: 100dvh; }

/* ---------- buttons ---------- */
.btn, .toggle {
  font: 600 15px/1.2 var(--font);
  min-height: 46px; min-width: 46px;
  padding: 10px 18px;
  color: var(--text);
  background: linear-gradient(180deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line);
  border-radius: 13px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, .25), 0 1px 0 rgba(255, 240, 210, .06) inset;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s, border-color .15s, transform .08s, box-shadow .15s;
}
.btn:hover:not(:disabled), .toggle:hover { border-color: #8a7458; background: linear-gradient(180deg, #43362a, var(--surface-2)); }
.btn:active:not(:disabled), .toggle:active { transform: translateY(1px); box-shadow: 0 0 0 rgba(0, 0, 0, .25); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  border-color: #f7c47c; color: var(--accent-ink);
  box-shadow: 0 6px 18px rgba(240, 179, 90, .28), 0 1px 0 rgba(255, 255, 255, .5) inset;
}
.btn.primary:hover:not(:disabled) { background: linear-gradient(180deg, #ffe0aa, #f5bd6e); border-color: #ffe0aa; }
.btn.big { min-height: 54px; font-size: 17px; padding: 12px 24px; letter-spacing: .01em; }
.btn.compact, .toggle.compact { padding: 8px 12px; font-size: 14px; min-height: 44px; }
.btn.confirm { background: linear-gradient(180deg, #7d332a, #6b2b22); border-color: var(--danger); }
.ic { font-size: 17px; line-height: 1; }

.toggle { gap: 10px; justify-content: space-between; }
.toggle .ts {
  position: relative; font-size: 12px; font-weight: 700; padding: 3px 10px 3px 26px; border-radius: 99px;
  background: #110d09; color: var(--muted); border: 1px solid var(--line); min-width: 62px; text-align: right;
}
.toggle .ts::before {
  content: ""; position: absolute; left: 4px; top: 50%; width: 14px; height: 14px; margin-top: -7px; border-radius: 50%;
  background: var(--muted); transition: transform .18s, background .18s;
}
.toggle[aria-pressed="true"] { border-color: var(--accent); background: linear-gradient(180deg, var(--accent-soft), rgba(240, 179, 90, .06)); }
.toggle[aria-pressed="true"] .ts { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); padding: 3px 26px 3px 10px; text-align: left; }
.toggle[aria-pressed="true"] .ts::before { left: auto; right: 4px; background: var(--accent-ink); }
.toggle.compact .ts { display: none; }
.toggle.compact[aria-pressed="false"] { color: var(--muted); }

/* ---------- menu ---------- */
.menu { display: flex; justify-content: center; padding: calc(var(--sat) + 14px) calc(var(--sar) + 16px) 0 calc(var(--sal) + 16px); }
.menu-inner { width: 100%; max-width: 1000px; display: flex; flex-direction: column; gap: 22px; min-height: calc(100vh - 14px); min-height: calc(100dvh - 14px - var(--sat)); }
.menu-head { text-align: center; padding-top: 6px; }
.menu-head h1 { font-size: clamp(34px, 8vw, 64px); line-height: 1.05; letter-spacing: .02em; }
.menu-head h1 em {
  font-style: italic;
  background: linear-gradient(100deg, var(--accent) 0%, #fff0cf 35%, var(--accent) 60%, #d98f2f 100%);
  background-size: 220% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-fill-color: transparent;
  animation: shimmer 9s ease-in-out infinite alternate;
}
@keyframes shimmer { from { background-position: 0% 0; } to { background-position: 100% 0; } }
.menu-head h1::after {
  content: ""; display: block; width: 84px; height: 2px; margin: 12px auto 0; border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}
.tagline { color: var(--muted); margin: 10px auto 0; font-size: 16px; max-width: 46ch; }
.sec-title { font-size: 20px; margin-bottom: 12px; display: flex; align-items: center; gap: 10px; }
.sec-title .num {
  width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center; font: 700 14px var(--font);
  background: linear-gradient(180deg, var(--accent-2), var(--accent)); color: var(--accent-ink);
  box-shadow: 0 2px 8px rgba(240, 179, 90, .3);
}

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr)); gap: 12px; }
.card {
  display: grid; grid-template-columns: 84px 1fr; gap: 14px; align-items: center; text-align: left;
  padding: 12px; min-height: 108px; width: 100%;
  background: var(--glass), var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: var(--text); font: inherit; cursor: pointer; touch-action: manipulation;
  transition: border-color .15s, background .15s, transform .15s, box-shadow .15s;
}
.card:hover { border-color: #8a7458; transform: translateY(-2px); }
.card[aria-checked="true"] {
  border-color: var(--accent);
  background: linear-gradient(160deg, rgba(240, 179, 90, .22), rgba(240, 179, 90, .05)), var(--surface);
  box-shadow: 0 0 0 1px var(--accent) inset, 0 10px 28px rgba(240, 179, 90, .14);
}
.card canvas { width: 84px; height: 84px; border-radius: 10px; display: block; box-shadow: 0 4px 12px rgba(0, 0, 0, .5); }
.card .nm { display: block; font: 700 17px/1.25 var(--serif); }
.card .bl { display: block; color: var(--muted); font-size: 14px; line-height: 1.35; margin-top: 2px; }
.card .st { display: block; color: var(--accent); font-size: 12.5px; margin-top: 4px; }

.opts {
  display: flex; flex-direction: column; gap: 14px; padding: 18px;
  background: var(--glass), var(--bg-2); border: 1px solid var(--line-soft); border-radius: 20px; box-shadow: var(--shadow);
}
.opts .sec-title { margin-bottom: 0; }
.field { display: grid; grid-template-columns: 120px 1fr; gap: 10px 16px; align-items: center; }
.lbl { font-weight: 600; color: var(--muted); }
.seg { display: flex; gap: 6px; padding: 4px; background: rgba(0, 0, 0, .28); border-radius: 15px; border: 1px solid var(--line-soft); }
.seg.wrap { flex-wrap: wrap; }
.seg [role="radio"] {
  flex: 1 1 0; min-height: 44px; padding: 8px 12px; font: 600 15px var(--font); color: var(--text);
  background: transparent; border: 1px solid transparent; border-radius: 11px; cursor: pointer; touch-action: manipulation;
  transition: background .15s, color .15s;
}
.seg.wrap [role="radio"] { flex: 1 1 88px; }
.seg [role="radio"]:hover { background: rgba(255, 238, 205, .08); }
.seg [role="radio"][aria-checked="true"] {
  background: linear-gradient(180deg, var(--accent-2), var(--accent)); color: var(--accent-ink);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .35);
}
.toggles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 190px), 1fr)); gap: 10px; }
.foot { color: var(--muted); font-size: 12.5px; text-align: center; padding: 4px 8px 0; }
.start-row {
  position: sticky; bottom: 0; z-index: 5; margin: auto -16px 0; padding: 14px 16px calc(var(--sab) + 14px);
  display: flex; gap: 12px;
  background: linear-gradient(to bottom, transparent, rgba(22, 17, 13, .86) 28%, rgba(22, 17, 13, .97));
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.start-row .primary { flex: 1 1 auto; }
.start-row .btn:not(.primary) { flex: 0 0 auto; min-width: 96px; }

/* ---------- help ---------- */
.help { display: flex; justify-content: center; padding: calc(var(--sat) + 10px) calc(var(--sar) + 16px) calc(var(--sab) + 40px) calc(var(--sal) + 16px); }
.help-inner { width: 100%; max-width: 760px; }
.help-top { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; position: sticky; top: 0; background: linear-gradient(var(--bg) 72%, transparent); padding: 8px 0 14px; z-index: 2; }
.help-top h1 { font-size: 28px; }
.help-body h2 { font-size: 22px; margin: 26px 0 8px; color: var(--accent); }
.help-body p, .help-body li { color: var(--text); }
.help-body ul { padding-left: 22px; margin: 6px 0; }
.help-body li { margin: 4px 0; }
.help-body .vr { background: var(--glass), var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 12px 14px; margin: 10px 0; }
.help-body .vr h3 { font-size: 18px; margin-bottom: 4px; }
.help-body kbd { font: 600 13px var(--font); background: #110d09; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 6px; padding: 1px 7px; }

/* ---------- game ---------- */
.game {
  --pad: 12px;
  height: 100vh; height: 100dvh; min-height: 0; overflow: hidden;
  display: grid; gap: 8px;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "hud" "board" "actions";
  padding: calc(var(--sat) + 8px) calc(var(--sar) + var(--pad)) calc(var(--sab) + 10px) calc(var(--sal) + var(--pad));
  max-width: 1600px; margin: 0 auto;
}
.hud { grid-area: hud; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.hud-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.vname { font-size: 21px; line-height: 1.15; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.tools { display: flex; gap: 6px; flex-shrink: 0; }
.scores { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.score {
  position: relative; display: flex; align-items: center; gap: 10px; padding: 6px 12px; min-height: 52px; min-width: 0;
  background: var(--glass), var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow);
  transition: border-color .25s, box-shadow .25s, background .25s;
}
.score.active {
  border-color: var(--accent);
  background: linear-gradient(160deg, rgba(240, 179, 90, .24), rgba(240, 179, 90, .05)), var(--surface);
  box-shadow: 0 0 0 1px var(--accent) inset, 0 0 22px rgba(240, 179, 90, .28);
}
.score .who { flex: 1; font-weight: 700; line-height: 1.15; min-width: 0; }
.score .who small { display: block; font-weight: 500; font-size: 12.5px; color: var(--muted); }
.score .who small:empty { display: none; }
.score b { font: 700 30px/1 var(--serif); font-variant-numeric: tabular-nums; }
.disc { width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center; flex-shrink: 0; box-shadow: 0 2px 5px rgba(0, 0, 0, .55); }
.disc.black { background: radial-gradient(circle at 35% 30%, #5a5a64, var(--disc-black) 62%); border: 1px solid #000; }
.disc.white { background: radial-gradient(circle at 35% 30%, #fff, var(--disc-white) 65%, #cfc8b5); border: 1px solid #a89f8a; }
.statusline { position: relative; min-height: 38px; display: grid; align-items: center; }
.turn { font-weight: 600; font-size: 16px; line-height: 1.25; text-align: center; padding: 2px 4px; }
.turn.thinking::after { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-left: 8px; animation: pulse 1s infinite ease-in-out; }
@keyframes pulse { 0%, 100% { opacity: .25; transform: scale(.8); } 50% { opacity: 1; transform: scale(1.2); } }
.banner {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center;
  background: #3a2a16; border: 1px solid var(--accent); color: var(--text); border-radius: 12px;
  padding: 2px 10px; font: 600 14px/1.2 var(--font); z-index: 2; box-shadow: var(--shadow);
}
.board-wrap { grid-area: board; display: flex; min-height: 0; min-width: 0; }
.board-host { flex: 1; min-width: 0; min-height: 0; position: relative; }
.actions {
  grid-area: actions; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px;
  padding: 8px; background: var(--glass), rgba(0, 0, 0, .25); border: 1px solid var(--line-soft); border-radius: 20px;
}
.actions .btn { padding: 6px 4px; flex-direction: column; gap: 2px; font-size: 13.5px; min-height: 52px; }
.actions .ic { font-size: 18px; }

/* short portrait phones */
@media (max-height: 640px) {
  .game { gap: 6px; }
  .vname { font-size: 18px; }
  .score { min-height: 46px; padding: 4px 10px; }
  .score b { font-size: 26px; }
  .disc { width: 24px; height: 24px; }
  .statusline { min-height: 34px; }
  .turn { font-size: 15px; }
  .actions { padding: 6px; gap: 6px; }
  .actions .btn { min-height: 48px; font-size: 13px; }
}
@media (max-width: 380px) { .vname { font-size: 17px; } .tools .compact { padding: 8px 8px; } .score .who { font-size: 14px; } }

/* landscape / wide: board left, panel right */
@media (orientation: landscape) and (min-width: 640px) {
  .game {
    --panel: clamp(250px, 32vw, 400px); --pad: 18px;
    grid-template-columns: minmax(0, 1fr) var(--panel);
    grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "board hud" "board actions";
    gap: 10px 18px;
  }
  .hud { align-self: start; gap: 8px; }
  .hud-top { flex-wrap: wrap; }
  .vname { flex: 1 1 100%; font-size: 24px; order: 2; white-space: normal; }
  .tools { order: 1; margin-left: auto; }
  .scores { grid-template-columns: 1fr; }
  .score { min-height: 56px; }
  .actions { align-self: end; grid-template-columns: 1fr 1fr; }
  .actions .btn { flex-direction: row; font-size: 15px; min-height: 48px; gap: 8px; }
}
/* landscape phones: very little height */
@media (orientation: landscape) and (max-height: 520px) {
  .game { gap: 6px 14px; padding-top: calc(var(--sat) + 6px); padding-bottom: calc(var(--sab) + 6px); }
  .hud { gap: 5px; }
  .hud-top { gap: 4px; }
  .vname { font-size: 17px; }
  .scores { grid-template-columns: 1fr 1fr; gap: 6px; }
  .score { min-height: 44px; padding: 3px 8px; gap: 6px; }
  .score b { font-size: 22px; }
  .disc { width: 20px; height: 20px; }
  .score .who small { display: none; }
  .statusline { min-height: 34px; }
  .turn { font-size: 14px; }
  .actions { padding: 5px; gap: 5px; }
  .actions .btn { min-height: 44px; font-size: 14px; }
}
/* tablets and big screens: roomier */
@media (min-width: 700px) and (min-height: 700px) {
  .game { --pad: 22px; gap: 12px; }
  .vname { font-size: 26px; }
  .score { min-height: 64px; padding: 8px 16px; }
  .score b { font-size: 36px; }
  .disc { width: 32px; height: 32px; }
  .turn { font-size: 18px; }
  .statusline { min-height: 44px; }
  .actions .btn { min-height: 60px; font-size: 15px; }
  .actions .ic { font-size: 20px; }
  .btn.compact, .toggle.compact { font-size: 15px; padding: 8px 16px; }
}
@media (orientation: landscape) and (min-width: 640px) and (min-height: 700px) {
  .game { --panel: clamp(300px, 30vw, 440px); }
  .hud { gap: 12px; padding: 18px; background: var(--glass), var(--bg-2); border: 1px solid var(--line-soft); border-radius: 22px; box-shadow: var(--shadow); }
  .actions .btn { min-height: 56px; }
}
@media (max-width: 560px) {
  .field { grid-template-columns: 1fr; gap: 6px; }
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card { grid-template-columns: 1fr; justify-items: start; align-content: start; align-items: start; gap: 8px; min-height: 0; padding: 10px; }
  .card canvas { width: 100%; height: auto; aspect-ratio: 1; max-width: 120px; }
  .card .bl { font-size: 13px; }
  .opts { padding: 14px; }
}
@media (max-width: 340px) { .cards { grid-template-columns: 1fr; } .card { grid-template-columns: 64px 1fr; align-items: center; } .card canvas { width: 64px; } }
@media (max-height: 520px) and (orientation: landscape) {
  .menu-head h1 { font-size: 30px; }
  .menu-head h1::after, .tagline { display: none; }
  .menu-inner { gap: 14px; }
  .start-row { padding-top: 8px; padding-bottom: calc(var(--sab) + 8px); }
}

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  padding: calc(var(--sat) + 12px) calc(var(--sar) + 12px) calc(var(--sab) + 12px) calc(var(--sal) + 12px);
  background: rgba(10, 7, 4, .78); -webkit-backdrop-filter: blur(5px); backdrop-filter: blur(5px);
}
.panel {
  width: 100%; max-width: 440px; max-height: 100%; overflow: auto; overscroll-behavior: contain;
  background: var(--glass), var(--bg-2); border: 1px solid rgba(255, 232, 190, .18); border-radius: 24px;
  padding: 24px 22px; box-shadow: var(--shadow-lg); animation: pop .24s ease-out;
}
@keyframes pop { from { transform: translateY(12px) scale(.97); opacity: 0; } to { transform: none; opacity: 1; } }
.panel h2 { font-size: 28px; text-align: center; margin-bottom: 16px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.toggles.in-panel { margin-top: 18px; grid-template-columns: 1fr; }
.result { text-align: center; position: relative; overflow-x: hidden; }
.result::before {
  content: ""; position: absolute; left: 50%; top: -90px; width: 300px; height: 200px; margin-left: -150px; pointer-events: none;
  background: radial-gradient(closest-side, rgba(240, 179, 90, .28), transparent);
}
.kicker { color: var(--accent); font-weight: 700; letter-spacing: .16em; text-transform: uppercase; font-size: 12.5px; position: relative; }
.result h2 { margin: 6px 0 6px; font-size: 36px; position: relative; }
.bigscore {
  font: 700 52px/1.1 var(--serif); font-variant-numeric: tabular-nums; margin: 4px 0 6px; position: relative;
  background: linear-gradient(180deg, #fff0cf, var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-fill-color: transparent;
}
.note { color: var(--muted); font-size: 14.5px; margin-bottom: 4px; position: relative; }
.stats { color: var(--text); font-size: 14px; background: rgba(0, 0, 0, .28); border: 1px solid var(--line-soft); border-radius: 12px; padding: 8px 12px; margin: 12px 0 18px; position: relative; }
.stats:empty { display: none; }
@media (max-height: 560px) {
  .panel { padding: 16px; }
  .panel h2 { font-size: 22px; margin-bottom: 10px; }
  .result h2 { font-size: 26px; }
  .bigscore { font-size: 36px; }
  .stack { gap: 8px; }
  .stats { margin: 8px 0 12px; }
  .toggles.in-panel { margin-top: 12px; }
}
@media (max-height: 460px) and (orientation: landscape) {
  .panel { max-width: 600px; }
  .panel .stack { display: grid; grid-template-columns: 1fr 1fr; }
  .result .stack .primary { grid-column: 1 / -1; }
  .toggles.in-panel { grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
  .toggles.in-panel .toggle { padding: 8px; font-size: 13px; }
  .toggles.in-panel .ts { display: none; }
}

/* ---------- reduced motion (system default or in-game option) ---------- */
body.reduce *, body.reduce *::before, body.reduce *::after { animation: none !important; transition: none !important; }
@media (prefers-reduced-motion: reduce) {
  .menu-head h1 em, .panel, .turn.thinking::after { animation: none; }
  .btn, .toggle, .card, .score { transition: none; }
}
