/* =============================================================
   Neon Breakout — presentation layer
   ============================================================= */

:root {
  --bg-0:        #05070f;
  --bg-1:        #0a0f1e;
  --ink:         #e8f1ff;
  --ink-dim:     #8ea3c4;
  --ink-faint:   #56688a;
  --cyan:        #22d3ee;
  --pink:        #f472b6;
  --lime:        #a3e635;
  --amber:       #facc15;
  --danger:      #fb7185;
  --line:        rgba(120, 170, 230, 0.16);
  --glass:       rgba(14, 22, 42, 0.72);
  --radius:      14px;
  --font:        "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-num:    ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  /* Height reserved for the HUD + toolbar so the stage can size itself.
     HUD ~53 + toolbar ~44 + two 9px gaps + 18px page padding. */
  --chrome:      136px;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  /* Ambient glow behind everything. */
  background:
    radial-gradient(1200px 700px at 50% -10%, rgba(34, 211, 238, 0.10), transparent 60%),
    radial-gradient(900px 600px at 85% 110%, rgba(244, 114, 182, 0.09), transparent 60%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0) 70%);
}

/* The whole column is exactly as wide as the 4:3 playfield, so the
   HUD and toolbar always line up with the canvas edges. */
#wrap {
  width: min(calc(100vw - 18px), calc((100vh - var(--chrome)) * 4 / 3));
  width: min(calc(100vw - 18px), calc((100dvh - var(--chrome)) * 4 / 3));
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  margin: 0 auto;
  padding: 9px 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 9px;
}

/* ------------------------------- HUD ------------------------------- */
#hud {
  display: grid;
  grid-template-columns: 1fr 1fr 2.2fr 1fr 1fr;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.hud-cell { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.hud-cell:nth-child(4), .hud-cell:nth-child(5) { align-items: flex-end; }

.hud-label {
  font-size: 9.5px;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  color: var(--ink-faint);
  font-weight: 700;
  white-space: nowrap;
}
.hud-label b { color: var(--cyan); font-variant-numeric: tabular-nums; }

.hud-value {
  font-family: var(--font-num);
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 0.3px;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  text-shadow: 0 0 14px rgba(34, 211, 238, 0.35);
  line-height: 1.1;
}
.hud-value.dim { color: var(--ink-dim); text-shadow: none; font-size: 16px; }

.hud-title { align-items: center; text-align: center; }
.hud-name {
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 2.4px;
  text-transform: uppercase;
  color: var(--pink);
  text-shadow: 0 0 16px rgba(244, 114, 182, 0.5);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

#combo.hot { color: var(--amber); text-shadow: 0 0 18px rgba(250, 204, 21, 0.7); }
#combo.bump { animation: bump 0.28s cubic-bezier(0.34, 1.7, 0.64, 1); }
@keyframes bump {
  0%   { transform: scale(1); }
  40%  { transform: scale(1.35); }
  100% { transform: scale(1); }
}

.lives { display: flex; align-items: center; gap: 5px; height: 21px; }
.life {
  width: 11px; height: 11px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 32%, #fff, var(--cyan) 65%, #0b7f94);
  box-shadow: 0 0 10px rgba(34, 211, 238, 0.8);
}
.lives.low .life {
  background: radial-gradient(circle at 35% 32%, #fff, var(--danger) 65%, #7f1d2b);
  box-shadow: 0 0 10px rgba(251, 113, 133, 0.9);
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.45; } }
.life-extra { font-family: var(--font-num); font-size: 12px; color: var(--ink-dim); }

/* ------------------------------ STAGE ------------------------------ */
#stage {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  min-height: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: #04060d;
  border: 1px solid rgba(120, 170, 230, 0.22);
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.6),
    0 24px 70px rgba(0, 0, 0, 0.75),
    0 0 90px rgba(34, 211, 238, 0.12);
  touch-action: none;
}
#stage.playing { cursor: none; }

#game { display: block; width: 100%; height: 100%; }

/* CRT scanlines — subtle, purely decorative. */
#stage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(190, 225, 255, 0.035) 0px,
    rgba(190, 225, 255, 0.035) 1px,
    transparent 1px,
    transparent 3px
  );
  /* Deliberately NOT mix-blend-mode: over an animating canvas that forces
     the compositor to re-blend the whole stage every frame, which on
     Firefox Android drops the page to software rendering. */
}

/* ------------------------- power-up chips -------------------------- */
#effects {
  position: absolute;
  left: 12px;
  /* The paddle lives in the bottom ~8% of the playfield — stay clear of it. */
  bottom: 9.5%;
  display: flex;
  flex-direction: column-reverse;
  gap: 5px;
  pointer-events: none;
  z-index: 3;
}

.chip {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  gap: 0 7px;
  align-items: center;
  padding: 4px 9px 5px;
  border-radius: 9px;
  background: rgba(6, 12, 26, 0.78);
  border: 1px solid hsla(var(--hue), 90%, 60%, 0.5);
  box-shadow: 0 0 18px hsla(var(--hue), 95%, 55%, 0.28);
  backdrop-filter: blur(4px);
  animation: chipIn 0.25s cubic-bezier(0.34, 1.6, 0.64, 1);
}
@keyframes chipIn {
  from { opacity: 0; transform: translateX(-14px) scale(0.9); }
}

.chip-letter {
  grid-row: 1 / 3;
  width: 20px; height: 20px;
  display: grid; place-items: center;
  border-radius: 6px;
  font-weight: 800; font-size: 11px;
  color: #05070f;
  background: hsl(var(--hue), 90%, 62%);
  box-shadow: 0 0 12px hsla(var(--hue), 100%, 60%, 0.7);
}

.chip-label {
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1.3px;
  color: hsl(var(--hue), 85%, 78%);
  white-space: nowrap;
}

.chip-bar {
  display: block;
  width: 100%;
  height: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.13);
  overflow: hidden;
}
.chip-bar > i {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: 2px;
  background: hsl(var(--hue), 90%, 62%);
  box-shadow: 0 0 8px hsla(var(--hue), 100%, 60%, 0.8);
  transition: width 0.1s linear;
}

.chip.bad { border-color: rgba(251, 113, 133, 0.6); }
.chip.expiring { animation: chipBlink 0.5s steps(2, end) infinite; }
@keyframes chipBlink { 50% { opacity: 0.4; } }

/* ------------------------- overlay screens ------------------------- */
.screen {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 18px;
  background: radial-gradient(circle at 50% 45%, rgba(6, 12, 28, 0.82), rgba(2, 4, 10, 0.94));
  backdrop-filter: blur(7px);
  animation: fadeIn 0.22s ease-out;
  overflow-y: auto;
}
.screen.hidden { display: none; }
@keyframes fadeIn { from { opacity: 0; } }

.panel {
  width: min(430px, 100%);
  padding: 26px 28px 24px;
  text-align: center;
  background: linear-gradient(180deg, rgba(16, 26, 50, 0.9), rgba(8, 14, 30, 0.9));
  border: 1px solid rgba(120, 170, 230, 0.28);
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.06);
  animation: rise 0.3s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.panel-wide { width: min(560px, 100%); padding: 22px 24px 20px; }
@keyframes rise { from { opacity: 0; transform: translateY(16px) scale(0.97); } }

/* ------------------------------ logo ------------------------------- */
.logo {
  margin: 0 0 6px;
  line-height: 0.94;
  font-weight: 800;
  letter-spacing: 4px;
}
.logo-neon, .logo-break { display: block; }
.logo-neon {
  font-size: clamp(30px, 8vw, 44px);
  color: var(--cyan);
  text-shadow: 0 0 10px rgba(34, 211, 238, 0.9), 0 0 34px rgba(34, 211, 238, 0.55);
  animation: flicker 4.5s infinite;
}
.logo-break {
  font-size: clamp(21px, 5.6vw, 30px);
  color: var(--pink);
  letter-spacing: 7px;
  text-shadow: 0 0 10px rgba(244, 114, 182, 0.85), 0 0 30px rgba(244, 114, 182, 0.45);
}
@keyframes flicker {
  0%, 92%, 100% { opacity: 1; }
  93% { opacity: 0.55; }
  94% { opacity: 1; }
  96% { opacity: 0.7; }
  97% { opacity: 1; }
}

.tagline {
  margin: 0 0 20px;
  font-size: 12.5px;
  letter-spacing: 1.4px;
  color: var(--ink-dim);
}

.screen-title {
  margin: 0 0 16px;
  font-size: clamp(24px, 6vw, 32px);
  font-weight: 800;
  letter-spacing: 5px;
  color: var(--cyan);
  text-shadow: 0 0 22px rgba(34, 211, 238, 0.6);
}
.screen-title.danger { color: var(--danger); text-shadow: 0 0 26px rgba(251, 113, 133, 0.65); }
.sub-title {
  margin: 16px 0 8px;
  font-size: 11px;
  letter-spacing: 3px;
  color: var(--ink-faint);
  font-weight: 800;
}

/* ----------------------------- buttons ----------------------------- */
.btn {
  display: block;
  width: 100%;
  margin: 8px 0 0;
  padding: 12px 18px;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(140, 180, 240, 0.35);
  border-radius: 11px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}
.btn:hover { background: rgba(255, 255, 255, 0.1); border-color: rgba(160, 210, 255, 0.6); transform: translateY(-1px); }
.btn:active { transform: translateY(1px) scale(0.99); }
.btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 3px; }

.btn-primary {
  margin-top: 4px;
  color: #04121a;
  background: linear-gradient(180deg, #5ce9ff, var(--cyan));
  border-color: transparent;
  box-shadow: 0 0 26px rgba(34, 211, 238, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}
.btn-primary:hover {
  background: linear-gradient(180deg, #7df1ff, #35dcf5);
  box-shadow: 0 0 38px rgba(34, 211, 238, 0.65), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

/* --------------------------- menu extras --------------------------- */
.best-line {
  margin: 14px 0 4px;
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.best-line b { font-family: var(--font-num); color: var(--amber); font-size: 14px; letter-spacing: 0; }

.controls-grid {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px 12px;
  font-size: 11px;
  color: var(--ink-dim);
}
.controls-grid > div { display: flex; align-items: center; gap: 7px; }

kbd {
  display: inline-block;
  min-width: 22px;
  padding: 2px 6px;
  font-family: var(--font-num);
  font-size: 10px;
  font-weight: 700;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid rgba(150, 190, 240, 0.3);
  border-bottom-width: 2px;
  border-radius: 5px;
  white-space: nowrap;
}

.hint { margin: 14px 0 0; font-size: 11px; color: var(--ink-faint); letter-spacing: 0.6px; }
.hint b { color: var(--amber); }

/* --------------------------- game over ----------------------------- */
.record {
  margin: -6px 0 14px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 3px;
  color: var(--amber);
  text-shadow: 0 0 20px rgba(250, 204, 21, 0.7);
  animation: shimmer 1.4s ease-in-out infinite;
}
.record.hidden { display: none; }
@keyframes shimmer { 50% { opacity: 0.5; transform: scale(1.04); } }

.stats { margin: 0 0 18px; display: grid; gap: 1px; background: var(--line); border-radius: 10px; overflow: hidden; }
.stats > div {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 9px 13px;
  background: rgba(8, 14, 30, 0.85);
}
.stats dt { font-size: 10.5px; letter-spacing: 1.6px; text-transform: uppercase; color: var(--ink-faint); }
.stats dd { margin: 0; font-family: var(--font-num); font-size: 16px; font-weight: 700; color: var(--ink); }
.stats > div:first-child dd { color: var(--cyan); font-size: 20px; text-shadow: 0 0 16px rgba(34, 211, 238, 0.5); }

/* ------------------------- power-up guide -------------------------- */
.pu-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; text-align: left; }
.pu-list li {
  display: grid;
  grid-template-columns: 24px 122px 1fr;
  align-items: center;
  gap: 10px;
  padding: 4px 8px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
}
.pu-list li.bad { background: rgba(251, 113, 133, 0.09); }
.pu-list b { font-size: 11.5px; font-weight: 700; letter-spacing: 0.4px; }
.pu-list span { font-size: 10.5px; color: var(--ink-dim); }

.pu {
  width: 24px; height: 15px;
  display: grid; place-items: center;
  border-radius: 8px;
  font-style: normal; font-weight: 800; font-size: 9.5px;
  color: #05070f;
  background: linear-gradient(180deg, hsl(var(--hue), 92%, 68%), hsl(var(--hue), 92%, 42%));
  box-shadow: 0 0 12px hsla(var(--hue), 100%, 60%, 0.55);
}

.bk {
  width: 24px; height: 15px;
  display: grid; place-items: center;
  border-radius: 3px;
  font-style: normal; font-weight: 800; font-size: 9px;
  color: rgba(0, 0, 0, 0.7);
}
.bk-hp { background: linear-gradient(90deg, #22d3ee, #a3e635 35%, #facc15 65%, #f472b6); font-size: 8px; }
.bk-solid { background: repeating-linear-gradient(45deg, #4b5563 0 3px, #6b7280 3px 6px); }
.bk-boom { background: linear-gradient(180deg, #fb923c, #ea580c); color: #fff; }
.bk-myst { background: linear-gradient(90deg, #a855f7, #22d3ee, #f472b6); color: #fff; }
.brick-list li { grid-template-columns: 24px 122px 1fr; }

/* ----------------------------- toolbar ----------------------------- */
#toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 12px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
}

.tips { display: flex; gap: 14px; font-size: 10px; color: var(--ink-faint); letter-spacing: 0.7px; }
.tips span { display: flex; align-items: center; gap: 5px; }

.tool-buttons { display: flex; gap: 6px; }
.icon-btn {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  font-size: 13px;
  font-family: inherit;
  color: var(--ink-dim);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s, border-color 0.15s, transform 0.1s;
}
.icon-btn:hover { color: var(--ink); background: rgba(255, 255, 255, 0.1); border-color: rgba(150, 200, 255, 0.4); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }
.icon-btn.off { color: var(--ink-faint); opacity: 0.6; }
#btnMusic { font-size: 15px; }
#btnPerf.on {
  color: var(--amber);
  border-color: rgba(250, 204, 21, 0.45);
  text-shadow: 0 0 12px rgba(250, 204, 21, 0.85);
}
#btnMusic:not(.off) {
  color: var(--pink);
  border-color: rgba(244, 114, 182, 0.42);
  text-shadow: 0 0 12px rgba(244, 114, 182, 0.8);
}

/* ---------------------------- responsive --------------------------- */
@media (max-width: 620px) {
  :root { --chrome: 126px; }
  #hud { grid-template-columns: 1fr 1.6fr 1fr; padding: 6px 10px; }
  .hud-cell:nth-child(2) { display: none; }          /* hide "Best" */
  .hud-cell:nth-child(4) { display: none; }          /* hide "Combo" */
  .hud-cell:nth-child(5) { align-items: flex-end; }
  .hud-value { font-size: 16px; }
  .only-wide { display: none; }
  .tips { gap: 9px; font-size: 9px; }
  .pu-list li { grid-template-columns: 24px 1fr; }
  .pu-list span { display: none; }
  .panel { padding: 22px 18px 20px; }
}

@media (max-height: 560px) {
  :root { --chrome: 120px; }
  #hud { padding: 5px 12px; }
  .hud-value { font-size: 16px; }
  .panel { padding: 16px 20px; }
  .controls-grid { display: none; }
}

/* ------------------ landscape: chrome moves to a side rail ---------------- */
/* Stacked vertically, a landscape phone sizes the playfield from its SHORT
   edge -- so the canvas ends up tiny while ~500px of width sits unused, and
   the HUD and toolbar overflow the viewport and get clipped. Here the whole
   layout becomes a grid: playfield on the left, chrome in a rail on the
   right. Also catches short desktop windows, which have the same problem. */
@media (orientation: landscape) and (max-height: 620px) {
  :root { --rail: clamp(132px, 20vw, 196px); }

  #wrap {
    display: grid;
    width: 100vw;
    height: 100dvh;
    padding: 6px calc(6px + env(safe-area-inset-right, 0px))
             6px calc(6px + env(safe-area-inset-left, 0px));
    gap: 6px;
    grid-template-columns: auto var(--rail);
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "stage hud"
      "stage tools";
    justify-content: center;
    align-content: center;
  }

  #stage {
    grid-area: stage;
    align-self: center;
    /* Same reasoning as the portrait width formula, transposed: take the
       smaller of "what's left beside the rail" and "what the height allows". */
    width: min(calc(100vw - var(--rail) - 30px), calc((100dvh - 14px) * 4 / 3));
    height: auto;
    aspect-ratio: 4 / 3;
  }

  /* ---- HUD becomes a vertical stack of label/value rows ---- */
  #hud {
    grid-area: hud;
    grid-template-columns: 1fr;
    align-content: start;
    gap: 4px;
    padding: 8px 10px;
  }
  #hud .hud-cell {
    flex-direction: row;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
  }
  /* The narrow-width breakpoint hides these two; the rail has room. */
  #hud .hud-cell:nth-child(2),
  #hud .hud-cell:nth-child(4) { display: flex; }
  #hud .hud-cell:nth-child(5) { align-items: center; }
  #hud .hud-title {
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    padding-top: 2px;
    margin-top: 2px;
    border-top: 1px solid var(--line);
  }
  .hud-name { font-size: 10.5px; letter-spacing: 1.4px; }
  .hud-value { font-size: 16px; }
  .hud-value.dim { font-size: 14px; }
  .lives { height: auto; }

  /* ---- toolbar becomes a button pad under the HUD ---- */
  #toolbar {
    grid-area: tools;
    align-self: start;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 8px;
  }
  .tips { display: none; }
  .tool-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
  }
  .icon-btn { width: 100%; height: 32px; }

  /* ---- overlay panels have to fit a short stage ---- */
  .screen { padding: 10px; }
  .panel { padding: 14px 18px 14px; }
  .panel-wide { padding: 12px 16px; }
  .logo { margin-bottom: 2px; }
  .logo-neon { font-size: clamp(24px, 4.4vw, 34px); }
  .logo-break { font-size: clamp(16px, 3vw, 23px); letter-spacing: 5px; }
  .tagline { margin-bottom: 12px; font-size: 11px; }
  .screen-title { margin-bottom: 10px; }
  .best-line { margin: 10px 0 2px; }
  /* Room enough to put the key list back -- the short-viewport rule drops it. */
  .controls-grid {
    display: grid;
    margin-top: 10px;
    padding-top: 10px;
    gap: 4px 12px;
    font-size: 10px;
  }
  .stats > div { padding: 6px 12px; }
  .stats dd { font-size: 14px; }
  .stats > div:first-child dd { font-size: 17px; }
  .pu-list li { padding: 2px 8px; }
  .hint { margin-top: 10px; }
}

/* ---------------------- performance mode --------------------------- */
/* Toggled by js/quality.js. Everything here is a compositor or GPU cost
   that mobile browsers handle badly. */
body.low-fx #stage::after { display: none; }          /* scanline overlay */
body.low-fx #hud,
body.low-fx #toolbar,
body.low-fx .screen,
body.low-fx .chip { backdrop-filter: none; }
body.low-fx #stage {
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.6), 0 10px 30px rgba(0, 0, 0, 0.7);
}
body.low-fx .logo-neon { animation: none; }
body.low-fx .life { box-shadow: none; }
body.low-fx .chip { box-shadow: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001s !important; transition-duration: 0.001s !important; }
}
