:root {
  --bg: #f5f7f6;
  --surface: #ffffff;
  --ink: #1d2428;
  --muted: #607078;
  --rule: #d8e0dd;
  --primary: #0f766e;
  --primary-weak: #d9f0ec;
  --accent: #b45309;
  --accent-weak: #fff2d8;
  --success: #166534;
  --success-weak: #dcfce7;
  --error: #b42318;
  --error-weak: #fee4e2;
  --focus: #f59e0b;
  --shadow: 0 8px 28px rgba(29, 36, 40, 0.08);
  --radius: 8px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    linear-gradient(90deg, rgba(15, 118, 110, 0.08) 1px, transparent 1px),
    linear-gradient(180deg, rgba(15, 118, 110, 0.06) 1px, transparent 1px),
    var(--bg);
  background-size: 36px 36px;
}

a {
  color: inherit;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(245, 158, 11, 0.42);
  outline-offset: 3px;
}

.app-shell {
  width: min(1180px, calc(100% - 28px));
  margin: 0 auto;
  padding: 28px 0 52px;
}

.topline {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 310px;
  gap: 18px;
  align-items: start;
}

header,
.score-panel,
.term-band,
.section,
.answer-note {
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

header {
  padding: 24px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 0.9rem;
  font-weight: 800;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: clamp(1.6rem, 3vw, 2.55rem);
  line-height: 1.2;
  letter-spacing: 0;
  overflow-wrap: anywhere;
}

.lead {
  max-width: 780px;
  margin: 12px 0 0;
  color: var(--muted);
  line-height: 1.75;
}

.meta-row,
.subject-nav,
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.meta-row {
  margin-top: 16px;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--accent-weak);
  color: #673f0c;
  font-size: 0.86rem;
  font-weight: 800;
}

.subject-nav {
  margin-top: 18px;
}

.subject-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 7px 10px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 800;
  background: #fff;
}

.subject-nav a[aria-current="page"] {
  color: #07534f;
  border-color: var(--primary);
  background: var(--primary-weak);
}

.score-panel {
  position: sticky;
  top: 16px;
  padding: 18px;
}

.score-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.score-value {
  margin: 6px 0 12px;
  font-size: 2.3rem;
  font-weight: 900;
  line-height: 1.1;
}

.progress-track {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8efed;
}

.progress-fill {
  width: 0;
  height: 100%;
  background: var(--primary);
  transition: width 160ms ease;
}

.progress-text {
  margin: 10px 0 14px;
  color: var(--muted);
  font-size: 0.92rem;
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

button {
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

button.secondary {
  border-color: #bcd1cc;
  background: var(--primary-weak);
  color: #07534f;
}

.history-panel {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--rule);
}

.history-panel h2 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.history-list {
  display: grid;
  gap: 8px;
  max-height: 260px;
  overflow: auto;
}

.history-item {
  padding: 10px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: #fbfdfc;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.history-item strong {
  display: block;
  color: var(--ink);
}

.term-band {
  margin-top: 18px;
  padding: 18px;
}

.term-band h2,
.section-title h2 {
  margin: 0;
  font-size: 1.14rem;
}

.term-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.term {
  min-height: 88px;
  padding: 12px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: #fbfdfc;
  color: var(--muted);
  line-height: 1.6;
}

.term strong {
  display: block;
  margin-bottom: 4px;
  color: var(--ink);
}

.sample-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);
}

.sample-field {
  display: grid;
  gap: 5px;
}

.sample-field label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.sample-checkbox {
  align-self: center;
}

.sample-checkbox label {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  min-height: 42px;
  margin: 0;
  color: #07534f;
}

.sample-checkbox input {
  width: auto;
  min-height: 0;
  margin: 0;
  accent-color: var(--primary);
}

select {
  min-height: 42px;
  padding: 8px 36px 8px 10px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 800;
}

.sample-summary {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 800;
}

#quiz {
  display: grid;
  gap: 18px;
  margin-top: 18px;
}

.section {
  padding: 18px;
}

.section-title {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}

.section-title p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.question-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.question {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: #fff;
}

.question.correct {
  border-color: rgba(22, 101, 52, 0.45);
  background: var(--success-weak);
}

.question.incorrect {
  border-color: rgba(180, 35, 24, 0.45);
  background: var(--error-weak);
}

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

.q-number,
.points {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--primary-weak);
  color: #07534f;
  font-size: 0.82rem;
  font-weight: 900;
}

.points {
  background: #f3f6f5;
  color: var(--muted);
}

.points.important {
  background: var(--accent-weak);
  color: #673f0c;
}

.stem {
  margin: 0;
  line-height: 1.75;
  overflow-wrap: anywhere;
}

.answer-block {
  display: grid;
  gap: 7px;
  margin-top: 10px;
}

.answer-block label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

input,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 11px;
  border: 1px solid #cbd8d4;
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font: inherit;
  line-height: 1.5;
}

textarea {
  min-height: 88px;
  resize: vertical;
}

.status,
.correct-answer {
  min-height: 1.45em;
  margin: 0;
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1.55;
}

.status {
  color: var(--muted);
}

.status.ok {
  color: var(--success);
}

.status.ng {
  color: var(--error);
}

.correct-answer {
  padding: 7px 9px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.78);
  color: var(--ink);
}

.answer-note {
  margin-top: 18px;
  padding: 14px 16px;
  color: var(--muted);
  line-height: 1.7;
}

code {
  padding: 2px 4px;
  border-radius: 4px;
  background: #eef4f2;
  color: #07534f;
}

@media (max-width: 1000px) {
  .topline,
  .term-grid,
  .question-grid {
    grid-template-columns: 1fr;
  }

  .score-panel {
    position: static;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 16px;
  }

  header,
  .score-panel,
  .term-band,
  .section {
    padding: 14px;
  }

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

  .subject-nav a {
    flex: 1 1 42%;
    justify-content: center;
  }
}

@media print {
  body {
    background: #fff;
  }

  .app-shell {
    width: 100%;
    padding: 0;
  }

  .score-panel,
  .term-band,
  .answer-note,
  button,
  .subject-nav {
    display: none !important;
  }

  header,
  .section,
  .question {
    box-shadow: none;
  }

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