:root{
  --bg:#f5f4f0; --surface:#fbfbf9; --panel:#ffffff; --panel-soft:#f7f6f2;
  --ink:#1c1c1a; --ink-hover:#3a3935; --ink-2:#55534d; --sub:#7a776f; --muted:#8a877f;
  --line:#e3e1db; --line-2:#dcdad3; --line-3:#efeee9; --hover:#efeee9; --soft:#f3f2ee; --track:#ebe9e3;
  --accent:#1c1c1a;
  --font:"IBM Plex Sans KR",sans-serif; --mono:"JetBrains Mono",monospace;
}
*{box-sizing:border-box}
[hidden]{display:none !important}
body{margin:0;background:var(--bg);color:var(--ink);font-family:var(--font);-webkit-font-smoothing:antialiased}
button{font:inherit;color:inherit}
.mono-label{font-family:var(--mono);font-size:11px;letter-spacing:.12em;color:var(--muted)}
.app{min-height:calc(100vh - 48px);display:flex;flex-direction:column}
.topbar{display:flex;align-items:center;justify-content:space-between;gap:16px;padding:16px 28px;border-bottom:1px solid var(--line);background:var(--surface);flex-wrap:wrap}
.brand{display:flex;align-items:baseline;gap:14px;min-width:0;flex-wrap:wrap}
.home{font-size:13px;color:var(--ink-2);text-decoration:none}
.home:hover{color:var(--ink)}
.brand-title{font-size:17px;font-weight:700;letter-spacing:-.01em}
.btn{height:36px;padding:0 14px;background:transparent;border:1px solid var(--line-2);border-radius:999px;font-size:13px;cursor:pointer}
.btn:hover{background:var(--hover)}
.btn:disabled{opacity:.4;cursor:default}
.btn:disabled:hover{background:transparent}
.btn--solid{background:var(--ink);color:#fff;border:none;font-weight:500}
.btn--solid:hover{background:var(--ink-hover)}
.text-input{height:40px;padding:0 12px;background:var(--surface);border:1px solid var(--line-2);border-radius:8px;font:inherit;font-size:14px;color:var(--ink)}
@media (max-width:640px){ .topbar{padding:14px 16px} }

/* ---------- 게임 공통 셸 ---------- */
.actions{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
.btn--accent{background:var(--accent);color:#fff;border:none;font-weight:500}
.btn--accent:hover{background:var(--accent);filter:brightness(1.08)}
:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
.game{flex:1;display:flex;flex-wrap:wrap;align-items:stretch;min-height:0}
.stage{flex:999 1 420px;min-width:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:20px;padding:40px 28px}
.side{flex:1 1 300px;min-width:0;max-width:100%;border-left:1px solid var(--line);background:var(--panel);padding:28px 24px 40px;display:flex;flex-direction:column;gap:28px}
.group{display:flex;flex-direction:column;gap:12px}
.group + .group{border-top:1px solid var(--line-3);padding-top:24px}
.rules{margin:0;padding:0;list-style:none;display:flex;flex-direction:column;gap:8px;font-size:13px;color:var(--ink-2);line-height:1.6;counter-reset:rule}
.rules li{display:flex;gap:10px}
.rules li::before{counter-increment:rule;content:counter(rule,decimal-leading-zero);font-family:var(--mono);font-size:11px;color:var(--accent);padding-top:3px;flex-shrink:0}
.keys{display:flex;flex-direction:column;gap:8px;font-size:12px;color:var(--ink-2)}
.keys div{display:flex;justify-content:space-between;align-items:center;gap:12px}
.kbd{display:inline-block;font-family:var(--mono);font-size:11px;line-height:1.4;padding:1px 6px;border:1px solid var(--line-2);border-bottom-width:2px;border-radius:5px;background:var(--surface);color:var(--ink)}
.best-card{display:flex;align-items:baseline;justify-content:space-between;gap:12px;padding:16px;border-radius:12px;background:var(--panel-soft)}
.best-val{font-family:var(--mono);font-size:28px;font-weight:500;letter-spacing:-.02em}
.seg{display:flex;background:var(--soft);border-radius:999px;padding:3px;gap:2px}
.seg-btn{flex:1;height:30px;padding:0 10px;background:transparent;color:var(--sub);border:none;border-radius:999px;font-size:12px;cursor:pointer;white-space:nowrap}
.seg-btn.is-active{background:#fff;color:var(--ink);box-shadow:0 1px 3px rgba(0,0,0,.12)}
.link-btn{padding:0;background:none;border:none;font-size:12px;color:var(--muted);text-decoration:underline;text-underline-offset:3px;cursor:pointer}
@media (max-width:640px){
  .stage{padding:24px 16px}
  .side{border-left:none;border-top:1px solid var(--line);padding:24px 16px 40px}
}
@media (prefers-reduced-motion:reduce){
  *,*::before,*::after{animation-duration:.01ms !important;animation-iteration-count:1 !important;transition-duration:.01ms !important}
}

.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.side-note{margin:0;font-size:12px;color:var(--muted);line-height:1.6}


/* ---------- 틱택토 ---------- */
:root{--accent:#2f5bea;--x:#e5484d;--o:#2f5bea;--paper:#fffdf5;--rule:#dfe7f5;--pencil:#2b2a28;--hand:"Gaegu","IBM Plex Sans KR",sans-serif}
.stage{gap:16px}
.controls{display:flex;flex-wrap:wrap;justify-content:center;gap:8px;width:min(100%,460px)}
.controls .seg{flex:1 1 200px}
#levelSeg.is-off{opacity:.35;pointer-events:none}
.scoreline{display:grid;grid-template-columns:1fr auto 1fr;align-items:center;gap:8px;width:min(100%,460px)}
.side-score{display:flex;align-items:center;gap:8px;padding:8px 12px;border-radius:14px;background:var(--panel);border:1px solid var(--line);transition:box-shadow .2s,border-color .2s}
.side-score strong{font-family:var(--mono);font-size:22px;font-weight:800;font-variant-numeric:tabular-nums}
.side-score--x strong{margin-left:auto;color:var(--x)}
.side-score--o{justify-content:flex-end}
.side-score--o strong{margin-right:auto;color:var(--o)}
.side-score--d{flex-direction:column;gap:0;padding:6px 14px;background:transparent;border-color:transparent}
.side-score--d strong{font-size:16px;color:var(--sub)}
.side-score.is-turn{border-color:currentColor;box-shadow:0 0 0 2px currentColor inset}
.side-score--x.is-turn{color:var(--x)}
.side-score--o.is-turn{color:var(--o)}
.side-score.is-turn .sc-name{color:var(--ink)}
.sc-name{font-size:13px;color:var(--ink-2);white-space:nowrap}
.mark-badge{display:inline-flex;align-items:center;justify-content:center;width:26px;height:26px;border-radius:8px;font-weight:800;font-size:15px;color:#fff;flex-shrink:0}
.mark-badge--x{background:var(--x)}
.mark-badge--o{background:var(--o)}

.paper{position:relative;width:min(100%,460px);padding:18px 22px 24px 46px;border-radius:6px 22px 22px 6px;background:var(--paper);background-image:linear-gradient(90deg,transparent 30px,#f3b7b7 30px,#f3b7b7 32px,transparent 32px),repeating-linear-gradient(transparent 0 27px,var(--rule) 27px 28px);box-shadow:0 1px 0 #e9e3d3,0 26px 40px -24px rgba(47,91,234,.35),0 2px 6px rgba(0,0,0,.06)}
.paper::before{content:"";position:absolute;left:8px;top:22px;bottom:22px;width:12px;background:radial-gradient(circle,#e9e4d8 4px,transparent 5px) 0 0/12px 56px repeat-y}
.status{margin:0 0 10px;font-family:var(--hand);font-size:26px;font-weight:700;line-height:1.2;text-align:center;color:var(--pencil);min-height:31px}
.status .x{color:var(--x)}
.status .o{color:var(--o)}
.board-wrap{position:relative;width:100%;aspect-ratio:1}
.grid-lines,.win-line{position:absolute;inset:0;width:100%;height:100%;pointer-events:none;overflow:visible}
.grid-lines path{fill:none;stroke:var(--pencil);stroke-width:4;stroke-linecap:round;opacity:.85}
.board{position:absolute;inset:0;display:grid;grid-template-columns:repeat(3,1fr);grid-template-rows:repeat(3,1fr)}
.cell{position:relative;padding:0;margin:0;background:transparent;border:none;border-radius:14px;cursor:pointer;-webkit-tap-highlight-color:transparent;touch-action:manipulation}
.cell:hover:not([aria-disabled="true"]){background:rgba(47,91,234,.06)}
.cell:focus-visible{outline:3px dashed var(--accent);outline-offset:-8px}
.cell[aria-disabled="true"]{cursor:default}
.cell svg{position:absolute;inset:16%;width:68%;height:68%;overflow:visible}
.cell .stroke{fill:none;stroke-width:13;stroke-linecap:round;stroke-dasharray:var(--len);stroke-dashoffset:var(--len);animation:draw .28s ease-out forwards}
.cell .stroke--2{animation-delay:.16s}
.cell .mx{stroke:var(--x)}
.cell .mo{stroke:var(--o)}
.cell .ghost{opacity:0;transition:opacity .15s}
.board.is-hover-x .cell:not([aria-disabled="true"]):hover .ghost--x,.board.is-hover-o .cell:not([aria-disabled="true"]):hover .ghost--o{opacity:.16}
.cell.is-win svg{animation:wiggle .5s ease-in-out .3s 2}
.board.is-over .cell:not(.is-win) svg{opacity:.3;transition:opacity .4s}
.win-line line{stroke:var(--pencil);stroke-width:9;stroke-linecap:round;stroke-dasharray:400;stroke-dashoffset:400;opacity:.85}
.win-line.is-on line{animation:drawLine .45s ease-out .2s forwards}
.win-line.is-x line{stroke:#b3262b}
.win-line.is-o line{stroke:#1d3c9e}
.end-actions{display:flex;justify-content:center;margin-top:16px}
.end-actions .btn{height:42px;padding:0 20px;display:inline-flex;align-items:center;gap:8px}
.kbd--inv{background:#ffffff26;border-color:#ffffff55;color:#fff}
.stage-hint{margin:0;font-size:12.5px;color:var(--muted);text-align:center}
.hint-touch{display:none}

.rec{width:100%;border-collapse:collapse;font-size:13px}
.rec th,.rec td{padding:8px 6px;text-align:center;border-bottom:1px solid var(--line-3)}
.rec thead th{font-family:var(--mono);font-size:11px;font-weight:500;color:var(--muted);letter-spacing:.06em}
.rec tbody th{text-align:left;font-weight:500;color:var(--ink-2)}
.rec td{font-family:var(--mono);font-weight:700}
.rec td:nth-of-type(1){color:#1e9e5a}
.rec td:nth-of-type(3){color:var(--x)}
.rec tr.is-current th{color:var(--accent)}
.rec tr.is-current{background:#f1f4fe}
.mini-rows{display:flex;flex-direction:column;gap:8px;font-size:13px;color:var(--ink-2)}
.mini-rows div{display:flex;justify-content:space-between;gap:12px}
.mini-rows strong{font-family:var(--mono);font-weight:500;color:var(--ink)}

@keyframes draw{to{stroke-dashoffset:0}}
@keyframes drawLine{to{stroke-dashoffset:0}}
@keyframes wiggle{0%,100%{transform:rotate(0)}25%{transform:rotate(-6deg)}75%{transform:rotate(6deg)}}
@media (max-width:640px),(hover:none){ .hint-desk{display:none} .hint-touch{display:inline} }
@media (max-width:640px){
  .paper{padding:14px 12px 18px 34px}
  .paper::before{left:4px}
  .paper{background-image:linear-gradient(90deg,transparent 22px,#f3b7b7 22px,#f3b7b7 24px,transparent 24px),repeating-linear-gradient(transparent 0 27px,var(--rule) 27px 28px)}
  .status{font-size:23px}
  .side-score{padding:7px 9px;gap:6px}
  .side-score strong{font-size:19px}
  .mark-badge{width:22px;height:22px;font-size:13px}
  .sc-name{font-size:12px}
}

/* 다크 모드 (인쇄는 라이트 그대로) — 공책은 밤 공책으로 */
@media screen{
  :root[data-theme="dark"]{
    color-scheme:dark;
    --bg:#131319; --surface:#191920; --panel:#1e1e26; --panel-soft:#24242d;
    --ink:#ebebf1; --ink-hover:#ffffff; --ink-2:#c8c8d3; --sub:#9f9fad; --muted:#898997;
    --line:#2d2d37; --line-2:#383843; --line-3:#25252e; --hover:#2a2a33; --soft:#25252e; --track:#33333e;
    --accent:#6f8fff; --x:#ff6268; --o:#6f8fff;
    --paper:#1c1c23; --rule:rgba(130,155,255,.13); --pencil:#e4e2dc;
  }
  :root[data-theme="dark"] .btn--solid{color:var(--bg)}
  :root[data-theme="dark"] .btn--accent{background:#2f5bea}
  :root[data-theme="dark"] .seg-btn.is-active{background:var(--hover);box-shadow:0 1px 3px rgba(0,0,0,.4)}
  :root[data-theme="dark"] .mark-badge--x{background:#e5484d}
  :root[data-theme="dark"] .mark-badge--o{background:#2f5bea}
  :root[data-theme="dark"] .paper{background-image:linear-gradient(90deg,transparent 30px,rgba(243,120,120,.4) 30px,rgba(243,120,120,.4) 32px,transparent 32px),repeating-linear-gradient(transparent 0 27px,var(--rule) 27px 28px);
    box-shadow:0 0 0 1px var(--line-2),0 26px 40px -24px rgba(0,0,0,.8)}
  :root[data-theme="dark"] .paper::before{background:radial-gradient(circle,var(--bg) 4px,transparent 5px) 0 0/12px 56px repeat-y}
  :root[data-theme="dark"] .cell:hover:not([aria-disabled="true"]){background:rgba(111,143,255,.08)}
  :root[data-theme="dark"] .win-line.is-x line{stroke:#ff8a8e}
  :root[data-theme="dark"] .win-line.is-o line{stroke:#93acff}
  :root[data-theme="dark"] .rec td:nth-of-type(1){color:#3cc47e}
  :root[data-theme="dark"] .rec tr.is-current{background:rgba(47,91,234,.18)}
}
@media screen and (max-width:640px){
  :root[data-theme="dark"] .paper{background-image:linear-gradient(90deg,transparent 22px,rgba(243,120,120,.4) 22px,rgba(243,120,120,.4) 24px,transparent 24px),repeating-linear-gradient(transparent 0 27px,var(--rule) 27px 28px)}
}
