:root {
  --bg: #0f1f17; --bg2: #24452f; --panel: #162b1f; --panel2: #1e3a29; --line: rgba(134, 239, 172, 0.18);
  --text: #effcf3; --dim: #a3bfae; --accent: #86efac; --accent2: #bbf7d0; --bad: #f87171; --gold: #facc15;
  --r: 16px;
  --soil: #3b2f22; --soil2: #4a3b2a; --pipe: #7c8a94; --dry: #2b343b; --water: #38bdf8; --rockc: #57534e;
}
body.t-desert { --bg: #2a1a0c; --bg2: #6b4a22; --panel: #3a2612; --panel2: #4a3219; --line: rgba(253, 230, 138, 0.2); --accent: #fcd34d; --accent2: #fde68a; --soil: #c2924f; --soil2: #d6a660; --pipe: #8b5e34; --dry: #5a3b1d; --water: #22d3ee; --rockc: #7c5a3a; }
body.t-winter { --bg: #0d1a2b; --bg2: #2c4766; --panel: #142438; --panel2: #1c3049; --line: rgba(186, 230, 253, 0.2); --accent: #bae6fd; --accent2: #e0f2fe; --soil: #cbd5e1; --soil2: #e2e8f0; --pipe: #64748b; --dry: #334155; --water: #0ea5e9; --rockc: #94a3b8; }
body.t-night { --bg: #070a17; --bg2: #1d2453; --panel: #121733; --panel2: #1a2045; --line: rgba(196, 181, 253, 0.2); --accent: #c4b5fd; --accent2: #ddd6fe; --soil: #1e2240; --soil2: #262b52; --pipe: #475080; --dry: #151935; --water: #fde047; --rockc: #3b3f6b; }
body.t-sakura { --bg: #2a1020; --bg2: #6e2c4f; --panel: #3a1730; --panel2: #4a1f3c; --line: rgba(249, 168, 212, 0.22); --accent: #f9a8d4; --accent2: #fbcfe8; --soil: #5b3a2e; --soil2: #6b4636; --pipe: #b08a7a; --dry: #3d2a22; --water: #f472b6; --rockc: #7a5a50; }
* { 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-grid; grid-template-columns: repeat(3, 34px); grid-auto-rows: 34px; gap: 2px; padding: 4px; border-radius: 10px; background: rgba(0, 0, 0, 0.25); --ts: 34px; }
.mini-board { display: inline-grid; grid-template-columns: repeat(3, 30px); grid-auto-rows: 30px; gap: 2px; padding: 4px; border-radius: 10px; background: rgba(0, 0, 0, 0.25); --ts: 30px; margin: 6px auto; }
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: #052e16; 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: #052e16; 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(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: #052e16; }
.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: #15803d; 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(163, 191, 174, 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(134, 239, 172, 0.4); }
.st.next { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(134, 239, 172, 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: #15803d; } .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(134, 239, 172, 0.3) inset; }
.th-garden { background: linear-gradient(#24452f, #3b2f22); } .th-desert { background: linear-gradient(#6b4a22, #c2924f); } .th-winter { background: linear-gradient(#2c4766, #cbd5e1); }
.th-night { background: linear-gradient(#1d2453, #070a17); } .th-sakura { background: linear-gradient(#6e2c4f, #f9a8d4); }

/* ── 판 ── */
#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; }
.board-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; position: relative; padding: 6px 8px; }
.board { display: grid; grid-template-columns: repeat(var(--w), var(--ts)); grid-auto-rows: var(--ts); gap: 2px; padding: 6px; border-radius: 14px; background: rgba(0, 0, 0, 0.28); border: 2px solid var(--line); touch-action: manipulation; }
.board.wrap { border: 2px dashed var(--accent); box-shadow: 0 0 0 4px rgba(134, 239, 172, 0.08); }
.tile { -webkit-touch-callout: none; position: relative; width: var(--ts); height: var(--ts); padding: 0; border: 0; border-radius: calc(var(--ts) * 0.14); background: linear-gradient(145deg, var(--soil2), var(--soil)); overflow: visible; touch-action: manipulation; }
.tile.rock { background: radial-gradient(circle at 40% 35%, color-mix(in srgb, var(--rockc) 75%, white), var(--rockc) 60%, color-mix(in srgb, var(--rockc) 60%, black)); cursor: default; }
.tile.fixed { box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.18); background: linear-gradient(145deg, color-mix(in srgb, var(--soil2) 70%, #000), color-mix(in srgb, var(--soil) 70%, #000)); }
.tile.lock { box-shadow: inset 0 0 0 3px var(--gold); }
.pipe { position: absolute; inset: 0; width: 100%; height: 100%; transition: transform 0.14s ease-out; pointer-events: none; }
.pipe .o { stroke: var(--pipe); stroke-width: 30; stroke-linecap: butt; fill: var(--pipe); }
.pipe .w { stroke: var(--dry); stroke-width: 14; stroke-linecap: butt; fill: var(--dry); transition: stroke 0.25s, fill 0.25s; }
.tile.wet .pipe .w { stroke: var(--water); fill: var(--water); }
.tile.wet .pipe { filter: drop-shadow(0 0 3px color-mix(in srgb, var(--water) 60%, transparent)); }
.tile .ov { position: absolute; inset: 0; display: grid; place-items: center; font-size: calc(var(--ts) * 0.46); line-height: 1; pointer-events: none; }
.tile .ov.fl { font-size: calc(var(--ts) * 0.42); transition: transform 0.25s; }
.tile.wet .ov.fl { animation: bloom 0.45s ease-out; }
@keyframes bloom { 0% { transform: scale(0.5); } 60% { transform: scale(1.25); } 100% { transform: none; } }
.tile .ov.src { font-size: calc(var(--ts) * 0.5); filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.6)); }
.tile .bolt, .tile .lk { position: absolute; right: 1px; top: 0; font-size: calc(var(--ts) * 0.22); line-height: 1; pointer-events: none; opacity: 0.85; }
.tile .lk { left: 1px; right: auto; }
.tile.leak::after { content: ''; position: absolute; inset: 2px; border-radius: inherit; box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.75); animation: leak 1.1s ease-in-out infinite; pointer-events: none; }
body.noleak .tile.leak::after { display: none; }
@keyframes leak { 50% { box-shadow: 0 0 0 2px rgba(248, 113, 113, 0.15); } }
.tile.hint { animation: hintp 0.9s ease-in-out 2; }
@keyframes hintp { 50% { box-shadow: 0 0 0 4px var(--gold), 0 0 16px var(--gold); } }
.tile.shake { animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.board.won .tile:not(.rock) { animation: wonp 0.7s ease-out both; animation-delay: calc(var(--d, 0) * 18ms); }
@keyframes wonp { 40% { filter: brightness(1.5); transform: scale(1.06); } 100% { filter: none; transform: none; } }
.cbtn.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 22%, var(--panel)); }
.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); }

/* ── 모달 ── */
.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; } }
.help .center { text-align: center; }
