/* ---------- Tokens ---------- */
:root {
  --bg: #ffffff;
  --surface: #f7f8fa;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #eff4ff;
  --radius: 10px;
  --sidebar-w: 248px;
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* never let a component's display style un-hide it */
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }

#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 20px 14px 40px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

main {
  flex: 1;
  min-width: 0;
  padding: 40px 48px 80px;
  max-width: 1100px;
}

/* ---------- Sidebar ---------- */
.brand {
  display: block;
  font-weight: 700;
  font-size: 1.1rem;
  padding: 4px 10px 16px;
}

.nav-home,
.nav-link {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 0.92rem;
}
.nav-home { font-weight: 600; margin-bottom: 8px; }
.nav-home:hover, a.nav-link:hover { background: #eceef2; }
.nav-home.active, .nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.nav-link.soon { color: #a0a6b1; cursor: default; }
.nav-link.soon em {
  font-style: normal;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.nav-group { margin-top: 14px; }
.nav-heading {
  margin: 0 0 4px;
  padding: 0 10px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.nav-group ul { list-style: none; margin: 0; padding: 0; }

/* ---------- Page header ---------- */
.page-header h1 { margin: 0 0 6px; font-size: 1.9rem; letter-spacing: -0.01em; }
.page-header p { margin: 0; color: var(--muted); }

/* ---------- Homepage grid ---------- */
.category { margin-top: 36px; }
.category h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 12px;
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.card {
  position: relative;
  display: block;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--bg);
  transition: border-color 0.15s, box-shadow 0.15s;
}
a.card:hover { border-color: var(--accent); box-shadow: 0 2px 10px rgba(37, 99, 235, 0.08); }
.card h3 { margin: 0 0 4px; font-size: 1rem; }
.card p { margin: 0; color: var(--muted); font-size: 0.88rem; }
.card.soon { opacity: 0.55; }
.badge {
  display: inline-block;
  margin-top: 10px;
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
}

/* ---------- Tool page ---------- */
.tool-area {
  margin-top: 28px;
  border: 1.5px dashed var(--border);
  border-radius: var(--radius);
  min-height: 320px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--surface);
}

.privacy-note { margin-top: 14px; font-size: 0.85rem; color: var(--muted); }

/* ---------- Shared tool pieces: dropzone, file list, buttons ---------- */
.dropzone {
  margin-top: 28px;
  border: 1.5px dashed #c9cdd4;
  border-radius: var(--radius);
  background: var(--surface);
  padding: 56px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, padding 0.15s;
}
.dropzone:hover, .dropzone:focus-visible, .dropzone.over {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}
.dropzone.compact { padding: 18px 20px; }
.dz-title { margin: 0; font-weight: 600; font-size: 1.05rem; }
.dz-sub { margin: 4px 0 0; color: var(--muted); font-size: 0.9rem; }
.dropzone.compact .dz-title { display: none; }
.dz-more { display: none; color: var(--text); font-weight: 600; }
.dropzone.compact .dz-more { display: inline; }
.link { color: var(--accent); font-weight: 500; }

.file-list { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 8px; }
.file-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.file-list li.dragging { opacity: 0.45; border-style: dashed; }
.file-list li.has-error { background: #fef6f6; border-color: #f3d0d0; }
.handle { color: #b6bbc4; cursor: grab; letter-spacing: -2px; user-select: none; }
.num {
  flex-shrink: 0;
  width: 24px; height: 24px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface);
  font-size: 0.78rem; font-weight: 600; color: var(--muted);
}
.file-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file-name { font-size: 0.92rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { font-size: 0.8rem; color: var(--muted); }
.file-error { color: #b42318; }

.row-buttons { display: flex; gap: 4px; flex-shrink: 0; }
.row-buttons button {
  width: 30px; height: 30px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.85rem;
}
.row-buttons button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.row-buttons button.remove:hover { border-color: #e5a3a3; color: #b42318; }
.row-buttons button:disabled { opacity: 0.35; cursor: default; }

.actions {
  margin-top: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.actions[hidden] { display: none; }
.summary { color: var(--muted); font-size: 0.9rem; }
.action-buttons { display: flex; gap: 8px; }

.btn {
  border-radius: 8px;
  padding: 10px 18px;
  font: inherit;
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #1d4fd8; }
.btn-primary:disabled { background: #a9bff3; cursor: not-allowed; }
.btn-ghost { background: var(--bg); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface); }

.btn-sm { padding: 6px 12px; font-size: 0.85rem; }

/* Single-file card (Split, Rotate, ...) */
.file-card {
  margin-top: 28px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.file-card .file-info { display: grid; grid-template-columns: auto 1fr; column-gap: 10px; }
.file-card .file-info::before { content: "📄"; grid-row: span 2; font-size: 1.4rem; align-self: center; }

/* Option cards (radio buttons) */
.modes { border: 0; padding: 0; margin: 24px 0 0; }
.modes legend { font-weight: 600; font-size: 0.95rem; margin-bottom: 10px; padding: 0; }
.modes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.modes legend { grid-column: 1 / -1; }
.mode {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.mode:hover { border-color: #c9cdd4; }
.mode:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.mode input { margin-top: 3px; accent-color: var(--accent); }
.mode-text { display: flex; flex-direction: column; }
.mode-text strong { font-size: 0.92rem; }
.mode-text small { color: var(--muted); font-size: 0.8rem; }

/* Text fields */
.field { margin-top: 20px; }
.field label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; }
.field input[type="text"], .field input[type="number"] {
  width: 100%;
  max-width: 360px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 0.95rem;
}
.field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field input[type="number"] { max-width: 120px; }
.hint { margin: 6px 0 0; font-size: 0.8rem; color: var(--muted); }

.preview { margin: 16px 0 0; font-size: 0.9rem; min-height: 1.4em; }
.preview.ok { color: var(--text); }
.preview.error { color: #b42318; }

/* Page thumbnails (assets/js/thumbs.js) */
.grid-header {
  margin-top: 28px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.grid-header .hint { margin: 0; }
.grid-buttons { display: flex; gap: 6px; }
.grid-buttons[hidden] { display: none; }

.thumb-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 14px;
  align-items: end;
}
.thumb {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px;
  border: 2px solid transparent;
  border-radius: 10px;
  background: none;
  font: inherit;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}
@media (hover: hover) {
  .thumb:hover { background: var(--surface); }
}
.thumb:focus-visible { outline: none; border-color: #9db8f5; }
.thumb-frame {
  position: relative;
  width: 100%;
  max-width: 150px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}
.thumb-frame:not(.ready) { background: linear-gradient(110deg, #f3f4f6 30%, #e9ebef 50%, #f3f4f6 70%); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
.thumb-frame.failed { animation: none; background: #f3f4f6; }
.thumb-frame canvas { display: block; width: 100%; height: 100%; }
@keyframes shimmer { to { background-position: -200% 0; } }

.thumb-num { font-size: 0.8rem; color: var(--muted); font-weight: 500; }
.thumb-check {
  position: absolute;
  top: 6px; right: 6px;
  z-index: 1;
  width: 22px; height: 22px;
  display: none;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}
.thumb-tag {
  position: absolute;
  top: -2px; left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  font-size: 0.68rem;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--text);
  color: #fff;
  white-space: nowrap;
}
.thumb.selected { background: var(--accent-soft); border-color: var(--accent); }
.thumb.selected .thumb-check { display: grid; }
.thumb.selected .thumb-num { color: var(--accent); font-weight: 600; }
.thumb-grid.readonly .thumb { cursor: default; }
.thumb-grid.readonly .thumb:hover { background: none; }
.thumb:disabled { color: inherit; }

/* Square frames: page preview centred and rotatable (Rotate tool) */
.thumb-grid.square .thumb-frame {
  max-width: 150px;
  border: 0;
  box-shadow: none;
  background: none;
  overflow: visible;
}
.thumb-grid.square .thumb-frame:not(.ready) {
  border-radius: 4px;
  background: linear-gradient(110deg, #f3f4f6 30%, #e9ebef 50%, #f3f4f6 70%);
  background-size: 200% 100%;
}
.thumb-grid.square .thumb-frame canvas {
  position: absolute;
  top: 50%;
  left: 50%;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  border: 1px solid var(--border);
  border-radius: 3px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
  background: #fff;
  transform: translate(-50%, -50%) rotate(var(--rot, 0deg));
  transition: transform 0.25s ease;
}
.thumb.is-rotated .thumb-num::after { content: " ↻"; color: var(--accent); }

/* Per-page buttons */
.thumb { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.tile-tools {
  position: absolute;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 3;
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
  opacity: 0;
  transition: opacity 0.12s;
}
.tile-tools button {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 6px;
  background: none;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  color: var(--text);
}
.tile-tools button:hover { background: var(--accent-soft); color: var(--accent); }
.tile-tools button.danger:hover { background: #fdecec; color: #b42318; }
.thumb:focus-within .tile-tools { opacity: 1; }
@media (hover: hover) {
  .thumb-grid.square .thumb:hover .tile-tools { opacity: 1; }
  .thumb-grid.square .thumb { cursor: grab; }
}
@media (hover: none) {
  .tile-tools { opacity: 1; position: static; transform: none; box-shadow: none; background: var(--surface); }
}

/* Dragging */
.thumb.drag-placeholder { background: var(--accent-soft); border: 2px dashed var(--accent); }
.thumb.drag-placeholder > * { opacity: 0.25; }
.drag-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  pointer-events: none;
  opacity: 0.92;
  filter: drop-shadow(0 8px 18px rgba(0, 0, 0, 0.22));
}
.drag-ghost .thumb-frame { max-width: none; aspect-ratio: 1; position: relative; }
.drag-ghost .tile-tools, .drag-ghost .thumb-check { display: none; }
body.is-dragging, body.is-dragging * { cursor: grabbing !important; }

/* Option pickers (segmented buttons) */
.option-row { margin-top: 24px; display: flex; gap: 28px; flex-wrap: wrap; }
.option-row .field { margin-top: 0; }
.option-row + .hint { margin-top: 10px; }
.field-label { display: block; font-weight: 600; font-size: 0.9rem; margin-bottom: 6px; }
.segmented {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: 9px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.segmented label { cursor: pointer; position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--muted);
  transition: background 0.12s, color 0.12s;
}
.segmented input:checked + span { background: var(--bg); color: var(--text); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 1px; }
/* Pickers wrap onto a second line instead of pushing the page sideways on small phones */
.segmented { flex-wrap: wrap; max-width: 100%; }

/* Thumbnail in file lists (Images to PDF) */
.file-thumb {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
}

/* Checkbox option with a description */
.check-option {
  margin-top: 14px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.check-option:has(input:checked) { border-color: #e7b56a; background: #fff8ec; }
.check-option input { margin-top: 3px; accent-color: #c4740a; }
.check-option span { display: flex; flex-direction: column; }
.check-option strong { font-size: 0.92rem; }
.check-option small { color: var(--muted); font-size: 0.8rem; }

/* Compression result */
.result-card {
  margin-top: 20px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.result-sizes { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.result-sizes small { display: block; color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; }
.result-sizes strong { font-size: 1.5rem; }
.result-arrow { color: var(--muted); font-size: 1.3rem; }
.saving-badge {
  margin-left: auto;
  padding: 4px 12px;
  border-radius: 999px;
  background: #e7f6ee;
  color: #067647;
  font-weight: 700;
  font-size: 0.9rem;
}
.saving-badge.none { background: #f0f1f3; color: var(--muted); }
.result-card .hint { margin: 12px 0 14px; }

/* ---------- Calculators (GPA, S/U) ---------- */
.hint a { color: var(--accent); }
.hint a:hover { text-decoration: underline; }

.calc-layout {
  margin-top: 24px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 24px;
  align-items: start;
}
.calc-summary {
  position: sticky;
  top: 24px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.sum-label { margin: 0; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; }
.sum-gpa { margin: 4px 0 0; }
.sum-gpa strong { font-size: 2.6rem; letter-spacing: -0.02em; line-height: 1.1; }
.sum-gpa span { color: var(--muted); font-size: 1rem; }
.sum-sub { margin: 4px 0 0; color: var(--muted); font-size: 0.85rem; }
.sum-band { margin: 6px 0 0; display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 0.8rem; font-weight: 600; }
.sem-gpas { list-style: none; margin: 14px 0 0; padding: 12px 0 0; border-top: 1px solid var(--border); }
.sem-gpas:empty { display: none; }
.sem-gpas li { display: flex; justify-content: space-between; font-size: 0.88rem; padding: 3px 0; }
.sem-gpas li span { color: var(--muted); }
.sum-actions { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.sum-actions .btn { text-align: center; }

.prior-box {
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
}
.prior-box summary { cursor: pointer; font-weight: 600; font-size: 0.92rem; }
.prior-fields { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 12px; }
.prior-fields label { display: flex; flex-direction: column; gap: 4px; font-size: 0.85rem; color: var(--muted); }
.prior-box .hint { margin: 8px 0 0; }

.calc-main input[type="text"], .calc-main input[type="number"], .calc-main select {
  font: inherit;
  font-size: 0.92rem;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text);
  min-width: 0;
}
.calc-main input:focus, .calc-main select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.calc-main input.invalid { border-color: #e5a3a3; background: #fef6f6; }
.prior-fields input { width: 130px; }

.sem-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.sem-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.calc-main .sem-name { flex: 1; border-color: transparent; font-weight: 700; font-size: 1rem; padding-left: 4px; }
.calc-main .sem-name:hover { border-color: var(--border); }
.sem-gpa { font-size: 0.85rem; font-weight: 600; color: var(--accent); white-space: nowrap; }

.course-head, .course-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 80px 110px 30px;
  gap: 8px;
  align-items: center;
}
.course-rows.has-su .course-row, .sem-card:has(.has-su) .course-head { grid-template-columns: minmax(0, 1fr) 80px 110px 62px 30px; }
.course-head { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; padding: 0 2px 4px; }
.course-rows { display: grid; gap: 6px; }
.course-row.is-su .c-grade, .course-row.is-su .c-units { opacity: 0.5; }

.su-toggle { display: flex; align-items: center; gap: 4px; font-size: 0.8rem; font-weight: 600; color: var(--muted); cursor: pointer; user-select: none; }
.su-toggle input { accent-color: var(--accent); margin: 0; }
.course-row.is-su .su-toggle { color: var(--accent); }

.row-remove {
  width: 30px; height: 30px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: #a0a6b1;
  cursor: pointer;
}
.row-remove:hover { background: #fdecec; color: #b42318; }

.add-course {
  margin-top: 8px;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 2px;
}
.add-course:hover { text-decoration: underline; }
.add-sem { width: 100%; border-style: dashed; }

@media (max-width: 820px) {
  .calc-layout { grid-template-columns: minmax(0, 1fr); }
  /* Summary becomes a compact bar pinned to the bottom of the screen */
  .calc-summary {
    position: sticky;
    top: auto;
    bottom: 0;
    order: 2;
    z-index: 10;
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    column-gap: 12px;
    padding: 12px 16px;
    margin: 0 -16px;
    border-radius: 0;
    border-width: 1px 0 0;
    background: var(--bg);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.05);
  }
  .sum-label { grid-column: 1 / -1; }
  .sum-gpa strong { font-size: 1.8rem; }
  .sum-sub { text-align: right; }
  .sem-gpas, .sum-actions { display: none; }

  .course-head { display: none; }
  .course-row, .course-rows.has-su .course-row {
    grid-template-columns: minmax(0, 1fr) 64px 92px 30px;
    row-gap: 6px;
  }
  .course-rows.has-su .course-row { grid-template-columns: minmax(0, 1fr) 64px 92px 30px; }
  .course-rows.has-su .su-toggle { grid-column: 1; grid-row: 2; }
  .course-row .c-name { grid-column: 1; }
  .sem-card { padding: 12px; }
}

/* S/U optimiser */
.tag {
  display: inline-block;
  vertical-align: middle;
  margin-left: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.import-box {
  margin-top: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  background: var(--accent-soft);
  font-size: 0.9rem;
}
.sem-title { font-size: 0.95rem; }
.course-head.su-grid, .course-row.su-grid { grid-template-columns: minmax(0, 1fr) 70px 100px 78px 30px; }
.rules-box ul { margin: 10px 0 0; padding-left: 18px; font-size: 0.88rem; }
.rules-box li { margin-bottom: 6px; }
.pick-title { margin: 16px 0 6px; font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.pick-list, .option-list { list-style: none; margin: 0; padding: 0; }
.pick-list li {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  margin-bottom: 4px;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  font-weight: 600;
}
.pick-list em { font-style: normal; color: var(--muted); }
.option-list li {
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.option-list li span { color: var(--text); overflow: hidden; text-overflow: ellipsis; }
.option-list li small { grid-column: 1; color: var(--muted); font-size: 0.75rem; }
.option-list li strong { grid-row: 1 / span 2; grid-column: 2; align-self: center; }
.option-list li.baseline span { color: var(--muted); }
.su-summary .hint { margin-top: 12px; }

@media (max-width: 820px) {
  .course-row.su-grid { grid-template-columns: minmax(0, 1fr) 60px 88px 30px; }
  .course-row.su-grid .su-toggle { grid-column: 1; grid-row: 2; }
  /* On phones the S/U answer matters more than the inputs: show it in full, not as a bar */
  .su-summary { position: static; display: block; margin: 0; border-radius: var(--radius); border-width: 1px; order: 2; box-shadow: none; background: var(--surface); }
  .su-summary .sum-sub { text-align: left; }
}

/* ---------- Exam countdown ---------- */
.next-card {
  margin-top: 24px;
  padding: 22px 24px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #1e3a8a, #2563eb);
  color: #fff;
}
.next-card .sum-label { color: rgba(255, 255, 255, 0.75); }
.next-name { margin: 4px 0 14px; font-size: 1.35rem; font-weight: 700; }
.next-clock { display: flex; gap: 10px; flex-wrap: wrap; }
.clock-unit {
  min-width: 72px;
  padding: 10px 8px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.14);
  text-align: center;
}
.clock-unit strong { display: block; font-size: 2rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.clock-unit span { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; opacity: 0.8; }
.clock-now { font-size: 1.3rem; font-weight: 700; }
.next-when { margin: 14px 0 0; font-size: 0.9rem; opacity: 0.9; }

.add-form {
  margin-top: 20px;
  display: grid;
  grid-template-columns: minmax(0, 2fr) 150px 120px 80px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.add-form label { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.add-form input {
  font: inherit;
  font-size: 0.92rem;
  font-weight: 400;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text);
  min-width: 0;
  width: 100%;
}
.add-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.list-head { margin-top: 24px; display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.list-head .hint { margin: 0; }
.exam-list { list-style: none; margin: 12px 0 0; padding: 0; }
.exam {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto 30px;
  gap: 14px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
}
.exam-date {
  display: flex; flex-direction: column; align-items: center;
  padding: 4px 0;
  border-radius: 8px;
  background: var(--surface);
  font-size: 0.68rem; text-transform: uppercase; color: var(--muted); font-weight: 600;
}
.exam-date strong { font-size: 1.3rem; color: var(--text); line-height: 1.1; }
.exam-info { display: flex; flex-direction: column; min-width: 0; }
.exam-info strong { font-size: 0.98rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.exam-info span { font-size: 0.82rem; color: var(--muted); }
.exam-rel { font-size: 0.85rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.exam.week .exam-rel { color: #b54708; }
.exam.soon .exam-rel, .exam.now .exam-rel { color: #b42318; }
.exam.soon, .exam.now { border-color: #f3c3c3; }
.exam.past { opacity: 0.5; }
.exam.past .exam-info strong { text-decoration: line-through; }

.gap { padding: 6px 0 6px 84px; font-size: 0.78rem; color: var(--muted); position: relative; }
.gap::before { content: ""; position: absolute; left: 41px; top: 0; bottom: 0; border-left: 2px dotted var(--border); }
.gap.tight { color: #b54708; }
.gap.same-day { color: #b54708; font-weight: 600; }
.gap.clash { color: #b42318; font-weight: 700; }
.empty-note { margin-top: 18px; }

@media (max-width: 820px) {
  .add-form { grid-template-columns: 1fr 1fr; }
  .add-form .f-name, .add-form .f-venue, .add-form .f-add { grid-column: 1 / -1; }
  .add-form .f-dur { grid-column: 2; }
  .add-form .f-date { grid-column: 1 / -1; }
  .exam { grid-template-columns: 48px minmax(0, 1fr) 30px; row-gap: 2px; }
  .exam-rel { grid-column: 2; grid-row: 2; }
  .exam .row-remove { grid-column: 3; grid-row: 1 / span 2; }
  .exam-date { grid-row: 1 / span 2; }
  .gap { padding-left: 70px; }
  .gap::before { left: 37px; }
  .clock-unit { min-width: 0; flex: 1; }
  .clock-unit strong { font-size: 1.6rem; }
}

/* ---------- Citation generator ---------- */
.cite-form {
  margin-top: 20px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.cite-form input, .cite-form select {
  font: inherit;
  font-size: 0.92rem;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text);
  min-width: 0;
  width: 100%;
}
.cite-form input:focus, .cite-form select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.paste-box {
  margin-top: 20px;
  padding: 18px;
  border: 1.5px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent-soft);
}
.paste-box > label { display: block; font-weight: 700; font-size: 0.98rem; margin-bottom: 8px; }
.qf-row { display: flex; gap: 8px; }
.qf-row input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 0.95rem;
  padding: 10px 12px;
  border: 1px solid #b9cdf7;
  border-radius: 8px;
  background: var(--bg);
}
.qf-row input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15); }
.qf-row .btn { flex-shrink: 0; }
.paste-box .hint { margin: 8px 0 0; }
.paste-box .hint:empty { display: none; }
.or-divider {
  margin: 22px 0 0;
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.or-divider::before, .or-divider::after { content: ""; flex: 1; border-top: 1px solid var(--border); }
.or-divider + .option-row { margin-top: 14px; }
.hint.ok { color: #067647; }
.hint.error { color: #b42318; }

.author-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 30px; gap: 8px; margin-bottom: 6px; }
.cite-authors .hint { margin: 2px 0 0; }
.cite-grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.cite-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.cite-grid .span-2 { grid-column: span 2; }

.cite-output {
  margin-top: 16px;
  padding: 18px;
  border: 1.5px solid var(--accent);
  border-radius: var(--radius);
  background: var(--bg);
}
.out-block { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 12px; align-items: start; margin-bottom: 14px; }
.out-block .sum-label { grid-column: 1 / -1; margin-bottom: 4px; }
.out-ref { margin: 0; padding-left: 2em; text-indent: -2em; line-height: 1.6; overflow-wrap: anywhere; }
.out-intext { margin: 0; font-size: 1.05rem; }
.placeholder { color: var(--muted); font-style: italic; }
.out-actions { display: flex; gap: 8px; padding-top: 4px; border-top: 1px solid var(--border); padding-top: 14px; }

.ref-list-section { margin-top: 32px; }
.ref-list-section h2 { margin: 0; font-size: 1.15rem; }
.ref-list { list-style: none; margin: 14px 0 0; padding: 0; }
.ref-list li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.ref-list.numbered li { grid-template-columns: 34px minmax(0, 1fr) auto; }
.ref-list li.editing { background: var(--accent-soft); border-radius: 8px; }
.ref-text { padding-left: 2em; text-indent: -2em; line-height: 1.6; overflow-wrap: anywhere; }
.ref-list.numbered .ref-text { padding-left: 0; text-indent: 0; }
.ref-num { color: var(--muted); font-weight: 600; }
.ref-actions { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn-link { border: 0; background: none; color: var(--accent); font: inherit; font-size: 0.82rem; font-weight: 600; cursor: pointer; padding: 4px; }
.btn-link:hover { text-decoration: underline; }

@media (max-width: 820px) {
  .cite-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cite-form { padding: 14px; }
  .ref-list li { grid-template-columns: minmax(0, 1fr); row-gap: 4px; }
  .ref-list.numbered li { grid-template-columns: 30px minmax(0, 1fr); }
  .ref-list.numbered .ref-actions { grid-column: 2; }
}

/* ---------- Pomodoro ---------- */
.pomo-card {
  --mode: #2563eb;
  --mode-soft: #eff4ff;
  margin-top: 24px;
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--mode-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  transition: background 0.3s;
}
.pomo-card[data-mode="short"] { --mode: #0f9f6e; --mode-soft: #ecfaf4; }
.pomo-card[data-mode="long"] { --mode: #7c3aed; --mode-soft: #f4effe; }
.pomo-modes { background: var(--bg); }
.pomo-modes input:checked + span { color: var(--mode); }

.pomo-ring { position: relative; width: min(280px, 72vw); aspect-ratio: 1; }
.pomo-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(0, 0, 0, 0.07); stroke-width: 10; }
.ring-fg { fill: none; stroke: var(--mode); stroke-width: 10; stroke-linecap: round; transition: stroke-dashoffset 0.25s linear, stroke 0.3s; }
.pomo-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.pomo-time { font-size: clamp(3rem, 14vw, 4.2rem); font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1; }
.pomo-mode-label { margin-top: 6px; color: var(--mode); font-weight: 600; font-size: 0.95rem; }

.pomo-controls { display: flex; align-items: center; gap: 14px; }
.pomo-start { min-width: 150px; padding: 14px 28px; font-size: 1.1rem; border-radius: 999px; background: var(--mode); }
.pomo-start:hover:not(:disabled) { background: var(--mode); filter: brightness(0.92); }
.pomo-start.is-running { background: var(--bg); color: var(--mode); border: 2px solid var(--mode); }
.btn.round { width: 46px; height: 46px; padding: 0; border-radius: 50%; font-size: 1.15rem; background: var(--bg); }

.pomo-session { text-align: center; }
.pomo-session .hint { margin: 6px 0 0; }
.pomo-dots { display: flex; justify-content: center; gap: 8px; }
.dot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--mode); opacity: 0.5; }
.dot.done { background: var(--mode); opacity: 1; }

.pomo-task {
  width: min(420px, 100%);
  text-align: center;
  font: inherit;
  font-size: 0.95rem;
  padding: 10px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
}
.pomo-task:focus { outline: none; border-color: var(--mode); background: var(--bg); }

.pomo-below { margin-top: 18px; display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 16px; align-items: start; }
.pomo-stats { padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius); }
.pomo-today { margin: 4px 0 0; }
.pomo-today strong { font-size: 1.8rem; }
.pomo-stats .hint { margin: 2px 0 0; }
.pomo-settings { margin-bottom: 0; }
.pomo-settings-grid { margin-top: 12px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.pomo-settings-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: var(--muted); font-weight: 600; }
.pomo-settings-grid input { font: inherit; padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px; width: 100%; }
.check-line { display: flex; gap: 8px; align-items: center; margin-top: 10px; font-size: 0.9rem; cursor: pointer; }
.check-line input { accent-color: var(--accent); }

@media (max-width: 820px) {
  .pomo-card { padding: 18px 14px; }
  .pomo-below { grid-template-columns: 1fr; }
  .pomo-settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* Link to a related tool */
.related { margin-top: 28px; font-size: 0.9rem; color: var(--muted); }
.related a { color: var(--accent); font-weight: 500; }
.related a:hover { text-decoration: underline; }

/* Tool bar above the grid */
.toolbar {
  margin-top: 24px;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.toolbar-group { display: flex; gap: 6px; }
.toolbar + .hint { margin-top: 10px; }
.btn-ghost:disabled { opacity: 0.45; cursor: default; }

/* Action bar pinned to the bottom of the screen while scrolling through pages */
.sticky-bar {
  position: sticky;
  bottom: 0;
  z-index: 10;
  margin-top: 24px;
  padding: 14px 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  flex-wrap: nowrap;
}
.bar-text { min-width: 0; }
.bar-text .preview, .bar-text .status { margin: 0; min-height: 0; }
.bar-text .status:empty { display: none; }

.status { margin: 12px 0 0; font-size: 0.9rem; min-height: 1.4em; color: var(--muted); }
.status.ok { color: #067647; }
.status.error { color: #b42318; }

@media (max-width: 820px) {
  .handle { display: none; }
  .dropzone { padding: 40px 16px; }
  .actions { flex-direction: column; align-items: stretch; }
  .action-buttons .btn { flex: 1; }
  .modes { grid-template-columns: 1fr; }
  .thumb-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .thumb { padding: 4px; }
  .sticky-bar { flex-direction: row; align-items: center; padding: 12px 0; }
  .sticky-bar .action-buttons .btn { flex: none; }
  .field input[type="text"] { max-width: none; }
}

/* ---------- Mobile ---------- */
.topbar { display: none; }
#scrim { display: none; }

@media (max-width: 820px) {
  .topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 20;
    padding: 12px 16px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
  }
  .topbar strong { font-size: 1rem; }
  #menu-toggle {
    border: 1px solid var(--border);
    background: var(--bg);
    border-radius: 6px;
    padding: 6px 10px;
    font-size: 1rem;
    cursor: pointer;
  }

  .app { display: block; }
  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
  }
  body.nav-open #sidebar { transform: none; }
  body.nav-open #scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(0, 0, 0, 0.3);
  }

  main { padding: 24px 16px 60px; }
  .page-header h1 { font-size: 1.5rem; }
}
