:root {
  --bg: #1c150e; --panel: #2a2017; --panel2: #352920; --line: rgba(250, 204, 21, 0.16);
  --text: #f8f1e3; --dim: #b9a98f; --accent: #facc15; --accent2: #fde68a; --ok: #4ade80; --bad: #f87171;
  --r: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 50% 0%, #3b2a1a 0%, var(--board-bg, #1c150e) 62%, #0e0a06 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: 760px; margin-left: auto; margin-right: auto; }
.logo { text-align: center; margin: 2px auto 12px; }
.logo-art { display: inline-grid; grid-template-columns: repeat(4, 30px); gap: 0; padding: 4px; background: #e9d8b4; border-radius: 8px; box-shadow: 0 0 0 4px #8b5e3c, 0 6px 16px rgba(0,0,0,0.45); }
.logo-art span { width: 30px; height: 30px; display: grid; place-items: center; font-size: 1.2rem; }
.lw { background: #a8754d; border-radius: 3px; }
.lk { animation: walk 2.6s ease-in-out infinite; }
.lb { background: #c8873f; border: 3px solid #8a5522; border-radius: 6px; animation: shove 2.6s ease-in-out infinite; }
.lg { background: radial-gradient(circle, #f59e0b 0 18%, transparent 20% 46%, #f59e0b 48% 56%, transparent 58%); }
@keyframes walk { 0%, 30% { transform: translateX(0); } 55%, 100% { transform: translateX(8px); } }
@keyframes shove { 0%, 30% { transform: translateX(0); } 55%, 100% { transform: translateX(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 4px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-weight: 700; font-size: 0.86rem; white-space: nowrap; }
.tab.on { background: var(--accent); color: #1c1306; border-color: var(--accent); }
.dim { color: var(--dim); }
.small { font-size: 0.82rem; }
.good { color: var(--ok); font-weight: 700; margin: 6px 0; }

.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(250, 204, 21, 0.5); background: linear-gradient(135deg, rgba(250,204,21,0.2), rgba(250,204,21,0.06));
}
.continue .ci { width: 34px; height: 34px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: #1c1306; font-size: 0.9rem; }
.continue b { display: block; }
.continue small { color: var(--dim); }

.zone { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; margin-bottom: 12px; }
.zone header { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.zone h3 { margin: 0; font-size: 1.05rem; }
.zn-meta { margin-left: auto; color: var(--dim); font-size: 0.85rem; font-weight: 700; }
.zone p { margin: 4px 0 8px; }
.lock-msg { color: var(--accent2); font-weight: 700; font-size: 0.9rem; }
.zone.locked .tiles { opacity: 0.4; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.tile {
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 4px 6px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel2); min-height: 116px;
}
.tile:not(:disabled):hover { border-color: var(--accent); transform: translateY(-1px); }
.tile canvas { width: 64px; height: 56px; object-fit: contain; image-rendering: pixelated; }
.tile.done { border-color: rgba(74, 222, 128, 0.35); }
.tile.wip { border-color: rgba(250, 204, 21, 0.7); }
.tile .tl { font-size: 0.8rem; font-weight: 800; }
.tile .ts { color: var(--accent); font-size: 0.75rem; letter-spacing: 1px; }
.tile .tp { color: var(--dim); font-size: 0.68rem; }

.opt-row { display: flex; align-items: center; gap: 6px; margin: 10px 0; flex-wrap: wrap; }
.pill { padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); font-weight: 700; }
.pill.on { background: var(--accent2); color: #1c1306; border-color: var(--accent2); }
.rec { color: var(--dim); }
.rec b { color: var(--text); }
.seed { margin: 14px 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.seed summary { cursor: pointer; font-weight: 700; }
.seed-row { display: flex; gap: 8px; margin-top: 8px; }
.seed-row input { flex: 1; min-width: 0; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); font: inherit; }
.seed-row input.bad { border-color: var(--bad); }
code { background: var(--panel2); padding: 1px 5px; border-radius: 5px; user-select: text; -webkit-user-select: text; }

.daily-card { text-align: center; background: linear-gradient(160deg, var(--panel2), var(--panel)); border: 1px solid var(--line); border-radius: var(--r); padding: 18px 14px; }
.dc-date { font-size: 1.2rem; font-weight: 800; }
.dc-size { color: var(--accent2); font-weight: 800; margin: 4px 0; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; margin-top: 10px; text-align: center; font-size: 0.82rem; }
.cal b { color: var(--dim); font-weight: 700; }
.cal span { padding: 7px 0; border-radius: 8px; background: var(--panel); border: 1px solid var(--line); }
.cal span.ok { background: rgba(74, 222, 128, 0.25); border-color: rgba(74, 222, 128, 0.6); }
.cal span.now { outline: 2px solid var(--accent); }
.cal span.fut { opacity: 0.35; }
.cal button { padding: 7px 0; border-radius: 8px; background: var(--panel); border: 1px dashed var(--line); color: inherit; font: inherit; cursor: pointer; }
.cal button:hover, .cal button:focus-visible { border-color: var(--accent); }
.cal .ok { background: rgba(74, 222, 128, 0.25); border: 1px solid rgba(74, 222, 128, 0.6); }
.cal .redo { background: rgba(167, 139, 250, 0.28); border: 1px solid rgba(167, 139, 250, 0.7); }
.cal i { display: block; font-style: normal; font-size: 0.6rem; line-height: 1; color: #fbbf24; }
.cal-note { margin-top: 8px; }

.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat-grid div { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 6px; text-align: center; }
.stat-grid b { display: block; font-size: 1.15rem; }
.stat-grid b small { color: var(--dim); font-size: 0.75rem; }
.stat-grid > div > small { color: var(--dim); font-size: 0.76rem; }
.sec { margin: 18px 0 8px; font-size: 1rem; }
.sec small { color: var(--dim); }
.ach-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px; }
.ach { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); opacity: 0.55; }
.ach.got { opacity: 1; border-color: rgba(253, 230, 138, 0.5); }
.ach .ai { font-size: 1.3rem; }
.ach b { display: block; font-size: 0.88rem; }
.ach small { color: var(--dim); font-size: 0.76rem; }
.opt { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; margin-bottom: 6px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); cursor: pointer; }
.opt input { margin-top: 3px; width: 18px; height: 18px; accent-color: var(--accent); }
.opt b { display: block; font-size: 0.9rem; }
.opt small { color: var(--dim); font-size: 0.78rem; }

.btn { padding: 10px 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); font-weight: 700; }
.btn.primary { background: var(--accent); color: #1c1306; border-color: var(--accent); }
.btn.danger { background: rgba(248, 113, 113, 0.15); border-color: rgba(248, 113, 113, 0.5); color: #fecaca; }
.btn.big { display: block; width: 100%; padding: 14px; font-size: 1.05rem; margin-top: 10px; }
.btn.small { padding: 6px 12px; }
.panel-wrap > .btn.danger { margin-top: 14px; }

/* ── 플레이 ── */
#play { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.p-head { display: flex; align-items: center; gap: 6px; padding: 2px 12px 6px; }
.p-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.p-title b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-title small { color: var(--dim); font-size: 0.75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { padding: 5px 9px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 0.85rem; white-space: nowrap; }
.chip small { color: var(--dim); }
#hPushChip.over3 { border-color: rgba(250, 204, 21, 0.6); }
#hPushChip.over2 { border-color: rgba(248, 113, 113, 0.6); }
.board-wrap { flex: 1; min-height: 0; position: relative; display: grid; place-items: center; padding: 4px; }
#board { display: block; touch-action: none; border-radius: 8px; }
.toast {
  position: absolute; left: 50%; top: 8px; transform: translateX(-50%); max-width: calc(100% - 24px);
  padding: 8px 14px; border-radius: 999px; background: rgba(14, 10, 6, 0.92); border: 1px solid var(--line);
  font-size: 0.85rem; font-weight: 700; text-align: center; pointer-events: none; z-index: 2;
}
.controls { display: flex; align-items: center; justify-content: center; gap: 18px; padding: 6px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.toolbar { display: flex; gap: 6px; }
.tbtn { display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 58px; padding: 7px 8px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 1.15rem; line-height: 1; }
.tbtn span { font-size: 0.68rem; color: var(--dim); font-weight: 700; }
.pad { display: grid; grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(2, 40px); gap: 4px; touch-action: none; }
.pb { border-radius: 10px; border: 1px solid var(--line); background: var(--panel2); font-size: 0.95rem; color: var(--accent2); touch-action: none; }
.pb:active { background: var(--accent); color: #1c1306; }
.pb.up { grid-column: 2; grid-row: 1; }
.pb.left { grid-column: 1; grid-row: 2; }
.pb.down { grid-column: 2; grid-row: 2; }
.pb.right { grid-column: 3; grid-row: 2; }

/* ── 모달 ── */
.modal { position: fixed; inset: 0; background: rgba(8, 6, 4, 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; }
.err { font-family: ui-monospace, monospace; font-size: 0.75rem; background: #0f0b08; padding: 8px; border-radius: 8px; white-space: pre-wrap; color: #fecaca; max-height: 140px; overflow: auto; user-select: text; -webkit-user-select: text; }
.loading { text-align: center; width: min(260px, 100%); }
.spin { font-size: 2.2rem; animation: bounce 0.7s ease-in-out infinite alternate; }
@keyframes bounce { from { transform: translateY(0) rotate(-8deg); } to { transform: translateY(-10px) rotate(8deg); } }
.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(--accent); letter-spacing: 4px; }
.win-line { margin: 4px 0; font-weight: 700; }
.win-line small { color: var(--dim); }
.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(253, 230, 138, 0.15); border: 1px solid rgba(253, 230, 138, 0.5); font-size: 0.82rem; font-weight: 700; }
.help ul { padding-left: 18px; margin: 8px 0; }
.help li { margin-bottom: 6px; line-height: 1.45; font-size: 0.9rem; }
.noscript { padding: 20px; text-align: center; }

@media (max-width: 480px) {
  .back-txt { display: none; }
  .tab { font-size: 0.74rem; }
  .hide-s { display: none; }
  .controls { gap: 10px; }
  .tbtn { min-width: 50px; padding: 6px 5px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-height: 520px) and (orientation: landscape) {
  #play { flex-direction: row; flex-wrap: wrap; }
  .p-head { width: 100%; }
  .board-wrap { flex: 1; height: calc(100% - 44px); }
  .controls { flex-direction: column; gap: 8px; height: calc(100% - 44px); }
  .toolbar { flex-direction: row; }
}
