:root {
  color-scheme: light;
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-soft: #f7f9fb;
  --ink: #17202a;
  --muted: #607080;
  --line: #d8e0e8;
  --primary: #165d7d;
  --primary-dark: #0f4158;
  --accent: #b45f3a;
  --excellent: #16714a;
  --strong: #1f658f;
  --moderate: #8a6317;
  --warning: #b23838;
  --shadow: 0 20px 50px rgba(28, 42, 55, 0.12);
}

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

html {
  overflow-x: clip; /* hard-stop horizontal overflow at the root */
}

body {
  margin: 0;
  min-width: 0;
  overflow-x: clip;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
input,
select,
textarea {
  font: inherit;
  max-width: 100%;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(18px, 4vw, 48px);
  background: #12384f;
  color: #fff;
}

.topbar h1 {
  margin: 3px 0 0;
  font-size: clamp(1.55rem, 3vw, 2.25rem);
  line-height: 1.05;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.topbar .eyebrow {
  color: rgba(255, 255, 255, 0.72);
}

.layout {
  display: grid;
  grid-template-columns: minmax(min(320px, 100%), 420px) minmax(0, 1fr);
  gap: 24px;
  padding: 24px clamp(18px, 4vw, 48px) 48px;
}

.input-panel,
.trend-section,
.leave-section,
.gpa-check-section,
.semesters-section,
.json-section {
  /* min-width: 0 is the key: lets grid items shrink below intrinsic content width */
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  /* No overflow:hidden here — it would clip position:absolute dropdowns inside cards */
}

.input-panel {
  align-self: start;
  position: sticky;
  top: 16px;
  display: grid;
  gap: 16px;
  padding: 20px;
}

/* ── Empty state (before any PDF is loaded) ─────────────────────────── */
.state-empty .layout {
  grid-template-columns: 1fr;
  max-width: 560px;
  margin: 0 auto;
}

.state-empty .results-panel {
  display: none;
}

.state-empty .input-panel {
  position: static;
}

/* Hide the "New PDF" and "Reset What-if" buttons until a PDF is loaded */
.state-empty .file-replace-button,
.state-empty #resetWhatIfButton {
  display: none;
}

/* Hide the export row until a PDF is loaded */
.state-empty #exportRow {
  display: none;
}

/* ── Compact mode (after PDF is loaded) ─────────────────────────────── */
.input-panel.is-compact .setup-only {
  display: none;
}

.input-panel.is-compact {
  gap: 12px;
}

.results-panel {
  min-width: 0; /* allow grid item to shrink below intrinsic size */
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(220px, 260px);
  align-items: start;
  gap: 18px;
}

.results-panel > section:not(.summary-grid) {
  grid-column: 1;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.section-heading h2 {
  margin: 2px 0 0;
  font-size: 1.08rem;
  letter-spacing: 0;
}

.section-heading.compact {
  padding: 18px 18px 0;
}

.section-note {
  margin: 8px 18px 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.file-drop {
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px dashed #9cafbf;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--primary-dark);
  font-weight: 800;
}

.primary-file {
  border-color: rgba(22, 93, 125, 0.42);
  background: #edf7fb;
}

.file-drop input {
  width: 100%;
}

.source-summary {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfcfe;
}

.edurec-notice {
  border: 1px solid #b8cce4;
  border-left: 4px solid #3a82c4;
  border-radius: 8px;
  padding: 12px 14px;
  color: #0d2a42;
  background: #eef4fb;
}

.edurec-notice strong {
  display: block;
  font-size: 1.05rem;
}

.edurec-notice span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.edurec-notice a {
  color: #3a82c4;
  text-decoration: underline;
}

.privacy-notice {
  border: 1px solid #b8d7c8;
  border-left: 4px solid var(--excellent);
  border-radius: 8px;
  padding: 12px 14px;
  color: #123c2a;
  background: #eef8f3;
}

.privacy-notice strong,
.source-summary strong {
  display: block;
  margin-top: 4px;
  font-size: 1.05rem;
}

.privacy-notice span,
.source-summary span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.source-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.source-meta span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  margin: 0;
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--primary-dark);
  background: #e7f1f6;
  font-weight: 800;
}

.advanced-json {
  display: none;
}

.textarea-label,
.debug-toggle {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

textarea {
  width: 100%;
  min-height: 280px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--ink);
  background: #fbfcfe;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.86rem;
}

textarea:focus,
button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(22, 93, 125, 0.26);
  outline-offset: 2px;
}

.control-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.input-panel.is-compact .control-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.input-panel.is-compact .control-row #resetWhatIfButton {
  grid-column: 1 / -1;
}

button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  color: #fff;
  background: var(--primary);
  font-weight: 800;
  cursor: pointer;
}

button:hover {
  background: var(--primary-dark);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid var(--line);
  color: var(--primary-dark);
  background: #fff;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 800;
  cursor: pointer;
  text-align: center;
}

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

.debug-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}

.error-box {
  border-left: 4px solid var(--warning);
  border-radius: 8px;
  padding: 12px;
  color: #7c2222;
  background: #fff0f0;
  font-weight: 700;
}

.summary-grid {
  display: grid;
  position: sticky;
  top: 16px;
  z-index: 4;
  grid-column: 2;
  grid-row: 1 / span 8;
  grid-template-columns: 1fr;
  gap: 14px;
}

.summary-card {
  min-height: 118px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.summary-card strong {
  display: block;
  margin-top: 10px;
  font-size: 2rem;
  line-height: 1;
}

.summary-card span {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.9rem;
}

.summary-card .delta {
  font-weight: 800;
}

.summary-card .delta.positive {
  color: var(--excellent);
}

.summary-card .delta.negative {
  color: var(--warning);
}

.summary-card.empty {
  grid-column: 1 / -1;
}

.chart-wrap {
  height: 260px;
  padding: 18px;
}

#gpaChart {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.chart-grid {
  stroke: #e4ebf1;
  stroke-width: 1;
}

.chart-axis-label,
.chart-point-label,
.chart-term-label {
  fill: var(--muted);
  font-size: 12px;
}

.chart-line {
  fill: none;
  stroke: var(--primary);
  stroke-width: 3;
}

.chart-point {
  fill: var(--accent);
  stroke: #fff;
  stroke-width: 3;
}

.leave-list {
  display: grid;
  gap: 10px;
  padding: 14px 18px 18px;
}

.leave-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  border-radius: 10px;
  padding: 14px 16px;
  background: #fef4ec;
  border: 1px solid #f0cba8;
  border-left: 4px solid var(--accent);
}

.leave-card-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 1.1rem;
}

.leave-card-body {
  flex: 1;
  min-width: 0;
}

.leave-card-title {
  margin: 0 0 6px;
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
  color: var(--accent);
}

.leave-card-dates {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  font-size: 0.97rem;
  font-weight: 800;
  color: var(--ink);
}

.leave-card-dates .leave-arrow {
  color: var(--muted);
  font-size: 0.85rem;
}

.leave-card-dates .leave-date {
  white-space: nowrap;
}

.leave-card-duration {
  margin-top: 5px;
  font-size: 0.84rem;
  color: var(--muted);
  font-weight: 700;
}

.semesters-section > .semester-cards,
.semesters-section > .new-semester-form {
  margin-left: 18px;
  margin-right: 18px;
}

.semesters-section > .semester-cards {
  margin-top: 18px;
}

.semesters-section > .new-semester-form {
  margin-bottom: 18px;
}

.semester-cards {
  display: grid;
  gap: 18px;
}

.new-semester-form {
  margin-top: 24px;
  border: 2px dashed var(--line);
  border-radius: 10px;
  background: var(--surface-soft);
}

.new-semester-form-header {
  padding: 14px 18px 0;
}

.new-semester-form-header .eyebrow {
  color: var(--muted);
}

.new-semester-form-header span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.88rem;
}

.new-semester-form-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 16px 18px 18px;
}

.new-semester-form label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

.new-semester-form select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  color: var(--ink);
  background: #fff;
  font-weight: 800;
}

.new-semester-form button {
  white-space: nowrap;
}

.semester-card {
  min-width: 0; /* allow card to shrink inside the semester-cards grid */
  overflow: visible;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.semester-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #ffffff, #f7f9fb);
}

.semester-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex: 1;
  min-width: 0;
}

.add-module-button {
  align-self: center;
}

.semester-header h3 {
  margin: 3px 0 0;
  font-size: 1.28rem;
  letter-spacing: 0;
}

.comparison-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: #fbfcfe;
}

.check-chip {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  padding: 5px 10px;
  color: var(--primary-dark);
  background: #e7f1f6;
  font-size: 0.82rem;
  font-weight: 800;
}

.check-chip.ok {
  color: #0e5738;
  background: #e6f5ee;
}

.check-chip.bad {
  color: #7c2222;
  background: #fff0f0;
}

.gpa-badge {
  min-width: 88px;
  padding: 10px 12px;
  border-radius: 8px;
  color: #fff;
  text-align: center;
  background: var(--primary);
}

.gpa-badge span {
  display: block;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
  opacity: 0.84;
}

.gpa-badge strong {
  display: block;
  font-size: 1.65rem;
  line-height: 1.05;
}

.band-excellent {
  background: var(--excellent);
}

.band-strong {
  background: var(--strong);
}

.band-moderate {
  background: var(--moderate);
}

.band-warning {
  background: var(--warning);
}

.semester-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  margin: 0;
  border-bottom: 1px solid var(--line);
}

.semester-stats div {
  padding: 14px 18px;
}

.semester-stats div + div {
  border-left: 1px solid var(--line);
}

.semester-stats dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.semester-stats dd {
  margin: 4px 0 0;
  font-size: 1.25rem;
  font-weight: 900;
}

.table-wrap {
  overflow-x: auto;
  overflow-y: visible;
}

.module-add-form {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: minmax(0, 0.8fr) minmax(0, 2fr) minmax(0, 0.6fr) minmax(0, 0.6fr) auto;
  gap: 10px;
  align-items: end;
  padding: 14px 18px 18px;
  background: #fbfcfe;
}

.module-add-form label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

.module-add-form input,
.module-add-form select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  color: var(--ink);
  background: #fff;
  font-weight: 800;
}

.module-code-wrap {
  position: relative;
}

.module-suggestions {
  position: absolute;
  z-index: 50;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 38px rgba(28, 42, 55, 0.18);
}

.module-suggestion {
  display: block;
  width: 100%;
  min-height: 0;
  border: 0;
  border-radius: 0;
  padding: 10px 12px;
  color: var(--ink);
  background: #fff;
  text-align: left;
}

.module-suggestion:hover {
  color: var(--ink);
  background: #edf7fb;
}

.module-suggestion + .module-suggestion {
  border-top: 1px solid var(--line);
}

.module-suggestion strong,
.module-suggestion span {
  display: block;
}

.module-suggestion strong {
  color: var(--primary-dark);
  font-size: 0.92rem;
}

.module-suggestion span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  white-space: normal;
}

.module-add-form button {
  min-height: 40px;
}

.nusmods-note {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-style: italic;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.94rem;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  background: #fbfcfe;
  font-size: 0.76rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

.text-excellent {
  color: var(--excellent);
}

.text-strong {
  color: var(--strong);
}

.text-moderate {
  color: var(--moderate);
}

.text-warning {
  color: var(--warning);
}

td:first-child {
  width: 116px;
  color: var(--primary-dark);
  font-weight: 900;
}

td:nth-child(3),
td:nth-child(4),
td:nth-child(5) {
  width: 84px;
  white-space: nowrap;
  font-weight: 800;
}

.grade-select {
  min-width: 76px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 8px;
  color: var(--ink);
  background: #fff;
  font-weight: 800;
}

.check-list {
  display: grid;
  gap: 10px;
  padding: 16px 18px 18px;
}

.remove-module-button {
  min-height: 34px;
  border: 1px solid #e5b8b8;
  color: #8b2a2a;
  background: #fff;
  font-size: 0.82rem;
}

.remove-module-button:hover {
  color: #fff;
  background: var(--warning);
}

/* ── Exchange semester row ─────────────────────────────────────── */
.exchange-row td.exchange-cell {
  /* Reset td:first-child width + color so the colspan-5 cell fills the full row */
  width: auto !important;
  color: inherit !important;
  font-weight: normal !important;
  background: #eaf4fb;
  border-bottom: 1px solid #c4dff0;
  padding: 10px 14px;
  /* Use inline layout so badge, institution and credits sit on one line */
  white-space: normal;
}

/* Inline layout for the badge + text pieces */
.exchange-row td.exchange-cell > * {
  display: inline;
  vertical-align: middle;
}

.exchange-row td.exchange-cell > * + * {
  margin-left: 8px;
}

.exchange-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: #1f658f;
  color: #fff;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.exchange-institution {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--primary-dark);
}

.exchange-credits {
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}

.remove-semester-button {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  min-height: 0;
  min-width: 0;
  padding: 0;
  border-radius: 50%;
  border: 1px solid #e5b8b8;
  color: #8b2a2a;
  background: #fff8f8;
  font-size: 0.82rem;
  line-height: 1;
  opacity: 0.6;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
}

.remove-semester-button:hover {
  color: #fff;
  background: var(--warning);
  border-color: var(--warning);
  opacity: 1;
}

.delete-pdf-button {
  min-height: 36px;
  border: 1px solid #e5b8b8;
  border-radius: 8px;
  padding: 0 16px;
  color: #8b2a2a;
  background: #fff8f8;
  font-weight: 800;
  cursor: pointer;
}

.delete-pdf-button:hover {
  color: #fff;
  background: var(--warning);
  border-color: var(--warning);
}

.check-item {
  border-left: 4px solid var(--excellent);
  border-radius: 8px;
  padding: 12px;
  background: #f8fbf9;
}

.check-item.bad {
  border-left-color: var(--warning);
  background: #fff7f7;
}

.check-item strong {
  display: block;
  margin-bottom: 3px;
}

.check-item span {
  color: var(--muted);
  font-size: 0.92rem;
}

.json-section pre,
.debug-panel pre {
  max-height: 360px;
  margin: 0;
  overflow: auto;
  padding: 18px;
  border-top: 1px solid var(--line);
  color: #1d2730;
  background: #f9fbfd;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

.drop-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(18, 56, 79, 0.76);
}

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

.drop-overlay div {
  width: min(520px, 100%);
  border: 2px dashed rgba(255, 255, 255, 0.82);
  border-radius: 8px;
  padding: 38px 28px;
  color: #fff;
  text-align: center;
  background: rgba(255, 255, 255, 0.1);
}

.drop-overlay strong {
  display: block;
  font-size: 1.6rem;
}

.drop-overlay span {
  display: block;
  margin-top: 8px;
  color: rgba(255, 255, 255, 0.8);
}

.export-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding-top: 4px;
  border-top: 1px solid var(--line);
}

.export-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  color: #fff;
  background: var(--primary);
  font-weight: 800;
  font-size: 0.88rem;
  cursor: pointer;
  white-space: nowrap;
}

.export-button:hover {
  background: var(--primary-dark);
}

.secondary-export-button {
  color: var(--primary-dark);
  background: #fff;
  border: 1px solid var(--line);
}

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

.debug-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.debug-panel .section-heading {
  padding: 12px 12px 0;
}

/* ── Responsive: large tablets (981–1280 px) ────────────────────────── */
@media (max-width: 1280px) and (min-width: 981px) {
  .layout {
    grid-template-columns: minmax(0, 360px) minmax(0, 1fr);
  }
}

/* ── Responsive: tablets / small laptops (≤ 980 px) ─────────────────── */
@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .input-panel {
    position: static;
  }

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

  .results-panel > section:not(.summary-grid),
  .summary-grid {
    grid-column: 1;
  }

  .summary-grid {
    position: static;
    grid-row: auto;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .summary-card {
    min-height: 0;
    padding: 12px;
    box-shadow: none;
  }

  .summary-card strong {
    margin-top: 5px;
    font-size: 1.45rem;
  }

  .summary-card span {
    margin-top: 4px;
    font-size: 0.8rem;
  }

  /* Module add form: collapse to 2 useful columns on mid-size screens */
  .module-add-form {
    grid-template-columns: minmax(0, 1fr) minmax(0, 2fr);
  }

  .module-add-form > div:nth-child(3),
  .module-add-form > div:nth-child(4) {
    grid-column: span 1;
  }

  .module-add-form > button {
    grid-column: 1 / -1;
  }
}

/* ── Responsive: mobile phones (≤ 620 px) ───────────────────────────── */
@media (max-width: 620px) {
  .topbar {
    flex-wrap: wrap;
    gap: 12px;
    padding: 18px 16px;
  }

  .topbar h1 {
    font-size: clamp(1.2rem, 5vw, 1.55rem);
  }

  .layout {
    gap: 16px;
    padding: 16px 12px 36px;
  }

  .section-heading {
    flex-wrap: wrap;
    gap: 10px;
  }

  .section-heading.compact {
    padding: 14px 14px 0;
  }

  .section-note {
    margin: 8px 14px 0;
  }

  .control-row {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .control-row > * {
    width: 100%;
  }

  /* Override the is-compact grid layout so control-row stacks on mobile too */
  .input-panel.is-compact .control-row {
    display: flex;
    flex-direction: column;
    grid-template-columns: none;
  }

  .input-panel.is-compact .control-row #resetWhatIfButton {
    grid-column: auto;
  }

  /* Semester cards */
  .semesters-section > .semester-cards,
  .semesters-section > .new-semester-form {
    margin-left: 12px;
    margin-right: 12px;
  }

  .semester-header {
    gap: 8px;
    padding: 12px 14px;
    flex-wrap: wrap;
  }

  .semester-header-left {
    gap: 10px;
    flex: 1;
    min-width: 0;
  }

  .gpa-badge {
    min-width: 72px;
    padding: 8px 10px;
  }

  .gpa-badge strong {
    font-size: 1.35rem;
  }

  .semester-header h3 {
    font-size: 1.05rem;
  }

  .semester-stats {
    grid-template-columns: 1fr;
  }

  .semester-stats div + div {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  /* Summary cards: single-column horizontal layout on mobile.
     Label + subtext on the left, big number on the right.
     Much more readable than a cramped 2×2 grid. */
  .summary-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .summary-card {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    column-gap: 16px;
    min-height: 0;
    padding: 12px 16px;
    box-shadow: none;
    align-items: center;
  }

  /* eyebrow label — top-left */
  .summary-card .eyebrow {
    grid-column: 1;
    grid-row: 1;
    align-self: end;
    font-size: 0.68rem;
    margin-bottom: 2px;
  }

  /* big number — right column, spans both rows */
  .summary-card strong {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: center;
    margin-top: 0;
    font-size: 1.9rem;
  }

  /* subtext / delta — bottom-left */
  .summary-card > span {
    grid-column: 1;
    grid-row: 2;
    margin-top: 0;
    align-self: start;
    font-size: 0.78rem;
  }

  /* Tables: allow horizontal scroll but limit first/last column widths */
  .table-wrap {
    -webkit-overflow-scrolling: touch;
  }

  table {
    font-size: 0.84rem;
  }

  th,
  td {
    padding: 10px 10px;
  }

  td:first-child {
    width: 90px;
  }

  td:nth-child(3),
  td:nth-child(4),
  td:nth-child(5) {
    width: 64px;
  }

  /* Module add form: single column on mobile */
  .module-add-form {
    grid-template-columns: 1fr;
    padding: 12px 14px 14px;
  }

  .module-add-form > button {
    grid-column: 1;
  }

  /* New semester form */
  .new-semester-form-inner {
    grid-template-columns: 1fr;
  }

  /* Chart */
  .chart-wrap {
    height: 200px;
    padding: 12px;
  }

  /* Leave cards */
  .leave-list {
    padding: 10px 14px 14px;
  }
}

/* ── Responsive: very small phones (≤ 380 px) ───────────────────────── */
@media (max-width: 380px) {
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .summary-card.empty {
    grid-column: 1;
  }
}
