:root {
  --bg: #1d1712; --panel: #2a2119; --panel2: #352a20; --line: rgba(253, 230, 138, 0.16);
  --text: #f8f1e3; --dim: #b8a88f; --accent: #f59e0b; --accent2: #fcd34d; --ok: #4ade80; --bad: #f87171;
  --paper: #fbf6ea; --ink: #2b2a33;
  --r: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 50% 0%, #3a2b1d 0%, #1d1712 60%, #110d0a 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-grid { display: inline-grid; grid-template-columns: repeat(5, 11px); gap: 2px; padding: 5px; background: var(--paper); border-radius: 6px; box-shadow: 0 4px 14px rgba(0,0,0,0.4); }
.logo-grid i { width: 11px; height: 11px; background: #eadfc6; border-radius: 1px; }
.logo-grid i.f { background: #e11d48; animation: pop 3.2s ease-in-out infinite; }
.logo-grid i.f:nth-child(3n) { animation-delay: 0.3s; }
.logo-grid i.f:nth-child(4n) { animation-delay: 0.6s; }
@keyframes pop { 0%, 70%, 100% { transform: scale(1); } 80% { transform: scale(0.75); } }
h1 { margin: 8px 0 2px; font-size: 1.55rem; letter-spacing: -0.02em; }
h1 span { color: var(--accent2); }
.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(245, 158, 11, 0.5); background: linear-gradient(135deg, rgba(245,158,11,0.2), rgba(245,158,11,0.06));
}
.continue.small { padding: 9px 12px; margin-bottom: 6px; }
.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); }

.pack { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; margin-bottom: 12px; }
.pack header { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.pack h3 { margin: 0; font-size: 1.05rem; }
.pack h3 small { color: var(--dim); font-weight: 600; margin-left: 4px; }
.pk-meta { margin-left: auto; color: var(--dim); font-size: 0.85rem; font-weight: 700; }
.pack p { margin: 4px 0 8px; }
.lock-msg { color: var(--accent2); font-weight: 700; font-size: 0.9rem; }
.pack.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: 4px; padding: 8px 4px 6px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel2); min-height: 110px;
}
.tile:not(:disabled):hover { border-color: var(--accent); transform: translateY(-1px); }
.tile canvas, .tile .q { width: 60px; height: 60px; border-radius: 6px; image-rendering: pixelated; }
.tile .q { display: grid; place-items: center; background: #efe5cf; color: #a39275; font-size: 1.6rem; font-weight: 800; }
.tile.done canvas { box-shadow: 0 0 0 2px rgba(255,255,255,0.25); }
.tile.wip { border-color: rgba(245, 158, 11, 0.6); }
.tile .tl { font-size: 0.78rem; font-weight: 700; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile .ts { color: var(--accent2); font-size: 0.75rem; letter-spacing: 1px; }

.opt-row { display: flex; align-items: center; gap: 6px; margin: 10px 0; flex-wrap: wrap; }
.opt-row .lbl { width: 52px; color: var(--dim); font-weight: 700; font-size: 0.88rem; }
.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); }
.wip-list { margin-bottom: 6px; }
.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; }
.rec-table { width: 100%; border-collapse: collapse; margin-top: 12px; text-align: center; font-size: 0.85rem; }
.rec-table th, .rec-table td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
.rec-table th { color: var(--dim); }
.rec-table small { color: var(--dim); }

.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; }

.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 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(252, 211, 77, 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; }
.stat-grid + .sec, .btn.danger { margin-top: 14px; }

/* ── 플레이 ── */
#play { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.p-head { display: flex; align-items: center; gap: 8px; 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 10px; border-radius: 999px; background: var(--panel); border: 1px solid var(--line); font-size: 0.85rem; white-space: nowrap; }
.board-wrap { flex: 1; min-height: 0; position: relative; display: grid; place-items: center; padding: 4px 8px; }
#board { display: block; touch-action: none; border-radius: 6px; box-shadow: 0 10px 30px rgba(0,0,0,0.45); background: var(--paper); }
.toast {
  position: absolute; left: 50%; top: 8px; transform: translateX(-50%); max-width: calc(100% - 24px);
  padding: 8px 14px; border-radius: 999px; background: rgba(17, 13, 10, 0.92); border: 1px solid var(--line);
  font-size: 0.85rem; font-weight: 700; text-align: center; pointer-events: none; z-index: 2;
}
.toolbar { display: flex; gap: 6px; padding: 8px 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); justify-content: center; flex-wrap: wrap; }
.seg { display: flex; border-radius: 14px; border: 1px solid var(--line); overflow: hidden; background: var(--panel); }
.tool { display: flex; align-items: center; gap: 6px; padding: 8px 12px; border: 0; background: transparent; font-weight: 800; font-size: 0.85rem; }
.tool.on { background: var(--accent2); color: #1c1306; }
.sw { width: 18px; height: 18px; border-radius: 3px; display: grid; place-items: center; font-size: 0.8rem; }
.sw.fill { background: var(--ink); box-shadow: inset 0 0 0 2px #fbf6ea; border: 1px solid #8c7f66; }
.sw.cross { background: var(--paper); color: #c2410c; border: 1px solid #8c7f66; }
.tbtn { display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 50px; padding: 5px 8px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); font-size: 1.1rem; line-height: 1; }
.tbtn span { font-size: 0.68rem; color: var(--dim); font-weight: 700; }

/* ── 모달 ── */
.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; }
.win { text-align: center; }
.win-pic { display: flex; justify-content: center; margin-bottom: 8px; }
.win-pic canvas { max-width: 200px; max-height: 200px; border-radius: 8px; image-rendering: pixelated; box-shadow: 0 0 0 4px #fbf6ea, 0 10px 30px rgba(0,0,0,0.5); 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(--accent2); 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(252, 211, 77, 0.15); border: 1px solid rgba(252, 211, 77, 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; }
.help-demo { display: inline-block; background: var(--paper); color: var(--ink); border-radius: 8px; padding: 6px 8px; font-weight: 800; font-size: 0.85rem; }
.help-demo > div { display: grid; grid-template-columns: 34px repeat(3, 24px); gap: 2px; align-items: center; }
.help-demo span { text-align: right; padding-right: 6px; }
.hd-cl span { text-align: center; padding: 0; }
.help-demo i { width: 24px; height: 24px; display: grid; place-items: center; background: #f1e7d0; font-style: normal; border-radius: 2px; }
.help-demo i.f { background: var(--ink); }
.help-demo i.x { color: #c2410c; font-size: 0.8rem; }
.noscript { padding: 20px; text-align: center; }

@media (max-width: 420px) {
  .back-txt { display: none; }
  .tab { font-size: 0.78rem; }
  .tool { padding: 8px 9px; }
  .tool span:last-child { font-size: 0.78rem; }
  .tbtn { min-width: 44px; padding: 5px 6px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
