:root {
  --bg: #E6F3F7;
  --surface: #FFFFFF;
  --surface-2: #FFF1D6;
  --ink: #2A1E14;
  --ink-soft: #6B5640;
  --line: #E5D0A6;
  --fort: #B8692A;
  --fort-deep: #7E4718;
  --palm: #2B7F48;
  --palm-deep: #1C5A32;
  --falaj: #13879A;
  --flag: #CC2638;
  --flag-deep: #8E1724;
  --sun: #F5B731;
  --ok-bg: #E1F3E6; --ok-fg: #1C5A32;
  --no-bg: #FDE6E3; --no-fg: #8E1724;
  --scrim: rgba(28, 18, 8, .55);
  --shadow: rgba(78, 52, 24, .18);
  --on-accent: #FFFFFF;
  --hud: #1B2A4A; --hud-ink: #FFFFFF;
  --w-blue: #1E63C4; --w-blue-deep: #123F80;
  --w-green: #2E8B3E; --w-green-deep: #1C5A28;
  --w-purple: #6B3FA0; --w-purple-deep: #452670;
  --w-orange: #E07A1F; --w-orange-deep: #9A4E0C;
  --t-green: #2E9B3E; --t-orange: #F07A12; --t-blue: #1D5FB8;
  --lv-easy: #2F8A4F; --lv-mid: #D98A0B; --lv-hard: #CC2638;
  --mark: #E0312F;
  --font-display: "Lalezar", "Baloo Bhaijaan 2", "Segoe UI", Tahoma, sans-serif;
  --font-body: "Baloo Bhaijaan 2", "Segoe UI", Tahoma, Arial, sans-serif;
  --r: 20px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1F33; --surface: #17304A; --surface-2: #1F3B57; --ink: #F6EAD6; --ink-soft: #BFCBD7; --line: #2E4D6C;
    --fort: #D9853F; --fort-deep: #8C4C16; --palm: #3FA765; --palm-deep: #23663B; --falaj: #2BB2C6; --flag: #E5485A; --flag-deep: #95202E; --sun: #F7C74F;
    --ok-bg: #173F2A; --ok-fg: #BDEBCB; --no-bg: #4A1D24; --no-fg: #FFD1D6; --scrim: rgba(3, 8, 16, .7); --shadow: rgba(0, 0, 0, .45);
    --hud: #0A1424; --hud-ink: #FFFFFF;
    --w-blue: #3D86E8; --w-blue-deep: #1D4F96; --w-green: #43A853; --w-green-deep: #24692F; --w-purple: #8A60C4; --w-purple-deep: #54327F; --w-orange: #F08F38; --w-orange-deep: #A35710;
    --t-green: #55C565; --t-orange: #FF9A3D; --t-blue: #6AA8F5;
    --lv-easy: #3FA765; --lv-mid: #E39D24; --lv-hard: #E5485A; --mark: #FF5A52;
    color-scheme: dark;
  }
}
.row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; }
.row.tight { gap: 6px; }
.row.start { justify-content: flex-start; }

/* ---------- buttons ---------- */
.btn {
  border: 0; border-radius: 999px; padding: .6em 1.2em; font-weight: 700; font-size: 1.05rem;
  background: var(--surface); color: var(--ink);
  box-shadow: 0 4px 0 var(--line), 0 8px 18px var(--shadow);
  transition: transform .12s, box-shadow .12s;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line), 0 4px 10px var(--shadow); }
.btn.primary { background: var(--fort); color: var(--on-accent); box-shadow: 0 5px 0 var(--fort-deep), 0 10px 20px var(--shadow); }
.btn.primary:active { box-shadow: 0 2px 0 var(--fort-deep); }
[class*="hue-"] .btn.primary { background: var(--w); box-shadow: 0 5px 0 var(--w-deep), 0 10px 20px var(--shadow); }
.btn.danger { background: var(--flag); color: var(--on-accent); box-shadow: 0 5px 0 var(--flag-deep); }
.btn.big { font-size: 1.25rem; padding: .7em 1.5em; }
.btn.small { font-size: .95rem; padding: .45em 1em; }
.btn[disabled] { opacity: .5; }
.btn[aria-pressed="true"] { background: var(--falaj); color: var(--on-accent); box-shadow: 0 3px 0 var(--palm-deep); }
.fld { display: grid; grid-template-columns: 6em minmax(0, 1fr); align-items: center; gap: 10px; font-weight: 800; }
.fld input { width: 100%; font: inherit; font-size: 1.1rem; padding: .45em .8em; border-radius: 14px; border: 3px solid var(--line); background: var(--surface); color: var(--ink); }
.fld input:focus { border-color: var(--falaj); outline: none; }
@media (max-width: 520px) { .fld { grid-template-columns: 1fr; gap: 4px; } }
.act-body.act-xo { display: grid; grid-template-columns: minmax(300px, 1fr) minmax(0, 1.15fr); gap: 18px; align-items: start; padding: 10px 16px 8px; }
.xo-play { display: grid; justify-items: center; gap: 8px; min-width: 0; }
.xo-players { display: flex; gap: 8px; align-items: stretch; justify-content: center; width: 100%; max-width: 520px; }
.xo-card { flex: 1 1 0; min-width: 0; display: flex; align-items: center; gap: 6px; padding: 4px 12px 4px 8px; border-radius: 18px; background: var(--surface); border: 3px solid var(--line); box-shadow: 0 4px 0 var(--line); transition: border-color .2s, box-shadow .2s; }
.xo-card.turn { border-color: var(--sun); box-shadow: 0 4px 0 #E0A21A, 0 0 0 4px rgba(245, 183, 49, .3); }
.xo-card canvas { flex: none; }
.xo-face { flex: none; width: 58px; text-align: center; font-size: 2.1rem; line-height: 72px; }
.xo-who { display: grid; min-width: 0; line-height: 1.2; }
.xo-who strong { font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xo-mark { font-family: 'Baloo Bhaijaan 2', Tahoma, sans-serif; font-weight: 800; font-size: 1.5rem; line-height: 1; }
.xo-mark.x { color: #2D6A3E; } .xo-mark.o { color: #C23A2E; }
.xo-pts { margin-inline-start: auto; font-size: 2rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.xo-draws { flex: none; align-self: center; display: grid; justify-items: center; font-weight: 800; color: var(--ink-soft); font-size: .9rem; }
.xo-draws b { font-size: 1.3rem; color: var(--ink); }
.xo-status { margin: 0; min-height: 1.5em; font-weight: 800; font-size: 1.2rem; text-align: center; }
.xo-frame { --b: 16px; padding: calc(var(--b) + 8px); border-radius: 4px; background-color: #F8F4F1; box-shadow: 0 10px 26px var(--shadow);
  background-repeat: no-repeat;
  background-position: top left, top right, bottom left, bottom right, top center, bottom center, left center, right center;
  background-size: var(--b) var(--b), var(--b) var(--b), var(--b) var(--b), var(--b) var(--b),
    calc(100% - 2 * var(--b)) var(--b), calc(100% - 2 * var(--b)) var(--b), var(--b) calc(100% - 2 * var(--b)), var(--b) calc(100% - 2 * var(--b)); }
.xo-board { position: relative; width: clamp(210px, min(78vw, 100dvh - 450px), 400px); aspect-ratio: 1; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 1fr); }
.xo-board > svg { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.xo-lines line { stroke: #241C17; stroke-width: 7; stroke-linecap: round; }
.xo-winline { z-index: 2; }
.xo-winline line { stroke-width: 11; stroke-linecap: round; opacity: .85; stroke-dasharray: 420; stroke-dashoffset: 420; animation: xoDraw .45s ease-out forwards; }
.xo-cell { position: relative; z-index: 1; padding: 13%; border: 0; border-radius: 14px; background: transparent; cursor: pointer; }
.xo-cell:not(.on):hover, .xo-cell:not(.on):focus-visible { background: rgba(245, 183, 49, .16); }
.xo-cell:focus-visible { outline: 3px solid #1D5FB8; outline-offset: -6px; }
.xo-board.wait .xo-cell { cursor: default; }
.xo-cell svg { display: block; width: 100%; height: 100%; overflow: visible; }
.xo-cell .mx path { fill: none; stroke: #2D6A3E; stroke-width: 13; stroke-linecap: round; stroke-dasharray: 80; stroke-dashoffset: 80; animation: xoDraw .16s ease-out forwards; }
.xo-cell .mx path + path { animation-delay: .13s; }
.xo-cell .mo circle { fill: none; stroke: #C23A2E; stroke-width: 12; stroke-dasharray: 175; stroke-dashoffset: 175; transform: rotate(-90deg); transform-origin: 50% 50%; animation: xoDraw .3s ease-out forwards; }
@keyframes xoDraw { to { stroke-dashoffset: 0; } }
.xo-actions { min-height: 3.2em; gap: 8px; }
.xo-sheet { margin: 0; min-width: 0; }
.xo-page { position: relative; }
.xo-page img { display: block; width: 100%; height: auto; border-radius: 8px; box-shadow: 0 8px 22px var(--shadow); }
.xo-ink { position: absolute; left: 0; top: 0; pointer-events: none; }
.xo-now { position: absolute; border: 3px dashed #E0A21A; border-radius: 12px; pointer-events: none; animation: xoPulse 1.2s ease-in-out infinite; }
@keyframes xoPulse { 50% { box-shadow: 0 0 0 6px rgba(245, 183, 49, .35); } }
.xo-sheet figcaption { margin-top: 6px; text-align: center; font-weight: 700; font-size: .95rem; color: var(--ink-soft); }
.xo-intro { width: min(220px, 50vw); border-radius: 16px; box-shadow: 0 6px 16px var(--shadow); }
.xo-fld { width: 100%; max-width: 360px; }
.xo-final { margin: 0; font-size: 1.3rem; font-weight: 800; }
.xo-final b { font-size: 1.8rem; }
@media (max-width: 900px), (max-aspect-ratio: 1/1) {
  .act-body.act-xo { grid-template-columns: 1fr; padding: 10px 12px 14px; }
  .xo-sheet { width: 100%; max-width: 620px; justify-self: center; }
}
@media (max-width: 520px) { .xo-frame { --b: 12px; } .xo-who strong { font-size: .95rem; } .xo-pts { font-size: 1.6rem; } .xo-card { padding: 2px 8px 2px 4px; } }
@media (prefers-reduced-motion: reduce) { .xo-cell .mx path, .xo-cell .mo circle, .xo-winline line { animation: none; stroke-dashoffset: 0; } .xo-now { animation: none; } }
/* ---------- overlay, modal, feedback ---------- */
#overlay { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: var(--scrim); }
.modal { width: 100%; max-width: 520px; max-height: calc(100dvh - 32px); overflow: auto; display: grid; gap: 14px; justify-items: center; text-align: center; padding: 24px; border-radius: 28px; background: var(--surface); color: var(--ink); box-shadow: 0 24px 60px rgba(0, 0, 0, .35); animation: pop .3s cubic-bezier(.2, 1.4, .4, 1); }
.modal h3 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 1.8rem; line-height: 1.3; }
.modal-text { margin: 0; font-weight: 700; font-size: 1.1rem; }
