:root {
  --cols: 10;
  --rows: 16;
  --cell: 32px;
  --gap: 2px;

  --blue: #5aa0ff;
  --orange: #ff9b50;
  --green: #26d07c;
  --red: #ff5d4a;
  --yellow: #ffd700;

  --ink: #e6ecff;
  --ink-dim: #aeb9d9;
  --bg: #1a2845;
  --panel: #0f172a;
  --tile: #111827;
  --tile-border: #243047;
  --grid: #1f2a44;
}

html, body {
  height: 100%;
  background: linear-gradient(180deg, #1a2845 0%, #0d1220 100%);
  color: var(--ink);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  margin: 0;
  overflow: hidden;
}

.game-container {
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(8px, 2vh, 16px) clamp(8px, 2vw, 16px);
  gap: clamp(12px, 2vh, 20px);
  box-sizing: border-box;
}

/* Level icons at top */
.level-icons {
  display: flex;
  gap: clamp(8px, 2vw, 16px);
  justify-content: center;
  flex-shrink: 0;
  padding: 8px;
}

.level-icon {
  appearance: none;
  background: #1a2742;
  border: 2px solid #2d4366;
  border-radius: 8px;
  width: clamp(48px, 12vw, 64px);
  height: clamp(48px, 12vw, 64px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  font-size: clamp(18px, 4.5vw, 24px);
  font-weight: 700;
  color: var(--ink);
  position: relative;
}

.level-icon::before {
  content: '';
  position: absolute;
  inset: 6px;
  border: 2px solid currentColor;
  border-radius: 4px;
  opacity: 0.4;
}

.level-icon:hover {
  background: #243555;
  border-color: #4a7fc4;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.level-icon.active {
  background: #2a4166;
  border: 3px solid #4a7fc4;
  color: #7eb3ff;
  box-shadow: 0 0 20px rgba(74, 127, 196, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
}

.level-icon.active::before {
  opacity: 0.8;
  border-color: #4a7fc4;
}

/* Star level button */
.level-icon.star {
  font-size: clamp(28px, 7vw, 36px);
  background: linear-gradient(135deg, #1a2742 0%, #2a3555 100%);
}

.level-icon.star::before {
  border-radius: 6px;
}

.level-icon.star.active {
  background: linear-gradient(135deg, #2a4166 0%, #3a5188 100%);
  border-color: #ffd700;
  box-shadow: 0 0 20px rgba(255, 215, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
}

.level-icon.star.active::before {
  border-color: #ffd700;
}

/* Board wrapper with progress on edge */
.board-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.progress-indicator {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #0d1a2e;
  border: 2px solid #4a7fc4;
  border-radius: 20px;
  padding: clamp(4px, 1vh, 6px) clamp(12px, 3vw, 18px);
  font-weight: 700;
  font-size: clamp(11px, 2.5vw, 14px);
  color: #7eb3ff;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Board with blue border */
.board {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--cell));
  grid-template-rows: repeat(var(--rows), var(--cell));
  gap: var(--gap);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  background: #0d1a2e;
  border: 3px solid #4a7fc4;
  border-radius: 16px;
  padding: clamp(4px, 1vh, 8px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3), inset 0 1px 3px rgba(74, 127, 196, 0.2);
  --stride: calc(var(--cell) + var(--gap));
}

.board::before {
  content: "";
  position: absolute;
  inset: clamp(4px, 1vh, 8px);
  background: radial-gradient(circle at 50% 50%, rgba(94, 156, 255, 0.08) 0%, transparent 70%);
  pointer-events: none;
  border-radius: 12px;
  z-index: 0;
}

/* Cells */
.cell {
  position: relative;
  width: var(--cell);
  height: var(--cell);
  background: #2a3f5c;
  border: 2px solid #4a6b8f;
  border-radius: clamp(4px, 1vw, 6px);
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  transition: transform 0.06s ease, box-shadow 0.06s ease;
  z-index: 1;
}

.cell.filled {
  border-color: #b7c3da;
}

.cell.disabled {
  background: transparent !important;
  border-color: transparent !important;
  opacity: 1 !important;
  pointer-events: none;
  filter: none !important;
}

@media (hover: hover) {
  .cell:not(.disabled):hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45), 0 0 0 2px rgba(255, 255, 255, 0.08) inset;
  }
}

.cell:active {
  transform: translateY(1px);
}

.cell .marker {
  position: absolute;
  inset: 2px;
  border-radius: 4px;
  opacity: 0.95;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.06), inset 0 -6px 10px rgba(0, 0, 0, 0.18);
}

.blue .marker {
  background: var(--blue);
  border: 2px solid color-mix(in srgb, var(--blue) 78%, black);
}

.orange .marker {
  background: var(--orange);
  border: 2px solid color-mix(in srgb, var(--orange) 74%, black);
}

.green .marker {
  background: var(--green);
  border: 2px solid color-mix(in srgb, var(--green) 70%, black);
}

.red .marker {
  background: var(--red);
  border: 2px solid color-mix(in srgb, var(--red) 70%, black);
}

/* Blue2 blocks */
.blue2 .marker {
  background: var(--blue);
  border: 2px solid color-mix(in srgb, var(--blue) 78%, black);
}

/* Blue2 symbol for origin blocks */
.blue2-symbol {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(18px, 4vw, 24px);
  font-weight: 900;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7);
  z-index: 25;
  pointer-events: none;
}

/* Phi blocks - yellow/gold */
.phi .marker {
  background: var(--yellow);
  border: 2px solid #daa520;
}

/* Phi symbol on endpoint cells */
.phi-symbol {
  position: absolute;
  font-size: clamp(16px, 3.5vw, 22px);
  font-weight: 900;
  color: rgba(0, 0, 0, 0.7);
  pointer-events: none;
  z-index: 25;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-shadow: 0 1px 3px rgba(255, 255, 255, 0.4);
}

/* Green step endpoints */
.green.child .marker::after {
  content: "";
  position: absolute;
  inset: 28%;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.3);
  border: 2px solid rgba(0, 0, 0, 0.4);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.2) inset;
}

/* Orange glue drop */
.orange.filled .marker::before {
  content: "";
  position: absolute;
  width: 24%;
  height: 24%;
  top: 15%;
  left: 15%;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0.15));
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  z-index: 1;
}

/* Direction arrows */
.arrow {
  position: absolute;
  width: 70%;
  height: 70%;
  z-index: 2;
}

.arrow svg {
  width: 100%;
  height: 100%;
  fill: #ffffff;
  stroke: rgba(0, 0, 0, 0.7);
  stroke-width: 2.2px;
  paint-order: stroke;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.35));
  opacity: 0.98;
}

/* Grouped cells (hide marker when overlaid) */
.cell.grouped .marker {
  opacity: 0;
}

/* Orange band overlays */
.group.orange-band {
  position: absolute;
  z-index: 5;
  height: calc(var(--cell) - 6px);
  border: 2px solid var(--orange);
  background: color-mix(in srgb, var(--orange) 22%, white);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35), 0 0 0 2px color-mix(in srgb, var(--orange) 30%, transparent) inset;
  border-radius: 12px;
  pointer-events: none;
  transform-origin: center center;
  opacity: 0.95;
}

.group.orange-band.ticked::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.8;
  background: repeating-linear-gradient(90deg, transparent 0 calc(var(--seg) - 1px), rgba(0, 0, 0, 0.4) calc(var(--seg) - 1px) var(--seg));
  background-size: var(--seg) 100%;
}

.group.orange-arrow {
  position: absolute;
  z-index: 6;
  width: calc(var(--cell) * 0.9);
  height: calc(var(--cell) * 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.group.orange-arrow svg {
  width: 100%;
  height: 100%;
  fill: #fff;
  stroke: rgba(0, 0, 0, 0.75);
  stroke-width: 2.6px;
  paint-order: stroke;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.35));
  opacity: 0.98;
}

.group.orange-glue {
  position: absolute;
  z-index: 5;
  width: calc(var(--cell) * 0.46);
  height: calc(var(--cell) * 0.46);
  background: color-mix(in srgb, var(--orange) 76%, white);
  border: 2px solid color-mix(in srgb, var(--orange) 68%, black);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--orange) 22%, transparent) inset, 0 4px 10px rgba(0, 0, 0, 0.35);
  border-radius: 58% 58% 70% 58%;
  transform: rotate(45deg);
  pointer-events: none;
  opacity: 0.95;
}

.group.orange-glue::after {
  content: "";
  position: absolute;
  width: 40%;
  height: 40%;
  top: 10%;
  left: 14%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.28);
  filter: blur(1px);
}

/* Blue2 band and glue overlays */
.group.blue2-band {
  position: absolute;
  pointer-events: none;
  z-index: 5;
  background: var(--blue);
  border: 2px solid color-mix(in srgb, var(--blue) 85%, black);
  box-shadow: 
    inset 0 1px 2px rgba(255, 255, 255, 0.2),
    inset 0 -2px 4px rgba(0, 0, 0, 0.15),
    0 2px 6px rgba(0, 0, 0, 0.25);
  border-radius: 6px;
  opacity: 1;
}

.group.blue2-glue {
  position: absolute;
  pointer-events: none;
  z-index: 5;
  background: var(--blue);
  border: 2px solid color-mix(in srgb, var(--blue) 75%, black);
  border-radius: 50%;
  box-shadow: 
    0 3px 8px rgba(0, 0, 0, 0.4),
    inset 0 0 0 2px rgba(255, 255, 255, 0.15),
    0 0 0 1px rgba(90, 160, 255, 0.3);
  opacity: 0.98;
}

/* Confetti */
.confetti {
  position: absolute;
  width: 8px;
  height: 8px;
  background: #26d07c;
  border-radius: 50%;
  pointer-events: none;
  z-index: 100;
  box-shadow: 0 0 4px rgba(38, 208, 124, 0.6);
}

/* GO button and bottom bar */
.bottom-bar {
  width: 100%;
  max-width: 600px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 3vw, 20px);
  flex-shrink: 0;
}

.go-btn {
  appearance: none;
  cursor: pointer;
  font-weight: 800;
  letter-spacing: 0.8px;
  font-size: clamp(18px, 4.5vw, 28px);
  padding: clamp(10px, 2vh, 14px) clamp(40px, 10vw, 60px);
  border-radius: 12px;
  border: none;
  color: #0d1220;
  background: linear-gradient(180deg, #32e590 0%, #26d07c 100%);
  box-shadow: 0 6px 20px rgba(38, 208, 124, 0.3), inset 0 2px 0 rgba(255, 255, 255, 0.3), inset 0 -2px 0 rgba(0, 0, 0, 0.2);
  transition: transform 0.1s ease;
  flex: 1;
  max-width: 300px;
}

.go-btn:active {
  transform: translateY(1px);
}

.control-btn {
  appearance: none;
  background: #1a2742;
  border: 2px solid #2d4366;
  border-radius: 12px;
  width: clamp(42px, 10vw, 52px);
  height: clamp(42px, 10vw, 52px);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--ink);
  transition: all 0.2s ease;
  padding: 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
}

.control-btn:hover {
  background: #243555;
  border-color: #4a7fc4;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.control-btn:active {
  transform: translateY(0);
}

.block-counter {
  appearance: none;
  background: #1a2742;
  border: 2px solid #2d4366;
  border-radius: 12px;
  width: clamp(42px, 10vw, 52px);
  height: clamp(42px, 10vw, 52px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #7eb3ff;
  font-weight: 800;
  font-size: clamp(18px, 5vw, 24px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
  transition: all 0.2s ease;
}

@keyframes flashOrange {
  0%, 100% { 
    background: #1a2742;
    border-color: #2d4366;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  }
  50% { 
    background: rgba(255, 155, 80, 0.5);
    border-color: #ff9b50;
    box-shadow: 0 0 25px rgba(255, 155, 80, 0.6), 0 0 10px rgba(255, 155, 80, 0.4) inset;
    transform: scale(1.1);
  }
}

.block-counter.limit-reached {
  animation: flashOrange 0.6s ease 2;
}

/* Flash animations */
@keyframes flashRedCell {
  0% { 
    background: inherit;
    box-shadow: 0 0 0 0 rgba(230, 75, 58, 0) inset; 
  }
  30% { 
    background: rgba(230, 75, 58, 0.85) !important;
    box-shadow: 0 0 0 8px rgba(230, 75, 58, 0.9) inset; 
  }
  100% { 
    background: inherit;
    box-shadow: 0 0 0 0 rgba(230, 75, 58, 0) inset; 
  }
}

.cell.flash-red {
  animation: flashRedCell 0.65s ease;
}

@keyframes flashGreenCell {
  0% { 
    background: inherit;
    box-shadow: 0 0 0 0 rgba(38, 208, 124, 0) inset, 0 0 0 0 rgba(38, 208, 124, 0); 
  }
  30% { 
    background: rgba(38, 208, 124, 0.95) !important;
    box-shadow: 0 0 0 6px rgba(38, 208, 124, 0.9) inset, 0 0 0 2px rgba(38, 208, 124, 0.5); 
  }
  100% { 
    background: inherit;
    box-shadow: 0 0 0 0 rgba(38, 208, 124, 0) inset, 0 0 0 0 rgba(38, 208, 124, 0); 
  }
}

.cell.flash-green {
  animation: flashGreenCell 0.7s ease;
}

@keyframes flashEdgeGreen {
  0% { border-color: #4a7fc4; }
  30% { border-color: #26d07c; box-shadow: 0 8px 32px rgba(38, 208, 124, 0.6), inset 0 0 0 3px rgba(38, 208, 124, 0.4); }
  100% { border-color: #4a7fc4; }
}

.board.flash-edge-green {
  animation: flashEdgeGreen 0.8s ease;
}

@keyframes flashEdge {
  0% { border-color: #4a7fc4; }
  30% { border-color: #ff5d4a; box-shadow: 0 0 0 3px rgba(255, 93, 74, 0.5) inset; }
  100% { border-color: #4a7fc4; }
}

.board.flash-edge {
  animation: flashEdge 0.7s ease;
}

.cell.ghost-bad::after {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 4px;
  background: rgba(230, 75, 58, 0.14);
  border: 2px dashed rgba(230, 75, 58, 0.55);
  pointer-events: none;
}

/* Compass */
.compass {
  position: fixed;
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(3, 44px);
  gap: 6px;
  background: #0f172a;
  border: 1px solid #2a3557;
  border-radius: 12px;
  padding: 8px;
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  z-index: 1000;
}

.compass .seg {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0e1530;
  border: 1px solid #2a3557;
  border-radius: 8px;
  cursor: pointer;
  user-select: none;
}

.compass .seg.active {
  outline: 2px solid var(--green);
  outline-offset: -2px;
}

.compass .seg svg {
  width: 22px;
  height: 22px;
  fill: #fff;
  stroke: rgba(0, 0, 0, 0.65);
  stroke-width: 2.2px;
  paint-order: stroke;
}

/* Scrim */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  z-index: 999;
}

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  top: clamp(60px, 15vh, 100px);
  background: #0f172a;
  border: 2px solid #4a7fc4;
  color: var(--ink);
  padding: 10px 20px;
  border-radius: 12px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  font-weight: 700;
  letter-spacing: 0.3px;
  z-index: 1200;
  font-size: clamp(14px, 3.5vw, 16px);
}