:root {
  --bg: #07072f;
  --panel: rgba(8, 13, 48, .80);
  --panel-2: rgba(9, 27, 73, .72);
  --line: rgba(68, 230, 255, .30);
  --cyan: #42e6ff;
  --blue: #3182ff;
  --gold: #ffd650;
  --green: #52f47f;
  --purple: #b85cff;
  --pink: #ff4ea3;
  --orange: #ff8e42;
  --red: #ff496e;
  --text: #f8fbff;
  --muted: rgba(248, 251, 255, .70);
  --shadow: 0 22px 70px rgba(0, 0, 0, .42);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, Segoe UI, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

body {
  background:
    radial-gradient(circle at 75% 18%, rgba(184,92,255,.22), transparent 30%),
    radial-gradient(circle at 18% 85%, rgba(66,230,255,.20), transparent 32%),
    linear-gradient(135deg, #050420, #0b0b3f 45%, #160629);
}

button {
  min-height: 42px;
  border: 1px solid rgba(66,230,255,.36);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(66,230,255,.18), rgba(49,130,255,.10));
  color: var(--text);
  font-weight: 1000;
  cursor: pointer;
  padding: 10px 13px;
  box-shadow: inset 0 0 18px rgba(255,255,255,.03), 0 0 18px rgba(66,230,255,.08);
}
button:hover { border-color: var(--cyan); transform: translateY(-1px); }
button:active { transform: translateY(0); }
button.primary {
  border-color: rgba(255,214,80,.70);
  background: linear-gradient(180deg, rgba(255,214,80,.34), rgba(255,142,66,.20));
}

.game-shell {
  height: 100dvh;
  max-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.topbar {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  background: rgba(3, 5, 28, .82);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.brand {
  min-width: 280px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-bolt,
.hero-badge {
  display: grid;
  place-items: center;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 22%, rgba(255,255,255,.40), transparent 20%),
    linear-gradient(145deg, #0ab8ff, #133bff 42%, #7a21ff);
  border: 3px solid rgba(66,230,255,.72);
  color: var(--gold);
  text-shadow: 0 0 18px rgba(255,214,80,.58);
  font-weight: 1000;
  box-shadow: 0 0 26px rgba(66,230,255,.30);
}
.brand-bolt { width: 52px; height: 52px; font-size: 30px; }
.hero-badge { width: 116px; height: 116px; font-size: 64px; margin: 0 auto 8px; }

.brand strong {
  display: block;
  font-size: 22px;
  letter-spacing: .2px;
  text-transform: uppercase;
}
.brand span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 900;
}

.hud {
  margin-left: auto;
  display: grid;
  grid-template-columns: repeat(5, minmax(74px, 1fr));
  gap: 8px;
}
.hud div {
  padding: 8px 10px;
  border: 1px solid rgba(66,230,255,.22);
  border-radius: 16px;
  background: rgba(0,0,0,.24);
  box-shadow: inset 0 0 18px rgba(66,230,255,.04);
}
.hud small {
  display: block;
  font-size: 10px;
  color: var(--muted);
  letter-spacing: .9px;
  text-transform: uppercase;
  font-weight: 900;
}
.hud b {
  display: block;
  color: var(--gold);
  font-size: 18px;
}

.main-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(285px, 360px) minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
}

.side-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  gap: 12px;
}

.panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(7,14,52,.88), rgba(5,8,30,.76));
  box-shadow: var(--shadow), inset 0 0 32px rgba(66,230,255,.04);
  backdrop-filter: blur(14px);
}
.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  background: rgba(0,0,0,.20);
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.panel-title span,
.panel-title b {
  font-size: 12px;
  font-weight: 1000;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.panel-title span { color: var(--cyan); }
.panel-title b { color: var(--gold); }

.panel h2 {
  margin: 14px 14px 4px;
  font-size: 24px;
  line-height: 1.1;
}
.panel p {
  margin: 10px 14px 14px;
  color: var(--muted);
  line-height: 1.42;
  font-weight: 760;
}

.progress-wrap {
  margin: 0 14px 8px;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255,255,255,.10);
}
.progress-wrap div {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--gold), var(--pink));
  box-shadow: 0 0 20px rgba(255,214,80,.28);
  transition: width .35s ease;
}
.progress-meta {
  display: flex;
  justify-content: space-between;
  padding: 0 14px 14px;
  color: var(--muted);
  font-weight: 900;
  font-size: 12px;
}

.reward-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  padding: 0 14px 14px;
}
.reward-row div {
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 16px;
  background: rgba(0,0,0,.20);
  text-align: center;
  padding: 10px 6px;
}
.reward-row strong { display: block; color: var(--gold); font-size: 21px; }
.reward-row span { display: block; color: var(--muted); font-size: 11px; font-weight: 900; text-transform: uppercase; }

.gate-list {
  padding: 12px 14px 14px;
  display: grid;
  gap: 8px;
  overflow: auto;
  max-height: 280px;
}
.gate {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  min-height: 62px;
  padding: 9px;
  border-radius: 17px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(0,0,0,.20);
  opacity: .48;
}
.gate.active,
.gate.unlocked { opacity: 1; }
.gate.active {
  border-color: rgba(255,214,80,.55);
  box-shadow: 0 0 24px rgba(255,214,80,.12);
}
.gate-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  color: #fff;
  font-weight: 1000;
}
.gate strong { display: block; font-size: 13px; }
.gate span { display: block; color: var(--muted); font-size: 11px; font-weight: 900; }
.gate em { color: var(--gold); font-style: normal; font-weight: 1000; }

.arena-column {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  gap: 10px;
}

.canvas-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: #08062e;
  box-shadow: var(--shadow);
}
#gameCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.question-pop {
  position: absolute;
  left: 50%;
  top: 18px;
  transform: translateX(-50%);
  z-index: 6;
  width: min(620px, calc(100% - 36px));
  border: 1px solid rgba(66,230,255,.35);
  border-radius: 24px;
  background: rgba(4, 8, 35, .78);
  box-shadow: 0 0 34px rgba(66,230,255,.15), inset 0 0 28px rgba(255,255,255,.04);
  padding: 12px 18px;
  text-align: center;
  backdrop-filter: blur(16px);
}
.question-pop span,
.question-pop em {
  display: inline-block;
  font-size: 12px;
  font-weight: 1000;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--cyan);
}
.question-pop em { color: var(--gold); margin-left: 12px; font-style: normal; }
.question-pop strong {
  display: block;
  font-size: clamp(28px, 6vw, 62px);
  line-height: 1;
  margin-top: 3px;
  color: white;
  text-shadow: 0 4px 0 rgba(0,0,0,.38), 0 0 22px rgba(255,255,255,.15);
}

.toast {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 7;
  max-width: min(760px, calc(100% - 36px));
  padding: 12px 15px;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(4,8,35,.78);
  box-shadow: 0 16px 40px rgba(0,0,0,.28);
  font-weight: 1000;
  opacity: 0;
  transform: translateY(12px);
  transition: .28s ease;
  backdrop-filter: blur(14px);
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.good { color: var(--green); }
.toast.bad { color: var(--red); }
.toast.warn { color: var(--gold); }

.answer-pad {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.answer-pad button {
  min-height: 66px;
  font-size: clamp(20px, 4vw, 34px);
  border-radius: 20px;
  background:
    radial-gradient(circle at 30% 20%, rgba(255,255,255,.25), transparent 23%),
    linear-gradient(180deg, rgba(255,214,80,.30), rgba(255,142,66,.15));
}
.answer-pad button:nth-child(1) { border-color: rgba(82,244,127,.55); background-color: rgba(82,244,127,.08); }
.answer-pad button:nth-child(2) { border-color: rgba(184,92,255,.55); background-color: rgba(184,92,255,.08); }
.answer-pad button:nth-child(3) { border-color: rgba(255,214,80,.58); background-color: rgba(255,214,80,.08); }
.answer-pad button:nth-child(4) { border-color: rgba(66,230,255,.58); background-color: rgba(66,230,255,.08); }

.bottombar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: max(0px, env(safe-area-inset-bottom));
}
.bottombar button {
  flex: 1 1 105px;
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: none;
  place-items: center;
  padding: 20px;
  background:
    radial-gradient(circle at 70% 20%, rgba(255,214,80,.18), transparent 32%),
    rgba(0,0,0,.66);
  backdrop-filter: blur(12px);
}
.overlay.active { display: grid; }
.overlay-card {
  width: min(760px, 100%);
  text-align: center;
  border-radius: 32px;
  border: 1px solid rgba(66,230,255,.38);
  background: linear-gradient(180deg, rgba(7,14,52,.98), rgba(4,7,28,.95));
  box-shadow: var(--shadow), inset 0 0 40px rgba(66,230,255,.05);
  padding: 28px;
}
.overlay-card h1 {
  margin: 4px 0 0;
  font-size: clamp(42px, 8vw, 82px);
  line-height: .9;
  text-transform: uppercase;
  text-shadow: 0 6px 0 rgba(0,0,0,.4);
}
.overlay-card h2 {
  margin: 4px 0 14px;
  font-size: clamp(26px, 5vw, 44px);
  color: var(--green);
  text-transform: uppercase;
}
.overlay-card p {
  max-width: 620px;
  margin: 0 auto 18px;
  color: var(--muted);
  line-height: 1.5;
  font-weight: 760;
}
.overlay-tags,
.overlay-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}
.overlay-tags { margin: 14px 0 22px; }
.overlay-tags span {
  border: 1px solid rgba(255,214,80,.28);
  border-radius: 999px;
  background: rgba(255,214,80,.10);
  padding: 8px 11px;
  font-weight: 1000;
}

@media (max-width: 1100px) {
  html, body { overflow: auto; }
  .game-shell { height: auto; min-height: 100dvh; max-height: none; }
  .topbar { flex-wrap: wrap; }
  .brand { min-width: 0; width: 100%; }
  .hud { margin-left: 0; width: 100%; grid-template-columns: repeat(5, 1fr); }
  .main-layout { grid-template-columns: 1fr; }
  .side-panel { grid-template-columns: 1fr 1fr; grid-template-rows: auto auto; }
  .gate-card { grid-column: 1 / -1; }
  .gate-list { max-height: 180px; grid-template-columns: repeat(2, 1fr); }
  .canvas-wrap { height: min(64dvh, 640px); min-height: 440px; }
}

@media (max-width: 720px) {
  .topbar { padding: 10px; }
  .brand strong { font-size: 18px; }
  .hud { grid-template-columns: repeat(2, 1fr); }
  .main-layout { padding: 8px; gap: 8px; }
  .side-panel { grid-template-columns: 1fr; }
  .canvas-wrap { height: min(56dvh, 500px); min-height: 335px; border-radius: 20px; }
  .gate-list { grid-template-columns: 1fr; }
  .answer-pad { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .answer-pad button { min-height: 58px; }
  .bottombar { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bottombar button { width: 100%; }
  .question-pop { top: 10px; padding: 9px 12px; border-radius: 18px; }
  .overlay-card { max-height: 88dvh; overflow: auto; padding: 20px; }
}

@media (orientation: landscape) and (max-height: 520px) {
  .topbar { display: none; }
  .main-layout { grid-template-columns: 1fr; padding: 6px; }
  .side-panel { display: none; }
  .canvas-wrap { height: calc(100dvh - 142px); min-height: 280px; }
  .answer-pad button { min-height: 46px; }
  .bottombar button { min-height: 38px; }
}
