:root {
  --blue: #003d7c;
  --blue-dark: #002a57;
  --orange: #ef7c00;
  --bg: #f4f6fa;
  --card: #ffffff;
  --border: #e2e8f1;
  --text: #1b2535;
  --muted: #6b7689;
  --green: #1a8a4a;
  --red: #c43d3d;
  --hover-blue: #f2f6fb;
  --hover-red: #fbecec;
  --switch-off: #d4dae4;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 30, 54, 0.05), 0 4px 14px rgba(16, 30, 54, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 20px 48px;
}

/* ---------- Header ---------- */

.header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.header h1 {
  margin: 0;
  font-size: 26px;
  letter-spacing: -0.02em;
  color: var(--blue);
}

.tagline {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.ghost-btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--muted);
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.ghost-btn:hover {
  border-color: var(--red);
  color: var(--red);
}

/* ---------- Summary ---------- */

.summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
  background: linear-gradient(120deg, var(--blue) 0%, var(--blue-dark) 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 22px 28px;
  box-shadow: var(--shadow);
}

.summary-label {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.75;
}

.summary-gpa {
  font-size: 46px;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.summary-class {
  font-size: 13px;
  color: #ffc98a;
  min-height: 18px;
}

.summary-stats {
  display: flex;
  gap: 28px;
}

.stat { text-align: center; }

.stat-value {
  font-size: 24px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 12px;
  opacity: 0.75;
}

.stat-total-goal {
  font-size: 15px;
  font-weight: 500;
  opacity: 0.7;
}

.mc-progress {
  width: 130px;
  height: 6px;
  margin: 6px auto 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.22);
  overflow: hidden;
}

.mc-progress-fill {
  height: 100%;
  width: 0;
  border-radius: 3px;
  background: var(--orange);
  transition: width 0.25s;
}

/* ---------- Data status ---------- */

.data-status {
  margin: 12px 4px 4px;
  font-size: 12.5px;
  color: var(--muted);
}

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

/* ---------- Year / semester layout ---------- */

.year-title {
  margin: 26px 4px 12px;
  font-size: 17px;
  color: var(--blue);
}

.year-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.sem-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 16px 14px;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s;
}

.sem-card:focus-within {
  border-color: var(--orange);
}

.sem-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}

.sem-title {
  margin: 0;
  font-size: 14.5px;
  font-weight: 650;
}

.sem-gpa {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.sem-gpa b {
  color: var(--orange);
  font-size: 15px;
}

.sem-rows-head,
.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px 64px 64px 28px;
  gap: 8px;
}

.sem-rows-head {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 0 2px 6px;
}

/* column alignment: MCs and S/U columns are centered, in both the
   header row and the data rows */
.sem-rows-head span:nth-child(3),
.sem-rows-head .su-col { text-align: center; }

.row {
  padding: 5px 0;
  border-top: 1px solid var(--border);
  align-items: start; /* tops align even when a module title hint appears */
}

/* every control shares the same height so rows line up cleanly */
.row > .grade-dd,
.row > .credits-input,
.row > .su-cell,
.row > .remove-btn,
.module-input {
  height: 37px;
}

.row.excluded .grade-trigger,
.row.excluded .credits-input {
  opacity: 0.55;
}

/* ---------- Inputs ---------- */

.module-cell { min-width: 0; position: relative; }

.module-input,
.credits-input,
.grade-trigger {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 9px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text);
  background: var(--card);
  transition: border-color 0.15s, box-shadow 0.15s;
}

.module-input { text-transform: uppercase; }
.module-input::placeholder { text-transform: none; }

.module-input:focus,
.credits-input:focus,
.grade-dd.open .grade-trigger,
.grade-trigger:focus-visible {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(239, 124, 0, 0.15);
}

/* ---------- Grade dropdown (custom, replaces native <select>) ---------- */

.grade-dd { position: relative; min-width: 0; }

.grade-trigger {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  padding: 0 9px;
  font-weight: 600;
  cursor: pointer;
}

/* caret */
.grade-trigger::after {
  content: "";
  flex-shrink: 0;
  width: 11px;
  height: 8px;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%236b7689' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") no-repeat center / contain;
  transition: transform 0.18s;
}

.grade-dd.open .grade-trigger::after { transform: rotate(180deg); }

.grade-menu {
  position: absolute;
  z-index: 90;
  top: calc(100% + 5px);
  left: 0;
  min-width: 100%;
  padding: 5px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(16, 30, 54, 0.18);
  max-height: 248px;
  overflow-y: auto;
  transform-origin: top;
  animation: dd-pop 0.14s ease;
}

@keyframes dd-pop {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to   { opacity: 1; transform: none; }
}

.grade-opt {
  display: flex;
  align-items: center;
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  line-height: 1.2;
  cursor: pointer;
}

.grade-opt + .grade-opt { margin-top: 1px; }

.grade-opt.active,
.grade-opt.selected { background: var(--hover-blue); }

.grade-opt.selected::after {
  content: "✓";
  margin-left: auto;
  padding-left: 8px;
  font-size: 11px;
  opacity: 0.8;
}

.module-title {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 2px 2px 0;
  min-height: 14px;
}

.credits-input { text-align: center; }
.credits-input::-webkit-outer-spin-button,
.credits-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.credits-input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

/* ---------- S/U toggle switch ---------- */

.su-cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center; /* switch sits centered under the S/U header */
}

.su-toggle {
  display: inline-flex;
  cursor: pointer;
  user-select: none;
}

.su-check {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.su-switch {
  width: 38px;
  height: 22px;
  border-radius: 11px;
  background: var(--switch-off);
  position: relative;
  transition: background 0.18s;
}

.su-switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(16, 30, 54, 0.3);
  transition: left 0.18s;
}

.su-check:checked + .su-switch {
  background: var(--orange);
}

.su-check:checked + .su-switch::after {
  left: 18px;
}

.su-check:focus-visible + .su-switch {
  box-shadow: 0 0 0 3px rgba(239, 124, 0, 0.25);
}

.su-toggle.disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.su-toggle.disabled .su-switch {
  background: var(--border);
}

.su-toggle.disabled .su-switch::after {
  background: var(--card);
  box-shadow: inset 0 0 0 1px var(--border);
}

.su-result {
  position: absolute;
  left: calc(50% + 23px);
  font-size: 11px;
  font-weight: 700;
}

.su-result.s { color: var(--green); }
.su-result.u { color: var(--red); }

/* ---------- Row buttons ---------- */

.remove-btn {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.remove-btn:hover { color: var(--red); background: var(--hover-red); }

.add-row-btn {
  margin-top: 8px;
  border: 1px dashed var(--border);
  background: none;
  color: var(--blue);
  border-radius: 8px;
  padding: 7px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

.add-row-btn:hover {
  border-color: var(--blue);
  background: var(--hover-blue);
}

/* ---------- Autocomplete ---------- */

.autocomplete {
  position: absolute;
  z-index: 100;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(16, 30, 54, 0.16);
  max-height: 290px;
  overflow-y: auto;
  min-width: 300px;
}

.ac-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
}

.ac-item.active { background: var(--hover-blue); }

.ac-code {
  font-weight: 700;
  color: var(--blue);
  flex-shrink: 0;
}

.ac-title {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.ac-badge {
  flex-shrink: 0;
  font-size: 10.5px;
  font-weight: 600;
  border-radius: 5px;
  padding: 2px 6px;
  background: var(--bg);
  color: var(--muted);
}

.ac-badge.su {
  background: #fdf0e2;
  color: var(--orange);
}

/* ---------- Dynamic island (floating GPA, visible while scrolling) ---------- */

.gpa-island {
  position: fixed;
  right: 18px;
  top: 50%;
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 138px;
  padding: 20px 16px;
  border-radius: 28px;
  background: rgba(16, 22, 34, 0.9);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(14px) saturate(120%);
  -webkit-backdrop-filter: blur(14px) saturate(120%);
  cursor: pointer;
  transform: translate(24px, -50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
}

.gpa-island.visible {
  opacity: 1;
  transform: translate(0, -50%);
  pointer-events: auto;
}

.gpa-island:hover {
  transform: translate(0, -50%) scale(1.04);
}

.island-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  opacity: 0.65;
}

.island-gpa {
  font-size: 42px;
  font-weight: 700;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

.island-class {
  font-size: 11.5px;
  font-weight: 600;
  color: #ffc98a;
  text-align: center;
  min-height: 14px;
  line-height: 1.25;
}

.island-progress {
  width: 100%;
  height: 5px;
  margin: 8px 0 4px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.18);
  overflow: hidden;
}

.island-progress-fill {
  height: 100%;
  width: 0;
  border-radius: 3px;
  background: var(--orange);
  transition: width 0.25s;
}

.island-mc {
  font-size: 11px;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}

@media (prefers-reduced-motion: reduce) {
  .gpa-island { transition: opacity 0.2s; }
  .gpa-island.visible,
  .gpa-island:hover { transform: translate(0, -50%); }
  .grade-menu { animation: none; }
  .grade-trigger::after { transition: none; }
}

/* ---------- Footer ---------- */

.footer {
  margin-top: 36px;
  font-size: 12px;
  color: var(--muted);
}

.footer a { color: var(--blue); }

.footer-source { margin-top: 14px; }

.footer .gh-link {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 600;
  background: var(--card);
  transition: border-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.footer .gh-link:hover {
  border-color: var(--blue);
  color: var(--blue);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.gh-icon { flex-shrink: 0; display: block; }

/* ---------- Responsive ---------- */

@media (max-width: 860px) {
  .year-grid { grid-template-columns: 1fr; }
  .summary { padding: 18px 20px; }
  .summary-gpa { font-size: 38px; }
  .summary-stats { gap: 18px; }
}

/* On narrow screens the side island would crowd the content, so it
   docks as a compact horizontal pill along the bottom edge instead. */
@media (max-width: 620px) {
  .gpa-island {
    right: 50%;
    top: auto;
    bottom: 14px;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    width: auto;
    max-width: calc(100vw - 28px);
    padding: 8px 16px;
    border-radius: 18px;
    transform: translate(50%, 24px);
  }
  .gpa-island.visible { transform: translate(50%, 0); }
  .gpa-island:hover { transform: translate(50%, 0) scale(1.03); }
  .island-gpa { font-size: 28px; }
  .island-label { display: none; }
  .island-progress {
    width: 54px;
    margin: 0;
    order: 3;
  }
  @media (prefers-reduced-motion: reduce) {
    .gpa-island.visible,
    .gpa-island:hover { transform: translate(50%, 0); }
  }
}

@media (max-width: 480px) {
  .sem-rows-head,
  .row { grid-template-columns: minmax(0, 1fr) 72px 48px 58px 24px; gap: 5px; }
  .page { padding: 18px 12px 40px; }
}
