:root {
  --bg-deep: #070512;
  --bg-panel: rgba(14, 11, 28, 0.78);
  --glass: rgba(255, 255, 255, 0.035);
  --c-text: #f4f2ff;
  --c-dim: rgba(244, 242, 255, 0.55);
  --c-border: rgba(255, 255, 255, 0.1);
  --radius: 20px;
  --radius-sm: 12px;
  --gap: clamp(8px, 2vmin, 14px);
  --font-display: "Orbitron", "Helvetica Neue", sans-serif;
  --font-body: "Outfit", "Helvetica Neue", sans-serif;
  --tile-transition: 0.15s cubic-bezier(0.4, 0, 0.2, 1);

  --t1: #00f2ff;  --t1-g: rgba(0, 242, 255, 0.45);
  --t2: #00e5c9;  --t2-g: rgba(0, 229, 201, 0.45);
  --t3: #39ff5a;  --t3-g: rgba(57, 255, 90, 0.45);
  --t4: #bfff00;  --t4-g: rgba(191, 255, 0, 0.5);
  --t5: #ffea00;  --t5-g: rgba(255, 234, 0, 0.5);
  --t6: #ff9d00;  --t6-g: rgba(255, 157, 0, 0.5);
  --t7: #ff3b3b;  --t7-g: rgba(255, 59, 59, 0.5);
  --t8: #ff00a0;  --t8-g: rgba(255, 0, 160, 0.55);
  --t9: #c500ff;  --t9-g: rgba(197, 0, 255, 0.55);
  --t10: #6a5cff; --t10-g: rgba(106, 92, 255, 0.55);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-deep);
  color: var(--c-text);
  font-family: var(--font-body);
  touch-action: none;
}

.game-stage {
  position: relative;
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.vignette,
.scanlines,
.prism-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
}

.vignette {
  background: radial-gradient(circle at 50% 35%, transparent 15%, rgba(7, 5, 18, 0.85) 100%);
}

.scanlines {
  opacity: 0.12;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.22),
      rgba(0, 0, 0, 0.22) 1px,
      transparent 1px,
      transparent 3px
    ),
    url("data:image/svg+xml,%3Csvg viewBox='0 0 300 300' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  mix-blend-mode: screen;
  animation: grain 0.4s steps(4) infinite;
}

@keyframes grain {
  0%, 100% { transform: translate(0, 0); }
  25% { transform: translate(-2px, 1px); }
  50% { transform: translate(1px, -1px); }
  75% { transform: translate(-1px, 2px); }
}

.prism-glow {
  background:
    radial-gradient(circle at 50% 55%, rgba(106, 92, 255, 0.18) 0%, transparent 45%),
    radial-gradient(circle at 20% 30%, rgba(0, 242, 255, 0.12) 0%, transparent 35%),
    radial-gradient(circle at 80% 30%, rgba(255, 0, 160, 0.12) 0%, transparent 35%);
  animation: prism 16s ease-in-out infinite alternate;
}

@keyframes prism {
  0% { filter: hue-rotate(0deg); }
  100% { filter: hue-rotate(30deg); }
}

.hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  padding: 24px 32px;
  gap: 18px;
  pointer-events: none;
}

.hud-group {
  display: flex;
  gap: 24px;
}

.hud-group--right {
  justify-content: flex-end;
}

.hud-block {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.hud-block--center {
  align-items: center;
}

.hud-block--next {
  align-items: center;
}

.hud-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--c-dim);
}

.hud-value {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 700;
  line-height: 1;
  color: var(--c-text);
  text-shadow: 0 0 18px rgba(255, 255, 255, 0.2);
  transition: color 0.2s ease;
}

.hud-value--dim {
  color: var(--c-dim);
  text-shadow: none;
}

.hud-value--pop {
  animation: valuePop 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes valuePop {
  0% { transform: scale(1); }
  50% { transform: scale(1.25); color: #fff; }
  100% { transform: scale(1); }
}

.logo {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.14em;
  color: var(--c-text);
  text-shadow: 0 0 20px rgba(106, 92, 255, 0.35), 0 0 40px rgba(0, 242, 255, 0.15);
}

.logo-sub {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4em;
  color: var(--c-dim);
  margin-top: 3px;
}

.hud-value--tier1 { color: var(--t1); text-shadow: 0 0 20px var(--t1-g); }
.hud-value--tier2 { color: var(--t2); text-shadow: 0 0 20px var(--t2-g); }
.hud-value--tier3 { color: var(--t3); text-shadow: 0 0 20px var(--t3-g); }
.hud-value--tier4 { color: var(--t4); text-shadow: 0 0 20px var(--t4-g); }
.hud-value--tier5 { color: var(--t5); text-shadow: 0 0 20px var(--t5-g); }
.hud-value--tier6 { color: var(--t6); text-shadow: 0 0 20px var(--t6-g); }
.hud-value--tier7 { color: var(--t7); text-shadow: 0 0 20px var(--t7-g); }
.hud-value--tier8 { color: var(--t8); text-shadow: 0 0 20px var(--t8-g); }
.hud-value--tier9 { color: var(--t9); text-shadow: 0 0 20px var(--t9-g); }
.hud-value--tier10 { color: var(--t10); text-shadow: 0 0 20px var(--t10-g); }

.next-tile {
  width: 46px;
  height: 46px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: inset 0 0 12px rgba(255, 255, 255, 0.12), 0 0 14px var(--tile-glow, var(--t1-g));
}

.board-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 22px;
  padding: 20px;
  position: relative;
  z-index: 15;
}

.board-frame {
  position: relative;
  width: min(520px, 92vmin, 90vw);
  aspect-ratio: 1 / 1;
  background: var(--bg-panel);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  box-shadow:
    inset 0 0 80px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(255, 255, 255, 0.04),
    0 24px 70px rgba(0, 0, 0, 0.55),
    0 0 50px rgba(106, 92, 255, 0.12);
  backdrop-filter: blur(8px);
}

.grid,
.tile-layer {
  position: absolute;
  inset: var(--gap);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(4, 1fr);
  gap: var(--gap);
}

.cell {
  background: var(--glass);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.05);
  box-shadow: inset 0 0 16px rgba(0, 0, 0, 0.25);
}

.tile-layer {
  pointer-events: none;
}

.tile {
  position: absolute;
  z-index: 2;
  will-change: transform;
  transition: transform var(--tile-transition), opacity 0.12s ease;
}

.tile__face {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: clamp(22px, 6.5vmin, 42px);
  font-weight: 700;
  line-height: 1;
  color: var(--tile-text, #fff);
  background:
    radial-gradient(circle at 32% 28%, var(--tile-bg-light), transparent 55%),
    linear-gradient(145deg, var(--tile-bg) 0%, var(--tile-bg-dark) 100%);
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow:
    inset 0 0 22px rgba(255, 255, 255, 0.18),
    0 0 0 1px rgba(255, 255, 255, 0.08),
    0 0 22px var(--tile-glow),
    0 8px 24px rgba(0, 0, 0, 0.35);
  text-shadow: 0 0 10px var(--tile-glow);
}

.tile__value {
  position: relative;
  z-index: 1;
}

.tile__value--small {
  font-size: 0.55em;
}

.tile--new .tile__face {
  animation: tileBirth 0.28s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.tile--pop .tile__face {
  animation: tileMerge 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
  z-index: 3;
}

.tile--fade .tile__face {
  animation: tileFade 0.18s ease forwards;
}

@keyframes tileBirth {
  0% { transform: scale(0); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes tileMerge {
  0% { transform: scale(0); opacity: 0; }
  55% { transform: scale(1.22); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes tileFade {
  0% { transform: scale(1); opacity: 1; }
  100% { transform: scale(1.15); opacity: 0; }
}

.tile--1, .next-tile--1 {
  --tile-bg: #00c2d0; --tile-bg-light: #a0fbff; --tile-bg-dark: #0098a8; --tile-glow: var(--t1-g); --tile-text: #fff;
}
.tile--2, .next-tile--2 {
  --tile-bg: #00c4ad; --tile-bg-light: #8dffe9; --tile-bg-dark: #009682; --tile-glow: var(--t2-g); --tile-text: #fff;
}
.tile--3, .next-tile--3 {
  --tile-bg: #2bd84a; --tile-bg-light: #a5ffaa; --tile-bg-dark: #1aa836; --tile-glow: var(--t3-g); --tile-text: #fff;
}
.tile--4, .next-tile--4 {
  --tile-bg: #a8e600; --tile-bg-light: #eaff80; --tile-bg-dark: #7db300; --tile-glow: var(--t4-g); --tile-text: #0e0c18;
}
.tile--5, .next-tile--5 {
  --tile-bg: #f0d800; --tile-bg-light: #fff27a; --tile-bg-dark: #bda500; --tile-glow: var(--t5-g); --tile-text: #0e0c18;
}
.tile--6, .next-tile--6 {
  --tile-bg: #f08a00; --tile-bg-light: #ffd27a; --tile-bg-dark: #b86200; --tile-glow: var(--t6-g); --tile-text: #0e0c18;
}
.tile--7, .next-tile--7 {
  --tile-bg: #e62a2a; --tile-bg-light: #ff9a9a; --tile-bg-dark: #a60f0f; --tile-glow: var(--t7-g); --tile-text: #fff;
}
.tile--8, .next-tile--8 {
  --tile-bg: #d9008c; --tile-bg-light: #ff7ac9; --tile-bg-dark: #9b0063; --tile-glow: var(--t8-g); --tile-text: #fff;
}
.tile--9, .next-tile--9 {
  --tile-bg: #a800e0; --tile-bg-light: #e07aff; --tile-bg-dark: #70009b; --tile-glow: var(--t9-g); --tile-text: #fff;
}
.tile--10, .next-tile--10 {
  --tile-bg: #5848e0; --tile-bg-light: #a8a0ff; --tile-bg-dark: #3326a8; --tile-glow: var(--t10-g); --tile-text: #fff;
}

.touch-controls {
  display: grid;
  grid-template-columns: repeat(3, 56px);
  grid-template-rows: repeat(3, 56px);
  gap: 10px;
  place-items: center;
}

.d-btn {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  border: 1px solid var(--c-border);
  background: var(--glass);
  color: var(--c-dim);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.d-btn:active {
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  box-shadow: 0 0 20px rgba(106, 92, 255, 0.25);
}

.d-btn--up { grid-column: 2; grid-row: 1; }
.d-btn--left { grid-column: 1; grid-row: 2; }
.d-btn--down { grid-column: 2; grid-row: 3; }
.d-btn--right { grid-column: 3; grid-row: 2; }

@media (hover: hover) and (pointer: fine) {
  .touch-controls {
    display: none;
  }
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 40%, rgba(7, 5, 18, 0.55) 0%, rgba(7, 5, 18, 0.94) 100%);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.38s ease, visibility 0.38s ease;
  backdrop-filter: blur(6px);
}

.overlay--active {
  opacity: 1;
  visibility: visible;
}

.overlay__panel {
  width: min(520px, 90vw);
  padding: 46px 40px;
  border: 1px solid rgba(106, 92, 255, 0.35);
  border-radius: var(--radius);
  background: var(--bg-panel);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.04),
    0 24px 80px rgba(0, 0, 0, 0.55),
    0 0 60px rgba(106, 92, 255, 0.14);
  text-align: center;
  transform: translateY(16px) scale(0.98);
  transition: transform 0.42s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.overlay--active .overlay__panel {
  transform: translateY(0) scale(1);
}

.overlay__kicker {
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.32em;
  color: var(--t1);
  text-shadow: 0 0 16px var(--t1-g);
  margin-bottom: 14px;
}

.overlay__kicker--alert {
  color: var(--t7);
  text-shadow: 0 0 18px var(--t7-g);
}

.overlay__title {
  font-family: var(--font-display);
  font-size: 44px;
  font-weight: 900;
  line-height: 1.1;
  margin-bottom: 6px;
  color: var(--c-text);
  text-shadow: 0 0 24px rgba(255, 255, 255, 0.18);
}

.overlay__subtitle {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.42em;
  color: var(--c-dim);
  margin-bottom: 18px;
}

.overlay__copy {
  font-size: 17px;
  line-height: 1.55;
  color: var(--c-dim);
  margin-bottom: 26px;
}

.overlay__stat {
  color: var(--t5);
  font-weight: 700;
  text-shadow: 0 0 12px var(--t5-g);
}

.overlay__controls {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 24px;
  font-size: 13px;
  color: var(--c-dim);
}

kbd {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 700;
  padding: 7px 11px;
  border-radius: 8px;
  border: 1px solid rgba(106, 92, 255, 0.35);
  background: rgba(106, 92, 255, 0.1);
  color: var(--c-text);
}

.tier-strip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 30px;
  flex-wrap: wrap;
}

.tier-strip__arrow,
.tier-strip__dots {
  color: var(--c-dim);
  font-weight: 700;
}

.tier-chip {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-size: 12px;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow: 0 0 14px var(--tile-glow);
}

.chroma-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 18px 46px;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  background: linear-gradient(135deg, rgba(106, 92, 255, 0.2), rgba(0, 242, 255, 0.14));
  box-shadow: 0 0 0 1px rgba(106, 92, 255, 0.45), 0 0 24px rgba(106, 92, 255, 0.25);
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.chroma-btn--secondary {
  background: linear-gradient(135deg, rgba(255, 59, 59, 0.16), rgba(197, 0, 255, 0.14));
  box-shadow: 0 0 0 1px rgba(255, 59, 59, 0.45), 0 0 24px rgba(255, 59, 59, 0.2);
}

.chroma-btn:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 0 0 1px rgba(106, 92, 255, 0.7), 0 0 36px rgba(106, 92, 255, 0.4);
}

.chroma-btn--secondary:hover {
  box-shadow: 0 0 0 1px rgba(255, 59, 59, 0.7), 0 0 36px rgba(255, 59, 59, 0.35);
}

.chroma-btn__text {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--c-text);
}

@media (max-width: 640px) {
  .hud {
    padding: 16px 18px;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
    gap: 12px;
  }
  .hud-block--center {
    grid-column: 1 / -1;
    order: -1;
  }
  .hud-group--left,
  .hud-group--right {
    justify-content: space-between;
    gap: 14px;
  }
  .hud-value {
    font-size: 26px;
  }
  .logo {
    font-size: 16px;
  }
  .next-tile {
    width: 38px;
    height: 38px;
    font-size: 11px;
  }
  .overlay__title {
    font-size: 34px;
  }
  .overlay__panel {
    padding: 34px 24px;
  }
  .board-frame {
    width: min(100%, 92vmin);
  }
}

@media (max-width: 360px) {
  .hud-value {
    font-size: 22px;
  }
  .overlay__title {
    font-size: 28px;
  }
}
