:root {
  --ink: #1f2a2e;
  --muted: #65737a;
  --line: #dce5e2;
  --paper: #f5f8f7;
  --panel: #ffffff;
  --accent: #0c7c78;
  --accent-2: #b77d24;
  --accent-soft: #e3f4ef;
  --accent-ink: #07524f;
  --danger: #b94d3a;
  --good: #2f7b4f;
  --shadow: 0 10px 28px rgba(32, 48, 52, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--accent) 14%, white), #eef5f2 380px, var(--paper) 381px),
    var(--paper);
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }

.app {
  display: block;
  min-height: 100vh;
}

aside {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(230px, auto) minmax(220px, 330px) minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  min-height: 88px;
  padding: 12px 22px;
  background: rgba(255, 255, 255, .96);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 10px 30px rgba(34, 51, 55, .07);
  backdrop-filter: blur(16px);
}

.brand {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 10px;
  align-items: center;
  padding: 8px;
}
.mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-weight: 900;
  letter-spacing: 0;
}
.brand h1 { margin: 0; font-size: 16px; line-height: 1.1; }
.brand p { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

.topic-picker {
  display: grid;
  gap: 6px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}
.topic-picker select {
  width: 100%;
  min-height: 44px;
  border: 2px solid var(--accent);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 8px 10px;
  text-transform: none;
  font-weight: 800;
}

nav {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 4px 0 6px;
  scrollbar-width: thin;
}
.tab {
  flex: 0 0 auto;
  display: inline-grid;
  grid-template-columns: 26px auto;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: #f8fbfa;
  color: var(--ink);
  padding: 6px 10px 6px 7px;
  text-align: left;
  white-space: nowrap;
}
.tab:hover { background: var(--accent-soft); }
.tab.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-ink);
  box-shadow: none;
  font-weight: 900;
}
.ico {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 900;
}

main {
  width: min(1480px, 100%);
  min-width: 0;
  margin: 0 auto;
  padding: 22px;
}
.hero {
  display: grid;
  grid-template-columns: minmax(0, .95fr) minmax(320px, 1.05fr);
  gap: 16px;
  align-items: stretch;
  margin: 8px 0 16px;
}
.hero-copy, .hero-visual {
  min-height: 230px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: rgba(255, 255, 255, .9);
  box-shadow: var(--shadow);
}
.hero-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px;
  border-left: 6px solid var(--accent);
}
.eyebrow {
  color: var(--accent);
  text-transform: uppercase;
  font-size: 12px;
  font-weight: 900;
}
.hero h2 {
  margin: 7px 0;
  max-width: 18ch;
  font-size: clamp(28px, 4vw, 50px);
  line-height: 1;
  letter-spacing: 0;
}
.hero p { margin: 6px 0; color: var(--muted); line-height: 1.55; max-width: 76ch; }
.hero-visual canvas { width: 100%; height: 100%; display: block; }

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, .86);
  box-shadow: var(--shadow);
}
.input, .select, textarea {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 9px 11px;
}
.input { flex: 1; min-width: min(100%, 320px); }
textarea { resize: vertical; width: 100%; }
.btn {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  padding: 9px 12px;
  font-weight: 850;
}
.btn.primary { color: #fff; background: var(--accent); border-color: var(--accent); }
.btn.danger { color: #fff; background: var(--danger); border-color: var(--danger); }
.btn.active, .practice-mode.active, .game-mode.active, .test-size.active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.icon-button { width: 42px; padding: 0; }

.panel { display: none; }
.panel.active { display: block; }
.school-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 16px;
}
.card {
  grid-column: span 4;
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.card.half { grid-column: span 6; }
.card.wide { grid-column: span 8; }
.card.full { grid-column: 1 / -1; }
.card h3 { margin: 0 0 10px; font-size: 18px; }
.card h4 { margin: 0 0 8px; font-size: 17px; }
.card p { color: var(--muted); line-height: 1.55; }
.empty { color: var(--muted); }

.pillrow, .score-row, .mode-menu, .prompt-grid {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  align-items: center;
}
.pill, .tag {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 850;
}
.tag { border-radius: 7px; background: #f0f4f2; color: var(--muted); }

.lesson-steps, .checklist {
  display: grid;
  gap: 9px;
}
.lesson-steps div, .checklist label {
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}
.lesson-steps b {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
}
.checklist input { width: 18px; height: 18px; accent-color: var(--accent); }

.term-cloud {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}
.mini-term {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  padding: 7px 10px;
  font-weight: 850;
}

.item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 11px 0;
  border-bottom: 1px solid #edf1ef;
}
.item:last-child { border-bottom: 0; }
.item strong { display: block; overflow-wrap: anywhere; }
.item small { display: block; margin-top: 4px; color: var(--muted); }

.download-note {
  margin: 0 0 10px;
  padding: 10px 12px;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent-ink) !important;
  font-size: 13px;
  font-weight: 750;
}
.resource-list { display: grid; gap: 7px; margin-top: 9px; }
.resource {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--paper);
}
.resource-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 13px;
  font-weight: 750;
}
.resource-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.resource-original {
  color: var(--accent-ink);
  font-size: 12px;
  font-weight: 850;
}
.classroom-link { text-decoration: none; }

.regents-downloads {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.regents-pack {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: linear-gradient(180deg, #fff, var(--accent-soft));
}
.regents-pack strong {
  display: block;
  font-size: 18px;
}
.regents-pack small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
}
.regents-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.regents-buttons .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}
.source-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.study-shell {
  min-height: 520px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}
.study-head {
  width: min(100%, 820px);
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}
.study-head h3 { margin: 0; }
.flashcard {
  width: min(100%, 760px);
  min-height: 300px;
  display: grid;
  place-items: center;
  gap: 10px;
  padding: 34px;
  border: 2px solid var(--accent);
  border-radius: 10px;
  background: linear-gradient(180deg, #fff, var(--accent-soft));
  color: var(--accent-ink);
  box-shadow: var(--shadow);
  text-align: center;
  transition: transform .25s ease, background .25s ease;
}
.flashcard:hover { transform: translateY(-3px); }
.flashcard.flipped { transform: rotateY(180deg); background: #fff; }
.flashcard.flipped span, .flashcard.flipped small { transform: rotateY(180deg); }
.flashcard span { font-size: clamp(28px, 5vw, 52px); font-weight: 900; }
.flashcard small { color: var(--muted); font-weight: 750; }
.flash-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

.question-list {
  display: grid;
  gap: 12px;
}
.question-card {
  display: grid;
  gap: 9px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}
.choice {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  padding: 9px 11px;
  text-align: left;
  font-weight: 750;
}
.choice:hover { border-color: var(--accent); }
.choice.correct { border-color: var(--good); background: #e7f4eb; color: #1f5d39; }
.choice.wrong { border-color: var(--danger); background: #fae8e4; color: #8d3428; }
.choice:disabled { cursor: default; }
.feedback {
  min-height: 22px;
  margin: 0;
  color: var(--accent-ink);
  font-weight: 750;
}
.response-box {
  min-height: 110px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
}
.cers-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
}
.cers-grid textarea { min-height: 120px; }
.reader {
  padding: 4px 2px;
  max-width: 980px;
}
.reader p {
  color: var(--ink);
  font-size: 17px;
  line-height: 1.75;
}
.evidence-box {
  display: grid;
  gap: 5px;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.match-board.simple {
  width: min(100%, 980px);
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 16px;
}
.match-board.simple > div { display: grid; gap: 10px; }
.match-node {
  min-height: 56px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  text-align: left;
  font-weight: 800;
}
.match-node.term { border-color: var(--accent); }
.match-node.definition { border-color: var(--accent-2); }
.match-node.selected { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.match-node.correct { background: #e7f4eb; border-color: var(--good); }
.match-node.wrong { background: #fae8e4; border-color: var(--danger); }

.sim-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(260px, .6fr);
  gap: 14px;
}
.sim-stage {
  min-height: 480px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #f8fbfa;
}
.sim-stage canvas { display: block; width: 100%; min-height: 480px; }
.sim-controls {
  display: grid;
  align-content: start;
  gap: 12px;
}
.sim-control {
  display: grid;
  gap: 8px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}
.sim-control label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.sim-control input[type="range"] { width: 100%; accent-color: var(--accent); }
.sim-explanation {
  padding: 12px;
  border-left: 4px solid var(--accent);
  border-radius: 7px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  line-height: 1.5;
  font-weight: 750;
}

.game-shell {
  display: grid;
  gap: 12px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, #fff, #f8fbfa);
}
.game-score {
  display: inline-flex;
  width: max-content;
  border-radius: 999px;
  padding: 7px 10px;
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 900;
}
.game-shell h4 {
  margin: 0;
  font-size: clamp(20px, 3vw, 34px);
  line-height: 1.15;
}
.tile, .quest-choice, .boss-choice {
  min-height: 52px;
  font-size: 16px;
}

.coach-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(280px, .7fr);
  gap: 14px;
}
.chat-log {
  min-height: 380px;
  max-height: 560px;
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
}
.message {
  max-width: 84%;
  margin: 8px 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  line-height: 1.5;
}
.message.user {
  margin-left: auto;
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.message.loading {
  display: flex;
  gap: 5px;
  width: max-content;
}
.message.loading span {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--accent);
  animation: loadingDot 1s infinite alternate;
}
.message.loading span:nth-child(2) { animation-delay: .2s; }
.message.loading span:nth-child(3) { animation-delay: .4s; }
@keyframes loadingDot { to { transform: translateY(-5px); opacity: .45; } }
.coach-entry {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-top: 10px;
}
.coach-entry textarea { min-height: 82px; }
.prompt-grid {
  align-items: stretch;
}
.prompt-grid .btn { flex: 1 1 190px; text-align: left; }

.download-toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  max-width: min(360px, calc(100vw - 28px));
  padding: 12px 14px;
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: #fff;
  color: var(--accent-ink);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 850;
}

@media (max-width: 980px) {
  aside {
    position: relative;
    grid-template-columns: 1fr;
    gap: 10px;
    border-bottom: 1px solid var(--line);
  }
  nav { overflow-x: auto; }
  .hero, .sim-layout, .coach-layout { grid-template-columns: 1fr; }
  .card, .card.half, .card.wide { grid-column: 1 / -1; }
  .regents-downloads { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  main { padding: 13px; }
  .hero h2 { font-size: 31px; }
  .resource, .item, .match-board.simple, .cers-grid, .coach-entry { grid-template-columns: 1fr; }
  .resource-actions { justify-content: flex-start; }
  .flashcard { min-height: 250px; padding: 22px; }
  .flash-actions .btn { width: 100%; }
  .study-head { align-items: flex-start; flex-direction: column; }
  .toolbar, .regents-buttons { grid-template-columns: 1fr; }
}
