:root {
  color-scheme: dark;
  --bg: #050913;
  --panel: rgba(9, 20, 39, 0.82);
  --panel-strong: rgba(11, 27, 53, 0.94);
  --line: rgba(78, 214, 255, 0.28);
  --cyan: #35d9ff;
  --blue: #3485ff;
  --pink: #ff3c9d;
  --purple: #bd63ff;
  --green: #60ff87;
  --yellow: #ffe45a;
  --orange: #ff9d24;
  --red: #ff3d45;
  --text: #f4fbff;
  --muted: #9ab0c8;
  --shadow: 0 0 24px rgba(44, 205, 255, 0.18), 0 0 70px rgba(255, 60, 157, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 50% -10%, rgba(48, 145, 255, 0.2), transparent 42%),
    radial-gradient(circle at 10% 30%, rgba(255, 60, 157, 0.12), transparent 28%),
    radial-gradient(circle at 92% 52%, rgba(69, 255, 139, 0.1), transparent 30%),
    linear-gradient(180deg, #050913 0%, #07101f 48%, #040712 100%);
  overflow-x: hidden;
  touch-action: manipulation;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.18;
  background-image:
    linear-gradient(rgba(84, 202, 255, 0.1) 1px, transparent 1px),
    linear-gradient(90deg, rgba(84, 202, 255, 0.1) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at center, black, transparent 78%);
}

button {
  color: inherit;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

.game-shell {
  width: min(100%, 1060px);
  min-height: 100svh;
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) clamp(10px, 2vw, 22px) max(14px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: auto auto minmax(360px, 1fr) auto auto;
  gap: clamp(10px, 1.6vh, 16px);
}

.topbar,
.hud,
.bottom-panel,
.reactor-status {
  position: relative;
  z-index: 2;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid rgba(53, 217, 255, 0.45);
  border-radius: 15px;
  background: linear-gradient(145deg, rgba(44, 96, 168, 0.22), rgba(255, 60, 157, 0.08));
  color: var(--cyan);
  box-shadow: 0 0 22px rgba(53, 217, 255, 0.18);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.85rem, 8vw, 4rem);
  line-height: 0.92;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-shadow: 0 0 18px rgba(53, 217, 255, 0.4), 0 0 32px rgba(255, 60, 157, 0.22);
}

h1::first-letter { color: var(--cyan); }

.icon-button,
.restart-button,
.primary-button,
.ghost-button {
  border: 1px solid rgba(53, 217, 255, 0.42);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(14, 42, 78, 0.96), rgba(8, 17, 36, 0.96));
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.icon-button {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  font-size: 1.15rem;
}

button:active { transform: translateY(1px) scale(0.985); }
button:focus-visible { outline: 3px solid rgba(255, 228, 90, 0.78); outline-offset: 3px; }

.hud {
  display: grid;
  grid-template-columns: 1.25fr 1fr 1.2fr;
  gap: clamp(8px, 1.5vw, 14px);
}

.hud-card {
  min-height: 78px;
  padding: 12px clamp(10px, 2vw, 18px);
  border: 1px solid var(--line);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(8, 19, 39, 0.9), rgba(5, 10, 22, 0.82));
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
}

.hud-label {
  color: var(--muted);
  font-size: clamp(0.65rem, 2.5vw, 0.88rem);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-weight: 800;
}

.hud-card strong {
  margin-top: 3px;
  font-size: clamp(1.55rem, 6vw, 3rem);
  line-height: 1;
  white-space: nowrap;
}

.combo-card strong { color: #d680ff; text-shadow: 0 0 18px rgba(189, 99, 255, 0.55); }

.pip-row {
  height: 10px;
  display: flex;
  gap: 5px;
  margin-top: 9px;
}

.pip-row span {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: rgba(189, 99, 255, 0.2);
  box-shadow: inset 0 0 0 1px rgba(189, 99, 255, 0.25);
}

.pip-row span.active {
  background: var(--purple);
  box-shadow: 0 0 12px rgba(189, 99, 255, 0.75);
}

.mini-meter,
.temp-meter {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: rgba(5, 11, 24, 0.82);
  border: 1px solid rgba(83, 190, 230, 0.24);
  overflow: hidden;
  margin-top: 9px;
}

.mini-meter span,
.temp-meter span {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), #d6ff66);
  box-shadow: 0 0 18px rgba(96, 255, 135, 0.45);
  transition: width 0.18s ease, background 0.18s ease;
}

.reactor-panel {
  position: relative;
  min-height: 360px;
  border: 1px solid rgba(53, 217, 255, 0.24);
  border-radius: 28px;
  background:
    radial-gradient(circle at 50% 44%, rgba(42, 123, 255, 0.14), transparent 43%),
    radial-gradient(circle at 50% 56%, rgba(255, 60, 157, 0.08), transparent 55%),
    linear-gradient(180deg, rgba(5, 13, 27, 0.76), rgba(4, 8, 18, 0.92));
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.03), 0 22px 90px rgba(0, 0, 0, 0.34), var(--shadow);
  overflow: hidden;
  isolation: isolate;
}

.reactor-panel::before,
.reactor-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.reactor-panel::before {
  background:
    linear-gradient(90deg, transparent 0 8%, rgba(53, 217, 255, 0.09) 8.2% 8.4%, transparent 8.6% 91.4%, rgba(255, 60, 157, 0.09) 91.6% 91.8%, transparent 92%),
    radial-gradient(circle at 18% 28%, rgba(255, 255, 255, 0.08), transparent 2px),
    radial-gradient(circle at 82% 72%, rgba(53, 217, 255, 0.1), transparent 2px);
}

.reactor-panel::after {
  border-radius: inherit;
  box-shadow: inset 0 0 70px rgba(0, 0, 0, 0.5), inset 0 0 50px rgba(53, 217, 255, 0.08);
}

#gameCanvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  min-height: 360px;
  cursor: crosshair;
  touch-action: none;
}

.toast-layer {
  position: absolute;
  z-index: 4;
  inset: 0;
  pointer-events: none;
}

.toast {
  position: absolute;
  transform: translate(-50%, -50%);
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(4, 9, 20, 0.82);
  color: #fff;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
  text-shadow: 0 0 12px currentColor;
  animation: toast-rise 820ms ease-out forwards;
}

@keyframes toast-rise {
  from { opacity: 0; translate: 0 14px; scale: 0.9; }
  14% { opacity: 1; }
  to { opacity: 0; translate: 0 -42px; scale: 1.05; }
}

.overlay {
  position: absolute;
  z-index: 6;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: radial-gradient(circle at 50% 45%, rgba(11, 28, 56, 0.42), rgba(2, 5, 12, 0.84));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.overlay-visible {
  opacity: 1;
  pointer-events: auto;
}

.overlay-card {
  width: min(92%, 520px);
  padding: clamp(18px, 5vw, 28px);
  border: 1px solid rgba(53, 217, 255, 0.38);
  border-radius: 28px;
  background: linear-gradient(180deg, rgba(10, 23, 47, 0.96), rgba(4, 8, 19, 0.96));
  box-shadow: 0 0 40px rgba(53, 217, 255, 0.14), 0 18px 80px rgba(0, 0, 0, 0.44);
  text-align: center;
}

.overlay-kicker {
  margin: 0 0 8px;
  color: var(--cyan);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.overlay-card h2 {
  margin: 0;
  font-size: clamp(1.7rem, 7vw, 3rem);
  line-height: 1;
  text-transform: uppercase;
  text-shadow: 0 0 18px rgba(255, 60, 157, 0.34);
}

.overlay-card p {
  color: var(--muted);
  line-height: 1.55;
  margin: 14px auto 0;
  max-width: 40rem;
}

.primary-button,
.ghost-button {
  min-height: 50px;
  padding: 0 20px;
  margin-top: 20px;
  font-weight: 950;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.primary-button {
  color: #06111f;
  border-color: rgba(255, 228, 90, 0.85);
  background: linear-gradient(135deg, #ffe45a, #ff9d24 48%, #ff3c9d);
  box-shadow: 0 0 28px rgba(255, 157, 36, 0.28), 0 0 60px rgba(255, 60, 157, 0.16);
}

.ghost-button {
  color: var(--cyan);
  background: rgba(8, 20, 38, 0.92);
}

.small-note {
  min-height: 1.3em;
  font-size: 0.82rem;
}

.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 18px;
}

.results-grid div {
  padding: 12px;
  border: 1px solid rgba(53, 217, 255, 0.18);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.035);
}

.results-grid span,
.run-meta span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 850;
}

.results-grid strong {
  display: block;
  margin-top: 5px;
  font-size: 1.35rem;
}

.overlay-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
}

.reactor-status {
  border: 1px solid rgba(255, 60, 69, 0.28);
  border-radius: 18px;
  background: rgba(13, 14, 23, 0.68);
  padding: 12px;
  box-shadow: var(--shadow);
}

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.82rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-weight: 900;
}

.status-row strong { color: var(--text); }

.temp-meter {
  height: 14px;
  margin-top: 10px;
  border-color: rgba(255, 60, 69, 0.26);
}

.temp-meter span {
  width: 0%;
  background: linear-gradient(90deg, var(--green), var(--yellow), var(--orange), var(--red));
  box-shadow: 0 0 18px rgba(255, 61, 69, 0.42);
}

.bottom-panel {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: stretch;
}

.instruction-card,
.run-meta,
.restart-button {
  border: 1px solid rgba(53, 217, 255, 0.24);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(9, 20, 39, 0.86), rgba(5, 10, 22, 0.88));
  box-shadow: var(--shadow);
}

.instruction-card {
  min-height: 68px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
}

.tap-icon {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  border-radius: 16px;
  border: 1px solid rgba(255, 60, 157, 0.45);
  color: var(--pink);
  font-size: 1.45rem;
  background: rgba(255, 60, 157, 0.09);
  box-shadow: 0 0 22px rgba(255, 60, 157, 0.16);
}

.instruction-card strong,
.instruction-card span:not(.tap-icon) {
  display: block;
}

.instruction-card span:not(.tap-icon) {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.92rem;
}

.run-meta {
  min-width: 176px;
  padding: 10px 14px;
  display: grid;
  gap: 8px;
  align-content: center;
}

.run-meta strong {
  display: block;
  margin-top: 2px;
  font-size: 1rem;
  white-space: nowrap;
}

.restart-button {
  min-width: 112px;
  padding: 0 16px;
  color: var(--cyan);
  font-weight: 950;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

@media (max-width: 720px) {
  .game-shell {
    grid-template-rows: auto auto minmax(330px, 1fr) auto auto;
  }

  .brand-mark { display: none; }

  .hud {
    grid-template-columns: 1.05fr 0.8fr 1fr;
    gap: 7px;
  }

  .hud-card {
    min-height: 66px;
    border-radius: 16px;
    padding: 10px 9px;
  }

  .hud-label {
    letter-spacing: 0.1em;
  }

  .pip-row { display: none; }

  .reactor-panel {
    border-radius: 22px;
  }

  #gameCanvas {
    min-height: 330px;
  }

  .bottom-panel {
    grid-template-columns: 1fr auto;
  }

  .instruction-card {
    grid-column: 1 / -1;
    min-height: 60px;
  }

  .run-meta {
    min-width: 0;
  }

  .restart-button {
    min-width: 102px;
  }
}

@media (max-width: 420px) {
  .game-shell { padding-inline: 8px; gap: 8px; }
  .icon-button { width: 42px; height: 42px; border-radius: 14px; }
  .hud-card strong { font-size: clamp(1.25rem, 6vw, 1.85rem); }
  .hud-card { min-height: 58px; }
  .reactor-status { padding: 10px; }
  .instruction-card { gap: 10px; }
  .tap-icon { width: 40px; height: 40px; }
  .instruction-card span:not(.tap-icon) { font-size: 0.82rem; }
  .results-grid { grid-template-columns: 1fr; }
}

@media (orientation: landscape) and (max-height: 620px) {
  .game-shell {
    max-width: 1180px;
    min-height: 100vh;
    grid-template-columns: minmax(260px, 0.82fr) minmax(380px, 1.25fr) minmax(230px, 0.82fr);
    grid-template-rows: auto 1fr auto;
    align-items: stretch;
  }

  .topbar { grid-column: 1 / -1; }
  .hud { grid-column: 1; grid-row: 2; grid-template-columns: 1fr; align-content: start; }
  .reactor-panel { grid-column: 2; grid-row: 2 / 4; }
  .reactor-status { grid-column: 1; grid-row: 3; }
  .bottom-panel { grid-column: 3; grid-row: 2 / 4; grid-template-columns: 1fr; align-content: start; }
  #gameCanvas { min-height: 420px; }
}


/* v2 performance/mobile pass: keep board visible and reduce GPU load on phones */
@media (max-width: 720px) {
  html, body { height: 100%; overflow: hidden; }
  .game-shell {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    padding: max(6px, env(safe-area-inset-top)) 7px max(7px, env(safe-area-inset-bottom));
    grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    gap: 6px;
  }
  .topbar { min-height: 42px; }
  .brand-lockup { gap: 7px; }
  .eyebrow { display: none; }
  h1 { font-size: clamp(1.18rem, 7vw, 1.78rem); line-height: 1; }
  .icon-button { width: 40px; height: 40px; border-radius: 13px; }
  .hud { gap: 5px; }
  .hud-card {
    min-height: 54px;
    padding: 7px 7px;
    border-radius: 14px;
  }
  .hud-label { font-size: 0.58rem; letter-spacing: 0.08em; }
  .hud-card strong { font-size: clamp(1.08rem, 5.5vw, 1.65rem); }
  .mini-meter { height: 7px; margin-top: 5px; }
  .reactor-panel {
    min-height: 0;
    border-radius: 18px;
  }
  #gameCanvas {
    height: 100%;
    min-height: 0;
  }
  .reactor-status {
    padding: 7px 8px;
    border-radius: 13px;
  }
  .status-row { font-size: 0.62rem; letter-spacing: 0.08em; }
  .temp-meter { height: 8px; margin-top: 5px; }
  .bottom-panel {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 7px;
  }
  .instruction-card { display: none; }
  .run-meta {
    min-width: 0;
    padding: 7px 9px;
    border-radius: 14px;
    grid-template-columns: 1fr 1fr;
    display: grid;
  }
  .run-meta span { font-size: 0.56rem; letter-spacing: 0.08em; }
  .run-meta strong { font-size: 0.78rem; }
  .restart-button {
    min-width: 84px;
    min-height: 44px;
    border-radius: 14px;
    padding: 0 10px;
    font-size: 0.78rem;
  }
  .overlay { padding: 10px; }
  .overlay-card {
    width: min(94%, 480px);
    padding: 16px;
    border-radius: 22px;
  }
  .overlay-card p { margin-top: 10px; line-height: 1.4; }
  .primary-button, .ghost-button { min-height: 44px; margin-top: 14px; }
}
@media (max-height: 690px) and (max-width: 720px) {
  .reactor-status { display: none; }
  .hud-card { min-height: 50px; }
  .run-meta div:last-child { display: none; }
  .run-meta { grid-template-columns: 1fr; }
}
