:root {
  --bg-deep: #07110c;
  --bg-panel: rgba(9, 22, 16, 0.88);
  --bg-panel-soft: rgba(14, 31, 23, 0.78);
  --line: rgba(132, 255, 194, 0.2);
  --line-strong: rgba(132, 255, 194, 0.45);
  --text-main: #e8fff1;
  --text-soft: #b7d8c2;
  --accent: #6df9a2;
  --accent-strong: #c2ff6f;
  --danger: #ff6b7a;
  --danger-soft: rgba(255, 107, 122, 0.18);
  --success: #79ffb1;
  --success-soft: rgba(121, 255, 177, 0.18);
  --teacher-accent: #7fd0ff;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 10px;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(circle at top, rgba(67, 137, 89, 0.18), transparent 35%),
    linear-gradient(180deg, #06100b 0%, #040805 100%);
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

input,
select {
  width: 100%;
  border: 1px solid var(--line);
  background: rgba(5, 16, 11, 0.85);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
}

input:focus,
select:focus,
button:focus {
  outline: 2px solid var(--accent-strong);
  outline-offset: 2px;
}

code,
.seed-code,
#timer-display,
.fact-input,
.result-copy-row input {
  font-family: "Consolas", "Monaco", monospace;
}

.primary-button,
.secondary-button,
.icon-button {
  border: none;
  border-radius: 999px;
  padding: 0.85rem 1.35rem;
  transition: transform 120ms ease, box-shadow 120ms ease, opacity 120ms ease;
}

.primary-button:hover,
.secondary-button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

.primary-button {
  color: #06110a;
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  box-shadow: 0 10px 24px rgba(109, 249, 162, 0.25);
}

.secondary-button,
.icon-button {
  color: var(--text-main);
  background: rgba(16, 39, 28, 0.95);
  border: 1px solid var(--line);
}

.primary-button:disabled,
.secondary-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.card-panel {
  background: var(--bg-panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(10px);
}

.eyebrow {
  margin: 0 0 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.18em;
  color: var(--accent-strong);
  font-size: 0.72rem;
}

.lead {
  font-size: 1.05rem;
  line-height: 1.6;
  color: var(--text-soft);
}

.lead.compact {
  max-width: 58ch;
}

.hidden-grid {
  display: none !important;
}

.error-text {
  min-height: 1.35rem;
  margin: 0;
  color: #ffc3ca;
}

.field-hint,
.grid-note,
.entry-copy {
  margin: 0;
  color: var(--text-soft);
  font-size: 0.92rem;
  line-height: 1.5;
}

.subtle-link {
  color: var(--teacher-accent);
}

.landing-page,
.teacher-page,
.student-page {
  padding: 32px 20px 48px;
}

.landing-shell,
.teacher-shell,
.student-shell {
  width: min(1100px, 100%);
  margin: 0 auto;
  position: relative;
  z-index: 1;
}

.landing-shell {
  min-height: calc(100vh - 80px);
  display: grid;
  align-content: center;
  gap: 24px;
}

.landing-panel,
.teacher-header,
.student-entry-panel,
.grid-panel,
.results-panel,
.teacher-form {
  padding: 24px;
}

.hero-panel h1,
.teacher-header h1,
.student-entry-panel h1 {
  margin: 0 0 0.75rem;
  font-size: clamp(2rem, 4vw, 3.3rem);
  line-height: 1.05;
}

.landing-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
}

.mode-card {
  padding: 24px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  background: var(--bg-panel-soft);
  display: grid;
  gap: 10px;
  min-height: 190px;
  box-shadow: var(--shadow);
}

.mode-card strong {
  font-size: 1.4rem;
}

.mode-tag {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 999px;
  padding: 0.5rem 0.95rem;
  font-size: 0.76rem;
  line-height: 1;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: rgba(255, 255, 255, 0.08);
}

.teacher-card .mode-tag {
  color: var(--teacher-accent);
}

.student-card .mode-tag {
  color: var(--accent-strong);
}

.teacher-page {
  background:
    linear-gradient(180deg, rgba(8, 17, 29, 0.98), rgba(5, 10, 17, 1)),
    radial-gradient(circle at top right, rgba(80, 152, 255, 0.18), transparent 35%);
}

.teacher-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: flex-start;
  margin-bottom: 22px;
  border-color: rgba(127, 208, 255, 0.22);
}

.teacher-layout {
  display: grid;
  grid-template-columns: minmax(320px, 1.2fr) minmax(280px, 0.8fr);
  gap: 22px;
}

.teacher-form,
.results-panel {
  display: grid;
  gap: 18px;
}

.results-panel {
  align-self: start;
  align-content: start;
}

.flow-step {
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(127, 208, 255, 0.14);
  background: rgba(10, 20, 30, 0.34);
}

.step-label {
  margin: 0;
  color: var(--teacher-accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.form-block,
.result-block {
  display: grid;
  gap: 10px;
}

.form-row.three-col {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.label-text,
.result-label,
.timer-label {
  color: var(--text-soft);
  font-size: 0.88rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.form-actions,
.result-copy-row,
.action-row,
.grid-heading-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.result-copy-row {
  align-items: stretch;
}

.seed-code,
.readonly-input {
  min-height: 48px;
  display: flex;
  align-items: center;
  width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: rgba(5, 12, 19, 0.88);
  padding: 0.85rem 1rem;
  overflow-wrap: anywhere;
}

.seed-code.empty-state {
  color: #87a0aa;
}

.preview-summary {
  display: grid;
  gap: 6px;
  color: var(--text-soft);
}

.presentation-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(2, 6, 4, 0.72);
  backdrop-filter: blur(6px);
}

.teacher-page.presentation-open {
  overflow: hidden;
}

.presentation-card {
  width: min(760px, 100%);
  min-height: auto;
  max-height: calc(100vh - 48px);
  border-radius: 24px;
  border: 1px solid rgba(132, 255, 194, 0.24);
  background: rgba(7, 16, 11, 0.98);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
  display: grid;
  place-items: center;
  text-align: center;
  padding: 30px;
  gap: 18px;
  overflow: auto;
}

.presentation-label {
  margin: 0;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.86rem;
}

.presentation-code {
  display: block;
  font-size: clamp(2rem, 5vw, 5rem);
  letter-spacing: 0.08em;
  line-height: 1.1;
  color: var(--accent-strong);
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
  padding: 0.18em 0.25em;
  border-radius: 20px;
  background: rgba(11, 26, 18, 0.72);
  border: 1px solid rgba(132, 255, 194, 0.18);
}

.presentation-copy {
  margin: 0;
  max-width: 52ch;
  color: var(--text-soft);
  font-size: 1.05rem;
  line-height: 1.55;
}

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

.student-page.entry-mode {
  overflow: hidden;
}

.student-page.exercise-mode::before {
  content: "";
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
  z-index: 0;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='480' height='320' viewBox='0 0 480 320'%3E%3Cg fill='%236df9a2' fill-opacity='.09' font-family='monospace' font-size='18' letter-spacing='3'%3E%3Ctext x='10' y='28'%3E01 x 12 + 8 / 2 34 - 6 0101%3C/text%3E%3Ctext x='10' y='64'%3EGRID FACT MATRIX 9 + 6 8 x 4%3C/text%3E%3Ctext x='10' y='100'%3ELOCK SCORE TIMER 2 x 6 = 12%3C/text%3E%3Ctext x='10' y='136'%3EMATRIX GRID 11 22 33 44 55%3C/text%3E%3Ctext x='10' y='172'%3E5 + 6 = 11 3 x 4 = 12 18 / 3 = 6%3C/text%3E%3Ctext x='10' y='208'%3E7 x 7 = 49 15 - 6 = 9 24 / 6 = 4%3C/text%3E%3Ctext x='10' y='244'%3EFACT GRID 14 28 42 56 70 CHECK SCORE%3C/text%3E%3Ctext x='10' y='280'%3E8 + 3 = 11 4 x 6 = 24 READY START%3C/text%3E%3C/g%3E%3C/svg%3E");
  background-repeat: repeat;
  background-position: 0 0;
  background-size: 480px 320px;
  opacity: 0.65;
}

.student-page.exercise-mode {
  min-height: 100vh;
}

.matrix-rain {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  opacity: 0.9;
}

.student-page.exercise-mode .matrix-rain {
  display: none;
}

.student-page {
  background:
    linear-gradient(180deg, rgba(5, 13, 9, 0.98), rgba(4, 8, 6, 1)),
    repeating-linear-gradient(
      90deg,
      rgba(102, 255, 167, 0.07) 0,
      rgba(102, 255, 167, 0.07) 1px,
      transparent 1px,
      transparent 64px
    );
}

.student-shell {
  min-height: calc(100vh - 80px);
  display: grid;
  align-items: center;
}

.student-page.exercise-mode .student-shell {
  align-items: start;
  min-height: calc(100vh - 80px);
}

.student-entry-panel {
  width: min(640px, 100%);
  margin: 0 auto;
  background: rgba(7, 16, 11, 0.82);
  border-color: rgba(132, 255, 194, 0.28);
}

.seed-form,
.seed-input-row {
  display: grid;
  gap: 12px;
}

.seed-input-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.exercise-panel {
  display: grid;
  gap: 18px;
}

.exercise-top,
.grid-panel {
  border-color: rgba(132, 255, 194, 0.22);
}

.exercise-top {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) auto auto;
  align-items: center;
  gap: 18px;
  padding: 20px 28px;
}

.exercise-header {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.exercise-header h2,
.grid-panel h3 {
  margin: 0 0 0.5rem;
}

.exercise-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.exercise-meta-row .lead.compact {
  margin: 0;
  max-width: none;
  font-size: 0.98rem;
  line-height: 1.35;
}

.timer-wrap {
  min-width: 112px;
  text-align: right;
}

#timer-display {
  display: block;
  margin-top: 0.2rem;
  font-size: clamp(1.8rem, 3.4vw, 2.5rem);
  color: var(--accent-strong);
}

.results-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0;
}

.summary-stat {
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: rgba(11, 26, 18, 0.74);
  display: grid;
  gap: 8px;
}

.summary-stat strong {
  font-size: 1.7rem;
}

.status-strip {
  color: var(--text-soft);
  font-size: 0.95rem;
  line-height: 1.35;
}

.exercise-actions {
  display: flex;
  justify-content: flex-end;
}

.exercise-actions .action-row {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.completion-pill {
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--accent-strong);
  font-size: 0.84rem;
}

.grid-panel {
  display: grid;
  gap: 18px;
}

.grid-heading-row {
  justify-content: space-between;
}

.grid-container {
  overflow-x: auto;
}

.fact-grid {
  display: grid;
  grid-template-columns: repeat(var(--matrix-columns, 5), minmax(140px, 1fr));
  gap: 10px;
  align-items: stretch;
}

.fact-cell {
  min-height: 132px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
}

.fact-cell {
  background: rgba(8, 19, 13, 0.9);
  padding: 12px;
  display: grid;
  gap: 10px;
  align-content: center;
}

.fact-prompt {
  text-align: center;
  color: var(--text-soft);
  font-size: 1rem;
  line-height: 1.4;
}

.fact-input {
  text-align: center;
  font-size: 1.4rem;
  min-height: 52px;
  appearance: textfield;
}

.fact-input::-webkit-outer-spin-button,
.fact-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.answer-reveal {
  text-align: center;
  font-weight: 700;
  color: var(--text-main);
}

.fact-cell.is-correct {
  border-color: rgba(121, 255, 177, 0.6);
  background: var(--success-soft);
}

.fact-cell.is-wrong {
  border-color: rgba(255, 107, 122, 0.66);
  background: var(--danger-soft);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (max-width: 860px) {
  .teacher-layout,
  .teacher-header {
    grid-template-columns: 1fr;
    display: grid;
  }

  .exercise-top {
    grid-template-columns: 1fr;
    align-items: start;
  }

  .exercise-actions {
    justify-content: start;
  }

  .exercise-actions .action-row {
    justify-content: start;
  }

  .timer-wrap {
    text-align: left;
  }

  .form-row.three-col,
  .seed-input-row,
  .form-actions,
  .result-copy-row,
  .action-row,
  .grid-heading-row {
    grid-template-columns: 1fr;
    display: grid;
  }

  .grid-corner,
  .fact-cell {
    min-height: 74px;
  }

  .results-summary {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  body {
    padding-inline: 14px;
  }

  .exercise-top {
    padding: 18px 18px 20px;
  }

  .landing-panel,
  .teacher-header,
  .student-entry-panel,
  .exercise-header,
  .exercise-actions,
  .grid-panel,
  .results-panel,
  .teacher-form {
    padding: 18px;
  }

  .fact-grid {
    gap: 8px;
  }

  .fact-input {
    font-size: 1.15rem;
  }

  .presentation-overlay {
    padding: 14px;
  }

  .presentation-card {
    width: 100%;
    max-height: calc(100vh - 28px);
    padding: 18px;
    gap: 14px;
  }

  .presentation-code {
    font-size: clamp(1.5rem, 8vw, 2.4rem);
    letter-spacing: 0.04em;
  }
}
