:root {
  --bg: #04030c;
  --bg-panel: rgba(14, 10, 38, 0.82);
  --bg-panel-2: rgba(8, 6, 26, 0.88);
  --line: rgba(120, 220, 255, 0.18);
  --text: #eaf6ff;
  --muted: #8aa0cf;
  --accent: #22e6ff;
  --pink: #ff3df0;
  --radius: 14px;
}

* { box-sizing: border-box; }

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

body {
  background:
    radial-gradient(900px 500px at 50% -8%, rgba(120, 40, 255, 0.35) 0%, transparent 65%),
    radial-gradient(700px 400px at 12% 110%, rgba(255, 40, 200, 0.2) 0%, transparent 60%),
    radial-gradient(700px 400px at 92% 105%, rgba(30, 220, 255, 0.18) 0%, transparent 60%),
    var(--bg);
  background-attachment: fixed;
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  position: relative;
}

/* a synthwave floor: a perspective grid sliding toward you */
body::before {
  content: "";
  position: fixed;
  left: -50%;
  right: -50%;
  bottom: 0;
  height: 46vh;
  background:
    linear-gradient(to bottom, transparent 0%, rgba(255, 60, 240, 0.12) 100%),
    repeating-linear-gradient(to right, rgba(255, 60, 240, 0.35) 0 1px, transparent 1px 64px),
    repeating-linear-gradient(to bottom, rgba(34, 230, 255, 0.35) 0 1px, transparent 1px 48px);
  transform: perspective(380px) rotateX(62deg);
  transform-origin: center bottom;
  animation: floor 3.2s linear infinite;
  opacity: 0.55;
  pointer-events: none;
  z-index: -1;
  -webkit-mask-image: linear-gradient(to top, #000 0%, transparent 92%);
  mask-image: linear-gradient(to top, #000 0%, transparent 92%);
}
@keyframes floor {
  from { background-position: 0 0, 0 0, 0 0; }
  to { background-position: 0 0, 0 0, 0 48px; }
}
@media (prefers-reduced-motion: reduce) { body::before { animation: none; } }

/* ---- top bar ---- */

.topbar {
  width: 100%;
  max-width: 900px;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.topbar h1 {
  font-size: 24px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  margin: 0;
  flex: 1;
  color: #fff;
  text-shadow: 0 0 6px var(--accent), 0 0 18px var(--accent), 0 0 36px var(--pink);
}

.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.back {
  color: var(--muted);
  text-decoration: none;
  font-size: 14px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
}
.back:hover { color: var(--text); border-color: var(--accent); box-shadow: 0 0 12px rgba(34, 230, 255, 0.35); }

.btn {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: rgba(20, 14, 52, 0.7);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 7px 14px;
  cursor: pointer;
  transition: box-shadow 0.15s, border-color 0.15s;
}
.btn:hover { border-color: var(--accent); box-shadow: 0 0 14px rgba(34, 230, 255, 0.4); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn-primary {
  background: linear-gradient(180deg, #2ff0ff, #14a6ff);
  border-color: transparent;
  color: #02131c;
  font-weight: 750;
  padding: 10px 24px;
  font-size: 15px;
  box-shadow: 0 0 22px rgba(34, 230, 255, 0.6);
}

/* ---- layout ---- */

.game {
  /* One source of truth for the board size: the grid column and the wrapper
     both read it, so the column can't be stretched by the canvas's intrinsic
     (device-pixel) width. */
  --board: max(140px, min(100%, 300px, calc((100vh - 220px) / 2)));
  display: grid;
  grid-template-columns: 160px var(--board) 150px;
  gap: 18px;
  align-items: start;
  justify-content: center;
}

.rail {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.panel {
  background: linear-gradient(180deg, var(--bg-panel), var(--bg-panel-2));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: 0 0 18px rgba(80, 60, 255, 0.12), inset 0 0 22px rgba(34, 230, 255, 0.04);
}

.panel h2 {
  margin: 0 0 10px;
  font-size: 11px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 650;
  text-shadow: 0 0 8px rgba(34, 230, 255, 0.7);
}

.panel canvas { display: block; margin: 0 auto; }

.stats dl { margin: 0; display: grid; gap: 8px; }
.stats dl div { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.stats dt { color: var(--muted); font-size: 12px; }
.stats dd {
  margin: 0;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 16px;
  text-shadow: 0 0 8px rgba(34, 230, 255, 0.5);
}

/* ---- combo + abilities ---- */

.combo {
  font-size: 34px;
  font-weight: 850;
  text-align: center;
  line-height: 1.1;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  transition: color 0.2s, text-shadow 0.2s, transform 0.2s;
}
.combo.hot {
  color: #fff;
  text-shadow: 0 0 8px var(--pink), 0 0 22px var(--pink), 0 0 40px var(--accent);
  transform: scale(1.12);
}

.energy {
  height: 10px;
  margin-top: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
  border: 1px solid var(--line);
}
.energy-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #22e6ff, #b06bff, #ff3df0);
  box-shadow: 0 0 12px rgba(176, 107, 255, 0.9);
  transition: width 0.25s;
}
.energy-num { text-align: right; font-size: 11px; color: var(--muted); margin: 3px 0 8px; font-variant-numeric: tabular-nums; }

.abilities { display: grid; gap: 6px; }
.ability {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 6px;
  font: inherit;
  font-size: 12px;
  color: var(--muted);
  background: rgba(20, 14, 52, 0.6);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 8px;
  cursor: pointer;
  text-align: left;
  opacity: 0.55;
  transition: opacity 0.2s, box-shadow 0.2s, border-color 0.2s, color 0.2s;
}
.ability b { font-weight: 650; }
.ability i { font-style: normal; font-size: 11px; opacity: 0.8; font-variant-numeric: tabular-nums; }
.ability.ready {
  opacity: 1;
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 14px rgba(34, 230, 255, 0.6), inset 0 0 10px rgba(34, 230, 255, 0.15);
  animation: ready 1.2s ease-in-out infinite;
}
@keyframes ready { 50% { box-shadow: 0 0 22px rgba(255, 60, 240, 0.75), inset 0 0 12px rgba(255, 60, 240, 0.2); } }

.track { font-weight: 650; color: #fff; text-shadow: 0 0 10px var(--pink); font-size: 14px; }

.keys ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.keys li { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.keys span { margin-left: auto; }
kbd {
  font: 600 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: rgba(30, 24, 80, 0.8);
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  padding: 3px 5px;
  color: var(--text);
}

/* ---- board ---- */

.board-wrap {
  --hue: 190;
  --beat: 0;
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 2px solid hsl(var(--hue), 100%, 62%);
  box-shadow:
    0 0 calc(14px + var(--beat) * 26px) hsla(var(--hue), 100%, 60%, calc(0.5 + var(--beat) * 0.4)),
    0 0 70px hsla(var(--hue), 100%, 55%, 0.25),
    inset 0 0 28px hsla(var(--hue), 100%, 60%, 0.2);
  line-height: 0;
}

/* The wrapper owns the size. The playfield is 10x20, so the height budget is
   halved to keep the cells square at every width. */
.board-wrap { width: var(--board); }

#board {
  display: block;
  width: 100%;
  height: auto;
}

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  padding: 24px;
  line-height: 1.5;
  background: rgba(4, 3, 12, 0.84);
  backdrop-filter: blur(6px);
}
.overlay[hidden] { display: none; }
.overlay h2 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #fff;
  text-shadow: 0 0 8px var(--accent), 0 0 24px var(--pink);
}
.overlay p { margin: 0 0 6px; color: var(--muted); font-size: 13px; max-width: 26ch; }

/* ---- touch controls ---- */

.touch { display: none; }

@media (max-width: 760px), (pointer: coarse) {
  .touch {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 8px;
    width: 100%;
    max-width: 460px;
  }
  .touch button {
    font: 600 18px/1 ui-sans-serif, system-ui, sans-serif;
    color: var(--text);
    background: rgba(20, 14, 52, 0.8);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 16px 0;
    cursor: pointer;
    touch-action: manipulation;
  }
  .touch button:active { background: rgba(60, 40, 160, 0.8); box-shadow: 0 0 14px rgba(34, 230, 255, 0.5); }
  .touch button.wide { grid-column: span 4; }
  .touch button.ab { grid-column: span 1; font-size: 10px; letter-spacing: 0.06em; padding: 12px 0; color: var(--accent); }
  .touch button.ab:nth-of-type(9) { grid-column: 2 / span 1; }
  .touch button[data-action="hold"],
  .touch button[data-action="hard"] { font-size: 13px; letter-spacing: 0.1em; }
}

@media (max-width: 760px) {
  body { gap: 12px; padding-top: 12px; }
  .topbar { justify-content: center; }
  .topbar h1 { flex: 0 0 auto; font-size: 18px; }
  .game {
    --board: max(140px, min(100%, 300px, calc((100vh - 300px) / 2)));
    grid-template-columns: var(--board) auto;
    grid-template-areas: "board right" "board left";
    gap: 12px;
  }
  .rail-left { grid-area: left; }
  .rail-right { grid-area: right; }
  .board-wrap { grid-area: board; }
  .rail { width: 110px; }
  .keys, .now-playing, .abilities { display: none; }
  .combo { font-size: 26px; }
}

@media (max-width: 420px) {
  .rail { width: 90px; }
  .panel { padding: 9px; }
}
