:root {
  --bg: #080a16; --bg2: #10142a; --panel: #161b36; --line: rgba(148, 163, 184, 0.18);
  --text: #f1f5f9; --dim: #94a3b8; --accent: #38bdf8; --pink: #e879f9; --gold: #fbbf24; --ok: #34d399; --bad: #f43f5e;
  --r: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(circle at 50% -10%, #1d1b4b, var(--bg) 65%);
  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; }
[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(255,255,255,0.07); border: 1px solid var(--line); color: var(--text);
  text-decoration: none; font-size: 0.85rem; font-weight: 600;
}
.back-btn:hover { background: rgba(255,255,255,0.14); }
.total { margin-left: auto; font-weight: 700; }
.total small { color: var(--dim); font-weight: 500; }
.tools { display: flex; gap: 6px; }
.mini { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255,255,255,0.07); font-weight: 700; }

/* ── 메뉴 ── */
.screen { flex: 1; overflow-y: auto; padding: 4px 16px 32px; }
.logo { text-align: center; margin: 2px 0 12px; }
.logo-hex {
  font-size: 2.8rem; line-height: 1; display: inline-block; color: var(--accent);
  text-shadow: 0 0 18px rgba(56,189,248,0.8), 0 0 36px rgba(232,121,249,0.5); animation: spin 8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.logo h1 { margin: 4px 0 4px; font-size: 1.55rem; letter-spacing: -0.5px; text-shadow: 0 0 18px rgba(56,189,248,0.45); }
.logo h1 span { background: linear-gradient(135deg, var(--accent), var(--pink)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.tagline { margin: 0; color: var(--dim); font-size: 0.9rem; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; max-width: 720px; margin: 0 auto 12px; }
.tab { padding: 9px 2px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg2); font-size: 0.82rem; font-weight: 700; white-space: nowrap; }
.tab.on { background: rgba(56,189,248,0.16); border-color: var(--accent); color: #bae6fd; }
.panel-wrap { max-width: 720px; margin: 0 auto; display: grid; gap: 12px; }
.card { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--r); padding: 12px; }
.card h2 { margin: 0 0 2px; font-size: 1.05rem; display: flex; gap: 8px; align-items: baseline; }
.card h2 small { margin-left: auto; color: var(--gold); font-size: 0.85rem; }
.card p { margin: 0 0 10px; color: var(--dim); font-size: 0.82rem; line-height: 1.45; }
.card p b { color: var(--text); }
.lv-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (min-width: 560px) { .lv-grid { grid-template-columns: repeat(6, 1fr); } }
.lv-btn {
  border: 1px solid var(--line); background: var(--panel); border-radius: 12px; padding: 8px 4px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; min-height: 92px;
}
.lv-btn:hover:not(:disabled) { border-color: var(--accent); }
.lv-btn b { font-size: 1rem; }
.lv-btn span { font-size: 0.7rem; color: var(--dim); text-align: center; line-height: 1.2; }
.lv-btn span.g { color: #bae6fd; font-size: 0.66rem; }
.lv-btn i { font-style: normal; font-size: 0.78rem; letter-spacing: 1px; color: var(--gold); margin-top: auto; }
.lv-btn:disabled { opacity: 0.38; cursor: not-allowed; }
.lv-btn.cleared { background: #1e2252; }
.resume {
  width: 100%; padding: 12px 14px; border-radius: 14px; border: 1px solid rgba(52,211,153,0.5);
  background: rgba(52,211,153,0.12); font-weight: 800; text-align: left; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap;
}
.resume span { font-weight: 500; font-size: 0.8rem; color: var(--dim); }
.diff-list { display: grid; gap: 8px; }
.diff {
  display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--panel); text-align: left; width: 100%;
}
.diff:hover { border-color: var(--accent); }
.diff .ico { font-size: 1.6rem; }
.diff b { display: block; font-size: 1rem; }
.diff span { color: var(--dim); font-size: 0.8rem; }
.diff .rec { margin-left: auto; text-align: right; color: var(--gold); font-weight: 700; font-size: 0.85rem; white-space: nowrap; }
.diff .rec small { display: block; color: var(--dim); font-weight: 500; }
.daily-rec, .stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 0 12px; }
.stat-grid { margin: 12px 0 0; }
.daily-rec div, .stat-grid div { background: var(--panel); border-radius: 12px; padding: 10px; text-align: center; }
.daily-rec small, .stat-grid small { display: block; color: var(--dim); font-size: 0.75rem; }
.daily-rec b, .stat-grid b { font-size: 1.25rem; color: var(--gold); }
.big-btn {
  display: block; width: 100%; padding: 14px; border-radius: 14px; border: 0; font-weight: 800; font-size: 1.05rem;
  background: linear-gradient(135deg, #38bdf8, #a855f7); color: #fff; box-shadow: 0 6px 22px rgba(56,189,248,0.3);
}
.stat-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.stat-table th, .stat-table td { padding: 7px 4px; border-bottom: 1px solid var(--line); text-align: center; }
.stat-table th { color: var(--dim); font-weight: 600; }

.btn {
  padding: 10px 16px; border-radius: 12px; border: 0; font-weight: 800;
  background: linear-gradient(135deg, #38bdf8, #a855f7); color: #fff;
}
.btn.ghost { background: rgba(255,255,255,0.08); border: 1px solid var(--line); }
.btn.danger { color: #fda4af; width: 100%; }
.btn.small { padding: 7px 11px; font-size: 0.85rem; background: rgba(255,255,255,0.08); border: 1px solid var(--line); font-weight: 700; }

/* ── 플레이 ── */
#play { flex: 1; display: flex; flex-direction: column; min-height: 0; padding: 0 12px max(10px, env(safe-area-inset-bottom)); max-width: 720px; width: 100%; margin: 0 auto; }
.p-head { display: flex; align-items: center; gap: 8px; }
.p-title { flex: 1; text-align: center; font-weight: 800; font-size: 0.98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 8px 0 4px; }
.chip { position: relative; padding: 5px 10px; border-radius: 999px; background: var(--bg2); border: 1px solid var(--line); font-size: 0.82rem; color: var(--dim); }
.chip b { color: var(--text); font-variant-numeric: tabular-nums; }
.chip.warn { border-color: var(--bad); }
.chip.warn b { color: #fda4af; }
.chip.goal { color: #bae6fd; }
.chip .stars { color: var(--gold); letter-spacing: 1px; margin-left: 4px; }
.float { position: absolute; left: 50%; top: -4px; transform: translateX(-50%); color: var(--gold); font-weight: 800; font-size: 0.85rem; pointer-events: none; animation: up 0.7s ease-out forwards; }
@keyframes up { to { transform: translate(-50%, -22px); opacity: 0; } }

.board-wrap { position: relative; flex: 1; min-height: 200px; touch-action: none; overflow: hidden; }
.board { position: absolute; inset: 0; }
.cell, .tile, .rock {
  position: absolute; left: 0; top: 0; width: var(--hw); height: var(--hh);
  margin-left: calc(var(--hw) / -2); margin-top: calc(var(--hh) / -2);
}
.cell, .tile > span, .rock > span { clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%); }
.cell { background: rgba(148, 163, 184, 0.09); box-shadow: inset 0 0 0 99px rgba(30, 41, 80, 0.4); }
.tile { transition: transform 0.1s ease-out; z-index: 2; }
.tile.dying { z-index: 1; opacity: 0.6; transition: transform 0.1s ease-out, opacity 0.1s; }
.tile > span {
  display: flex; align-items: center; justify-content: center; width: 100%; height: 100%;
  font-weight: 900; font-variant-numeric: tabular-nums; letter-spacing: -0.5px;
  font-size: min(var(--fs), calc(var(--fs) * 2.6 / (var(--len) + 0.6)));
  color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.45);
  background: var(--c1); background-image: linear-gradient(160deg, var(--c1), var(--c2));
}
.tile.spawn > span { animation: spawn 0.16s ease-out 0.09s backwards; }
.tile.pop > span { animation: pop 0.18s ease-out; }
@keyframes spawn { from { transform: scale(0.2); opacity: 0.3; } }
@keyframes pop { 50% { transform: scale(1.18); } }
.tile.v1 { --c1: #1e3a8a; --c2: #2563eb; }
.tile.v2 { --c1: #1d4ed8; --c2: #0ea5e9; }
.tile.v3 { --c1: #0891b2; --c2: #22d3ee; }
.tile.v4 { --c1: #0d9488; --c2: #2dd4bf; }
.tile.v5 { --c1: #059669; --c2: #4ade80; }
.tile.v6 { --c1: #65a30d; --c2: #bef264; }
.tile.v7 { --c1: #ca8a04; --c2: #facc15; }
.tile.v8 { --c1: #ea580c; --c2: #fb923c; }
.tile.v9 { --c1: #dc2626; --c2: #f87171; }
.tile.v10 { --c1: #db2777; --c2: #f472b6; }
.tile.v11 { --c1: #9333ea; --c2: #e879f9; }
.tile.v12, .tile.v13, .tile.v14, .tile.v15, .tile.v16, .tile.v17 { --c1: #312e81; --c2: #7c3aed; }
.tile.v6 > span, .tile.v7 > span { color: #1a1a1a; text-shadow: none; }
.tile.v11 > span, .tile.v12 > span, .tile.v13 > span { box-shadow: inset 0 0 18px rgba(255,255,255,0.6); }
.tile.wild > span {
  --c1: #f0abfc; --c2: #fde68a; color: #4c1d95; text-shadow: 0 0 6px #fff;
  background-image: conic-gradient(from 0deg, #f0abfc, #a5f3fc, #fde68a, #f0abfc);
  font-size: calc(var(--fs) * 1.1);
}
.tile.frozen::after {
  content: attr(data-pips); position: absolute; inset: 0; z-index: 1; pointer-events: none;
  clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%);
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 8%;
  font-size: calc(var(--fs) * 0.32); color: #0c4a6e; text-shadow: 0 0 4px #38bdf8; letter-spacing: 1px;
  background: linear-gradient(150deg, rgba(224,242,254,0.88), rgba(125,211,252,0.6) 45%, rgba(186,230,253,0.82)),
    repeating-linear-gradient(120deg, transparent 0 9px, rgba(255,255,255,0.35) 9px 11px);
  box-shadow: inset 0 0 0 3px rgba(224,242,254,0.8);
}
.tile.frozen[data-ice="1"]::after { background: linear-gradient(150deg, rgba(224,242,254,0.4), rgba(125,211,252,0.12) 45%, rgba(186,230,253,0.35)), repeating-linear-gradient(40deg, transparent 0 12px, rgba(255,255,255,0.35) 12px 13px); }
.tile.crack::after { animation: shake 0.2s; }
.tile.melt::after { animation: melt 0.38s ease-in forwards; }
@keyframes melt { to { opacity: 0; transform: scale(1.25); filter: blur(3px); } }
.rock { z-index: 3; }
.rock > span {
  display: flex; align-items: center; justify-content: center; width: 100%; height: 100%;
  background: radial-gradient(circle at 35% 30%, #a8a29e, #57534e 60%, #292524);
  color: #fde68a; font-size: calc(var(--fs) * 0.42); letter-spacing: 1px; text-shadow: 0 0 4px #f59e0b;
}
.rock[data-hp="1"] > span { background: radial-gradient(circle at 35% 30%, #a8a29e, #57534e 60%, #292524), repeating-linear-gradient(60deg, transparent 0 10px, rgba(0,0,0,0.5) 10px 12px); background-blend-mode: multiply; }
.rock.hit > span { animation: shake 0.2s; }
.rock.break > span { animation: crumble 0.38s ease-in forwards; }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.ach-got { margin: 10px auto 4px; padding: 8px 12px; border-radius: 12px; border: 1px solid var(--gold); background: rgba(251,191,36,0.1); display: flex; flex-wrap: wrap; gap: 6px 12px; justify-content: center; font-size: 0.9rem; }
.ach-got small { width: 100%; color: var(--gold); font-weight: 800; }
.ach-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 6px; }
.ach-list li { display: flex; gap: 8px; align-items: center; padding: 7px 9px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg2); opacity: 0.55; }
.ach-list li.on { opacity: 1; border-color: rgba(251,191,36,0.6); }
.ach-list i { font-style: normal; font-size: 1.3rem; }
.ach-list span { display: flex; flex-direction: column; min-width: 0; }
.ach-list small { color: var(--dim); font-size: 0.75rem; }
@keyframes crumble { to { transform: scale(1.4) rotate(18deg); opacity: 0; filter: blur(2px); } }

.toast {
  position: absolute; left: 50%; top: 8px; transform: translateX(-50%); z-index: 9; pointer-events: none;
  background: rgba(15, 23, 42, 0.92); border: 1px solid var(--accent); border-radius: 999px; padding: 7px 14px;
  font-size: 0.85rem; font-weight: 700; white-space: nowrap;
}
.toast.show { animation: tin 0.25s ease-out; }
@keyframes tin { from { opacity: 0; transform: translate(-50%, -8px); } }

.controls { display: flex; align-items: center; justify-content: center; gap: 18px; margin-top: 6px; }
.pad { display: grid; grid-template-columns: repeat(4, 46px); grid-template-rows: repeat(3, 40px); gap: 4px; }
.dir {
  border: 1px solid var(--line); background: var(--bg2); border-radius: 12px; font-size: 1.15rem; font-weight: 800; color: #bae6fd;
  touch-action: manipulation;
}
.dir:active { background: rgba(56,189,248,0.25); }
/* ↖ ↗ / ← → / ↙ ↘ 를 육각형 모양으로 */
.dir[data-d="4"] { grid-area: 1 / 2; } .dir[data-d="5"] { grid-area: 1 / 3; }
.dir[data-d="3"] { grid-area: 2 / 1; } .dir[data-d="0"] { grid-area: 2 / 4; }
.dir[data-d="2"] { grid-area: 3 / 2; } .dir[data-d="1"] { grid-area: 3 / 3; }
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 12px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--bg2); font-size: 0.75rem; color: var(--dim);
}
.tool i { font-style: normal; font-size: 1.3rem; color: var(--text); }
.tool:disabled { opacity: 0.4; }
.keys { text-align: center; color: var(--dim); font-size: 0.72rem; margin: 6px 0 0; }
@media (hover: none) { .keys { display: none; } }
@media (max-height: 640px) { .pad { grid-template-rows: repeat(3, 34px); } .keys { display: none; } }

/* ── 모달 ── */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(2, 6, 23, 0.72); display: flex; align-items: center; justify-content: center; padding: 16px; }
.dialog {
  background: var(--bg2); border: 1px solid var(--line); border-radius: 18px; padding: 18px; width: 100%; max-width: 420px;
  max-height: 90vh; overflow-y: auto; text-align: center; animation: tin2 0.22s ease-out;
}
@keyframes tin2 { from { transform: scale(0.92); opacity: 0; } }
.dialog h2 { margin: 0 0 8px; }
.dialog p { margin: 6px 0; color: var(--text); }
.dialog .dim { color: var(--dim); font-size: 0.85rem; }
.dialog .row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 14px; }
.big-num { font-size: 2rem; font-weight: 900; color: var(--gold); }
.big-stars { font-size: 2.6rem; letter-spacing: 6px; }
.big-stars span { color: #334155; display: inline-block; }
.big-stars span.on { color: var(--gold); animation: starIn 0.4s ease-out both; text-shadow: 0 0 14px rgba(251,191,36,0.7); }
@keyframes starIn { from { transform: scale(0) rotate(-90deg); } }
.help { text-align: left; padding-left: 18px; margin: 0; font-size: 0.88rem; line-height: 1.55; color: var(--dim); }
.help b { color: var(--text); }
kbd { display: inline-block; min-width: 1.4em; padding: 0 4px; border-radius: 5px; border: 1px solid var(--line); background: var(--panel); font-size: 0.78rem; text-align: center; color: var(--text); }
.noscript { text-align: center; padding: 40px; }
