:root {
  --bg: #0f1724; --bg2: #1b2a44; --panel: #18233a; --panel2: #213049; --line: rgba(147, 197, 253, 0.18);
  --text: #eef4ff; --dim: #9fb0c9; --accent: #7dd3fc; --accent2: #bae6fd; --bad: #f87171; --gold: #facc15;
  --r: 16px;
  --glass: rgba(220, 235, 255, 0.10); --glass-line: rgba(220, 235, 255, 0.55); --shelf: #6b4a2b; --shelf2: #4a3220;
}
body.t-sea { --bg: #062a3a; --bg2: #0e5a78; --panel: #0b3446; --panel2: #114257; --shelf: #c9a26b; --shelf2: #a07a48; }
body.t-forest { --bg: #0f1f14; --bg2: #2c4a2a; --panel: #172a1b; --panel2: #1f3824; --shelf: #7a5530; --shelf2: #5a3c1f; --accent: #86efac; --accent2: #bbf7d0; }
body.t-night { --bg: #0a0b1e; --bg2: #24205a; --panel: #15163a; --panel2: #1f2150; --shelf: #3b3f7a; --shelf2: #2a2d5e; --accent: #c4b5fd; --accent2: #ddd6fe; }
body.t-candy { --bg: #3a1030; --bg2: #8a2c64; --panel: #4a173c; --panel2: #5e1f4c; --shelf: #f9a8d4; --shelf2: #db7bb3; --accent: #f9a8d4; --accent2: #fbcfe8; --glass-line: rgba(255, 230, 245, 0.7); }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 50% 0%, var(--bg2) 0%, var(--bg) 62%, #05080f 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;
}
body.t-night { background: radial-gradient(circle at 20% 10%, rgba(255, 255, 255, 0.06) 0 1px, transparent 2px) 0 0 / 60px 60px, radial-gradient(circle at 50% 0%, var(--bg2) 0%, var(--bg) 62%, #05060f 100%); }
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: 10px; align-items: flex-end; height: 96px; }
.lt { display: flex; flex-direction: column-reverse; width: 26px; height: 86px; padding: 3px 3px 4px; border: 2px solid var(--glass-line); border-top-width: 0; border-radius: 0 0 13px 13px; background: var(--glass); overflow: hidden; }
.lt b { display: block; height: 19px; background: var(--c); }
.lt b:first-child { border-radius: 0 0 9px 9px; }
.lt.up { animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 0%, 100% { transform: none; } 50% { transform: translateY(-8px); } }
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 2px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-weight: 700; font-size: 0.82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tab.on { background: var(--accent); color: #06121f; 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: #06121f; border-color: var(--accent); }
.btn.small { padding: 6px 10px; font-size: 0.85rem; }
.btn.wide { width: 100%; }
.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(125, 211, 252, 0.5); background: linear-gradient(135deg, rgba(125, 211, 252, 0.2), rgba(125, 211, 252, 0.05));
}
.continue .ci { width: 34px; height: 34px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #06121f; }
.continue b { display: block; } .continue small { color: var(--dim); }
.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: #0e7490; color: #fff; font-weight: 800; } .cal .t { outline: 2px solid var(--accent); }
.cal button { aspect-ratio: 1; border-radius: 6px; background: var(--panel2); display: grid; place-items: center; font: inherit; font-size: 0.7rem; color: var(--dim); border: 1px dashed rgba(148, 163, 184, 0.45); padding: 0; cursor: pointer; touch-action: manipulation; }
.cal button.w { border-style: solid; border-color: transparent; }
.cal button.pw { background: #6d28d9; color: #fff; font-weight: 800; border-color: transparent; }
.cal button:hover, .cal button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.cal-note { margin: 8px 0 0; }
.wk { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; font-size: 0.66rem; color: var(--dim); text-align: center; margin-top: 8px; }

.zone { margin-bottom: 14px; }
.zone-h { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.zone-h .zi { font-size: 1.4rem; }
.zone-h b { font-size: 1rem; } .zone-h .zs { margin-left: auto; font-weight: 800; color: var(--accent2); font-size: 0.85rem; white-space: nowrap; }
.zone-d { margin: 0 0 6px; font-size: 0.78rem; color: var(--dim); }
.sts { display: grid; grid-template-columns: repeat(6, 1fr); gap: 5px; }
.st { aspect-ratio: 1.1; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 800; padding: 0; font-size: 0.85rem; }
.st small { font-size: 0.55rem; color: var(--gold); letter-spacing: -1px; min-height: 0.9em; }
.st.done { background: var(--panel2); border-color: rgba(125, 211, 252, 0.4); }
.st.next { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(125, 211, 252, 0.25) inset; }
.locked { opacity: 0.42; }
.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: #3b4558; 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: #0e7490; } .sw.on::after { transform: translateX(22px); }
.themes { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.th { padding: 6px 2px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); font-size: 0.68rem; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.th i { width: 34px; height: 34px; border-radius: 8px; display: block; border: 2px solid rgba(0, 0, 0, 0.3); }
.th.on { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(125, 211, 252, 0.3) inset; }
.th-lab { background: linear-gradient(#1b2a44, #0f1724); } .th-sea { background: linear-gradient(#0e5a78, #062a3a); } .th-forest { background: linear-gradient(#2c4a2a, #0f1f14); }
.th-night { background: linear-gradient(#24205a, #0a0b1e); } .th-candy { background: linear-gradient(#8a2c64, #3a1030); }
.mini-shelf { display: flex; gap: 6px; justify-content: center; margin: 8px 0; flex-wrap: wrap; }
.mini-shelf .lt { width: 18px; height: 56px; }
.mini-shelf .lt b { height: 12px; }

/* ── 판 ── */
#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: 640px; 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; }
.moves { text-align: center; min-width: 54px; padding: 4px 8px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); line-height: 1.05; }
.moves b { display: block; font-size: 1.25rem; } .moves small { font-size: 0.66rem; color: var(--dim); }
.goal { text-align: center; font-size: 0.8rem; color: var(--dim); min-height: 1.3em; padding: 0 12px; }
.goal .gs { color: var(--gold); letter-spacing: 1px; font-weight: 800; }
.shelf-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative; padding: 6px 8px; }
.shelf { display: flex; flex-direction: column; gap: calc(var(--sh, 26px) * 1.4); align-items: center; }
.srow { display: flex; gap: var(--gap, 12px); align-items: flex-end; justify-content: center; position: relative; padding: 0 10px 6px; }
.srow::after { content: ''; position: absolute; left: 0; right: 0; bottom: -6px; height: 10px; border-radius: 4px; background: linear-gradient(var(--shelf), var(--shelf2)); box-shadow: 0 6px 12px rgba(0, 0, 0, 0.35); }
.tube {
  position: relative; width: var(--tw, 46px); height: calc(var(--sh, 26px) * var(--cap, 4) + 18px); padding: 0; z-index: 1;
  border: 0; background: none; touch-action: manipulation; transition: transform 0.16s ease-out;
}
.tube .glass {
  position: absolute; inset: 0; border: 2.5px solid var(--glass-line); border-top: 0; border-radius: 0 0 calc(var(--tw) / 2) calc(var(--tw) / 2);
  background: var(--glass); overflow: hidden; display: flex; flex-direction: column-reverse; padding: 0 2px 3px;
  box-shadow: inset 6px 0 8px rgba(255, 255, 255, 0.06);
}
.tube .glass::before { content: ''; position: absolute; left: -4px; right: -4px; top: 0; height: 5px; border-radius: 3px; background: var(--glass-line); opacity: 0.6; }
.tube .glass::after { content: ''; position: absolute; left: 18%; top: 10px; bottom: 14px; width: 12%; border-radius: 4px; background: rgba(255, 255, 255, 0.16); pointer-events: none; z-index: 2; }
.seg { height: var(--sh, 26px); flex: none; background: var(--c); position: relative; display: grid; place-items: center; font-size: calc(var(--sh) * 0.48); color: rgba(0, 0, 0, 0.45); font-weight: 900; }
.seg:first-child { border-radius: 0 0 calc(var(--tw) / 2 - 4px) calc(var(--tw) / 2 - 4px); }
.seg.top::before { content: ''; position: absolute; left: 0; right: 0; top: -3px; height: 5px; border-radius: 50%; background: var(--c); filter: brightness(1.25); }
.seg.hid { background: repeating-linear-gradient(135deg, #374151 0 6px, #2b3442 6px 12px); color: #cbd5e1; }
.seg.fill { animation: fill 0.26s ease-out both; transform-origin: bottom; }
@keyframes fill { from { transform: scaleY(0); } to { transform: none; } }
.seg.rev { animation: rev 0.4s ease-out; }
@keyframes rev { from { filter: brightness(2) saturate(0); } to { filter: none; } }
.tube.sel { transform: translateY(calc(var(--sh) * -0.7)); }
.tube.sel .glass { border-color: #fff; box-shadow: 0 0 12px rgba(255, 255, 255, 0.45); }
.tube.hint-a .glass { border-color: var(--gold); box-shadow: 0 0 14px rgba(250, 204, 21, 0.7); }
.tube.hint-b .glass { border-color: var(--gold); border-style: dashed; }
.tube.can .glass { border-color: rgba(134, 239, 172, 0.95); }
.tube.shake { animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.tube.sealed .glass { border-color: rgba(255, 255, 255, 0.8); }
.cork { position: absolute; left: 50%; top: -9px; width: calc(var(--tw) * 0.62); height: 14px; transform: translateX(-50%); border-radius: 4px 4px 2px 2px; background: linear-gradient(#c08a52, #8a5a2e); box-shadow: 0 2px 3px rgba(0, 0, 0, 0.4); z-index: 3; animation: corkin 0.35s ease-out; }
@keyframes corkin { from { transform: translate(-50%, -18px); opacity: 0; } to { transform: translateX(-50%); opacity: 1; } }
.tube.done .glass { animation: glow 0.6s ease-out; }
@keyframes glow { 0% { box-shadow: 0 0 0 rgba(255, 255, 255, 0); } 40% { box-shadow: 0 0 22px rgba(255, 255, 255, 0.8); } 100% { box-shadow: none; } }
.ice-cover { position: absolute; inset: 0; border-radius: 0 0 calc(var(--tw) / 2) calc(var(--tw) / 2); background: linear-gradient(160deg, rgba(186, 230, 253, 0.75), rgba(125, 211, 252, 0.45) 60%, rgba(224, 242, 254, 0.7)); border: 2px solid #e0f2fe; z-index: 3; display: grid; place-items: center; font-weight: 900; color: #0c4a6e; font-size: 0.85rem; text-shadow: 0 1px 0 #fff; }
.ice-cover.melt { animation: melt 0.6s ease-in forwards; }
@keyframes melt { to { opacity: 0; transform: translateY(10px) scaleY(0.6); } }
.label { position: absolute; left: 50%; bottom: -16px; transform: translateX(-50%); width: 22px; height: 14px; border-radius: 4px; background: var(--c); border: 2px solid #fff; z-index: 3; font-size: 0.55rem; display: grid; place-items: center; color: rgba(0, 0, 0, 0.6); font-weight: 900; }
.tube.lab .glass { border-style: solid; border-color: color-mix(in srgb, var(--lc) 70%, white); }
.tnum { position: absolute; left: 0; right: 0; bottom: -17px; text-align: center; font-size: 0.6rem; color: var(--dim); opacity: 0.7; pointer-events: none; }
.tube.lab .tnum { display: none; }
.stream { position: fixed; width: 6px; border-radius: 3px; z-index: 6; pointer-events: none; transform-origin: top; animation: stream 0.3s ease-in-out both; }
@keyframes stream { 0% { transform: scaleY(0); } 30%, 70% { transform: scaleY(1); } 100% { transform: scaleY(1); opacity: 0; } }
.toast { position: absolute; top: 4px; left: 50%; transform: translateX(-50%); background: #f1f5f9; color: #0f172a; padding: 8px 14px; border-radius: 10px; font-weight: 800; font-size: 0.88rem; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4); z-index: 7; max-width: calc(100% - 24px); text-align: center; pointer-events: none; }
.toast.bad { background: #fee2e2; color: #7f1d1d; }
.ctrl { display: flex; gap: 8px; justify-content: center; padding: 4px 12px 12px; max-width: 560px; width: 100%; margin: 0 auto; }
.cbtn { flex: 1; max-width: 120px; display: flex; flex-direction: column; align-items: center; padding: 6px 8px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel); font-size: 1.15rem; line-height: 1.15; }
.cbtn span { font-size: 0.7rem; color: var(--dim); }
.cbtn.used { border-color: rgba(250, 204, 21, 0.5); }
.cbtn.go { border-color: var(--accent); background: rgba(125, 211, 252, 0.16); }
#rctrl { gap: 6px; }
#rctrl .cbtn { padding: 6px 4px; }
#play.replay .tube { cursor: default; }
#play.replay .goal b { color: var(--accent); }
/* 풀이 다시 보기 고르기 */
.rp-pick { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-top: 10px; }
.rp-list { display: grid; gap: 8px; margin-top: 8px; }
.rp-item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line); background: var(--panel2); }
.rp-item:disabled { opacity: 0.55; }
.rp-item .ri { font-size: 1.5rem; flex: none; }
.rp-item b { display: block; } .rp-item small { color: var(--dim); font-size: 0.78rem; }
body.sym .seg:not(.hid)::after { content: attr(data-s); }

/* ── 모달 ── */
.modal { position: fixed; inset: 0; background: rgba(3, 6, 12, 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: #060a12; 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; } }
.stars { font-size: 2rem; color: var(--gold); letter-spacing: 4px; }
.stars i { font-style: normal; color: #475569; }
.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(186, 230, 253, 0.12); border: 1px solid rgba(186, 230, 253, 0.45); font-size: 0.82rem; font-weight: 700; }
.help ul { margin: 6px 0; padding-left: 20px; font-size: 0.88rem; line-height: 1.55; }
.noscript { padding: 20px; text-align: center; }

@media (max-width: 400px) { .back-txt { display: none; } .tab { font-size: 0.74rem; } .sts { gap: 3px; } }
@media (max-height: 620px) { .cbtn span { display: none; } .p-title small { display: none; } .logo-art { display: none; } }
