: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-drop { display: inline-flex; gap: 4px; }
.logo-drop span {
  width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; font-weight: 900; color: #fff;
  background: linear-gradient(160deg, #2563eb, #a855f7); box-shadow: 0 0 14px rgba(56,189,248,0.5);
  animation: fall 2.4s cubic-bezier(.5,0,.6,1.4) infinite;
}
.logo-drop span:nth-child(2) { animation-delay: 0.15s; background: linear-gradient(160deg, #0891b2, #22d3ee); }
.logo-drop span:nth-child(3) { animation-delay: 0.3s; background: linear-gradient(160deg, #ca8a04, #facc15); color: #1a1a1a; }
.logo-drop span:nth-child(4) { animation-delay: 0.45s; background: linear-gradient(160deg, #db2777, #f472b6); }
@keyframes fall { 0% { transform: translateY(-14px); opacity: 0; } 18%, 80% { transform: none; opacity: 1; } 100% { transform: translateY(6px); opacity: 0; } }
.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; }
.chip .done { color: var(--ok); }
.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: 220px; touch-action: none; overflow: hidden; }
.board {
  position: absolute; left: 50%; top: 50%; width: calc(var(--s) * var(--w)); height: calc(var(--s) * (var(--h) + 1));
  transform: translate(-50%, -50%);
}
.lane { position: absolute; left: 0; right: 0; top: 0; height: var(--s); }
.well {
  position: absolute; left: 0; right: 0; top: var(--s); bottom: 0; border-radius: 12px;
  background: rgba(16, 20, 42, 0.85); border: 1px solid var(--line); box-shadow: inset 0 0 30px rgba(56,189,248,0.08);
}
.colhl { position: absolute; top: var(--s); bottom: 0; width: var(--s); background: linear-gradient(to bottom, rgba(56,189,248,0.18), rgba(56,189,248,0.04)); border-radius: 10px; transition: transform 0.08s; pointer-events: none; }
.colhl.full { background: linear-gradient(to bottom, rgba(244,63,94,0.3), rgba(244,63,94,0.05)); }
.colhl.hammer { background: none; }
.danger { position: absolute; left: 0; width: calc(var(--s) * var(--w)); top: var(--s); height: 0; border-top: 2px dashed rgba(244,63,94,0.55); pointer-events: none; }
.slot { position: absolute; top: var(--s); bottom: 0; width: var(--s); }
.slot.warn { background: linear-gradient(to bottom, rgba(244,63,94,0.16), transparent 40%); }
.tile, .rock {
  position: absolute; left: 0; top: 0; width: var(--s); height: var(--s); padding: 3px; z-index: 2;
  transition: transform var(--t, 0.12s) ease-in;
}
.tile > span, .rock > span {
  position: relative; display: flex; align-items: center; justify-content: center; width: 100%; height: 100%; border-radius: 10px;
}
.tile > span {
  font-weight: 900; font-variant-numeric: tabular-nums; letter-spacing: -0.5px;
  font-size: min(calc(var(--s) * 0.42), calc(var(--s) * 1.15 / (var(--len) + 0.4)));
  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));
  box-shadow: 0 2px 0 rgba(0,0,0,0.35), inset 0 1px 0 rgba(255,255,255,0.25);
}
.tile.aim { z-index: 4; transition: transform 0.07s ease-out; }
.tile.aim > span { box-shadow: 0 0 16px var(--c2); }
.tile.aim.blocked > span { filter: grayscale(0.8) brightness(0.6); }
.tile.ghost { z-index: 1; opacity: 0.28; transition: transform 0.07s ease-out; pointer-events: none; }
.tile.dying { z-index: 1; opacity: 0; transition: transform 0.11s ease-in, opacity 0.13s ease-in; }
.tile.pop > span { animation: pop 0.22s ease-out; }
.tile.spawn > span { animation: spawn 0.2s ease-out; }
@keyframes pop { 45% { transform: scale(1.22); } }
@keyframes spawn { from { transform: scale(0.3); opacity: 0.2; } }
.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.ice > span {
  color: #e0f2fe; text-shadow: 0 0 4px #0ea5e9;
  background-image: linear-gradient(135deg, rgba(224,242,254,0.75), rgba(125,211,252,0.45) 45%, rgba(224,242,254,0.7)), linear-gradient(160deg, var(--c1), var(--c2));
  box-shadow: inset 0 0 0 2px rgba(224,242,254,0.85), 0 0 10px rgba(125,211,252,0.5);
}
.tile.ice > span::after { content: '❄'; position: absolute; top: 4px; right: 6px; font-size: calc(var(--s) * 0.2); }
.tile.thaw > span { animation: thaw 0.35s ease-out; }
@keyframes thaw { 0% { filter: brightness(2.2); transform: scale(1.12); } }
.rock { z-index: 3; }
.rock > span {
  background: radial-gradient(circle at 35% 30%, #a8a29e, #57534e 60%, #292524);
  color: #fde68a; font-size: calc(var(--s) * 0.2); letter-spacing: 1px; text-shadow: 0 0 4px #f59e0b;
  box-shadow: 0 2px 0 rgba(0,0,0,0.4);
}
.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, .tile.smash { transition: none; }
.rock.break > span, .tile.smash > span { animation: crumble 0.38s ease-in forwards; }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
@keyframes crumble { to { transform: scale(1.4) rotate(18deg); opacity: 0; filter: blur(2px); } }
.tile.bomb > span, .tile.wild > span { font-size: calc(var(--s) * 0.5); text-shadow: none; }
.tile.bomb > span { background: radial-gradient(circle at 35% 30%, #57534e, #1c1917 70%); box-shadow: inset 0 0 0 2px #f97316, 0 0 10px rgba(249,115,22,0.55); animation: fuse 1.1s ease-in-out infinite; }
.tile.wild > span { background: conic-gradient(from 0deg, #f43f5e, #f59e0b, #facc15, #4ade80, #22d3ee, #6366f1, #d946ef, #f43f5e); box-shadow: inset 0 0 0 2px rgba(255,255,255,0.7), 0 0 12px rgba(217,70,239,0.5); }
.tile.aim.bomb > span, .tile.ghost.bomb > span { animation: none; }
@keyframes fuse { 50% { box-shadow: inset 0 0 0 2px #fde047, 0 0 16px rgba(250,204,21,0.8); } }
.tile.bomb.break > span { animation: crumble 0.38s ease-in forwards; }
.boom { position: absolute; left: 0; top: 0; width: var(--s); height: var(--s); z-index: 6; pointer-events: none; }
.boom::before { content: ''; position: absolute; inset: calc(var(--s) * -1); border-radius: 50%;
  background: radial-gradient(circle, rgba(254,240,138,0.95), rgba(249,115,22,0.7) 40%, rgba(239,68,68,0) 70%); animation: boom 0.5s ease-out forwards; }
@keyframes boom { from { transform: scale(0.2); opacity: 1; } to { transform: scale(1.1); opacity: 0; } }
.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; }
.hammering .tile:not(.aim), .hammering .rock { cursor: crosshair; }
.hammering .well { box-shadow: inset 0 0 0 2px var(--gold), inset 0 0 30px rgba(251,191,36,0.2); }

.combo {
  position: absolute; left: 50%; top: 38%; transform: translate(-50%, -50%); z-index: 8; pointer-events: none;
  font-size: 2rem; font-weight: 900; color: var(--gold); text-shadow: 0 0 18px rgba(251,191,36,0.8), 0 2px 0 #000; white-space: nowrap;
}
.combo.show { animation: comboIn 0.7s ease-out forwards; }
@keyframes comboIn { 0% { transform: translate(-50%, -50%) scale(0.4); opacity: 0; } 25% { transform: translate(-50%, -50%) scale(1.15); opacity: 1; } 100% { transform: translate(-50%, -90%) scale(1); opacity: 0; } }
.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); } }
.shake { animation: bshake 0.3s; }
@keyframes bshake { 25% { margin-top: -4px; } 75% { margin-top: 3px; } }

.controls { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 6px; }
.next-box { display: flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 14px; border: 1px solid var(--line); background: var(--bg2); color: var(--dim); font-size: 0.8rem; }
.next-tile { position: relative; width: 40px; height: 40px; --s: 40px; }
.next-tile .tile { position: static; padding: 0; }
.tool {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--bg2); font-size: 0.8rem; color: var(--dim);
}
.tool i { font-style: normal; font-size: 1.3rem; color: var(--text); }
.tool:disabled { opacity: 0.4; }
.tool.on { border-color: var(--gold); background: rgba(251,191,36,0.15); color: var(--gold); }
.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) { .keys { display: none; } .hud { margin: 4px 0 2px; } }

/* ── 모달 ── */
.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; }
