/* ChromaChain — dark neon arcade, mobile portrait (companion to Neon Flood) */

:root {
  --bg: #07060f;
  --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;
  --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(0, 240, 255, 0.14), transparent 55%),
    radial-gradient(700px 400px at 0% 90%, rgba(255, 43, 214, 0.1), transparent 50%),
    radial-gradient(600px 360px at 100% 70%, rgba(155, 92, 255, 0.1), transparent 45%),
    var(--bg);
  overflow: hidden;
}

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

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

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

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

.toast {
  position: fixed;
  left: 50%;
  top: 28%;
  transform: translate(-50%, -20px);
  z-index: 22;
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(12, 10, 28, 0.88);
  border: 1px solid rgba(0, 240, 255, 0.35);
  color: #e8ffff;
  font-weight: 700;
  font-size: 0.9rem;
  box-shadow: 0 0 24px rgba(0, 240, 255, 0.25);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  white-space: nowrap;
  max-width: 90vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

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

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

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

.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: 1.4fr 1fr 1fr 1fr 1fr;
  gap: 6px;
  margin-top: 10px;
  flex-shrink: 0;
}

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

.stat.wide { grid-column: span 1; }

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

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

/* Board stage — tall Tetris-like */
.stage {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 0 6px;
}

.board {
  --cols: 8;
  --rows: 12;
  --gap: 3px;
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  grid-template-rows: repeat(var(--rows), 1fr);
  gap: var(--gap);
  /* Tall rectangle: width constrained, height follows rows */
  width: min(92vw, calc((100dvh - 300px) * 8 / 12), 360px);
  aspect-ratio: 8 / 12;
  max-height: min(calc(100dvh - 290px), 62dvh);
  padding: 7px;
  border-radius: 16px;
  background: linear-gradient(165deg, rgba(20, 16, 40, 0.96), 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 14px 40px rgba(0, 0, 0, 0.55),
    0 0 36px rgba(255, 43, 214, 0.1);
  /* Allow falling / spawning tiles to travel outside the cell briefly */
  overflow: visible;
}

.board.animating {
  /* Keep grid chrome; tiles may paint above neighbors */
  z-index: 2;
}

.board.shake {
  animation: shake 0.35s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

.tile {
  position: relative;
  border-radius: clamp(3px, 1vw, 5px);
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  will-change: transform, opacity;
  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, #1a1628);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    inset 0 -2px 4px rgba(0, 0, 0, 0.35),
    0 0 8px color-mix(in srgb, var(--g, transparent) 50%, transparent),
    0 2px 3px rgba(0, 0, 0, 0.35);
}

.tile.empty {
  background: rgba(255, 255, 255, 0.03);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04);
}

.tile.cleared-slot {
  background: rgba(0, 240, 255, 0.06);
  box-shadow:
    inset 0 0 0 1px rgba(0, 240, 255, 0.2),
    inset 0 0 12px rgba(255, 43, 214, 0.12);
  animation: slot-fade 0.35s ease-out;
}

@keyframes slot-fade {
  from {
    background: rgba(255, 255, 255, 0.2);
    box-shadow: inset 0 0 16px rgba(255, 255, 255, 0.35);
  }
  to {
    background: rgba(0, 240, 255, 0.06);
  }
}

.tile.special {
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.35) 0%, transparent 40%),
    linear-gradient(160deg, #1a1030, #0a0818);
  border: 1px solid rgba(255, 255, 255, 0.25);
}

.tile.special-line {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 0 14px rgba(0, 240, 255, 0.55),
    0 0 4px #00f0ff;
}

.tile.special-bomb {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 0 14px rgba(255, 43, 214, 0.55),
    0 0 4px #ff2bd6;
}

.special-icon {
  font-size: clamp(0.7rem, 3.2vw, 1rem);
  line-height: 1;
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.5));
}

.tile.pop,
.tile.clearing,
.tile.bursting {
  animation: tile-burst 0.34s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
  z-index: 5;
  pointer-events: none;
}

@keyframes tile-burst {
  0% {
    transform: scale(1);
    filter: brightness(1) saturate(1);
    opacity: 1;
    box-shadow:
      inset 0 1px 0 rgba(255, 255, 255, 0.4),
      0 0 8px color-mix(in srgb, var(--g, #fff) 50%, transparent);
  }
  35% {
    transform: scale(1.22);
    filter: brightness(1.85) saturate(1.4);
    opacity: 1;
    box-shadow:
      0 0 22px color-mix(in srgb, var(--g, #fff) 90%, transparent),
      0 0 40px rgba(255, 255, 255, 0.35);
  }
  100% {
    transform: scale(0.15);
    filter: brightness(2.2);
    opacity: 0;
    box-shadow: 0 0 28px color-mix(in srgb, var(--g, #fff) 80%, transparent);
  }
}

.tile.falling {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.4),
    0 8px 18px rgba(0, 0, 0, 0.45),
    0 0 14px color-mix(in srgb, var(--g, #00f0ff) 55%, transparent);
}

.tile.spawning {
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.45),
    0 0 16px color-mix(in srgb, var(--g, #00f0ff) 65%, transparent);
}

.tile.land {
  animation: tile-land 0.18s ease-out;
}

@keyframes tile-land {
  0% { transform: translateY(0) scale(1.06); filter: brightness(1.35); }
  60% { transform: translateY(0) scale(0.96); }
  100% { transform: translateY(0) scale(1); filter: brightness(1); }
}

.fx-shock {
  position: fixed;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border-radius: 50%;
  border: 2px solid rgba(0, 240, 255, 0.9);
  box-shadow:
    0 0 12px rgba(0, 240, 255, 0.7),
    inset 0 0 8px rgba(0, 240, 255, 0.4);
  pointer-events: none;
  z-index: 26;
  animation: shock-out 0.5s ease-out forwards;
}

.fx-shock.special {
  border-color: rgba(255, 43, 214, 0.95);
  box-shadow:
    0 0 16px rgba(255, 43, 214, 0.75),
    0 0 28px rgba(0, 240, 255, 0.35),
    inset 0 0 10px rgba(255, 43, 214, 0.45);
  animation-duration: 0.58s;
}

@keyframes shock-out {
  0% {
    transform: scale(0.4);
    opacity: 0.95;
  }
  100% {
    transform: scale(14);
    opacity: 0;
  }
}

.cb-mark {
  font-size: clamp(0.5rem, 2.6vw, 0.75rem);
  color: rgba(0, 0, 0, 0.55);
  font-weight: 800;
  line-height: 1;
  text-shadow: 0 0 4px rgba(255, 255, 255, 0.35);
}

.legend {
  display: flex;
  gap: 16px;
  font-size: 0.72rem;
  color: var(--muted);
}

.legend .lg {
  font-style: normal;
  margin-right: 4px;
}

/* Controls */
.controls {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hint-line {
  margin: 0;
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
}

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

.color-btn {
  aspect-ratio: 1;
  max-height: 72px;
  min-height: 54px;
  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);
  transition: transform 0.12s ease, opacity 0.12s;
}

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

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

.cb-symbol {
  font-size: 1.3rem;
  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.5rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  background: linear-gradient(90deg, #00f0ff, #ff2bd6, #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;
}

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

.feature-list {
  text-align: left;
  margin: 0 auto;
  padding-left: 1.15rem;
  color: var(--muted);
  font-size: 0.88rem;
}

.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.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

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

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

.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.72rem; }

.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); }

@media (max-height: 700px) {
  .stats { margin-top: 6px; }
  .stage { padding: 4px 0; }
  .color-btn { min-height: 48px; max-height: 56px; }
  .hint-line { display: none; }
  .legend { font-size: 0.65rem; }
}

@media (max-width: 360px) {
  .stats {
    grid-template-columns: repeat(3, 1fr);
  }
  .stat:nth-child(4),
  .stat:nth-child(5) {
    /* keep all visible in 3-col: wrap naturally */
  }
}

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