:root {
  --ink: #e9edf6;
  --muted: #8d96a8;
  --panel: rgba(22, 27, 40, 0.72);
  --line: rgba(255, 255, 255, 0.1);
  --accent: #a8ff3e;
}

* { box-sizing: border-box; }

html { background: #090b10; }

body {
  margin: 0;
  color: var(--ink);
  font-family: "Segoe UI", Arial, sans-serif;
  background:
    radial-gradient(circle at 68% 42%, rgba(58, 87, 122, 0.24), transparent 33%),
    radial-gradient(circle at 20% 100%, rgba(67, 255, 150, 0.06), transparent 30%),
    #090b10;
  min-height: 100vh;
  overflow-x: hidden;
}

button, a { font: inherit; }
button { color: inherit; }

main {
  min-height: 100vh;
  position: relative;
}

main::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .16;
  background-image: linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, black, transparent 85%);
}

.topbar {
  height: 82px;
  max-width: 1440px;
  padding: 0 5vw;
  margin: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 5;
}

.brand {
  color: #fff;
  text-decoration: none;
  font-weight: 900;
  font-size: 18px;
  letter-spacing: .16em;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand > span:last-child { color: var(--accent); }

.brand-mark {
  width: 30px;
  height: 30px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 2px;
  transform: rotate(-8deg);
}

.brand-mark i { display: block; border-radius: 2px; background: var(--accent); }
.brand-mark i:nth-child(2) { background: #3478f6; }
.brand-mark i:nth-child(3) { background: #ff3b4e; grid-column: 1 / 3; width: 48%; justify-self: end; }

.status-pill {
  color: #adb5c5;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 13px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .12em;
  display: flex;
  align-items: center;
  gap: 8px;
}

.live-dot { width: 7px; height: 7px; border-radius: 50%; background: #71798a; }
.live-dot.active { background: var(--accent); box-shadow: 0 0 11px var(--accent); }

.game-layout {
  width: min(1560px, 92vw);
  min-height: 100vh;
  margin: auto;
  display: grid;
  grid-template-columns: minmax(410px, 1.05fr) minmax(470px, 1.25fr) minmax(310px, .8fr);
  align-items: center;
  gap: clamp(30px, 2.5vw, 52px);
  padding: 42px 0 58px;
}

.intro { position: relative; z-index: 2; min-width: 0; max-width: 460px; }

.eyebrow {
  margin: 0 0 22px;
  color: var(--accent);
  letter-spacing: .24em;
  font-weight: 800;
  font-size: 11px;
}

h1 {
  margin: 0;
  font-size: clamp(44px, 4vw, 68px);
  line-height: .91;
  letter-spacing: -.065em;
  text-transform: uppercase;
  font-weight: 950;
}

h1 em {
  display: block;
  max-width: 100%;
  font-size: .64em;
  line-height: 1.08;
  letter-spacing: -.035em;
  overflow-wrap: anywhere;
  font-style: normal;
  color: transparent;
  -webkit-text-stroke: 1px #647083;
}

.lead {
  color: var(--muted);
  max-width: 390px;
  line-height: 1.65;
  font-size: 15px;
  margin: 28px 0 30px;
}

.stats {
  display: flex;
  gap: 36px;
  border-top: 1px solid var(--line);
  padding-top: 21px;
  max-width: 330px;
}

.stats div { display: grid; gap: 3px; }
.stats strong { font: 700 22px/1 Consolas, monospace; }
.stats span { color: #697386; font-size: 10px; text-transform: uppercase; letter-spacing: .18em; }

.cube-zone {
  height: min(650px, 68vw);
  min-height: 520px;
  position: relative;
  display: grid;
  place-items: center;
  perspective: 980px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.cube-zone:active { cursor: grabbing; }

.cube {
  width: 62px;
  height: 62px;
  position: relative;
  transform-style: preserve-3d;
  transition: transform .08s linear;
  z-index: 2;
}

.cube.animating { animation: cube-pop .24s ease-out; }

@keyframes cube-pop {
  50% { scale: 1.035; filter: brightness(1.2); }
}

.cubie {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform .22s cubic-bezier(.2,.8,.2,1);
  background: #101217;
  border-radius: 8px;
  box-shadow: inset 0 0 0 1px #252936;
}

.turn-group {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  pointer-events: none;
}

.sticker {
  width: 58px;
  height: 58px;
  left: 2px;
  top: 2px;
  position: absolute;
  border-radius: 7px;
  border: 3px solid #151820;
  box-shadow: inset 0 0 10px rgba(255,255,255,.18), 0 0 3px rgba(0,0,0,.8);
  backface-visibility: hidden;
}

.cube-shadow {
  position: absolute;
  width: 260px;
  height: 70px;
  background: rgba(0,0,0,.7);
  filter: blur(25px);
  border-radius: 50%;
  transform: translateY(155px) rotateX(65deg);
}

.orbit {
  position: absolute;
  width: 420px;
  height: 420px;
  border: 1px solid rgba(255,255,255,.07);
  border-radius: 50%;
  pointer-events: none;
}

.orbit-one { transform: rotateX(68deg) rotateZ(15deg); }
.orbit-two { transform: rotateY(70deg) rotateZ(-15deg); border-style: dashed; opacity: .6; }

.drag-hint {
  position: absolute;
  bottom: 7%;
  color: #697386;
  font-size: 10px;
  letter-spacing: .13em;
  text-transform: uppercase;
}
.drag-hint span { color: var(--accent); font-size: 16px; vertical-align: -1px; margin-right: 5px; }

.controls {
  background: var(--panel);
  backdrop-filter: blur(18px);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px;
  box-shadow: 0 30px 70px rgba(0,0,0,.24);
}

.control-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 15px; }
.control-heading > span { font-size: 11px; letter-spacing: .2em; font-weight: 800; }
.control-heading small { font-size: 9px; color: #697386; }

.move-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.move-grid button {
  min-height: 68px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 5px;
  background: rgba(255,255,255,.035);
  border: 1px solid var(--line);
  border-radius: 11px;
  cursor: pointer;
  transition: .18s ease;
}
.move-grid button:hover:not(:disabled) { border-color: var(--accent); background: rgba(168,255,62,.08); transform: translateY(-2px); }
.move-grid button:active:not(:disabled) { transform: translateY(1px); }
.move-grid b { font: 800 17px/1 Consolas, monospace; }
.move-grid span { color: #727c8d; text-transform: uppercase; font-size: 8px; letter-spacing: .1em; }
button:disabled { opacity: .38; cursor: not-allowed; }

.action-row { display: grid; grid-template-columns: 1fr 44px 44px; gap: 8px; margin-top: 14px; }
.action-row button {
  height: 44px;
  border-radius: 10px;
  border: 1px solid var(--line);
  cursor: pointer;
}
.primary { background: var(--accent); color: #0a0d0b; border: none !important; text-transform: uppercase; letter-spacing: .13em; font-size: 10px; font-weight: 900; }
.primary:hover { filter: brightness(1.12); }
.icon-button { background: rgba(255,255,255,.04); font-size: 20px; }

.solve-button {
  width: 100%;
  min-height: 64px;
  margin-top: 10px;
  padding: 10px 14px;
  display: grid;
  grid-template-columns: 36px 1fr 20px;
  align-items: center;
  gap: 10px;
  text-align: left;
  color: #e9edf6;
  background: linear-gradient(110deg, rgba(52,120,246,.13), rgba(168,255,62,.1));
  border: 1px solid rgba(168,255,62,.28);
  border-radius: 11px;
  cursor: pointer;
  transition: .2s ease;
}
.solve-button:hover:not(:disabled) { border-color: var(--accent); transform: translateY(-2px); box-shadow: 0 9px 25px rgba(168,255,62,.08); }
.solve-button:disabled { filter: saturate(.4); }
.solve-button > span:nth-child(2) { display: grid; gap: 3px; }
.solve-button b { text-transform: uppercase; letter-spacing: .13em; font-size: 10px; }
.solve-button small { color: #758094; font-size: 9px; }
.solve-button > i { color: var(--accent); font-style: normal; font-size: 18px; }
.solve-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: #0b0e0d;
  background: var(--accent);
  border-radius: 9px;
  box-shadow: 0 0 20px rgba(168,255,62,.2);
}

.solver-progress {
  margin-top: 10px;
  padding: 14px;
  border-radius: 11px;
  background: rgba(7,10,15,.75);
  border: 1px solid rgba(168,255,62,.18);
}
.solver-progress[hidden] { display: none; }
.solver-topline { display: flex; justify-content: space-between; align-items: center; font-size: 8px; letter-spacing: .13em; color: var(--accent); }
.solver-topline strong { color: #8f99aa; font-weight: 500; letter-spacing: .06em; }
.solver-topline strong b { color: #fff; font: 700 13px Consolas, monospace; }
.progress-track { height: 3px; margin: 10px 0 12px; border-radius: 5px; background: #272d39; overflow: hidden; }
.progress-track i { display: block; width: 0; height: 100%; background: var(--accent); box-shadow: 0 0 8px var(--accent); transition: width .35s ease; }
.current-move { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 4px; }
.current-move > span { color: #626d7f; text-transform: uppercase; letter-spacing: .1em; font-size: 8px; }
.current-move > b { color: #fff; font: 800 17px Consolas, monospace; }
.current-move small { grid-column: 1 / -1; color: #626d7f; font: 9px Consolas, monospace; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tip { margin: 18px 0 0; color: #687284; font-size: 10px; line-height: 1.55; }
.tip > span { color: var(--accent); font-weight: 900; letter-spacing: .12em; margin-right: 7px; }
kbd { color: #c7cfda; background: #252a35; border: 1px solid #3a4150; border-radius: 3px; padding: 1px 4px; }

.game-panel[hidden] { display: none !important; }

.game-switch {
  position: fixed;
  z-index: 15;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(13, 16, 24, .8);
  backdrop-filter: blur(16px);
  box-shadow: 0 12px 35px rgba(0,0,0,.25);
}

.game-switch button {
  min-width: 108px;
  padding: 9px 15px;
  color: #717b8d;
  background: transparent;
  border: 0;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .13em;
  text-transform: uppercase;
  cursor: pointer;
}

.game-switch button span { margin-right: 7px; font-size: 8px; }
.game-switch button.active { color: #0a0d0b; background: var(--accent); }

.snake-layout {
  width: min(1560px, 92vw);
  min-height: 100vh;
  margin: auto;
  display: grid;
  grid-template-columns: minmax(320px, .8fr) minmax(500px, 1.35fr) minmax(290px, .72fr);
  align-items: center;
  gap: clamp(30px, 2.5vw, 52px);
  padding: 72px 0 46px;
}

.snake-intro { min-width: 0; max-width: 410px; }
.snake-intro h1 { font-size: clamp(48px, 4.2vw, 72px); }
.snake-intro h1 em { font-size: .86em; }
.snake-stats { max-width: 390px; gap: 28px; }

.snake-arena-wrap {
  width: min(64vh, 630px);
  aspect-ratio: 1;
  max-width: 100%;
  position: relative;
  justify-self: center;
  display: grid;
  place-items: center;
}

#snake-canvas {
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 2;
  border: 1px solid rgba(255,255,255,.13);
  border-radius: 18px;
  background: #0b0e15;
  box-shadow: inset 0 0 80px rgba(0,0,0,.5), 0 35px 80px rgba(0,0,0,.3);
}

.arena-glow {
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  background: rgba(52,120,246,.18);
  filter: blur(55px);
}

.snake-overlay {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  text-align: center;
  padding: 35px;
  border-radius: 18px;
  background: rgba(7,9,14,.78);
  backdrop-filter: blur(8px);
}

.snake-overlay[hidden] { display: none; }
.snake-overlay p { margin: 0 0 10px; color: var(--accent); font-size: 9px; font-weight: 900; letter-spacing: .2em; }
.snake-overlay h2 { margin: 0; font-size: clamp(30px, 3vw, 46px); letter-spacing: -.04em; }
.snake-overlay > span { margin-top: 10px; color: #7e889a; font-size: 12px; }
.snake-overlay button { margin-top: 25px; padding: 12px 22px; color: #090c0b; background: var(--accent); border: 0; border-radius: 9px; font-size: 10px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; cursor: pointer; }

.level-flash {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  place-items: center;
  align-content: center;
  pointer-events: none;
  border-radius: 18px;
  background: rgba(8,11,17,.72);
  backdrop-filter: blur(3px);
  animation: level-in .7s ease both;
}
.level-flash[hidden] { display: none; }
.level-flash span { color: var(--accent); font-size: 9px; font-weight: 900; letter-spacing: .2em; }
.level-flash b { margin-top: 8px; font-size: 42px; letter-spacing: -.04em; }
.level-flash i { color: var(--accent); font-style: normal; }
@keyframes level-in { from { opacity: 0; scale: .92; } 35% { opacity: 1; scale: 1.02; } }

.snake-controls {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: 0 30px 70px rgba(0,0,0,.24);
}

.danger-card {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(255,255,255,.025);
}
.danger-card > div:first-child { display: flex; justify-content: space-between; }
.danger-card span { color: #747e90; font-size: 9px; letter-spacing: .12em; text-transform: uppercase; }
.danger-card b { color: #fff; font-size: 10px; }
.danger-track { height: 4px; margin-top: 11px; overflow: hidden; border-radius: 4px; background: #272d39; }
.danger-track i { display: block; width: 8%; height: 100%; background: linear-gradient(90deg, var(--accent), #ffd600, #ff426d); transition: width .4s ease; }

.snake-rules { display: grid; gap: 10px; margin: 17px 0; }
.snake-rules > div { display: flex; align-items: center; gap: 10px; color: #737e90; font-size: 9px; }
.snake-rules b { color: #cbd2de; font-size: 8px; letter-spacing: .1em; }
.food-dot { width: 12px; height: 12px; flex: 0 0 auto; border-radius: 4px; }
.food-dot.normal { background: #ff426d; box-shadow: 0 0 10px rgba(255,66,109,.5); }
.food-dot.bonus { background: #ffd600; border-radius: 50%; box-shadow: 0 0 10px rgba(255,214,0,.5); }
.food-dot.wall { background: #3b4353; }

.snake-action-row { display: grid; grid-template-columns: 1fr 46px; gap: 8px; }
.snake-action-row button { height: 46px; border-radius: 10px; border: 1px solid var(--line); cursor: pointer; }

.dpad {
  width: 126px;
  margin: 18px auto 4px;
  display: grid;
  grid-template-columns: repeat(3, 38px);
  gap: 5px;
}
.dpad button {
  width: 38px;
  height: 38px;
  color: #aeb7c6;
  background: rgba(255,255,255,.04);
  border: 1px solid var(--line);
  border-radius: 9px;
  cursor: pointer;
}
.dpad button:first-child { grid-column: 2; }
.dpad button:nth-child(2) { grid-column: 1; grid-row: 2; }
.dpad button:nth-child(3) { grid-column: 2; grid-row: 2; }
.dpad button:nth-child(4) { grid-column: 3; grid-row: 2; }
.dpad button:active { color: #0a0d0b; background: var(--accent); }

.win-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4,6,10,.78);
  backdrop-filter: blur(12px);
  display: grid;
  place-items: center;
  z-index: 20;
  padding: 20px;
}

.win-overlay[hidden] { display: none; }

.win-card {
  text-align: center;
  width: min(420px, 100%);
  padding: 45px;
  border-radius: 24px;
  background: #151a24;
  border: 1px solid rgba(168,255,62,.3);
  box-shadow: 0 0 80px rgba(168,255,62,.12);
}
.confetti { color: var(--accent); letter-spacing: 14px; margin-bottom: 24px; }
.win-card p { color: var(--accent); letter-spacing: .2em; font-size: 10px; font-weight: 900; }
.win-card h2 { font-size: 40px; margin: 8px 0; }
.win-card > span { color: var(--muted); }
.win-card button { margin-top: 28px; border: 0; border-radius: 10px; background: var(--accent); color: #0a0d0b; font-weight: 900; padding: 13px 24px; cursor: pointer; }

@media (max-width: 1250px) {
  .game-layout { grid-template-columns: 1fr 1.5fr; }
  .controls { grid-column: 1 / -1; width: min(570px, 100%); justify-self: center; }
  .cube-zone { height: 540px; }
  .snake-layout { grid-template-columns: minmax(260px, .7fr) minmax(480px, 1.3fr); }
  .snake-controls { grid-column: 1 / -1; width: min(570px, 100%); justify-self: center; }
}

@media (max-width: 680px) {
  .game-layout { display: flex; flex-direction: column; padding: 42px 18px; width: 100%; }
  .intro { width: 100%; }
  h1 { font-size: clamp(48px, 14vw, 68px); }
  .lead { max-width: 100%; }
  .cube-zone { width: 100%; height: 430px; min-height: 430px; }
  .cube { scale: .82; }
  .orbit { width: 330px; height: 330px; }
  .cube-shadow { transform: translateY(130px) rotateX(65deg); }
  .drag-hint { bottom: 2%; }
  .controls { width: 100%; padding: 18px; }
  .control-heading small { display: none; }
  .game-switch { top: 10px; }
  .game-switch button { min-width: 95px; padding: 8px 11px; }
  .snake-layout { display: flex; flex-direction: column; width: 100%; padding: 82px 18px 42px; }
  .snake-intro, .snake-controls { width: 100%; max-width: none; }
  .snake-intro h1 { font-size: clamp(48px, 14vw, 68px); }
  .snake-arena-wrap { width: min(94vw, 600px); }
}

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