:root {
  --bg: #14201b; --panel: #1e2d26; --panel2: #263a31; --line: rgba(134, 239, 172, 0.16);
  --text: #eefaf2; --dim: #9fb8aa; --accent: #86efac; --accent2: #bbf7d0; --bad: #f87171;
  --g: #22a35a; --y: #d4a017; --b: #3b4a43; --r: 16px;
}
body.cb { --g: #f08a24; --y: #3b82f6; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 50% 0%, #22392e 0%, var(--bg) 60%, #0b120f 100%);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
  -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none;
}
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; opacity: 0.45; }
[hidden] { display: none !important; }

.topbar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top)); }
.back-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px;
  background: rgba(56, 189, 248, 0.12); border: 1px solid rgba(56, 189, 248, 0.3); color: #7dd3fc;
  text-decoration: none; font-size: 0.85rem; font-weight: 700;
}
.back-btn:hover { background: rgba(56, 189, 248, 0.22); }
.total { margin-left: auto; font-weight: 800; }
.tools { display: flex; gap: 6px; }
.mini { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--panel); font-weight: 800; }

/* ── 메뉴 ── */
.screen { flex: 1; overflow-y: auto; padding: 4px 16px 32px; }
.screen > * { max-width: 680px; margin-left: auto; margin-right: auto; }
.logo { text-align: center; margin: 2px auto 12px; }
.logo-art { display: inline-flex; gap: 4px; }
.logo-art span { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; font-weight: 900; font-size: 1.15rem; animation: pop 3.2s ease-in-out infinite; }
.logo-art span:nth-child(2) { animation-delay: 0.12s; } .logo-art span:nth-child(3) { animation-delay: 0.24s; }
.logo-art span:nth-child(4) { animation-delay: 0.36s; } .logo-art span:nth-child(5) { animation-delay: 0.48s; } .logo-art span:nth-child(6) { animation-delay: 0.6s; }
.logo-art .g { background: var(--g); } .logo-art .y { background: var(--y); } .logo-art .b { background: var(--b); }
@keyframes pop { 0%, 70%, 100% { transform: none; } 78% { transform: translateY(-6px) rotateX(40deg); } 86% { transform: none; } }
h1 { margin: 10px 0 2px; font-size: 1.6rem; letter-spacing: -0.02em; }
h1 span { color: var(--accent); }
.tagline { margin: 0; color: var(--dim); font-size: 0.9rem; }

.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 12px; }
.tab { padding: 9px 4px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-weight: 700; font-size: 0.84rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tab.on { background: var(--accent); color: #0b2415; border-color: var(--accent); }
.dim { color: var(--dim); }
.small { font-size: 0.82rem; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px; margin-bottom: 12px; }
.card h3 { margin: 0 0 6px; font-size: 1.05rem; }
.btn { padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); font-weight: 800; }
.btn.go { background: var(--accent); color: #0b2415; border-color: var(--accent); }
.btn.small { padding: 6px 10px; font-size: 0.85rem; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.continue {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px 14px; margin-bottom: 12px;
  border-radius: var(--r); border: 1px solid rgba(134, 239, 172, 0.5); background: linear-gradient(135deg, rgba(134,239,172,0.2), rgba(134,239,172,0.05));
}
.continue .ci { width: 34px; height: 34px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #0b2415; }
.continue b { display: block; } .continue small { color: var(--dim); }
.big-num { font-size: 1.6rem; font-weight: 900; color: var(--accent); }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; text-align: center; margin: 8px 0; }
.kpis div { background: var(--panel2); border-radius: 12px; padding: 8px 2px; }
.kpis b { display: block; font-size: 1.2rem; } .kpis small { color: var(--dim); font-size: 0.72rem; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-top: 8px; }
.cal span { aspect-ratio: 1; border-radius: 6px; background: var(--panel2); display: grid; place-items: center; font-size: 0.7rem; color: var(--dim); }
.cal .w { background: var(--g); color: #fff; font-weight: 800; } .cal .l { background: #6b2b2b; color: #fecaca; } .cal .t { outline: 2px solid var(--accent); }
.mini-board { display: inline-grid; gap: 3px; margin: 6px 0; }
.mini-board div { display: flex; gap: 3px; } .mini-board i { width: 16px; height: 16px; border-radius: 3px; display: block; }
i.g { background: var(--g); } i.y { background: var(--y); } i.b { background: var(--b); }

.zone { margin-bottom: 12px; }
.zone-h { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.zone-h b { font-size: 1rem; } .zone-h small { color: var(--dim); }
.zone-h .zs { margin-left: auto; font-weight: 800; color: var(--accent2); font-size: 0.85rem; }
.stages { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.st { aspect-ratio: 1; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 800; padding: 0; }
.st small { font-size: 0.6rem; color: #facc15; letter-spacing: -1px; min-height: 0.8em; }
.st.done { background: var(--panel2); border-color: rgba(134,239,172,0.4); }
.st.next { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(134,239,172,0.3) inset; }
.locked { opacity: 0.45; }
.lens { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.len-card { text-align: center; padding: 14px 6px; border-radius: var(--r); border: 1px solid var(--line); background: var(--panel); }
.len-card b { display: block; font-size: 1.15rem; } .len-card small { color: var(--dim); display: block; margin-top: 2px; }
.dist { display: grid; gap: 4px; margin-top: 6px; }
.dist div { display: flex; align-items: center; gap: 6px; font-size: 0.82rem; }
.dist span { min-width: 1.2em; text-align: right; color: var(--dim); }
.dist i { display: block; height: 18px; background: var(--b); border-radius: 4px; min-width: 18px; text-align: right; padding-right: 5px; font-style: normal; font-weight: 800; font-size: 0.75rem; line-height: 18px; }
.dist i.hi { background: var(--g); }
.achs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.ach { display: flex; gap: 8px; align-items: center; padding: 8px; border-radius: 12px; background: var(--panel2); font-size: 0.8rem; }
.ach .ai { font-size: 1.3rem; } .ach b { display: block; font-size: 0.85rem; } .ach small { color: var(--dim); }
.ach.off { opacity: 0.45; filter: grayscale(1); }
.opt { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.opt:first-of-type { border-top: 0; }
.opt div { flex: 1; } .opt small { display: block; color: var(--dim); }
.sw { width: 50px; height: 28px; border-radius: 999px; border: 1px solid var(--line); background: var(--b); position: relative; flex: none; }
.sw::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.sw.on { background: var(--g); } .sw.on::after { transform: translateX(22px); }

/* ── 플레이 ── */
#play { flex: 1; display: flex; flex-direction: column; min-height: 0; padding-bottom: env(safe-area-inset-bottom); }
.p-head { display: flex; align-items: center; gap: 8px; padding: 2px 12px 4px; max-width: 560px; width: 100%; margin: 0 auto; }
.p-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.p-title b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .p-title small { color: var(--dim); font-size: 0.76rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hbtn { display: flex; flex-direction: column; align-items: center; padding: 3px 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); font-size: 1rem; line-height: 1.1; }
.hbtn span { font-size: 0.62rem; color: var(--dim); }
.hbtn.used { border-color: rgba(250, 204, 21, 0.5); }
.hintbar { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; min-height: 26px; padding: 0 12px; }
.hintbar span { padding: 3px 10px; border-radius: 999px; background: rgba(250, 204, 21, 0.14); border: 1px solid rgba(250, 204, 21, 0.4); font-size: 0.8rem; font-weight: 700; }
.board-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative; padding: 4px 8px; }
.board { display: grid; gap: var(--gap, 5px); }
.brow { display: flex; gap: var(--gap, 5px); align-items: center; }
.cell {
  width: var(--cs, 48px); height: var(--cs, 48px); border-radius: 8px; border: 2px solid rgba(255,255,255,0.12);
  display: grid; place-items: center; font-weight: 900; font-size: calc(var(--cs, 48px) * 0.5); background: rgba(255,255,255,0.03);
}
.cell.f { border-color: rgba(255,255,255,0.4); animation: tap 0.1s ease-out; }
.cell.ghost { color: rgba(250, 204, 21, 0.55); border-style: dashed; border-color: rgba(250, 204, 21, 0.45); }
.cell.g, .cell.y, .cell.b { border-color: transparent; color: #fff; }
.cell.g { background: var(--g); } .cell.y { background: var(--y); } .cell.b { background: var(--b); }
.cell.flip { animation: flip 0.42s ease-in-out both; }
@keyframes flip { 0% { transform: rotateX(0); } 50% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes tap { from { transform: scale(1.12); } to { transform: none; } }
.brow.shake { animation: shake 0.36s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
.brow.dance .cell { animation: dance 0.5s ease-in-out both; }
@keyframes dance { 40% { transform: translateY(-14px); } 70% { transform: translateY(3px); } }
.word { width: calc(var(--cs, 48px) * 1.7); font-weight: 800; font-size: calc(var(--cs, 48px) * 0.36); color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 4px; }
.word.cur { color: var(--text); } .word.bad { color: var(--bad); }
.toast { position: absolute; top: 6px; left: 50%; transform: translateX(-50%); background: #f1f5f9; color: #0f172a; padding: 8px 14px; border-radius: 10px; font-weight: 800; font-size: 0.9rem; box-shadow: 0 6px 18px rgba(0,0,0,0.4); z-index: 3; white-space: nowrap; pointer-events: none; }

.kb { display: grid; gap: 6px; padding: 6px 4px 10px; max-width: 560px; width: 100%; margin: 0 auto; }
.kr { display: flex; gap: 4px; justify-content: center; }
.k { flex: 1; max-width: 50px; height: 52px; border-radius: 8px; border: 0; background: #50625a; font-weight: 800; font-size: 1.1rem; padding: 0; touch-action: manipulation; }
.k:active { filter: brightness(1.3); }
.k.g { background: var(--g); } .k.y { background: var(--y); } .k.b { background: #26302b; color: #7b8a83; }
.k.wide { flex: 1.5; max-width: 76px; font-size: 0.9rem; }
.k.on { background: var(--accent); color: #0b2415; }
.k.enter { flex: none; width: 100%; max-width: none; height: 44px; background: var(--accent); color: #0b2415; font-size: 1rem; }

/* ── 모달 ── */
.modal { position: fixed; inset: 0; background: rgba(4, 8, 6, 0.7); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal-box { width: min(440px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 18px; box-shadow: 0 20px 50px rgba(0,0,0,0.5); }
.modal-box h2 { margin: 0 0 8px; font-size: 1.25rem; }
.modal-box p { line-height: 1.5; }
.modal-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.modal-btns .btn { flex: 1; white-space: nowrap; padding: 10px 8px; }
.err { font-family: ui-monospace, monospace; font-size: 0.75rem; background: #08100c; padding: 8px; border-radius: 8px; white-space: pre-wrap; color: #fecaca; max-height: 140px; overflow: auto; user-select: text; -webkit-user-select: text; }
.win { text-align: center; }
.win-ico { font-size: 2.6rem; animation: rise 0.5s ease-out; }
@keyframes rise { from { transform: scale(0.6) rotate(-6deg); opacity: 0; } to { transform: none; opacity: 1; } }
.answer { font-size: 2rem; font-weight: 900; letter-spacing: 0.1em; margin: 4px 0; }
.answer-j { color: var(--dim); letter-spacing: 0.25em; }
.stars { font-size: 2rem; color: #facc15; letter-spacing: 4px; }
.win-line { margin: 4px 0; font-weight: 700; }
.ach-got { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin-top: 8px; }
.ach-got span { padding: 5px 10px; border-radius: 999px; background: rgba(187, 247, 208, 0.12); border: 1px solid rgba(187, 247, 208, 0.45); font-size: 0.82rem; font-weight: 700; }
.ex { display: flex; gap: 4px; margin: 6px 0 2px; }
.ex b { width: 30px; height: 30px; border-radius: 6px; display: grid; place-items: center; background: var(--b); }
.ex b.g { background: var(--g); } .ex b.y { background: var(--y); }
.noscript { padding: 20px; text-align: center; }

@media (max-height: 640px) { .k { height: 44px; } .k.enter { height: 38px; } .logo-art span { width: 28px; height: 28px; } }
@media (max-width: 380px) { .back-txt { display: none; } .tab { font-size: 0.76rem; } .stages { gap: 4px; } }
.past { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 6px; margin-top: 8px; }
.pd { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 6px 4px; color: inherit; font: inherit; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 1px; }
.pd b { font-size: 0.95rem; } .pd small { font-size: 0.68rem; color: var(--dim); }
.pd.w { border-color: var(--g); } .pd.w small:last-child { color: var(--g); font-weight: 700; }
.pd.c { outline: 2px solid var(--accent); }
