/* Neon Flood — dark neon arcade, mobile-first portrait */

:root {
  --bg: #07060f;
  --bg-2: #0e0c1c;
  --panel: rgba(18, 14, 36, 0.92);
  --text: #f2f0ff;
  --muted: #8b86a8;
  --line: rgba(255, 255, 255, 0.1);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
  --safe-x: max(env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
  --flash: #00f0ff;
  --radius: 16px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
  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);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  position: relative;
  min-height: 100%;
  min-height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding:
    max(8px, var(--safe-top))
    max(12px, var(--safe-x))
    max(10px, var(--safe-bot));
  background:
    radial-gradient(900px 500px at 50% -10%, rgba(155, 92, 255, 0.18), transparent 55%),
    radial-gradient(700px 400px at 100% 80%, rgba(0, 240, 255, 0.08), transparent 50%),
    radial-gradient(600px 360px at 0% 90%, rgba(255, 43, 214, 0.08), transparent 45%),
    var(--bg);
  overflow: hidden;
}

#app.screen-flash::after {
  content: "";
  pointer-events: none;
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--flash) 25%, transparent), transparent 65%);
  animation: flash 0.18s ease-out;
  z-index: 8;
}

@keyframes flash {
  from { opacity: 1; }
  to { opacity: 0; }
}

#app.celebrate .board,
#app.celebrate-finale .board {
  animation: board-glow 0.9s ease-out;
}

#app.celebrate-finale .board {
  animation: board-glow-finale 1.4s ease-out;
}

@keyframes board-glow {
  0% { filter: brightness(1); box-shadow: 0 0 0 transparent; }
  40% { filter: brightness(1.35); box-shadow: 0 0 40px rgba(0, 240, 255, 0.45); }
  100% { filter: brightness(1); box-shadow: 0 0 24px rgba(0, 0, 0, 0.4); }
}

@keyframes board-glow-finale {
  0% { filter: brightness(1) saturate(1); transform: scale(1); }
  30% { filter: brightness(1.5) saturate(1.3); transform: scale(1.03); }
  60% { filter: brightness(1.25) saturate(1.4); }
  100% { filter: brightness(1); transform: scale(1); }
}

#fx-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 20;
}

.fx-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.fx-ring {
  position: absolute;
  left: 50%;
  top: 38%;
  width: 24px;
  height: 24px;
  margin: -12px 0 0 -12px;
  border-radius: 50%;
  border: 3px solid #00f0ff;
  box-shadow: 0 0 20px #00f0ff, inset 0 0 12px rgba(0, 240, 255, 0.5);
  animation: ring-out 0.9s ease-out forwards;
}

.fx-ring.finale {
  border-color: #ff2bd6;
  box-shadow: 0 0 28px #ff2bd6, 0 0 60px #00f0ff, inset 0 0 16px rgba(255, 43, 214, 0.5);
  animation: ring-out-finale 1.15s ease-out forwards;
}

@keyframes ring-out {
  to {
    transform: scale(22);
    opacity: 0;
  }
}

@keyframes ring-out-finale {
  to {
    transform: scale(28);
    opacity: 0;
  }
}

/* —— Header —— */
.top-bar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.brand .title {
  margin: 0;
  font-size: clamp(1.25rem, 5.5vw, 1.55rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: linear-gradient(90deg, #ff2bd6, #00f0ff, #b8ff00);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 12px rgba(0, 240, 255, 0.35));
}

.level-name {
  margin: 2px 0 0;
  font-size: 0.75rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: 0 0 16px rgba(0, 240, 255, 0.08);
}

.icon-btn.off {
  opacity: 0.55;
}

.icon-btn.on {
  border-color: #00f0ff;
  box-shadow: 0 0 18px rgba(0, 240, 255, 0.35);
}

/* —— Stats —— */
.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-top: 10px;
  flex-shrink: 0;
}

.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 6px;
  text-align: center;
  box-shadow: 0 0 20px rgba(155, 92, 255, 0.08);
}

.stat-label {
  display: block;
  font-size: 0.62rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
}

.stat-value {
  display: block;
  margin-top: 2px;
  font-size: clamp(0.95rem, 3.8vw, 1.15rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 0 12px rgba(0, 240, 255, 0.25);
}

.mono {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

.progress-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  flex-shrink: 0;
}

.progress-track {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
  border: 1px solid var(--line);
}

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #ff2bd6, #00f0ff, #b8ff00);
  box-shadow: 0 0 12px rgba(0, 240, 255, 0.5);
  transition: width 0.25s ease;
}

.progress-label {
  font-size: 0.7rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 3.2rem;
  text-align: right;
}

/* —— Board —— */
.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 12px 0;
}

.board {
  --n: 6;
  --gap: 3px;
  display: grid;
  grid-template-columns: repeat(var(--n), 1fr);
  gap: var(--gap);
  width: min(100%, 92vw, calc(100dvh - 320px));
  aspect-ratio: 1;
  max-height: min(92vw, calc(100dvh - 300px));
  padding: 8px;
  border-radius: 18px;
  background: linear-gradient(160deg, rgba(20, 16, 40, 0.95), rgba(8, 6, 18, 0.98));
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow:
    0 0 0 1px rgba(0, 240, 255, 0.08),
    0 12px 40px rgba(0, 0, 0, 0.55),
    0 0 40px rgba(155, 92, 255, 0.12);
}

.board.board-in {
  animation: board-in 0.35s ease-out;
}

@keyframes board-in {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.tile {
  position: relative;
  border-radius: clamp(3px, 1.2vw, 6px);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.28) 0%, transparent 42%),
    linear-gradient(320deg, rgba(0, 0, 0, 0.45) 0%, transparent 50%),
    var(--c);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    inset 0 -2px 4px rgba(0, 0, 0, 0.35),
    0 0 10px color-mix(in srgb, var(--g) 55%, transparent),
    0 2px 3px rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
}

.tile.origin::after {
  content: "";
  position: absolute;
  inset: 18%;
  border-radius: 50%;
  border: 1.5px solid rgba(255, 255, 255, 0.55);
  box-shadow: 0 0 8px rgba(255, 255, 255, 0.35);
  pointer-events: none;
  opacity: 0.85;
}

.tile.flood-pop {
  animation: tile-pop 0.28s ease-out;
}

@keyframes tile-pop {
  0% { transform: scale(1); filter: brightness(1); }
  40% { transform: scale(1.08); filter: brightness(1.35); }
  100% { transform: scale(1); filter: brightness(1); }
}

.cb-mark {
  font-size: clamp(0.55rem, 2.8vw, 0.85rem);
  color: rgba(0, 0, 0, 0.55);
  font-weight: 800;
  text-shadow: 0 0 4px rgba(255, 255, 255, 0.35);
  line-height: 1;
  pointer-events: none;
}

/* —— Controls —— */
.controls {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 4px;
}

.tool-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.tool-btn {
  min-height: 48px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 0 16px rgba(155, 92, 255, 0.1);
}

.tool-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.tool-icon {
  font-size: 1.1rem;
}

.color-bar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
}

.color-btn {
  aspect-ratio: 1;
  max-height: 72px;
  min-height: 56px;
  border-radius: 16px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.35) 0%, transparent 45%),
    linear-gradient(320deg, rgba(0, 0, 0, 0.4) 0%, transparent 55%),
    var(--c);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.35),
    inset 0 -3px 6px rgba(0, 0, 0, 0.35),
    0 0 18px color-mix(in srgb, var(--g) 70%, transparent),
    0 6px 14px rgba(0, 0, 0, 0.35);
  position: relative;
  transition: transform 0.12s ease, opacity 0.12s;
}

.color-btn:active:not(:disabled) {
  transform: scale(0.94);
}

.color-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.color-btn.active {
  outline: 2px solid #fff;
  outline-offset: 2px;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.4),
    0 0 24px var(--g),
    0 0 8px #fff;
}

.color-btn.hint-pulse {
  animation: hint-pulse 0.9s ease-in-out infinite;
}

@keyframes hint-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 16px var(--g); }
  50% { transform: scale(1.08); box-shadow: 0 0 32px var(--g), 0 0 12px #fff; }
}

.cb-symbol {
  font-size: 1.35rem;
  font-weight: 800;
  color: rgba(0, 0, 0, 0.55);
  text-shadow: 0 0 6px rgba(255, 255, 255, 0.4);
}

/* —— Overlay —— */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(16px, var(--safe-top)) 18px max(16px, var(--safe-bot));
  background: rgba(4, 3, 12, 0.78);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.overlay.hidden {
  display: none;
}

.overlay-card {
  width: min(100%, 22rem);
  max-height: min(86dvh, 640px);
  overflow: auto;
  padding: 26px 22px 22px;
  border-radius: 22px;
  background: linear-gradient(165deg, rgba(28, 22, 52, 0.98), rgba(10, 8, 22, 0.98));
  border: 1px solid rgba(0, 240, 255, 0.2);
  box-shadow:
    0 0 40px rgba(255, 43, 214, 0.15),
    0 0 60px rgba(0, 240, 255, 0.1),
    0 24px 50px rgba(0, 0, 0, 0.55);
  text-align: center;
}

.overlay-card h2 {
  margin: 0 0 12px;
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  background: linear-gradient(90deg, #ff2bd6, #00f0ff, #b8ff00);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.overlay-body {
  font-size: 0.95rem;
  color: rgba(242, 240, 255, 0.88);
  line-height: 1.45;
}

.overlay-body .lead {
  margin: 0 0 12px;
  font-size: 1rem;
}

.overlay-body .lead.finale {
  font-size: 1.1rem;
  color: #00f0ff;
  text-shadow: 0 0 16px rgba(0, 240, 255, 0.5);
}

.overlay-body .muted {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 12px 0 0;
}

.feature-list {
  text-align: left;
  margin: 0 auto 8px;
  padding-left: 1.2rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin: 14px 0;
}

.stat-grid > div {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 8px;
}

.stat-grid .k {
  display: block;
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-grid .v {
  display: block;
  margin-top: 4px;
  font-size: 1.15rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.stat-grid .v.neon {
  background: linear-gradient(90deg, #ff2bd6, #00f0ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-size: 1.4rem;
}

.stat-grid.big {
  grid-template-columns: 1fr 1fr;
}

.score-list {
  list-style: none;
  margin: 0;
  padding: 0;
  text-align: left;
}

.score-list li {
  display: grid;
  grid-template-columns: 2.2rem 1fr auto;
  gap: 8px;
  align-items: baseline;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}

.score-list .rank {
  color: var(--muted);
  font-weight: 700;
}

.score-list .sc {
  font-weight: 800;
  color: #00f0ff;
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.35);
}

.score-list .meta {
  color: var(--muted);
  font-size: 0.75rem;
}

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}

.btn {
  min-height: 50px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}

.btn-primary {
  border: none;
  color: #0a0614;
  background: linear-gradient(135deg, #00f0ff, #9b5cff 55%, #ff2bd6);
  box-shadow: 0 0 24px rgba(0, 240, 255, 0.35);
}

.btn:active {
  transform: scale(0.98);
}

/* Short phones */
@media (max-height: 700px) {
  .stats { margin-top: 6px; }
  .stage { padding: 6px 0; }
  .color-btn { min-height: 48px; max-height: 58px; }
  .brand .title { font-size: 1.15rem; }
}

@media (min-width: 480px) {
  #app {
    max-width: 440px;
    margin: 0 auto;
  }
}
