:root {
  color-scheme: dark;
  --bg: #04050b;
  --panel: rgba(10, 14, 28, 0.88);
  --line: rgba(126, 231, 255, 0.18);
  --text: #e9f3ff;
  --muted: #90a4bd;
  --cyan: #67e8f9;
  --blue: #56a8ff;
  --violet: #a78bfa;
  --gold: #f9e675;
  --red: #ff6b81;
  font-family: Inter, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 15% 15%, rgba(103, 232, 249, 0.12), transparent 28%),
    radial-gradient(circle at 85% 10%, rgba(167, 139, 250, 0.13), transparent 30%),
    var(--bg);
  color: var(--text);
}

#app {
  min-height: 100%;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px clamp(14px, 3vw, 32px);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
  z-index: 3;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  border: 0; background: transparent; color: var(--text);
  font: 700 clamp(17px, 2.4vw, 22px)/1 inherit;
  cursor: pointer; letter-spacing: -0.02em;
}
.brand-mark {
  width: 32px; height: 32px; display: grid; place-items: center;
  border-radius: 9px; color: #06131d; background: linear-gradient(135deg, var(--cyan), var(--gold));
  box-shadow: 0 0 24px rgba(103,232,249,.42);
}
.stats { display: flex; gap: 8px; min-width: 0; }
.icon-button { width: 38px; height: 38px; padding: 0; border-radius: 10px; }
.stat {
  min-width: 72px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px;
  background: rgba(255,255,255,.03);
  display: grid; gap: 2px;
}
.stat span { font-size: 10px; color: var(--muted); letter-spacing: .08em; }
.stat strong { font-size: 17px; }

.stage-wrap {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  padding: clamp(10px, 2vw, 24px);
}
canvas {
  max-width: 100%; max-height: 100%;
  aspect-ratio: var(--game-aspect, 16 / 9);
  border: 1px solid rgba(126,231,255,.24);
  border-radius: 14px;
  background: #05060e;
  box-shadow: 0 24px 90px rgba(0,0,0,.72), 0 0 60px rgba(86,168,255,.08);
  touch-action: none;
}

.overlay {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  padding: 20px;
  background: linear-gradient(180deg, rgba(4,5,11,.72), rgba(4,5,11,.88));
  backdrop-filter: blur(7px);
  opacity: 0; visibility: hidden;
  transition: .2s ease;
  z-index: 4;
}
.overlay.visible { opacity: 1; visibility: visible; }
.panel {
  width: min(760px, 100%);
  max-height: 100%; overflow: auto;
  padding: clamp(22px, 4vw, 42px);
  border: 1px solid var(--line); border-radius: 20px;
  background: var(--panel);
  box-shadow: 0 30px 100px rgba(0,0,0,.55);
  text-align: center;
}
.eyebrow {
  margin: 0 0 12px; color: var(--muted);
  font-size: 11px; letter-spacing: .34em;
}
h1, h2 { margin: 0; letter-spacing: -0.045em; }
h1 { font-size: clamp(38px, 8vw, 69px); line-height: .98; }
h2 { font-size: clamp(28px, 5vw, 44px); }
.accent { color: var(--gold); text-shadow: 0 0 32px rgba(249,230,117,.45); }
.lead { color: #c8d5e8; font-size: clamp(15px, 2.2vw, 19px); line-height: 1.7; }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 24px; }
button[type="button"] {
  border: 1px solid rgba(126,231,255,.28); border-radius: 11px;
  padding: 11px 17px; color: var(--text); cursor: pointer;
  background: rgba(255,255,255,.035);
  font: 650 14px/1 inherit;
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
}
button:hover { transform: translateY(-1px); border-color: rgba(126,231,255,.65); background: rgba(103,232,249,.09); }
button.primary {
  border-color: transparent; color: #04121a;
  background: linear-gradient(135deg, var(--cyan), var(--gold));
  box-shadow: 0 12px 38px rgba(103,232,249,.22);
}
.keys { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 16px; margin-top: 22px; color: var(--muted); font-size: 12px; }
.keys b { color: var(--cyan); }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 24px 0; }
.result { padding: 16px 10px; border: 1px solid var(--line); border-radius: 12px; background: rgba(255,255,255,.025); }
.result strong { display: block; margin-top: 5px; font-size: 27px; color: var(--cyan); }
.level-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(88px, 1fr)); gap: 8px; margin-top: 22px; }
.level-button { padding: 14px 8px; }
.level-button[disabled] { opacity: .32; cursor: not-allowed; transform: none; }
.share {
  margin-top: 12px; padding: 14px; border-radius: 12px; text-align: left;
  color: #b8c7dc; background: rgba(0,0,0,.28); border: 1px dashed rgba(126,231,255,.25);
  font: 500 14px/1.7 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.hint { color: var(--gold); }
.small { color: var(--muted); font-size: 12px; }

.mobile-controls {
  position: fixed; right: max(14px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom));
  display: none; grid-template-columns: repeat(4, 58px); gap: 8px; z-index: 5;
}
.mobile-controls button[data-action="sacrifice"] { border-color: rgba(249,230,117,.55); color: var(--gold); }
.mobile-controls button {
  height: 58px; font-size: 20px; border-radius: 16px;
  background: rgba(10,16,30,.78); user-select: none; -webkit-user-select: none;
}
@media (hover: none) and (pointer: coarse) { .mobile-controls { display: grid; } }

@media (max-width: 560px) {
  .stat { min-width: 58px; padding: 6px 7px; }
  .stat strong { font-size: 14px; }
  .brand span:last-child { display: none; }
  .topbar { flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; }
  .icon-button { order: 3; margin-left: auto; }
  .result-grid { grid-template-columns: 1fr; }
}
