: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:#ffb41f;
  --font:"IBM Plex Sans KR",sans-serif; --mono:"JetBrains Mono",monospace;
  /* 도구 합치기 전용 */
  --peg:#e7d3ab; --peg-hole:#b89a66; --steel:#2f3539; --steel-2:#454d52;
}
*{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)}
.sr-only{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}
.app{min-height:100vh;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}
.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;white-space:nowrap}
.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)}
.btn--accent{background:var(--accent);color:var(--ink);border:none;font-weight:700;box-shadow:0 2px 0 #c98400}
.btn--accent:hover{background:#ffc040}
@media (max-width:640px){ .topbar{padding:14px 16px} }
.actions{display:flex;align-items:center;gap:8px;flex-wrap:wrap}
:focus-visible{outline:2px solid var(--ink);outline-offset:2px}

/* ---------- 레이아웃 ---------- */
.game{flex:1;display:flex;flex-wrap:wrap;align-items:stretch;min-height:0}
.stage{flex:999 1 440px;min-width:0;display:flex;flex-direction:column;align-items:center;gap:14px;padding:28px 28px 32px;
  background-color:var(--peg);
  background-image:radial-gradient(circle,var(--peg-hole) 0 2.6px,transparent 3.2px),linear-gradient(180deg,rgba(255,255,255,.18),rgba(0,0,0,.04));
  background-size:26px 26px,100% 100%;background-position:13px 13px,0 0;
  box-shadow:inset 0 1px 0 rgba(0,0,0,.06)}
.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:24px}
.group{display:flex;flex-direction:column;gap:12px}
.group + .group{border-top:1px solid var(--line-3);padding-top:22px}
.group-head{display:flex;justify-content:space-between;align-items:baseline;gap:8px}
.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{position:relative;padding-left:28px}
.rules li::before{counter-increment:rule;content:counter(rule,decimal-leading-zero);position:absolute;left:0;top:3px;font-family:var(--mono);font-size:11px;line-height:1.4;color:#c98400}
.rules b{color:var(--ink)}
.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)}
.side-note{margin:0;font-size:12px;color:var(--muted);line-height:1.6}

/* ---------- HUD ---------- */
.hud{width:100%;max-width:420px;display:grid;grid-template-columns:1fr auto auto;gap:8px;align-items:stretch}
.tape{position:relative;display:flex;align-items:center;justify-content:space-between;gap:10px;padding:10px 16px;background:#1d1f21;color:#fff;border-radius:6px;
  box-shadow:0 2px 0 rgba(0,0,0,.25),inset 0 1px 0 rgba(255,255,255,.08);transform:rotate(-1deg)}
.tape::before,.tape::after{content:"";position:absolute;top:0;bottom:0;width:8px;background:repeating-linear-gradient(180deg,#1d1f21 0 4px,transparent 4px 8px)}
.tape::before{left:-4px}
.tape::after{right:-4px}
.tape-label{font-family:var(--mono);font-size:10.5px;letter-spacing:.2em;color:#9aa0a6}
.tape-num{font-family:var(--mono);font-weight:800;font-size:26px;letter-spacing:.06em;line-height:1;text-shadow:0 1px 0 rgba(0,0,0,.6),0 -1px 0 rgba(255,255,255,.18)}
.tape-num.is-bump{animation:bump .3s ease-out}
.hud-box{display:flex;flex-direction:column;justify-content:center;gap:2px;padding:8px 12px;border-radius:10px;background:rgba(255,255,255,.88);border:1px solid rgba(0,0,0,.08);min-width:72px}
.hud-num{font-family:var(--mono);font-size:18px;font-weight:700;line-height:1.1}
.hud-next{flex-direction:row;align-items:center;gap:8px}
.next-icon{width:40px;height:40px;transition:transform .2s cubic-bezier(.2,1.4,.4,1)}
.next-icon.is-pop{animation:popIn .3s cubic-bezier(.2,1.4,.4,1)}

/* ---------- 상자 ---------- */
.box-wrap{position:relative;width:100%;max-width:420px;display:flex;justify-content:center}
.box{box-sizing:content-box;display:block;border-radius:6px 6px 18px 18px;background:#fffaf1;touch-action:none;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent;outline:none;cursor:crosshair;
  border:10px solid var(--steel);border-top-width:4px;
  box-shadow:inset 0 0 0 2px rgba(255,255,255,.6),0 2px 0 10px #23292c,0 30px 50px -20px rgba(0,0,0,.45)}
.box:focus-visible{box-shadow:inset 0 0 0 2px rgba(255,180,31,.5),0 2px 0 10px #23292c,0 30px 50px -20px rgba(0,0,0,.45)}
.combo{position:absolute;top:56px;left:50%;transform:translateX(-50%);font-family:var(--mono);font-weight:800;font-size:22px;color:#fff;
  text-shadow:0 2px 0 #c98400,0 0 14px rgba(255,180,31,.9);opacity:0;pointer-events:none;white-space:nowrap}
.combo.is-on{animation:combo .9s ease-out}

.overlay{position:absolute;inset:0;z-index:5;display:flex;align-items:center;justify-content:center;padding:16px;border-radius:6px 6px 18px 18px;background:rgba(255,250,241,.78);backdrop-filter:blur(3px);-webkit-backdrop-filter:blur(3px);animation:fade .25s ease-out}
.overlay--over{background:rgba(29,31,33,.6)}
.ov-card{width:100%;max-width:330px;display:flex;flex-direction:column;align-items:center;gap:12px;padding:22px 20px;background:var(--panel);border-radius:18px;box-shadow:0 18px 50px rgba(0,0,0,.25);text-align:center;animation:rise .35s cubic-bezier(.2,1.2,.4,1)}
.ov-card--s{max-width:240px}
.ov-title{font-size:19px;line-height:1.35;letter-spacing:-.02em}
.ov-sub{margin:0;font-size:12.5px;line-height:1.6;color:var(--ink-2)}
.ov-chain{width:100%;max-width:300px;height:auto}
.ov-btn{height:44px;padding:0 26px;font-size:15px}
.ov-hint{font-size:11.5px;color:var(--muted)}

.result{width:100%;max-width:340px;display:flex;flex-direction:column;gap:12px;padding:20px;border-radius:18px;background:#fff;
  box-shadow:0 0 0 6px #ffb41f,0 0 0 8px #1d1f21,0 22px 60px rgba(0,0,0,.4);animation:rise .4s cubic-bezier(.2,1.2,.4,1)}
.result-head{display:flex;justify-content:space-between;align-items:center;gap:8px}
.result-badge{font-family:var(--mono);font-size:10px;letter-spacing:.12em;padding:3px 8px;border-radius:999px;background:#1d1f21;color:#ffb41f}
.result-main{display:flex;align-items:center;gap:14px}
.result-icon{width:84px;height:84px;flex-shrink:0;animation:spin 6s linear infinite}
.result-sub{display:block;font-size:11.5px;color:var(--muted)}
.result-tool{display:block;font-size:18px;letter-spacing:-.01em}
.result-score{display:block;margin-top:4px;font-family:var(--mono);font-size:38px;font-weight:800;letter-spacing:-.03em;line-height:1}
.result-stats{margin:0;display:grid;grid-template-columns:1fr 1fr;gap:6px}
.result-stats div{padding:8px 10px;border-radius:10px;background:var(--panel-soft)}
.result-stats dt{font-size:11px;color:var(--muted)}
.result-stats dd{margin:2px 0 0;font-weight:700;font-size:15px;font-family:var(--mono)}
.result-actions{display:flex;gap:8px;justify-content:flex-end}
.result-actions .btn{height:40px;padding:0 18px}

/* 진화 스트립 (상자 아래) */
.dex-strip{width:100%;max-width:420px;display:flex;justify-content:space-between;align-items:center;gap:2px;padding:8px 12px;border-radius:999px;background:#1d1f21;box-shadow:0 2px 0 rgba(0,0,0,.2)}
.dex-strip canvas{width:26px;height:26px;opacity:.3;filter:grayscale(1) brightness(.8);transition:opacity .3s,filter .3s,transform .3s}
.dex-strip canvas.is-on{opacity:1;filter:none}
.dex-strip canvas.is-now{transform:scale(1.25)}
.stage-hint{margin:0;padding:6px 14px;border-radius:999px;background:rgba(255,253,247,.92);font-size:12px;color:var(--ink-2);text-align:center;line-height:1.5;max-width:420px}

/* 도감 */
.dex{margin:0;padding:0;list-style:none;display:grid;grid-template-columns:repeat(auto-fill,minmax(82px,1fr));gap:6px}
.dex li{display:flex;flex-direction:column;align-items:center;gap:4px;padding:10px 4px 8px;border-radius:12px;background:var(--panel-soft);font-size:12px;text-align:center}
.dex li canvas{width:40px;height:40px}
.dex li .n{font-family:var(--mono);font-size:10px;color:var(--muted)}
.dex li.is-locked canvas{filter:brightness(0) opacity(.18)}
.dex li.is-locked .t{color:var(--muted)}
.dex li.is-fresh{animation:fresh 1s ease-out}

.toast{position:fixed;left:50%;bottom:28px;z-index:100;transform:translate(-50%,20px);padding:10px 16px;border-radius:999px;background:var(--ink);color:#fff;font-size:13px;opacity:0;pointer-events:none;transition:opacity .2s,transform .2s}
.toast.is-on{opacity:1;transform:translate(-50%,0)}

@keyframes fade{from{opacity:0}to{opacity:1}}
@keyframes rise{from{opacity:0;transform:translateY(14px) scale(.97)}to{opacity:1;transform:none}}
@keyframes bump{0%{transform:scale(1)}40%{transform:scale(1.1)}100%{transform:scale(1)}}
@keyframes popIn{from{transform:scale(.4)}to{transform:scale(1)}}
@keyframes combo{0%{opacity:0;transform:translate(-50%,10px) scale(.7)}20%{opacity:1;transform:translate(-50%,0) scale(1.1)}70%{opacity:1}100%{opacity:0;transform:translate(-50%,-14px) scale(1)}}
@keyframes spin{to{transform:rotate(360deg)}}
@keyframes fresh{0%{background:#ffe3a0}100%{background:var(--panel-soft)}}

@media (max-width:640px){
  .stage{padding:16px 16px 24px;gap:10px}
  .side{border-left:none;border-top:1px solid var(--line);padding:24px 16px 40px}
  .tape{padding:8px 12px}
  .tape-num{font-size:21px}
  .hud-box{min-width:0;padding:6px 10px}
  .hud-num{font-size:16px}
  .next-icon{width:34px;height:34px}
  .box{border-width:8px;border-top-width:3px}
  .dex-strip{padding:6px 8px}
  .dex-strip canvas{width:22px;height:22px}
}
@media (prefers-reduced-motion:reduce){
  *,*::before,*::after{animation-duration:.01ms !important;animation-iteration-count:1 !important;transition-duration:.01ms !important}
}

/* 다크 모드 (인쇄는 라이트 그대로) — 상자 안 캔버스 색은 --tm-* 로 app.js가 읽음, 도구 그림 색은 그대로 */
@media screen{
  :root[data-theme="dark"]{
    color-scheme:dark;
    --bg:#151412; --surface:#1b1a17; --panel:#201f1c; --panel-soft:#252421;
    --ink:#eeece7; --ink-hover:#ffffff; --ink-2:#cbc8c0; --sub:#a29f96; --muted:#8c897f;
    --line:#312f2b; --line-2:#3c3a35; --line-3:#292824; --hover:#2c2a26; --soft:#292824; --track:#36342f;
    --peg:#2b261f; --peg-hole:#17140f;
    --tm-boxTop:#24221e; --tm-boxBot:#1b1916; --tm-grid:rgba(255,230,180,.05); --tm-line:230,225,215; --tm-claw:#8a9096;
    --tm-popupStroke:#1b1916; --tm-popupDark:#f2efe8; --tm-popupGold:#ffc040;
  }
  :root[data-theme="dark"] .btn--solid,:root[data-theme="dark"] .toast{color:var(--bg)}
  :root[data-theme="dark"] .btn--accent{color:#1c1c1a}
  :root[data-theme="dark"] .rules li::before{color:#ffb41f}
  :root[data-theme="dark"] .stage{background-image:radial-gradient(circle,var(--peg-hole) 0 2.6px,transparent 3.2px),linear-gradient(180deg,rgba(255,255,255,.03),rgba(0,0,0,.1));box-shadow:inset 0 1px 0 rgba(0,0,0,.3)}
  :root[data-theme="dark"] .hud-box{background:rgba(32,31,28,.92);border-color:rgba(255,255,255,.08)}
  :root[data-theme="dark"] .box{background:#211f1b;box-shadow:inset 0 0 0 2px rgba(255,255,255,.05),0 2px 0 10px #23292c,0 30px 50px -20px rgba(0,0,0,.7)}
  :root[data-theme="dark"] .box:focus-visible{box-shadow:inset 0 0 0 2px rgba(255,180,31,.5),0 2px 0 10px #23292c,0 30px 50px -20px rgba(0,0,0,.7)}
  :root[data-theme="dark"] .overlay{background:rgba(20,19,17,.8)}
  :root[data-theme="dark"] .overlay--over{background:rgba(0,0,0,.6)}
  :root[data-theme="dark"] .ov-card{box-shadow:0 18px 50px rgba(0,0,0,.6),0 0 0 1px var(--line-2)}
  :root[data-theme="dark"] .result{background:var(--panel)}
  :root[data-theme="dark"] .dex-strip{box-shadow:0 0 0 1px var(--line-2)}
  :root[data-theme="dark"] .stage-hint{background:rgba(32,31,28,.92)}
  :root[data-theme="dark"] .dex li.is-locked canvas{filter:brightness(0) invert(1) opacity(.16)}
  :root[data-theme="dark"] .dex li.is-fresh{animation:fresh-dark 1s ease-out}
  @keyframes fresh-dark{0%{background:#4a3a14}100%{background:var(--panel-soft)}}
}
