:root {
  color-scheme: light;
  --ink: #18212f;
  --muted: #667085;
  --line: #d8dee8;
  --panel: #ffffff;
  --page: #f5f7fa;
  --soft: #eef3f7;
  --field: #ffffff;
  --subtle: #f9fafb;
  --canvas: #fbfcfe;
  --chart-grid: #edf1f6;
  --chart-axis: #18212f;
  --chart-muted: #667085;
  --chart-point-stroke: #ffffff;
  --prompt-bg: #fff7e6;
  --topbar: rgba(255, 255, 255, 0.94);
  --subject: #007f7a;
  --subject-soft: #e5f5f3;
  --teal: #007f7a;
  --teal-dark: #005d59;
  --coral: #c44d35;
  --amber: #d88b00;
  --blue: #2f68b0;
  --violet: #6b5aa6;
  --good: #177245;
  --danger: #b42318;
  --shadow: 0 18px 44px rgba(24, 33, 47, 0.09);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #f3f7fb;
  --muted: #a9b6c7;
  --line: #2b3848;
  --panel: #111923;
  --page: #0b1118;
  --soft: #182331;
  --field: #0f1722;
  --subtle: #162130;
  --canvas: #0d1520;
  --chart-grid: #223044;
  --chart-axis: #d9e3ef;
  --chart-muted: #9fb0c4;
  --chart-point-stroke: #0b1118;
  --prompt-bg: #2a2112;
  --topbar: rgba(12, 18, 26, 0.94);
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.32);
}

body[data-subject="mathematics"] {
  --subject: #007f7a;
  --subject-soft: #e5f5f3;
}

body[data-subject="integrated-science"] {
  --subject: #177245;
  --subject-soft: #e8f6ee;
}

body[data-subject="social-studies"] {
  --subject: #b85712;
  --subject-soft: #fff0e3;
}

body[data-subject="english"] {
  --subject: #6b5aa6;
  --subject-soft: #f0edfb;
}

body[data-subject="computing"] {
  --subject: #2f68b0;
  --subject-soft: #e8f1fb;
}

body[data-subject="economics"] {
  --subject: #af2f5b;
  --subject-soft: #fde8f0;
}

:root[data-theme="dark"] body {
  --subject-soft: #182331;
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--page);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.topbar {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--topbar);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(12px);
}

.brand-block,
.session-strip,
.insight-header,
.stage-heading,
.activity-buttons,
.metric-grid,
.response-row,
.formula-row,
.range-row,
.join-line {
  display: flex;
  align-items: center;
}

.brand-block {
  gap: 12px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: var(--subject);
  color: #fff;
  border-radius: 8px;
  font-weight: 800;
}

.brand-name {
  font-weight: 800;
  letter-spacing: 0;
}

.brand-subtitle,
.eyebrow,
.tiny-note,
.response-meta,
.event-line {
  color: var(--muted);
}

.brand-subtitle {
  font-size: 0.85rem;
}

.session-strip {
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.code-pill,
.presence-pill,
.status-pill,
.theme-toggle {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: var(--field);
  font-weight: 750;
}

.code-pill {
  color: var(--subject);
}

.theme-toggle {
  color: var(--ink);
  cursor: pointer;
}

.app-layout {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr) minmax(290px, 360px);
  gap: 16px;
  padding: 16px;
  max-width: 1640px;
  margin: 0 auto;
}

.control-panel,
.stage-panel,
.insight-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.control-panel,
.insight-panel {
  align-self: start;
  min-height: calc(100vh - 106px);
  padding: 14px;
}

.stage-panel {
  min-height: calc(100vh - 106px);
  padding: 16px;
  overflow: hidden;
}

.role-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 4px;
  background: var(--soft);
  border-radius: 8px;
  margin-bottom: 14px;
}

.role-tab,
.activity-button,
.primary-button,
.ghost-button,
.small-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 38px;
  padding: 0 12px;
  font-weight: 760;
}

.role-tab,
.primary-button,
.ghost-button,
.small-button,
.theme-toggle,
.choice-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.button-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.role-tab {
  background: transparent;
  color: var(--muted);
}

.role-tab.is-active {
  background: var(--field);
  color: var(--ink);
  border-color: var(--line);
}

.form-block {
  display: grid;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  font-size: 0.82rem;
  font-weight: 780;
  color: var(--ink);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  padding: 9px 10px;
  outline: none;
}

.field textarea {
  min-height: 86px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--subject) 20%, transparent);
}

.primary-button {
  background: var(--subject);
  color: #fff;
  border-color: var(--subject);
}

.primary-button:hover {
  background: var(--teal-dark);
}

.ghost-button,
.small-button {
  background: var(--field);
  border-color: var(--line);
  color: var(--ink);
}

.ghost-button:hover,
.small-button:hover {
  border-color: #aeb8c7;
  background: var(--subtle);
}

.ghost-button.danger {
  color: var(--danger);
}

.stage-toolbar {
  margin-bottom: 14px;
  overflow-x: auto;
}

.activity-buttons {
  gap: 8px;
  min-width: max-content;
}

.activity-button {
  background: var(--subject-soft);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.activity-button.is-active {
  background: var(--subject);
  color: #fff;
}

.tab-icon {
  min-width: 32px;
  min-height: 24px;
  display: inline-grid;
  place-items: center;
  border-radius: 6px;
  background: color-mix(in srgb, var(--subject) 14%, var(--field));
  color: var(--subject);
  font-size: 0.72rem;
  font-weight: 900;
}

.activity-button.is-active .tab-icon {
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
}

.stage-heading {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.stage-heading h1,
.insight-header h2,
.panel-title {
  margin: 0;
  letter-spacing: 0;
}

.stage-heading h1 {
  font-size: clamp(1.35rem, 2vw, 2.2rem);
  line-height: 1.05;
}

.insight-header h2 {
  font-size: 1.1rem;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 0.72rem;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.prompt-band {
  border-left: 5px solid var(--amber);
  background: var(--prompt-bg);
  padding: 12px 14px;
  border-radius: 8px;
  font-weight: 720;
  margin-bottom: 14px;
}

.manipulative-shell {
  min-height: 560px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 14px;
}

.tool-grid {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(230px, 300px);
  gap: 14px;
  min-height: 520px;
}

.scenario-layout {
  display: grid;
  grid-template-columns: minmax(390px, 1fr) minmax(260px, 340px);
  gap: 14px;
  min-height: 520px;
}

.preview-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(260px, 0.9fr);
  gap: 14px;
}

.preview-main,
.preview-demo,
.preview-question {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  padding: 16px;
}

.preview-main {
  min-height: 250px;
  background: var(--canvas);
}

.preview-main h3,
.preview-demo h3,
.preview-question h3 {
  margin: 0 0 10px;
  font-size: clamp(1.1rem, 1.7vw, 1.55rem);
  line-height: 1.18;
}

.preview-main p,
.preview-demo p,
.preview-question p {
  color: var(--ink);
  line-height: 1.5;
}

.preview-tags,
.preview-token-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preview-tags span,
.preview-token-row span {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  padding: 6px 10px;
  font-weight: 760;
}

.preview-question {
  grid-column: 1 / -1;
}

.scenario-main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 12px;
}

.scenario-context,
.token-bank {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  padding: 14px;
}

.scenario-context h3 {
  margin: 0;
  font-size: clamp(1rem, 1.5vw, 1.35rem);
  line-height: 1.25;
}

.scenario-guidance {
  border: 1px solid color-mix(in srgb, var(--subject) 35%, var(--line));
  border-radius: 8px;
  background: color-mix(in srgb, var(--subject) 10%, var(--field));
  color: var(--ink);
  padding: 10px 12px;
  font-size: 0.9rem;
  font-weight: 700;
}

.drop-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.drop-zone {
  min-height: 190px;
  border: 1px dashed var(--chart-muted);
  border-radius: 8px;
  background: var(--canvas);
  padding: 12px;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.drop-zone.can-place {
  cursor: copy;
  border-color: color-mix(in srgb, var(--subject) 60%, var(--chart-muted));
}

.drop-zone:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--subject) 28%, transparent);
  outline-offset: 2px;
}

.drop-zone.is-hot {
  background: color-mix(in srgb, var(--subject) 14%, var(--canvas));
  border-color: var(--subject);
  transform: translateY(-2px);
}

.zone-hint {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 680;
}

.zone-tokens,
.token-bank {
  display: flex;
  align-content: flex-start;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 8px;
}

.zone-tokens {
  margin-top: 10px;
}

.evidence-token,
.choice-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  font-weight: 760;
}

.evidence-token {
  min-height: 36px;
  padding: 8px 10px;
  box-shadow: 0 8px 18px rgba(24, 33, 47, 0.08);
  touch-action: none;
  animation: tokenIn 180ms ease both;
}

.evidence-token.is-dragging {
  opacity: 0.86;
  box-shadow: 0 18px 36px rgba(0, 127, 122, 0.18);
}

.evidence-token.is-selected {
  border-color: var(--subject);
  background: color-mix(in srgb, var(--subject) 18%, var(--field));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--subject) 18%, transparent);
}

.choice-list {
  display: grid;
  gap: 8px;
}

.choice-button {
  min-height: 42px;
  padding: 9px 10px;
  text-align: left;
  justify-content: flex-start;
}

.choice-button.is-active {
  border-color: var(--violet);
  background: color-mix(in srgb, var(--violet) 18%, var(--field));
  color: var(--ink);
}

.quick-place {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.scenario-question {
  margin: 0;
  color: var(--ink);
  font-weight: 680;
  line-height: 1.45;
}

.scenario-feedback {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  line-height: 1.35;
}

.scenario-feedback span {
  color: var(--muted);
  font-size: 0.9rem;
}

.scenario-feedback.good {
  border-color: color-mix(in srgb, var(--good) 55%, var(--line));
  background: color-mix(in srgb, var(--good) 12%, var(--field));
}

.scenario-feedback.mixed {
  border-color: color-mix(in srgb, var(--amber) 65%, var(--line));
  background: color-mix(in srgb, var(--amber) 14%, var(--field));
}

.scenario-feedback.needs-work {
  border-color: color-mix(in srgb, var(--coral) 65%, var(--line));
  background: color-mix(in srgb, var(--coral) 12%, var(--field));
}

.scenario-feedback.neutral {
  background: var(--subtle);
}

@keyframes tokenIn {
  from {
    transform: translateY(4px) scale(0.98);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.canvas-wrap,
.workbench,
.response-list,
.student-list,
.event-list,
.summary-strip,
.analytics-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
}

.canvas-wrap {
  min-height: 360px;
  position: relative;
  overflow: hidden;
}

canvas.math-canvas {
  width: 100%;
  height: 100%;
  min-height: 360px;
  display: block;
  background: var(--canvas);
  touch-action: none;
}

.workbench {
  padding: 14px;
  display: grid;
  align-content: start;
  gap: 12px;
}

.panel-title {
  font-size: 1rem;
}

.range-row {
  gap: 10px;
}

.range-row input[type="range"] {
  min-width: 0;
  flex: 1;
  accent-color: var(--teal);
}

.readout {
  min-width: 72px;
  min-height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
  font-weight: 800;
}

.metric-grid {
  align-items: stretch;
  gap: 8px;
  flex-wrap: wrap;
}

.metric {
  flex: 1 1 95px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--subtle);
}

.metric-value {
  display: block;
  font-size: 1.25rem;
  font-weight: 850;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 720;
}

.formula-row {
  gap: 8px;
  justify-content: center;
  font-size: clamp(1.1rem, 2vw, 1.6rem);
  font-weight: 850;
  padding: 16px;
  background: var(--subtle);
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
  flex-wrap: wrap;
}

.balance-visual {
  min-height: 170px;
  display: grid;
  grid-template-columns: 1fr 80px 1fr;
  align-items: end;
  gap: 10px;
}

.pan {
  min-height: 70px;
  border-bottom: 8px solid var(--ink);
  display: grid;
  place-items: end center;
  padding: 8px;
  color: #fff;
  font-weight: 850;
}

.pan.left {
  background: var(--blue);
}

.pan.right {
  background: var(--coral);
}

.fulcrum {
  width: 0;
  height: 0;
  border-left: 40px solid transparent;
  border-right: 40px solid transparent;
  border-bottom: 90px solid #394150;
  justify-self: center;
}

.confidence-control {
  display: grid;
  gap: 8px;
}

.confidence-options {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.confidence-options button {
  min-height: 36px;
  border: 1px solid var(--line);
  background: var(--field);
  border-radius: 8px;
  font-weight: 800;
}

.confidence-options button.is-active {
  color: #fff;
  background: var(--violet);
  border-color: var(--violet);
}

.insight-header {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.insight-stack {
  display: grid;
  gap: 12px;
}

.summary-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  overflow: hidden;
}

.summary-strip .metric {
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
}

.summary-strip .metric:last-child {
  border-right: 0;
}

.analytics-card {
  padding: 10px;
}

.analytics-canvas {
  width: 100%;
  height: 168px;
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--canvas);
}

.analytics-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.student-list,
.response-list,
.event-list {
  display: grid;
  gap: 8px;
  padding: 10px;
  max-height: 260px;
  overflow: auto;
}

.response-row {
  align-items: flex-start;
  gap: 10px;
  padding: 10px;
  background: var(--subtle);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.avatar {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #dcefed;
  color: var(--teal-dark);
  font-weight: 850;
  flex: 0 0 auto;
}

.response-text {
  margin: 2px 0 0;
  word-break: break-word;
}

.response-detail {
  display: grid;
  gap: 4px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
}

.student-token {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  background: var(--subtle);
  border-radius: 8px;
  border: 1px solid var(--line);
}

.event-line {
  font-size: 0.82rem;
}

.empty-state {
  min-height: 120px;
  display: grid;
  place-items: center;
  text-align: center;
  border: 1px dashed #bac3d0;
  border-radius: 8px;
  color: var(--muted);
  padding: 16px;
}

.tiny-note {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.4;
}

.join-line {
  gap: 8px;
}

.join-line input {
  text-transform: uppercase;
}

.setting-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  min-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
  transition: opacity 160ms ease, transform 160ms ease;
  text-align: center;
  font-weight: 720;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 1380px) {
  .app-layout {
    grid-template-columns: 290px minmax(0, 1fr);
  }

  .insight-panel {
    grid-column: 1 / -1;
    min-height: auto;
  }
}

body.is-display .control-panel,
body.is-display #shareButton {
  display: none;
}

body.is-display .workbench {
  display: none;
}

body.is-display .tool-grid {
  grid-template-columns: 1fr;
}

body.is-display .app-layout {
  max-width: none;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
}

body.is-display .stage-panel,
body.is-display .insight-panel {
  min-height: calc(100vh - 106px);
}

body.is-display .insight-panel {
  grid-column: auto;
}

body.is-display .manipulative-shell {
  min-height: 620px;
}

@media (max-width: 900px) {
  body.is-display .app-layout {
    grid-template-columns: 1fr;
  }

  body.is-display .insight-panel {
    grid-column: auto;
    min-height: auto;
  }
}

@media (max-width: 900px) {
  .topbar {
    position: static;
    align-items: flex-start;
    flex-direction: column;
  }

  .session-strip {
    justify-content: flex-start;
  }

  .app-layout {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .control-panel,
  .stage-panel,
  .insight-panel {
    min-height: auto;
  }

  .tool-grid {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .scenario-layout,
  .preview-shell,
  .drop-grid {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  .preview-question {
    grid-column: auto;
  }

  .manipulative-shell {
    min-height: auto;
  }

  .canvas-wrap,
  canvas.math-canvas {
    min-height: 330px;
  }
}

@media (max-width: 560px) {
  .stage-heading,
  .brand-block {
    align-items: flex-start;
  }

  .stage-heading {
    flex-direction: column;
  }

  .setting-grid,
  .summary-strip {
    grid-template-columns: 1fr;
  }

  .summary-strip .metric {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .summary-strip .metric:last-child {
    border-bottom: 0;
  }
}
