:root {
  --bg: #120b2b;
  --panel: #1d1444;
  --text: #d9f7ff;
  --muted: #8bc3d9;
  --border: #46e4ff;
  --accent: #ff9f1c;
  --accent-strong: #ffd166;
  --good: #36ff8b;
  --bad: #ff5d8f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Courier New", "Lucida Console", monospace;
  background: linear-gradient(180deg, #100725 0%, #180f3a 55%, #0f0822 100%);
  color: var(--text);
  position: relative;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.035) 0px,
    rgba(255, 255, 255, 0.035) 1px,
    rgba(0, 0, 0, 0) 3px,
    rgba(0, 0, 0, 0) 4px
  );
  mix-blend-mode: screen;
  opacity: 0.25;
  z-index: 999;
}

body.snake-focus::after {
  content: "";
  position: fixed;
  inset: 0;
  background: rgba(4, 3, 12, 0.72);
  z-index: 1500;
}

.app {
  max-width: 1450px;
  margin: 0 auto;
  padding: 20px;
}

.app-header h1 {
  margin: 0;
  font-size: clamp(1.6rem, 2.8vw, 2.2rem);
}

.subtitle {
  margin-top: 8px;
  color: var(--muted);
}

.controls {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 2px;
  padding: 12px;
  box-shadow: 0 0 0 2px #2f1f69, 0 0 0 4px #46e4ff33;
}

.mode-menu {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 4px;
}

.mode-chip {
  background: #231a53;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 8px 10px;
  min-height: 36px;
}

.mode-chip.active {
  background: #ff9f1c;
  color: #1d1444;
  border-color: #ff9f1c;
}

.menu-empty {
  margin: 0;
  color: var(--muted);
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 700;
}

select,
button,
input {
  font-size: 1rem;
  padding: 10px 12px;
  border-radius: 2px;
  border: 1px solid var(--border);
}

button {
  background: var(--accent);
  color: #2a1130;
  border-color: var(--accent);
  cursor: pointer;
  min-height: 44px;
}

button:hover {
  background: var(--accent-strong);
}

.hidden {
  display: none;
}

#activitySection {
  margin-top: 18px;
  background: var(--panel);
  border: 2px solid var(--border);
  border-radius: 2px;
  padding: 14px;
  box-shadow: 0 0 0 2px #2f1f69, 0 0 0 4px #46e4ff33;
}

.board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.board > div {
  min-width: 0;
}

.board.timeline-layout {
  grid-template-columns: 1fr;
}

.board.term-match-layout {
  grid-template-columns: 1fr 1fr;
  align-items: start;
}

.board.problem-bridge-layout {
  grid-template-columns: 1fr;
}

.board.problem-bridge-layout > div:first-child {
  display: none;
}

.board.problem-bridge-layout > div:last-child {
  width: 100%;
}

.board.timeline-layout > div:first-child {
  order: 2;
}

.board.timeline-layout > div:last-child {
  order: 1;
}

.card-bank,
.timeline {
  min-height: 280px;
  max-height: 64vh;
  overflow: auto;
  border: 2px dashed var(--border);
  border-radius: 2px;
  padding: 10px;
  background: #141034;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.term-match-layout .card-bank {
  display: grid;
  grid-template-columns: repeat(2, minmax(210px, 1fr));
  gap: 12px;
  align-content: start;
}

.term-match-layout .timeline.term-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 12px;
  align-content: start;
}

.timeline.category-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  align-content: start;
}

.term-match-layout .term-row {
  min-height: 120px;
}

.timeline-track {
  background: linear-gradient(180deg, #1d1646 0%, #17103b 100%);
  display: block;
  overflow-x: auto;
  overflow-y: visible;
  max-height: none;
}

.board.timeline-layout .card-bank {
  display: grid;
  grid-template-columns: repeat(4, minmax(170px, 1fr));
  gap: 10px;
  align-content: start;
  max-height: 30vh;
}

.timeline-scale {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: #1f1850;
  min-width: 1360px;
  position: sticky;
  bottom: 0;
  z-index: 5;
}

.timeline-row {
  position: relative;
  display: block;
  min-width: 1360px;
  height: 520px;
  padding: 8px 0;
  overflow: hidden;
}

.timeline-row::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 30px;
  height: 4px;
  background: #46e4ff;
  border-radius: 999px;
}

.flow-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(220px, 1fr));
  gap: 14px;
  align-content: start;
}

.problem-bridge {
  display: grid;
  grid-template-columns: 1fr 1.75fr 1fr;
  gap: 12px;
  align-items: start;
}

.bridge-bank-wrap h4 {
  margin: 0 0 8px;
}

.bridge-bank {
  min-height: 220px;
  border: 1px dashed var(--border);
  padding: 8px;
  display: grid;
  gap: 8px;
  align-content: start;
}

.bridge-center {
  display: grid;
  gap: 10px;
  align-content: start;
}

.bridge-row {
  display: grid;
  grid-template-columns: 1fr 1.45fr 1fr;
  gap: 8px;
  align-items: stretch;
}

.bridge-problem {
  border: 1px solid var(--border);
  background: #231a53;
  padding: 10px;
  font-weight: 700;
  font-size: 1.06rem;
  line-height: 1.35;
  border-radius: 2px;
}

.bridge-slot {
  min-height: 90px;
}

.flow-slot {
  min-height: 170px;
  padding: 10px;
  position: relative;
}

.flow-slot::after {
  content: "->";
  position: absolute;
  right: -12px;
  top: 50%;
  transform: translateY(-50%);
  color: #ffd166;
  font-weight: 700;
}

.flow-slot:nth-child(3n)::after {
  content: "";
}

.timeline-tick {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 700;
}

.slot {
  min-height: 54px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: #231a53;
  padding: 4px;
}

.slot.filled {
  border-color: #ffd166;
}

.slot-label {
  font-size: 0.84rem;
  color: var(--muted);
  margin: 4px 8px;
}

.timeline-slot {
  position: relative;
  z-index: 1;
  width: 142px;
  min-height: 104px;
  padding: 10px;
  position: absolute;
}

.timeline-slot::before {
  content: "";
  position: absolute;
  left: 50%;
  width: 2px;
  background: #46e4ff;
  opacity: 0.55;
  transform: translateX(-50%);
}

.timeline-slot.lane-above::before {
  top: 100%;
  height: var(--stem, 44px);
}

.slot-definition {
  font-weight: 700;
  margin-bottom: 6px;
  color: #b7efff;
  font-size: 0.82rem;
  line-height: 1.2;
}

.slot-date {
  margin-top: 6px;
  font-size: 0.9rem;
  color: #7fe0ff;
  font-weight: 700;
}

.card {
  border: 1px solid #58d9ff;
  border-radius: 2px;
  background: #2d2166;
  padding: 10px;
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.card:active {
  cursor: grabbing;
}

.card.selected {
  outline: 3px solid #ffd166;
}

.card.correct {
  border-color: var(--good);
  background: #123e30;
}

.card.incorrect {
  border-color: var(--bad);
  background: #4a1c37;
}

.term-row {
  min-height: 74px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: #231a53;
  padding: 10px;
  display: grid;
  gap: 8px;
  align-items: center;
}

.term-name {
  font-weight: 700;
  font-size: 1.05rem;
}

.drop-label {
  font-size: 0.84rem;
  color: var(--muted);
}

.definition-bank .card,
.category-cards .card {
  background: #31246d;
}

.bucket {
  min-height: 140px;
  border: 2px dashed var(--border);
  border-radius: 2px;
  padding: 10px;
  background: #17103b;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.bucket h4 {
  margin: 0;
}

.bucket.correct {
  border-color: var(--good);
  background: #edf9f1;
}

.bucket.incorrect {
  border-color: var(--bad);
  background: #fff3f1;
}

.date {
  display: none;
  margin-top: 6px;
  font-weight: 700;
  color: #15364f;
}

.show-dates .date {
  display: block;
}

.actions {
  margin-top: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.score {
  margin: 0 0 0 auto;
  font-weight: 700;
}

.arcade {
  margin-top: 14px;
  border: 1px solid #46e4ff;
  border-radius: 2px;
  padding: 12px;
  background: #17103b;
}

.arcade-entry {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

#arcadePanel .arcade-entry {
  display: none;
}

#initialsInput {
  width: 90px;
  text-transform: uppercase;
  font-weight: 700;
}

.leaderboards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.snake-panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 560px);
  z-index: 2000;
  margin-top: 14px;
  border: 1px solid #46e4ff;
  border-radius: 2px;
  padding: 12px;
  background: #120d2f;
}

.score-popup {
  position: fixed;
  inset: 0;
  background: rgba(3, 2, 12, 0.78);
  display: grid;
  place-items: center;
  z-index: 2100;
}

.score-popup.hidden {
  display: none;
}

.score-popup-card {
  width: min(92vw, 720px);
  border: 1px solid #46e4ff;
  border-radius: 2px;
  background: #120d2f;
  padding: 14px;
}

.pixel-lincoln {
  width: 16px;
  height: 16px;
  margin-bottom: 8px;
  box-shadow:
    16px 0 #1a1328, 32px 0 #1a1328, 48px 0 #1a1328, 64px 0 #1a1328,
    0 16px #1a1328, 16px 16px #5b3a29, 32px 16px #5b3a29, 48px 16px #5b3a29, 64px 16px #1a1328,
    0 32px #1a1328, 16px 32px #d2a17b, 32px 32px #d2a17b, 48px 32px #d2a17b, 64px 32px #1a1328,
    0 48px #1a1328, 16px 48px #d2a17b, 32px 48px #120d2f, 48px 48px #d2a17b, 64px 48px #1a1328,
    0 64px #1a1328, 16px 64px #d2a17b, 32px 64px #d2a17b, 48px 64px #d2a17b, 64px 64px #1a1328,
    16px 80px #1a1328, 32px 80px #1a1328, 48px 80px #1a1328;
}

.snake-start {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.snake-lives {
  margin: 4px 0 6px;
  color: #ffd166;
  font-weight: 700;
  letter-spacing: 0.5px;
}

#snakeCanvas {
  display: block;
  margin-top: 8px;
  width: min(100%, 420px);
  height: auto;
  border: 2px solid #46e4ff;
  image-rendering: pixelated;
  background: #060611;
}

.leaderboards ol {
  margin: 0;
  padding-left: 22px;
}

.teacher-access {
  background: #eef4f8;
  color: #345;
  border-color: #c8d6e2;
  font-size: 0.85rem;
  padding: 6px 10px;
}

.teacher-controls {
  margin-top: 10px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

@media (max-width: 900px) {
  .controls {
    grid-template-columns: 1fr;
  }

  .mode-chip {
    width: 100%;
    text-align: left;
  }

  .board {
    grid-template-columns: 1fr;
  }

  .score {
    width: 100%;
    margin-left: 0;
  }

  .term-match-layout .timeline.term-grid {
    grid-template-columns: 1fr;
  }

  .timeline.category-grid {
    grid-template-columns: 1fr;
  }

  .timeline.category-grid .bucket {
    grid-column: span 1;
  }

  .term-match-layout .card-bank {
    grid-template-columns: 1fr;
  }

  .board.timeline-layout .card-bank {
    grid-template-columns: 1fr;
    max-height: 38vh;
  }

  .flow-grid {
    grid-template-columns: 1fr;
  }

  .problem-bridge {
    grid-template-columns: minmax(170px, 1fr) minmax(300px, 1.6fr) minmax(170px, 1fr);
    min-width: 760px;
  }

  .bridge-row {
    grid-template-columns: minmax(150px, 1fr) minmax(260px, 1.45fr) minmax(150px, 1fr);
  }

  .flow-slot::after {
    content: "v";
    right: 50%;
    top: auto;
    bottom: -12px;
    transform: translateX(50%);
  }

  .flow-slot:last-child::after {
    content: "";
  }
}
