:root {
  color-scheme: light;
  --bg: #f4f7f1;
  --surface: #ffffff;
  --ink: #17221c;
  --muted: #5e6c62;
  --line: #d7dfd3;
  --water: #86c5c8;
  --native: #2f7d4e;
  --invasive: #b64135;
  --plant: #78a743;
  --accent: #206a75;
  --warning: #bd6b19;
  --shadow: 0 18px 50px rgba(39, 61, 43, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(233, 243, 235, 0.95), rgba(244, 247, 241, 1)),
    radial-gradient(circle at 20% 20%, rgba(134, 197, 200, 0.28), transparent 36%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.intro-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 36, 29, 0.48);
  backdrop-filter: blur(8px);
}

.intro-overlay[hidden] {
  display: none;
}

.intro-card {
  width: min(460px, 100%);
  display: grid;
  gap: 12px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.intro-card h2 {
  margin-bottom: 0;
  font-size: 1.8rem;
  line-height: 1.05;
}

.intro-card p:not(.eyebrow) {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.intro-label {
  display: block;
  margin: 4px 0 -6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

#studentNameInput {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  color: var(--ink);
  background: #fbfdf9;
}

.resume-block {
  display: grid;
  gap: 8px;
  margin-top: 6px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.resume-row,
.save-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

#resumeCodeInput,
#saveCodeInput {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  color: var(--ink);
  background: #fbfdf9;
  font-weight: 850;
}

.student-name {
  margin: 8px 0 0;
  color: var(--muted);
  font-weight: 800;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: #f8faf7;
  cursor: pointer;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

button:hover {
  transform: translateY(-1px);
  border-color: #9fb2a2;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(32, 106, 117, 0.28);
  outline-offset: 2px;
}

.app-shell {
  width: min(1500px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 22px 0 28px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: end;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 3vw, 3rem);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 10px;
  font-size: 1rem;
  letter-spacing: 0;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(90px, 1fr));
  gap: 8px;
  width: min(480px, 100%);
}

.status-strip > div,
.metric-grid > div,
.chart-card,
.insight-box,
.prompt-box,
.role-list,
.controls-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.status-strip > div {
  padding: 10px 12px;
}

.status-label,
.metric-grid span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.status-strip strong,
.metric-grid strong {
  display: block;
  margin-top: 2px;
  font-size: 1.35rem;
}

.workspace {
  display: grid;
  grid-template-columns: 300px minmax(420px, 1fr) 340px;
  gap: 16px;
  align-items: start;
}

.controls-panel,
.data-panel {
  display: grid;
  gap: 14px;
}

.controls-panel {
  padding: 14px;
}

.save-panel {
  display: grid;
  gap: 9px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdf9;
}

.save-panel .primary-button {
  width: 100%;
  font-weight: 850;
}

.save-code-label {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.save-actions button {
  width: 100%;
  padding: 0 10px;
  font-size: 0.86rem;
  font-weight: 800;
}

.save-feedback {
  min-height: 20px;
  margin: 0;
  padding: 4px 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 750;
  line-height: 1.35;
}

.save-feedback.good {
  color: #234f35;
}

.save-feedback.error {
  color: var(--invasive);
}

.control-actions,
.scenario-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.control-actions button,
.scenario-button {
  padding: 0 10px;
  font-size: 0.9rem;
  font-weight: 750;
}

.primary-button,
.scenario-button.active {
  color: #ffffff;
  border-color: var(--accent);
  background: var(--accent);
}

.introduce-button {
  width: 100%;
  color: #ffffff;
  border-color: var(--invasive);
  background: var(--invasive);
  font-weight: 850;
}

.introduce-button:disabled {
  color: #456052;
  border-color: #b8c8bd;
  background: #dce7df;
  cursor: default;
  transform: none;
}

.invasion-note {
  margin: -4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.invasion-note strong {
  color: var(--ink);
}

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

fieldset {
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdf9;
}

legend {
  padding: 0 6px;
  font-size: 0.86rem;
  font-weight: 850;
}

label {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px 12px;
  align-items: center;
  margin-top: 13px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

output {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  grid-column: 1 / -1;
  width: 100%;
  accent-color: var(--accent);
}

select {
  grid-column: 1 / -1;
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  color: var(--ink);
  background: #ffffff;
  font-weight: 750;
}

.sim-panel {
  min-width: 0;
  display: grid;
  gap: 16px;
}

.canvas-wrap {
  position: relative;
  overflow: hidden;
  border: 1px solid #b8cfc4;
  border-radius: 8px;
  background: linear-gradient(180deg, #bfe5dd, #85c2c8 42%, #5e9aa4);
  box-shadow: var(--shadow);
}

canvas {
  display: block;
  width: 100%;
  height: auto;
}

#ecosystemCanvas {
  aspect-ratio: 980 / 620;
}

.question-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.93);
  box-shadow: var(--shadow);
  padding: 16px 18px 18px;
}

.question-panel h2 {
  margin-bottom: 0;
  font-size: 1.08rem;
}

.question-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
}

.question-header span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
  white-space: nowrap;
}

.question-card {
  display: grid;
  gap: 10px;
}

.question-task,
.question-prompt,
.answer-feedback {
  margin: 0;
  line-height: 1.42;
}

.question-task {
  color: var(--muted);
  font-weight: 800;
}

.question-prompt {
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 850;
}

.answer-label {
  display: block;
  margin: 2px 0 -4px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 96px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 12px;
  color: var(--ink);
  background: #fbfdf9;
  font: inherit;
  line-height: 1.4;
}

textarea:focus-visible {
  outline: 3px solid rgba(32, 106, 117, 0.28);
  outline-offset: 2px;
}

.question-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.question-actions button {
  padding: 0 16px;
  font-weight: 800;
}

.question-actions button:disabled {
  color: #78867c;
  cursor: default;
  background: #edf2ed;
  transform: none;
}

.answer-feedback {
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--muted);
  background: #f8faf7;
}

.answer-feedback.good {
  color: #234f35;
  border-color: #b9d4c1;
  background: #eef8ef;
}

.answer-feedback.revise {
  color: #6d4317;
  border-color: #e2c393;
  background: #fff7e8;
}

.completion-panel {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid #b9d4c1;
  border-radius: 8px;
  background: #eef8ef;
}

.completion-panel[hidden] {
  display: none;
}

.completion-panel h3 {
  margin: 0;
  font-size: 1.35rem;
}

.completion-results {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.completion-results div {
  padding: 10px;
  border: 1px solid #c8decf;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.68);
}

.completion-results span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.completion-results strong {
  display: block;
  margin-top: 2px;
  font-size: 1.2rem;
}

.legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: calc(100% - 24px);
  padding: 9px 10px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 7px;
  color: #183027;
  background: rgba(247, 252, 247, 0.86);
  backdrop-filter: blur(8px);
  font-size: 0.82rem;
  font-weight: 800;
}

.legend span,
.mini-legend {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.legend i,
.mini-legend i {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 999px;
}

.native-dot {
  background: var(--native);
}

.producer-dot {
  background: var(--plant);
}

.predator-dot {
  background: var(--accent);
}

.decomposer-dot {
  background: #7d5a2f;
}

.invasive-dot {
  background: var(--invasive);
}

.plant-dot {
  background: var(--plant);
}

.data-panel {
  min-width: 0;
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric-grid > div {
  padding: 12px;
}

.role-list {
  display: grid;
  gap: 8px;
  padding: 14px;
}

.role-list h2 {
  margin-bottom: 2px;
}

.role-list > div {
  display: grid;
  grid-template-columns: 14px 1fr;
  gap: 1px 8px;
  align-items: center;
}

.role-list i {
  grid-row: span 2;
  width: 12px;
  height: 12px;
  border-radius: 999px;
}

.role-list strong {
  font-size: 0.9rem;
}

.role-list span {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.25;
}

.chart-card,
.insight-box,
.prompt-box {
  padding: 14px;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
}

.chart-header h2 {
  margin: 0;
}

.mini-legend {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.producer-line,
.native-line,
.predator-line,
.invasive-line {
  height: 4px !important;
  width: 18px !important;
  border-radius: 4px !important;
}

.producer-line {
  background: var(--plant);
}

.native-line {
  background: var(--native);
}

.predator-line {
  background: var(--accent);
}

.invasive-line {
  background: var(--invasive);
}

#chartCanvas {
  margin-top: 10px;
  border-radius: 6px;
  background: #f8fbf6;
}

.insight-box p,
.prompt-box p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.prompt-box {
  border-color: #d7c29e;
  background: #fffaf0;
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 290px 1fr;
  }

  .data-panel {
    grid-column: 1 / -1;
    grid-template-columns: 1fr 1fr;
  }

  .role-list {
    grid-column: 1 / -1;
  }

  .metric-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 20px, 680px);
    padding-top: 14px;
  }

  .topbar,
  .workspace,
  .data-panel {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
    align-items: start;
  }

  .status-strip,
  .metric-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 500px) {
  .control-actions,
  .status-strip,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .chart-header {
    display: grid;
  }

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