: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}
}

/* ---------- 1 to 50 ---------- */
:root{--accent:#2b5bff;--accent-soft:#e7edff;--accent-mid:#c9d6ff;--bad:#ff3b5c}
.hud{width:100%;max-width:460px;display:flex;justify-content:space-between;align-items:flex-end}
.hud-cell{display:flex;flex-direction:column;gap:2px}
.hud-cell--right{align-items:flex-end}
.next-num{font-family:var(--mono);font-size:56px;font-weight:700;line-height:1;color:var(--accent);letter-spacing:-.04em;min-width:2ch}
.next-num.is-tick{animation:tick .22s ease-out}
.time{font-family:var(--mono);font-size:40px;font-weight:500;line-height:1;letter-spacing:-.03em;font-variant-numeric:tabular-nums}
.progress{width:100%;max-width:460px;height:4px;background:var(--track);border-radius:999px;overflow:hidden}
.progress-bar{height:100%;width:0;background:var(--accent);border-radius:999px;transition:width .15s ease-out}

.board-wrap{position:relative;width:100%;max-width:460px}
.board{display:grid;grid-template-columns:repeat(5,minmax(0,1fr));gap:8px;padding:10px;background:var(--panel);border:1px solid var(--line);border-radius:20px;box-shadow:0 1px 2px rgba(0,0,0,.04),0 18px 40px -18px rgba(43,91,255,.25)}
.board.is-wrong{animation:boardBad .3s}
.cell{position:relative;aspect-ratio:1;display:flex;align-items:center;justify-content:center;padding:0;border:none;border-radius:12px;font-family:var(--mono);font-size:clamp(18px,5.6vw,28px);font-weight:700;cursor:pointer;touch-action:manipulation;-webkit-tap-highlight-color:transparent;user-select:none;-webkit-user-select:none;transition:transform .08s,background .15s,color .15s;overflow:hidden}
.cell.lo{background:var(--accent-soft);color:var(--ink)}
.cell.hi{background:var(--accent);color:#fff}
.cell.empty{background:transparent;box-shadow:inset 0 0 0 1px var(--line-3);cursor:default}
.cell:not(.empty):hover{transform:translateY(-1px)}
.cell:not(.empty):active{transform:scale(.94)}
.cell.lo:hover{background:var(--accent-mid)}
.cell.pop{animation:pop .28s cubic-bezier(.2,1.4,.4,1)}
.cell.wrong{animation:shake .3s;background:var(--bad) !important;color:#fff !important}
.cell::after{content:"";position:absolute;inset:0;border-radius:inherit;background:radial-gradient(circle,rgba(255,255,255,.85) 0,rgba(255,255,255,0) 70%);opacity:0;transform:scale(.2);pointer-events:none}
.cell.pop::after{animation:ripple .4s ease-out}
.cell.is-hint{box-shadow:0 0 0 2px var(--accent) inset}

.result{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;background:rgba(245,244,240,.82);backdrop-filter:blur(4px);-webkit-backdrop-filter:blur(4px);border-radius:20px;animation:fadeIn .25s ease-out}
.result-card{display:flex;flex-direction:column;align-items:center;gap:8px;padding:28px 32px;background:var(--panel);border:1px solid var(--line);border-radius:20px;box-shadow:0 24px 60px rgba(40,36,28,.18);animation:rise .35s cubic-bezier(.2,1.2,.4,1);max-width:calc(100% - 32px)}
.result-time{font-family:var(--mono);font-size:56px;font-weight:700;line-height:1;letter-spacing:-.04em;color:var(--accent)}
.result-time small{font-size:18px;margin-left:4px;color:var(--ink-2);font-weight:500}
.result-badge{padding:4px 12px;border-radius:999px;background:var(--ink);color:#fff;font-size:12px;font-weight:700;animation:pop .4s .2s backwards}
.result-sub{margin:0;font-size:13px;color:var(--sub);text-align:center}
.result-btn{margin-top:8px;height:42px;padding:0 24px;font-size:14px}
.stage-hint{margin:0;font-size:13px;color:var(--muted);text-align:center}

.best-label{font-size:13px;color:var(--ink-2)}
.history{margin:0;padding:0;list-style:none;display:flex;flex-direction:column;gap:6px}
.history li{display:flex;justify-content:space-between;font-family:var(--mono);font-size:12px;color:var(--sub);padding:6px 2px;border-bottom:1px dashed var(--line-2)}
.history li.is-best{color:var(--accent);font-weight:500}
.history:empty::before{content:"아직 기록이 없어요";font-size:12px;color:var(--muted);font-family:var(--font)}
.link-btn{align-self:flex-start}

@keyframes pop{0%{transform:scale(.6)}100%{transform:scale(1)}}
@keyframes ripple{0%{opacity:.9;transform:scale(.2)}100%{opacity:0;transform:scale(1.6)}}
@keyframes shake{0%,100%{transform:translateX(0)}20%{transform:translateX(-5px)}40%{transform:translateX(5px)}60%{transform:translateX(-3px)}80%{transform:translateX(3px)}}
@keyframes tick{0%{transform:translateY(6px);opacity:.3}100%{transform:none;opacity:1}}
@keyframes boardBad{0%,100%{box-shadow:0 0 0 0 rgba(255,59,92,0)}30%{box-shadow:0 0 0 4px rgba(255,59,92,.35)}}
@keyframes fadeIn{from{opacity:0}to{opacity:1}}
@keyframes rise{from{opacity:0;transform:translateY(16px) scale(.96)}to{opacity:1;transform:none}}
@media (max-width:640px){
  .board{gap:6px;padding:8px;border-radius:16px}
  .cell{border-radius:10px}
  .next-num{font-size:44px}
  .time{font-size:32px}
  .result-time{font-size:44px}
}

/* 다크 모드 (인쇄는 라이트 그대로) */
@media screen{
  :root[data-theme="dark"]{
    color-scheme:dark;
    --bg:#131419; --surface:#191a20; --panel:#1e1f26; --panel-soft:#23242c;
    --ink:#eaebf0; --ink-hover:#ffffff; --ink-2:#c6c8d1; --sub:#9ea0ab; --muted:#888a95;
    --line:#2c2d36; --line-2:#373843; --line-3:#25262e; --hover:#282932; --soft:#24252d; --track:#32333d;
    --accent:#7393ff; --accent-soft:#1f2850; --accent-mid:#2b3870; --bad:#ff5a75;
  }
  :root[data-theme="dark"] .btn--solid,:root[data-theme="dark"] .result-badge,:root[data-theme="dark"] .tb-presets button[aria-pressed="true"]{color:var(--bg)}
  :root[data-theme="dark"] .btn--accent,:root[data-theme="dark"] .btn--accent:hover,:root[data-theme="dark"] .cell.hi{background:#2b5bff}
  :root[data-theme="dark"] .seg-btn.is-active{background:var(--line-2);box-shadow:0 1px 3px rgba(0,0,0,.4)}
  :root[data-theme="dark"] .board{box-shadow:0 18px 40px -18px rgba(0,0,0,.6)}
  :root[data-theme="dark"] .result{background:rgba(19,20,25,.82)}
  :root[data-theme="dark"] .result-card{box-shadow:0 24px 60px rgba(0,0,0,.5)}
}
