:root {
  --bg: #05060c;
  --panel: rgba(10, 14, 28, 0.86);
  --accent: #34e0ff;
  --accent2: #ff5bd0;
  --good: #7cff6b;
  --warn: #ffb03a;
  --bad: #ff4d4d;
  --text: #e8f0ff;
  --muted: #8aa0c0;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: var(--font); }
#gl { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.hidden { display: none !important; }

/* ---------------- Screens ---------------- */
.screen {
  position: fixed; inset: 0; z-index: 20;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 18px; padding: 28px; text-align: center;
  background: radial-gradient(120% 120% at 50% 0%, rgba(20,30,60,0.6), rgba(3,4,10,0.96));
  backdrop-filter: blur(3px);
}
.screen.overlay { background: rgba(3,4,10,0.78); }
.screen h2 { font-size: clamp(28px, 6vw, 52px); letter-spacing: 6px; margin: 0; text-shadow: 0 0 24px rgba(52,224,255,0.5); }

.menu { display: flex; flex-direction: column; gap: 12px; width: min(340px, 80vw); }
.btn {
  font: inherit; font-weight: 700; letter-spacing: 2px; cursor: pointer;
  padding: 14px 18px; border-radius: 12px; color: var(--text);
  background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.16);
  transition: transform .08s ease, background .15s ease, box-shadow .15s ease;
}
.btn:hover { background: rgba(255,255,255,0.12); transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #2b8cff); color: #04121a; border: none; box-shadow: 0 8px 30px rgba(52,224,255,0.35); }
.btn.danger { border-color: var(--bad); color: var(--bad); }

/* ---------------- Logo ---------------- */
.logo { font-weight: 900; line-height: 0.9; }
.logo-iq { font-size: clamp(60px, 18vw, 150px); color: var(--accent); text-shadow: 0 0 40px rgba(52,224,255,0.6); }
.logo-uad { font-size: clamp(60px, 18vw, 150px); color: var(--text); }
.logo-sub { font-size: clamp(12px, 3vw, 20px); letter-spacing: 10px; color: var(--muted); margin-top: 6px; }
.tagline { max-width: 520px; color: var(--muted); margin: 0; }
.best { color: var(--muted); font-size: 14px; }
.best span { color: var(--accent); font-weight: 700; }

/* ---------------- How to ---------------- */
.howto-grid { display: grid; gap: 12px; max-width: 620px; text-align: left; }
.howto-grid > div { display: flex; align-items: center; gap: 12px; background: var(--panel); padding: 12px 14px; border-radius: 10px; border: 1px solid rgba(255,255,255,0.08); }
.howto-controls { max-width: 620px; color: var(--muted); text-align: left; }
.swatch { width: 26px; height: 26px; border-radius: 5px; flex: 0 0 auto; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.25); }
.swatch.normal { background: #9aa6b8; }
.swatch.advantage { background: #36d97a; }
.swatch.forbidden { background: #14161d; box-shadow: inset 0 0 0 1px #444; }
.swatch.arrow { background: conic-gradient(#34e0ff, #ffd23a, #ff5bd0, #7cff6b, #34e0ff); }
.arrow-legend { display: flex; flex-wrap: wrap; gap: 8px; max-width: 620px; justify-content: center; }
.arrow-legend .chip { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); background: var(--panel); padding: 4px 8px; border-radius: 20px; }
.arrow-legend .dot { width: 12px; height: 12px; border-radius: 50%; }

/* ---------------- Level select ---------------- */
.diff-pills { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.pill { padding: 8px 16px; border-radius: 20px; cursor: pointer; border: 1px solid rgba(255,255,255,0.16); background: rgba(255,255,255,0.04); font-weight: 700; letter-spacing: 1px; font-size: 13px; }
.pill.active { background: var(--accent); color: #04121a; border-color: var(--accent); }
.level-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 10px; width: min(680px, 92vw); max-height: 56vh; overflow-y: auto; padding: 6px; }
.level-cell {
  aspect-ratio: 1; border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; font-weight: 800; border: 1px solid rgba(255,255,255,0.12); background: rgba(255,255,255,0.05); position: relative;
}
.level-cell.locked { opacity: 0.35; cursor: not-allowed; }
.level-cell.cleared { border-color: var(--good); box-shadow: inset 0 0 14px rgba(124,255,107,0.25); }
.level-cell .lc-num { font-size: 20px; }
.level-cell .lc-stars { font-size: 11px; color: var(--warn); height: 12px; }
.level-cell:not(.locked):hover { background: rgba(52,224,255,0.18); }

/* ---------------- Settings ---------------- */
.setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; width: min(420px, 86vw); background: var(--panel); padding: 12px 16px; border-radius: 10px; }
.setting label { color: var(--muted); font-size: 14px; }
.setting input[type=range] { width: 160px; accent-color: var(--accent); }
.setting select { font: inherit; background: #0c1224; color: var(--text); border: 1px solid rgba(255,255,255,0.2); border-radius: 8px; padding: 6px 10px; }

/* ---------------- HUD ---------------- */
#hud { position: fixed; inset: 0; z-index: 10; pointer-events: none; }
.hud-row { position: fixed; left: 0; right: 0; display: flex; gap: 10px; justify-content: center; padding: 10px; flex-wrap: wrap; }
.hud-top { top: 0; background: linear-gradient(180deg, rgba(3,4,10,0.7), transparent); }
.hud-bottom { bottom: 0; background: linear-gradient(0deg, rgba(3,4,10,0.7), transparent); }
.hud-stat { background: var(--panel); border: 1px solid rgba(255,255,255,0.08); border-radius: 10px; padding: 6px 14px; min-width: 78px; text-align: center; }
.hud-stat label { display: block; font-size: 10px; letter-spacing: 2px; color: var(--muted); }
.hud-stat span { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; }
.icon-btn { position: fixed; top: 12px; right: 12px; pointer-events: auto; width: 44px; height: 44px; border-radius: 10px; background: var(--panel); color: var(--text); border: 1px solid rgba(255,255,255,0.14); cursor: pointer; font-size: 14px; }
.action-btn {
  position: fixed; pointer-events: auto; cursor: pointer;
  width: 90px; height: 90px; border-radius: 50%;
  font-weight: 900; letter-spacing: 1px; font-size: 14px; color: #04121a;
  border: 3px solid rgba(255,255,255,0.6);
  -webkit-user-select: none; user-select: none; transition: transform .08s, filter .15s, opacity .15s;
}
.action-btn:active { transform: scale(0.92); }
.action-btn.charge { right: 124px; bottom: 84px; background: radial-gradient(circle at 35% 30%, #ffd98a, #ff9b2a); box-shadow: 0 6px 26px rgba(255,155,42,0.45); }
.action-btn.detonate { right: 18px; bottom: 84px; background: radial-gradient(circle at 35% 30%, #ff8a7a, #ff3320); box-shadow: 0 6px 26px rgba(255,51,32,0.5); color: #2a0606; }
.action-btn.unarmed { filter: grayscale(1) brightness(0.6); opacity: 0.45; }
#controls-hint {
  position: fixed; left: 50%; bottom: 64px; transform: translateX(-50%);
  color: var(--muted); font-size: 11px; letter-spacing: 0.5px; text-align: center;
  background: rgba(5,6,12,0.5); padding: 4px 10px; border-radius: 16px; max-width: 70vw;
  pointer-events: none; opacity: 0.8;
}
@media (max-width: 560px) {
  #controls-hint { display: none; }
  .action-btn { width: 74px; height: 74px; font-size: 12px; bottom: 96px; }
  .action-btn.charge { right: 104px; bottom: 96px; }
  .action-btn.detonate { right: 18px; bottom: 96px; }
}
#toast { position: fixed; top: 38%; left: 50%; transform: translateX(-50%); font-size: clamp(28px, 7vw, 64px); font-weight: 900; letter-spacing: 4px; opacity: 0; pointer-events: none; text-shadow: 0 0 30px currentColor; }
#toast.show { animation: pop 1.1s ease forwards; }
@keyframes pop { 0% { opacity: 0; transform: translateX(-50%) scale(0.6); } 20% { opacity: 1; transform: translateX(-50%) scale(1.1); } 70% { opacity: 1; transform: translateX(-50%) scale(1); } 100% { opacity: 0; transform: translateX(-50%) scale(1.2); } }

.result-body { background: var(--panel); border-radius: 14px; padding: 20px 28px; min-width: min(420px, 88vw); border: 1px solid rgba(255,255,255,0.1); }
.result-body .line { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed rgba(255,255,255,0.1); }
.result-body .line:last-child { border-bottom: none; }
.result-body .line.big { font-size: 22px; font-weight: 800; color: var(--accent); }
.result-body .val { font-variant-numeric: tabular-nums; font-weight: 700; }

#loading { z-index: 50; }
.spinner { width: 46px; height: 46px; border-radius: 50%; border: 4px solid rgba(255,255,255,0.15); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 560px) {
  .hud-stat { min-width: 64px; padding: 4px 8px; }
  .hud-stat span { font-size: 16px; }
}
