:root {
  --bg: #0a0a1f;
  --bg-2: #15153d;
  --ink: #f4f4ff;
  --muted: #9a9ac8;
  --pink: #ff2e88;
  --cyan: #00e5ff;
  --yellow: #ffd400;
  --green: #39ff14;
  --red: #ff4545;
  --font: "Press Start 2P", ui-monospace, monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
}

body {
  min-height: 100vh;
  background: radial-gradient(ellipse at top, #1d1d55 0%, var(--bg) 65%);
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 12px;
  line-height: 1.9;
}

/* CRT scanlines over everything */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    transparent 0 2px,
    rgba(0, 0, 0, 0.22) 2px 3px
  );
  z-index: 1000;
}

a {
  color: var(--cyan);
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* Layout */

.screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 32px 16px 48px;
}

.screen.center {
  min-height: 100vh;
  justify-content: center;
  text-align: center;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 4px solid var(--pink);
  background: rgba(0, 0, 0, 0.45);
}

.topbar .brand {
  color: var(--yellow);
  text-decoration: none;
  text-shadow: 2px 2px 0 #000;
}

.topbar nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* The student's points total, in the top bar and the question box. */
.points-badge {
  display: inline-flex;
  align-items: center;
  padding: 8px 10px;
  border: 2px solid var(--yellow);
  color: var(--yellow);
  font-size: 9px;
  white-space: nowrap;
}

.points-badge[hidden],
.question-points[hidden] {
  display: none;
}

.points-badge.bump,
.question-points.bump {
  animation: points-bump 0.6s ease-out;
}

@keyframes points-bump {
  30% {
    transform: scale(1.25);
    color: var(--green);
  }
}

/* Type */

.title {
  margin: 0;
  color: var(--pink);
  font-size: clamp(28px, 9vw, 60px);
  line-height: 1.25;
  text-shadow: 4px 4px 0 var(--cyan), 8px 8px 0 #000;
}

.heading {
  margin: 0;
  color: var(--yellow);
  font-size: clamp(16px, 4.5vw, 24px);
  text-shadow: 3px 3px 0 #000;
  text-align: center;
}

.subtitle {
  margin: 0;
  color: var(--yellow);
}

.note {
  color: var(--muted);
  font-size: 10px;
}

.fine {
  max-width: 40em;
  margin: 0;
  color: var(--muted);
  font-size: 9px;
}

.blink {
  animation: blink 1.1s steps(1) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* Panels and buttons */

.panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  width: min(100%, 440px);
  padding: 24px 16px;
  border: 4px solid var(--cyan);
  background: var(--bg-2);
  box-shadow: 6px 6px 0 #000;
}

.panel p {
  margin: 0;
}

.btn {
  font-family: var(--font);
  font-size: 12px;
  line-height: 1.4;
  color: var(--bg);
  background: var(--yellow);
  border: none;
  padding: 12px 16px;
  cursor: pointer;
  text-decoration: none;
  text-transform: uppercase;
  box-shadow:
    inset -4px -4px 0 rgba(0, 0, 0, 0.35),
    inset 4px 4px 0 rgba(255, 255, 255, 0.45),
    4px 4px 0 #000;
}

.btn:hover {
  filter: brightness(1.1);
}

.btn:active {
  transform: translate(2px, 2px);
  box-shadow: inset 4px 4px 0 rgba(0, 0, 0, 0.35), 2px 2px 0 #000;
}

.btn:disabled {
  cursor: not-allowed;
  filter: grayscale(1) brightness(0.7);
}

.btn:focus-visible,
.cell:focus-visible,
.game-card:focus-visible,
input:focus-visible {
  outline: 3px dashed var(--green);
  outline-offset: 3px;
}

.btn.small {
  font-size: 9px;
  padding: 8px 10px;
}

.btn.ghost {
  background: transparent;
  color: var(--cyan);
  box-shadow: inset 0 0 0 3px var(--cyan);
}

.btn.danger {
  background: var(--red);
  color: var(--ink);
}

.btn.alt {
  background: var(--cyan);
}

/* Arcade menu */

.games {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 24px;
  width: min(100%, 960px);
}

.game-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px 16px;
  border: 4px solid var(--cyan);
  background: var(--bg-2);
  box-shadow: 6px 6px 0 #000;
  color: inherit;
  text-align: center;
  text-decoration: none;
  transition: transform 80ms steps(2);
}

.game-card:hover {
  border-color: var(--yellow);
  transform: translate(-3px, -3px);
  box-shadow: 9px 9px 0 #000;
}

.game-card h2 {
  margin: 0;
  color: var(--yellow);
  font-size: 14px;
}

.game-card p {
  margin: 0;
  color: var(--muted);
  font-size: 9px;
}

.game-card.locked {
  border-style: dashed;
  border-color: var(--muted);
  opacity: 0.55;
}

.game-card.locked:hover {
  transform: none;
  box-shadow: 6px 6px 0 #000;
}

.mystery {
  font-size: 40px;
  color: var(--muted);
}

/* Tic-tac-toe */

.scores {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
}

.score {
  min-width: 96px;
  padding: 8px 12px;
  border: 3px solid currentColor;
  background: rgba(0, 0, 0, 0.4);
  text-align: center;
  font-size: 10px;
}

.score strong {
  display: block;
  font-size: 18px;
}

.score.you {
  color: var(--pink);
}

.score.draw {
  color: var(--muted);
}

.score.cpu {
  color: var(--cyan);
}

.status {
  min-height: 2em;
  margin: 0;
  color: var(--green);
  text-align: center;
  text-shadow: 2px 2px 0 #000;
}

.board {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  width: min(100%, 360px);
  aspect-ratio: 1;
  padding: 8px;
  background: var(--cyan);
  box-shadow: 6px 6px 0 #000;
}

.cell {
  display: grid;
  place-items: center;
  border: none;
  background: var(--bg-2);
  color: var(--ink);
  font-family: var(--font);
  font-size: clamp(30px, 12vw, 60px);
  cursor: pointer;
}

.cell:disabled {
  cursor: default;
}

.cell:empty:enabled:hover::after {
  content: "X";
  color: var(--pink);
  opacity: 0.3;
}

.cell.x {
  color: var(--pink);
  text-shadow: 4px 4px 0 #000;
}

.cell.o {
  color: var(--cyan);
  text-shadow: 4px 4px 0 #000;
}

.cell.win {
  background: var(--yellow);
  animation: flash 0.5s steps(1) 4;
}

@keyframes flash {
  50% {
    background: var(--bg-2);
  }
}

/* Question modal */

dialog.question {
  width: min(calc(100vw - 32px), 440px);
  padding: 24px 20px;
  border: 4px solid var(--yellow);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  box-shadow: 8px 8px 0 #000;
  text-align: center;
}

dialog.question::backdrop {
  background: rgba(5, 5, 20, 0.82);
}

.question form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.question p {
  margin: 0;
}

.question-label {
  color: var(--pink);
  font-size: 10px;
}

.question-points {
  color: var(--yellow);
  font-size: 9px;
}

.question-prompt {
  color: var(--ink);
  font-size: clamp(14px, 4.5vw, 18px);
  line-height: 1.8;
}

.question input,
.teacher input {
  width: 100%;
  padding: 12px;
  border: 4px solid var(--green);
  background: #000;
  color: var(--green);
  font-family: var(--font);
}

.question input {
  font-size: 20px;
  text-align: center;
}

.feedback {
  min-height: 1.9em;
  font-size: 11px;
}

.feedback.good {
  color: var(--green);
}

.feedback.bad {
  color: var(--red);
}

/* Teacher */

.teacher {
  width: min(100%, 960px);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.teacher .panel {
  width: 100%;
  align-items: stretch;
}

.teacher h2 {
  margin: 0;
  color: var(--yellow);
  font-size: 13px;
}

.teacher label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 9px;
}

.teacher input {
  font-size: 11px;
  padding: 10px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
}

.toolbar label {
  width: 110px;
}

.toolbar label.wide {
  width: min(100%, 360px);
}

.teacher select {
  width: 100%;
  padding: 10px;
  border: 4px solid var(--green);
  background: #000;
  color: var(--green);
  font-family: var(--font);
  font-size: 10px;
}

.warning {
  padding: 12px;
  border: 3px dashed var(--yellow);
  color: var(--yellow);
  font-size: 9px;
}

.q-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.q-row {
  display: grid;
  grid-template-columns: 32px 1fr 140px auto;
  align-items: end;
  gap: 12px;
  padding: 12px;
  border: 3px solid var(--bg);
  background: rgba(0, 0, 0, 0.3);
}

.q-row.invalid {
  border-color: var(--red);
}

.q-num {
  padding-bottom: 10px;
  color: var(--pink);
}

@media (max-width: 640px) {
  .q-row {
    grid-template-columns: 1fr;
  }

  .q-num {
    padding-bottom: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .blink,
  .points-badge.bump,
  .question-points.bump,
  .cell.win {
    animation: none;
  }

  .game-card {
    transition: none;
  }
}

/* Deus Draconis */

.game-canvas {
  display: block;
  width: min(100%, 720px);
  aspect-ratio: 4 / 3;
  border: 4px solid var(--cyan);
  box-shadow: 6px 6px 0 #000;
  image-rendering: pixelated;
  touch-action: none;
  cursor: crosshair;
}

/* Pages that opt out of the scanline overlay, so it doesn't stripe the game. */
body.no-scanlines::after {
  display: none;
}

.game-frame {
  width: min(100%, 720px);
}

/* Fullscreen: black surround, canvas scaled as large as fits at 4:3. */
.game-frame:fullscreen {
  display: grid;
  place-items: center;
  background: #000;
}

.game-frame:fullscreen .game-canvas {
  width: min(100vw, calc(100vh * 4 / 3));
  border: 0;
  box-shadow: none;
}

.controls {
  width: min(100%, 720px);
  margin: 0;
  color: var(--muted);
  font-size: 9px;
}

.controls strong {
  color: var(--yellow);
}

.card-shot {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border: 3px solid #000;
  background: #000;
}

/* A "NEW!" sticker slapped on the top-right corner of a card's picture. */
.card-shot-wrap {
  position: relative;
  width: 100%;
}

.card-sticker {
  position: absolute;
  top: -10px;
  right: -10px;
  padding: 7px 8px;
  border: 3px solid #000;
  background: var(--yellow);
  box-shadow: 3px 3px 0 #000;
  color: #000;
  font-size: 10px;
  transform: rotate(12deg);
  pointer-events: none;
}

/* Widescreen canvas (Astro Stomp). */
.game-canvas.wide {
  width: min(100%, 960px);
  aspect-ratio: 16 / 9;
  cursor: default;
}

.game-frame.wide {
  width: min(100%, 960px);
}

/* Fullscreen Astro Stomp: as large as fits at 16:9. */
.game-frame.wide:fullscreen .game-canvas {
  width: min(100vw, calc(100vh * 16 / 9));
}

.controls.wide {
  width: min(100%, 960px);
}

/* Login form */

.login label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  color: var(--muted);
  font-size: 9px;
  text-align: left;
}

.login input {
  width: 100%;
  padding: 12px;
  border: 4px solid var(--green);
  background: #000;
  color: var(--green);
  font-family: var(--font);
  font-size: 14px;
}

.login input:focus-visible {
  outline: 3px dashed var(--green);
  outline-offset: 3px;
}

/* Teacher dashboard tables */

.table-wrap {
  overflow-x: auto;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 9px;
  line-height: 1.6;
}

table.data th,
table.data td {
  padding: 8px;
  border-bottom: 2px solid var(--bg);
  text-align: left;
  vertical-align: top;
}

table.data th {
  color: var(--cyan);
  font-weight: normal;
}

table.data tbody tr:hover {
  background: rgba(0, 0, 0, 0.3);
}

table.data .good {
  color: var(--green);
}

table.data .bad {
  color: var(--red);
}

.link-btn {
  padding: 0;
  border: none;
  background: none;
  color: var(--yellow);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/* Printable login cards (Print login cards on the teacher page) */

.print-cards {
  display: none;
}

@media print {
  body > *,
  body::after {
    display: none !important;
  }

  body {
    background: #fff;
    color: #000;
  }

  .print-cards {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
  }

  .login-card {
    padding: 12px;
    border: 2px dashed #000;
    font-size: 10px;
    break-inside: avoid;
  }

  .login-card p {
    margin: 0 0 6px;
  }
}

/* Geometry figures in the question box */

dialog.question.has-figure {
  width: min(calc(100vw - 32px), 560px);
}

.question-figure:empty {
  display: none;
}

.figure {
  display: block;
  width: 100%;
  height: auto;
  background: #000;
  border: 3px solid var(--bg-2);
}

.fig-shape {
  fill: rgba(0, 229, 255, 0.08);
  stroke: var(--ink);
  stroke-width: 2.5;
  stroke-linejoin: round;
}

.fig-marks {
  stroke: var(--pink);
  stroke-width: 2.5;
  stroke-linecap: round;
}

.fig-labels {
  fill: var(--yellow);
  font-family: var(--font);
  font-size: 13px;
  text-anchor: middle;
  dominant-baseline: central;
}

.fig-lines {
  fill: none;
  stroke: var(--ink);
  stroke-width: 2.5;
  stroke-linecap: round;
}

.fig-arrow {
  fill: none;
  stroke-linejoin: round;
}

.fig-dots {
  fill: var(--ink);
}

/* Measurements: a system font, since the pixel font has no ° or ℓ. */
.fig-values {
  fill: var(--pink);
  font-family: system-ui, "Segoe UI", sans-serif;
  font-size: 15px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
}

.has-figure .question-prompt {
  font-size: clamp(10px, 3vw, 13px);
}

/* Segment names, e.g. segment AB, drawn with a bar over the letters. */
.segment {
  text-decoration: overline;
  text-decoration-thickness: 2px;
}

.q-row .figure {
  grid-column: 1 / -1;
  max-width: 360px;
}

.math-symbol {
  font-family: "Segoe UI Symbol", "Apple Symbols", "DejaVu Sans", sans-serif;
  font-size: 1.5em;
  line-height: 1;
  vertical-align: -0.1em;
}

/* Feedback form (arcade page) and Feedback panel (teacher page) */

.fb-cta {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 10px;
  text-align: center;
}

.fb-cta p {
  margin: 0;
}

dialog.fb-dialog {
  width: min(calc(100vw - 32px), 480px);
  padding: 24px 20px;
  border: 4px solid var(--cyan);
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  box-shadow: 8px 8px 0 #000;
}

dialog.fb-dialog::backdrop {
  background: rgba(5, 5, 20, 0.82);
}

.fb-dialog form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.fb-dialog h2 {
  margin: 0;
  color: var(--yellow);
  font-size: 14px;
  text-align: center;
}

.fb-dialog p {
  margin: 0;
}

.fb-dialog label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 9px;
}

.fb-dialog select,
.fb-dialog input,
.fb-dialog textarea {
  width: 100%;
  padding: 10px;
  border: 4px solid var(--green);
  background: #000;
  color: var(--green);
  font-family: var(--font);
  font-size: 10px;
  line-height: 1.7;
}

.fb-dialog textarea {
  resize: vertical;
}

.fb-dialog select:focus-visible,
.fb-dialog input:focus-visible,
.fb-dialog textarea:focus-visible {
  outline: 3px dashed var(--green);
  outline-offset: 3px;
}

.fb-count {
  align-self: flex-end;
}

.fb-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
}

.fb-toolbar label {
  width: 150px;
}

.fb-message {
  max-width: 36em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.fb-asked {
  margin-bottom: 6px;
  color: var(--cyan);
  overflow-wrap: anywhere;
}

table.data .fb-new {
  color: var(--yellow);
}

/* Teacher dashboard: larger type for readability. */

.teacher-page .teacher h2 {
  font-size: 18px;
}

.teacher-page .note {
  font-size: 13px;
  line-height: 1.7;
}

.teacher-page .teacher label {
  font-size: 12px;
}

.teacher-page .teacher input,
.teacher-page .teacher select {
  font-size: 14px;
}

.teacher-page .btn {
  font-size: 14px;
}

.teacher-page .btn.small {
  font-size: 12px;
}

.teacher-page table.data {
  font-size: 12px;
  line-height: 1.7;
}

.teacher-page table.data th,
.teacher-page table.data td {
  padding: 10px;
}

.teacher-page .toolbar label:not(.wide) {
  width: 150px;
}

.teacher-page .fb-toolbar label {
  width: 180px;
}

/* Click-to-sort headings on the teacher dashboard tables */

.sort-btn {
  padding: 0;
  border: none;
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.sort-btn:hover,
.sort-btn:focus-visible {
  color: var(--yellow);
  text-decoration: underline;
}

th[aria-sort] .sort-btn {
  color: var(--yellow);
}

th[aria-sort="ascending"] .sort-btn::after {
  content: " \25B2";
}

th[aria-sort="descending"] .sort-btn::after {
  content: " \25BC";
}
