:root {
  --ink: #14233a;
  --ink-soft: #3a4a63;
  --muted: #5c6b82;
  --line: #d5dde8;
  --paper: #f4f7fb;
  --panel: #ffffff;
  --accent: #0e7c6b;
  --accent-deep: #0a5c50;
  --accent-soft: #d8f0eb;
  --warn: #b45309;
  --warn-soft: #fff1df;
  --good: #157a3a;
  --good-soft: #e4f6ea;
  --bad: #b42318;
  --bad-soft: #fde8e6;
  --partial: #9a6700;
  --partial-soft: #fff6d8;
  --shadow: 0 18px 50px rgba(20, 35, 58, 0.08);
  --radius: 18px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "Source Sans 3", "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: var(--font-body);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(14, 124, 107, 0.16), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(20, 35, 58, 0.08), transparent 50%),
    linear-gradient(180deg, #eef3f8 0%, var(--paper) 40%, #e8eef5 100%);
}

a {
  color: var(--accent-deep);
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.4rem;
  background: rgba(244, 247, 251, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(213, 221, 232, 0.9);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: inherit;
}

.brand-mark {
  width: 2.5rem;
  height: 2.5rem;
  display: grid;
  place-items: center;
  border-radius: 0.85rem;
  background: linear-gradient(145deg, var(--accent), #146b8a);
  color: white;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.02em;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand-text strong {
  font-family: var(--font-display);
  font-size: 1.05rem;
}

.brand-text em {
  font-style: normal;
  color: var(--muted);
  font-size: 0.82rem;
}

.topnav {
  display: flex;
  gap: 0.35rem;
}

.topnav a {
  text-decoration: none;
  color: var(--ink-soft);
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.92rem;
}

.topnav a:hover,
.topnav a.active {
  background: var(--accent-soft);
  color: var(--accent-deep);
}

#main {
  flex: 1;
  width: min(1120px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 1.75rem 0 3rem;
}

.site-footer {
  padding: 1.25rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.hero {
  display: grid;
  gap: 1rem;
  margin-bottom: 1.75rem;
  animation: rise 0.55s ease both;
}

.hero h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2.1rem, 4vw, 3.1rem);
  letter-spacing: -0.03em;
  line-height: 1.08;
}

.hero p {
  margin: 0;
  max-width: 40rem;
  color: var(--ink-soft);
  font-size: 1.08rem;
  line-height: 1.55;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.35rem;
}

.exam-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.exam-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.2rem 1.25rem 1.25rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: rise 0.6s ease both;
}

.exam-card:nth-child(2) { animation-delay: 0.05s; }
.exam-card:nth-child(3) { animation-delay: 0.1s; }
.exam-card:nth-child(4) { animation-delay: 0.15s; }
.exam-card:nth-child(5) { animation-delay: 0.2s; }

.exam-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 22px 55px rgba(20, 35, 58, 0.12);
}

.exam-card .tag {
  align-self: flex-start;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.exam-card h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.35rem;
  letter-spacing: -0.02em;
}

.exam-card .meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.exam-card p {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.45;
  flex: 1;
}

.exam-card .card-cta {
  font-weight: 700;
  color: var(--accent-deep);
}

.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.7rem 1.05rem;
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  transition: background 0.15s ease, transform 0.15s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-deep);
}

.btn-secondary {
  background: white;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn-secondary:hover {
  background: #f8fafc;
}

.btn-ghost {
  background: transparent;
  color: var(--ink-soft);
  border: 1px solid transparent;
}

.btn-ghost:hover {
  background: rgba(20, 35, 58, 0.05);
}

.exam-shell {
  display: grid;
  gap: 1rem;
}

.exam-header {
  display: grid;
  gap: 0.85rem;
  padding: 1.35rem 1.4rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  animation: rise 0.45s ease both;
}

.exam-header h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.7rem, 3vw, 2.3rem);
  letter-spacing: -0.02em;
}

.exam-header .lede {
  margin: 0;
  color: var(--ink-soft);
  line-height: 1.55;
}

.exam-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.progress-chip {
  margin-left: auto;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-deep);
  font-weight: 700;
  font-size: 0.9rem;
}

.context-box,
.question-block,
.part-block,
.score-panel,
.formula-panel,
.concept-list article {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.context-box {
  padding: 1.15rem 1.3rem;
}

.context-box h2,
.question-block > h2,
.score-panel h2,
.formula-panel h2 {
  margin: 0 0 0.65rem;
  font-family: var(--font-display);
  letter-spacing: -0.02em;
}

.prose p,
.part-prompt p,
.model-answer p,
.explanation p {
  line-height: 1.55;
  color: var(--ink-soft);
}

.prose p:first-child,
.part-prompt p:first-child {
  margin-top: 0;
}

.stats-table,
.prose table,
.part-prompt table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin: 0.75rem 0 1rem;
}

.part-prompt,
.prose,
.context-box {
  overflow-x: auto;
}

.stats-table th,
.stats-table td,
.prose th,
.prose td,
.part-prompt th,
.part-prompt td {
  border: 1px solid var(--line);
  padding: 0.35rem 0.5rem;
  text-align: right;
  white-space: nowrap;
}

.stats-table th:first-child,
.stats-table td:first-child,
.prose th:first-child,
.prose td:first-child,
.part-prompt th:first-child,
.part-prompt td:first-child {
  text-align: left;
  font-weight: 600;
}

.stats-table thead th,
.prose thead th,
.part-prompt thead th {
  background: #eef3f8;
}

.figure-frame {
  margin: 0.85rem 0 0.2rem;
  padding: 0.7rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f8fafc;
}

.figure-frame img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
}

.figure-frame figcaption {
  margin-top: 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.question-block {
  padding: 1.2rem 1.25rem 1.35rem;
  animation: rise 0.5s ease both;
}

.question-block > h2 {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: baseline;
}

.question-block .pts {
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 600;
}

.part-block {
  margin-top: 0.9rem;
  padding: 1rem 1.05rem;
  box-shadow: none;
}

.part-head {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.55rem;
}

.part-label {
  font-weight: 800;
  font-size: 1.05rem;
}

.part-pts {
  color: var(--muted);
  font-size: 0.88rem;
}

.concept-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-left: auto;
}

.concept-chip {
  border: 1px solid var(--line);
  background: #f8fafc;
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 0.2rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.concept-chip:hover {
  border-color: var(--accent);
  color: var(--accent-deep);
  background: var(--accent-soft);
}

.answer-area {
  margin-top: 0.65rem;
}

.answer-area textarea,
.answer-area input[type="text"],
.answer-area input[type="number"] {
  width: 100%;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  font: inherit;
  background: #fcfdff;
}

.answer-area textarea {
  min-height: 5.5rem;
  resize: vertical;
}

.mc-options {
  display: grid;
  gap: 0.4rem;
}

.mc-option {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fcfdff;
  cursor: pointer;
}

.mc-option:hover {
  border-color: #b7c6d8;
}

.mc-option.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.mc-option input {
  margin-top: 0.2rem;
}

.graded .mc-option.correct-option {
  border-color: var(--good);
  background: var(--good-soft);
}

.graded .mc-option.wrong-option {
  border-color: var(--bad);
  background: var(--bad-soft);
}

.result-box {
  margin-top: 0.85rem;
  padding: 0.85rem 0.95rem;
  border-radius: 12px;
  border: 1px solid var(--line);
}

.result-box.auto-correct {
  background: var(--good-soft);
  border-color: #b7e4c5;
}

.result-box.auto-wrong {
  background: var(--bad-soft);
  border-color: #f0b8b2;
}

.result-box.self-pending {
  background: var(--warn-soft);
  border-color: #f0d2a8;
}

.result-box.self-correct {
  background: var(--good-soft);
  border-color: #b7e4c5;
}

.result-box.self-partial {
  background: var(--partial-soft);
  border-color: #ecd48a;
}

.result-box.self-wrong {
  background: var(--bad-soft);
  border-color: #f0b8b2;
}

.result-title {
  font-weight: 800;
  margin-bottom: 0.35rem;
}

.self-grade-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.65rem 0 0.35rem;
}

.self-grade-controls button {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 0.4rem 0.75rem;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.self-grade-controls button.active-correct {
  background: var(--good-soft);
  border-color: var(--good);
  color: var(--good);
}

.self-grade-controls button.active-partial {
  background: var(--partial-soft);
  border-color: var(--partial);
  color: var(--partial);
}

.self-grade-controls button.active-wrong {
  background: var(--bad-soft);
  border-color: var(--bad);
  color: var(--bad);
}

.sticky-gradebar {
  position: sticky;
  bottom: 0.75rem;
  z-index: 15;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  padding: 0.85rem 1rem;
  margin-top: 0.5rem;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: 0 12px 40px rgba(20, 35, 58, 0.12);
}

.score-panel {
  padding: 1.25rem 1.35rem;
  animation: rise 0.45s ease both;
}

.score-big {
  font-family: var(--font-display);
  font-size: clamp(2rem, 4vw, 2.8rem);
  letter-spacing: -0.03em;
  margin: 0.2rem 0 0.6rem;
}

.score-breakdown {
  display: grid;
  gap: 0.35rem;
  margin-top: 0.75rem;
}

.score-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft);
}

.formula-panel,
.concept-list article {
  padding: 1.15rem 1.25rem;
  margin-bottom: 0.85rem;
}

.concept-list {
  display: grid;
  gap: 0.85rem;
}

.concept-list h3 {
  margin: 0 0 0.4rem;
  font-family: var(--font-display);
}

.modal[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 36, 0.45);
}

.modal-panel {
  position: relative;
  width: min(560px, 100%);
  max-height: min(80vh, 720px);
  overflow: auto;
  background: white;
  border-radius: 18px;
  padding: 1.25rem 1.35rem 1.4rem;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.25);
  animation: rise 0.25s ease both;
}

.modal-panel h2 {
  margin: 0 1.5rem 0.65rem 0;
  font-family: var(--font-display);
}

.modal-close {
  position: absolute;
  top: 0.65rem;
  right: 0.75rem;
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}

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

.loading {
  padding: 3rem 1rem;
  text-align: center;
  color: var(--muted);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 720px) {
  .topbar {
    padding: 0.75rem 0.9rem;
  }

  .topnav a {
    padding: 0.4rem 0.55rem;
    font-size: 0.85rem;
  }

  #main {
    width: min(100% - 1.2rem, 1120px);
  }

  .progress-chip {
    margin-left: 0;
  }

  .sticky-gradebar {
    border-radius: 18px;
  }

  .concept-chips {
    margin-left: 0;
    width: 100%;
  }
}
