:root {
  --bg: #0d1830;
  --panel: #16264a;
  --panel2: #1e335f;
  --line: #2f4a80;
  --text: #e8f1ff;
  --muted: #9fb3d6;
  --accent: #6fd3ff;
  --good: #7ee0a1;
  --bad: #ff8a8a;
  --wood: #c48a4f;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: radial-gradient(ellipse at top, #1c3266, var(--bg) 70%); color: var(--text); font-family: 'Fredoka', system-ui, sans-serif; overflow: hidden; }
button { font: inherit; color: inherit; }

#app { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 8px 12px; }

#hud, #toolbar, #stage { width: min(calc(100vw - 24px), calc((100vh - 170px) * 5 / 3)); }

#hud { display: flex; align-items: center; gap: 16px; padding: 6px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
.brand { font-weight: 700; font-size: 22px; letter-spacing: .5px; color: var(--accent); text-shadow: 0 2px 0 #0a1530; }
.lvl { flex: 1; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats { display: flex; gap: 14px; }
.stat { color: var(--muted); white-space: nowrap; }
.stat b { color: var(--text); font-size: 18px; }
.stat.good b { color: var(--good); }
.stat.bad b { color: var(--bad); }
.stat small { color: var(--muted); }

#stage { position: relative; aspect-ratio: 5 / 3; border-radius: 16px; overflow: hidden; border: 1px solid var(--line); box-shadow: 0 10px 40px rgba(0,0,0,.45); }
#game { display: block; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }

#toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
.tools { display: flex; gap: 6px; flex-wrap: wrap; }
.tool { position: relative; display: flex; flex-direction: column; align-items: center; width: 70px; padding: 4px 2px 3px; background: var(--panel2); border: 2px solid transparent; border-radius: 12px; cursor: pointer; transition: transform .08s, border-color .1s; }
.tool:hover { transform: translateY(-2px); }
.tool.active { border-color: var(--accent); background: #24407a; }
.tool.empty { opacity: .45; }
.tool canvas { width: 48px; height: 36px; }
.tool .name { font-size: 12px; color: var(--muted); }
.tool .count { position: absolute; top: -6px; right: -4px; min-width: 22px; height: 22px; padding: 0 5px; border-radius: 11px; background: var(--wood); color: #2a1606; font-weight: 700; font-size: 13px; display: grid; place-items: center; border: 2px solid var(--panel); }
.tool .key { position: absolute; top: 2px; left: 6px; font-size: 10px; color: #6f86b3; }

.controls { display: flex; gap: 6px; }
.controls button, .row button { padding: 9px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); cursor: pointer; font-weight: 600; }
.controls button:hover, .row button:hover { background: #2a467e; }
button.primary { background: #2a8fc4; border-color: #47b5ec; }
button.primary:hover { background: #33a2db; }

#overlay { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(8, 16, 36, .55); backdrop-filter: blur(2px); }
#overlay.hidden { display: none; }
.card { width: min(520px, 90%); padding: 22px 26px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; text-align: center; box-shadow: 0 16px 50px rgba(0,0,0,.5); }
.card h1 { margin: 0 0 8px; font-size: 30px; color: var(--accent); }
.card p { margin: 0 0 14px; color: var(--text); line-height: 1.45; }
.row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.levels { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.levels button { padding: 10px 6px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel2); cursor: pointer; }
.levels button:disabled { opacity: .35; cursor: not-allowed; }
.levels button .n { display: block; font-size: 20px; font-weight: 700; color: var(--accent); }
.levels button .t { font-size: 12px; color: var(--muted); }
.levels button.done .n::after { content: ' ✓'; color: var(--good); font-size: 14px; }
.toolsum { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 14px; color: var(--muted); }
.toolsum span { padding: 3px 10px; border-radius: 10px; background: var(--panel2); }

#toast { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); padding: 6px 14px; border-radius: 10px; background: rgba(10, 20, 44, .85); color: var(--text); font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; }
#toast.show { opacity: 1; }
#tip { color: var(--muted); font-size: 13px; min-height: 18px; text-align: center; }

@media (max-width: 720px) {
  .brand { display: none; }
  .tool { width: 56px; }
  .tool .name { display: none; }
  #hud { gap: 8px; }
  .stats { gap: 8px; font-size: 13px; }
}
