/* Course GPA — the one calculator at /. Loads after site.css.
   Apple tokens from DESIGN.md; one definition per selector per context. */

body {
  background: var(--parchment);
}

.calc-page {
  width: min(100% - 2rem, var(--wrap-wide));
  margin: 0 auto;
  padding: 1rem 0 2rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.calc-page .field input,
.calc-page .field select,
.calc-page .search-input {
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
}

.calc-page .field label {
  margin-bottom: 4px;
}

/* ---------- heading + school chip ---------- */

.head-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.75rem;
}

.head-copy h1 {
  margin: 0 0 4px;
  font-size: clamp(1.5rem, 4vw, 27px);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.head-sub {
  margin: 0;
  color: var(--ink-muted-80);
  font-size: 15px;
  letter-spacing: -0.224px;
}

.school-wrap {
  position: relative;
}

.school-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--hairline);
  border-radius: var(--pill);
  background: var(--canvas);
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
  letter-spacing: -0.224px;
  cursor: pointer;
}

.chip-icon {
  flex: none;
  font-size: 15px;
  line-height: 1;
}

.chip-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: left;
}

.chip-text b {
  font-weight: 600;
}

.chip-action {
  flex: none;
  margin-left: auto;
  color: var(--primary);
}

.school-pop {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  right: 0;
  left: 0;
  padding: 0.85rem 1rem 0.9rem;
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-lg);
}

.school-pop[hidden] {
  display: none;
}

.pop-foot {
  margin: 0.5rem 0 0;
}

.pop-foot[hidden] {
  display: none;
}

/* ---------- school combobox ---------- */

.combo-list {
  margin: 0.45rem 0 0;
  padding: 0;
  max-height: min(46vh, 20rem);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  list-style: none;
}

.combo-list[hidden] {
  display: none;
}

.combo-list li {
  margin: 0;
}

.result-heading {
  padding: 0.7rem 0.15rem 0.2rem;
  color: var(--ink-muted-48);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -0.12px;
}

.opt {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 0.5rem 0.6rem;
  border: 0;
  border-bottom: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 17px;
  text-align: left;
  cursor: pointer;
}

.opt[aria-selected="true"] {
  background: var(--parchment);
}

.opt-name {
  display: block;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.opt-meta {
  display: block;
  margin-top: 0.1rem;
  color: var(--ink-muted-48);
  font-size: 12px;
  letter-spacing: -0.12px;
}

.opt-empty {
  margin: 0.5rem 0 0;
  color: var(--ink-muted-48);
  font-size: 14px;
}

/* ---------- notices ---------- */

.error-note,
.notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem 0.6rem;
  color: var(--ink-muted-80);
  font-size: 14px;
  letter-spacing: -0.224px;
}

.error-note {
  margin: 0.6rem 0 0;
}

.notice {
  margin: 0;
  padding: 0.4rem 0.85rem;
  background: var(--parchment);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
}

.error-note[hidden],
.notice[hidden] {
  display: none;
}

.link-btn {
  min-width: 44px;
  min-height: 44px;
  padding: 0 0.1rem;
  border: 0;
  background: none;
  color: var(--primary);
  font-family: inherit;
  font-size: 14px;
  letter-spacing: -0.224px;
  cursor: pointer;
}

/* ---------- pinned head (mobile) ---------- */

.dock {
  position: sticky;
  top: 52px;
  z-index: 14;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin: 0 -1rem;
  padding: 0.7rem 1rem 0.6rem;
  background: var(--canvas);
  border-bottom: 1px solid var(--hairline);
}

.dock-plan {
  text-align: right;
}

.dock-value {
  display: block;
  font-size: 1.75rem;
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.dock-value[data-empty="true"] {
  color: var(--ink-muted-48);
  font-weight: 500;
}

.dock-after {
  display: block;
  font-size: 1.375rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.dock-note {
  display: block;
  color: var(--ink-muted-80);
  font-size: 12px;
  letter-spacing: -0.12px;
}

/* ---------- layout ---------- */

.calc-grid {
  display: grid;
  align-items: start;
  gap: 1rem;
}

.panels {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.calc-page .panel {
  margin: 0;
  padding: 0.9rem 1.15rem 0.75rem;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding-bottom: 0.35rem;
}

.panel-head h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.panel-foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem 0.85rem;
  padding-top: 0.35rem;
}

.foot-end {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
}

.add-btn {
  min-height: 44px;
  padding: 0 0.1rem;
  border: 0;
  background: none;
  color: var(--primary);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.224px;
  cursor: pointer;
}

.plan-hint {
  margin: 0.2rem 0 0.4rem;
  color: var(--ink-muted-48);
  font-size: 14px;
}

.plan-hint[hidden] {
  display: none;
}

/* ---------- rows ---------- */

.row-head {
  display: none;
}

.rows {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 0;
  list-style: none;
}

.rows-empty {
  margin: 0;
  padding: 0.8rem 0;
  color: var(--ink-muted-48);
  font-size: 14px;
}

.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px 72px;
  gap: 0.5rem;
  align-items: end;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--hairline);
}

.row:last-child {
  border-bottom: 0;
}

.cell {
  min-width: 0;
}

.cell-course {
  position: relative;
  grid-column: 1;
}

.cell-letter {
  grid-column: 2;
}

.cell-credits {
  grid-column: 3;
}

.cell input,
.cell select {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
  background: var(--canvas);
  color: var(--ink);
  font-family: inherit;
  font-size: 17px;
  letter-spacing: -0.374px;
}

.cell input:focus,
.cell select:focus {
  border-color: var(--primary);
}

.cell-points {
  display: none;
}

.points {
  display: flex;
  align-items: center;
  min-height: 44px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.points[data-empty="true"] {
  color: var(--ink-muted-48);
}

.cell-type {
  display: none;
}

.row.is-weighted .cell-type {
  display: block;
  grid-column: 1 / -1;
}

.cell-actions {
  display: flex;
  grid-column: 1 / -1;
  align-items: center;
  justify-content: flex-end;
  gap: 0.25rem;
}

.move-btn {
  min-height: 44px;
  padding: 0 0.35rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--ink-muted-48);
  font-family: inherit;
  font-size: 12px;
  letter-spacing: -0.12px;
  cursor: pointer;
}

.remove-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--ink-muted-48);
  font-family: inherit;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

/* ---------- term groups ---------- */

.term-group + .term-group {
  margin-top: 0.5rem;
}

.term-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.5rem 0 0.3rem;
  border-bottom: 1px solid var(--hairline);
}

.term-select {
  min-height: 44px;
  padding: 4px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-muted-48);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: -0.12px;
  text-transform: uppercase;
  cursor: pointer;
}

.term-select:focus {
  border-color: var(--primary);
}

/* ---------- course typeahead ---------- */

.typeahead {
  position: absolute;
  z-index: 12;
  top: calc(100% + 4px);
  right: 0;
  left: 0;
  max-height: min(40vh, 18rem);
  margin: 0;
  padding: 0;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--canvas);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
}

.typeahead[hidden] {
  display: none;
}

.hit {
  display: grid;
  grid-template-columns: 6.5rem minmax(0, 1fr) auto;
  align-items: baseline;
  gap: 0.15rem 0.6rem;
  width: 100%;
  min-height: 44px;
  padding: 0.45rem 0.75rem;
  border: 0;
  border-bottom: 1px solid var(--divider-soft);
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}

.hit:last-child {
  border-bottom: 0;
}

.hit[aria-selected="true"] {
  background: var(--parchment);
}

.hit-code {
  overflow: hidden;
  font-weight: 600;
  letter-spacing: -0.016em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hit-name {
  min-width: 0;
  overflow: hidden;
  color: var(--ink-muted-80);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hit-meta {
  color: var(--ink-muted-48);
  font-size: 14px;
  white-space: nowrap;
}

.hit-add .hit-code {
  color: var(--primary);
}

.hit-empty {
  margin: 0;
  padding: 0.6rem 0.75rem;
  color: var(--ink-muted-48);
  font-size: 14px;
}

/* ---------- result card ---------- */

.result-card {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.now-block {
  display: none;
}

.now-value {
  display: block;
  font-size: 2.25rem;
  font-weight: 600;
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.now-value[data-empty="true"] {
  color: var(--ink-muted-48);
  font-weight: 500;
}

.formula {
  margin: 0.2rem 0 0;
  padding: 0;
  background: none;
  color: var(--ink-muted-80);
  font-size: 14px;
  letter-spacing: -0.224px;
}

.rule {
  height: 1px;
  background: var(--hairline);
}

.plan-summary {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.plan-summary[hidden],
.plan-summary[hidden] + .chips {
  display: none;
}

.plan-lines {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.plan-line {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  color: var(--ink-muted-80);
  font-size: 14px;
  letter-spacing: -0.224px;
}

.plan-after {
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.plan-open {
  color: var(--ink-muted-48);
}

.chips {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.5rem;
}

.chips[hidden] {
  display: none;
}

.chip {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-md);
}

.chip.is-native {
  border-color: var(--primary);
}

.chip-name {
  color: var(--ink-muted-48);
  font-size: 12px;
  letter-spacing: -0.12px;
}

.chip.is-native .chip-name {
  color: var(--primary);
}

.chip-gpa {
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.pair-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.6rem;
}

.target-block {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.target-block .field {
  max-width: 9rem;
}

.need-line {
  margin: 0;
  font-size: 17px;
  line-height: 1.35;
}

.need-line strong {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.need-line[data-state="idle"] {
  color: var(--ink-muted-48);
  font-size: 14px;
}

.need-line[data-state="impossible"] strong {
  color: var(--err);
}

.card-actions {
  display: none;
}

.disclaimer {
  margin: 0;
  color: var(--ink-muted-48);
  font-size: 14px;
  letter-spacing: -0.224px;
}

/* ---------- fixed bar (mobile) ---------- */

.mobile-bar {
  position: sticky;
  bottom: 0;
  z-index: 15;
  display: flex;
  gap: 0.6rem;
  padding: 0.6rem 1rem calc(0.7rem + env(safe-area-inset-bottom, 0px));
  background: rgba(245, 245, 247, 0.92);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--hairline);
}

.mobile-bar .btn {
  flex: 1;
  min-height: 44px;
}

.mobile-bar .btn-ghost {
  flex: 0 0 auto;
  padding: 0 18px;
}

/* ---------- desktop ---------- */

@media (min-width: 900px) {
  .calc-page {
    padding-top: 2rem;
    gap: 1rem;
  }

  .head-row {
    flex-direction: row;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1.5rem;
  }

  .head-sub {
    font-size: 17px;
  }

  .school-wrap {
    flex: 0 0 auto;
    max-width: 22rem;
  }

  .school-chip {
    width: auto;
    min-height: 40px;
  }

  .school-pop {
    right: 0;
    left: auto;
    width: 24rem;
  }

  .dock {
    display: none;
  }

  .calc-grid {
    grid-template-columns: minmax(0, 1fr) 22.5rem;
    gap: 1.5rem;
  }

  .row-head {
    display: grid;
    grid-template-columns: minmax(0, 1.6fr) 120px 110px 64px 104px;
    gap: 0.75rem;
    padding: 0.2rem 0 0.4rem;
    color: var(--ink-muted-48);
    font-size: 12px;
    letter-spacing: -0.12px;
  }

  .row {
    grid-template-columns: minmax(0, 1.6fr) 120px 110px 64px 104px;
    gap: 0.75rem;
    padding: 0.55rem 0;
  }

  .cell-points {
    display: block;
    grid-column: 4;
  }

  .row.is-weighted .cell-type {
    grid-column: 2 / -1;
    grid-row: 2;
    max-width: 15rem;
  }

  .cell-actions {
    grid-column: 5;
    grid-row: 1;
    justify-content: flex-end;
    gap: 0;
  }

  .move-btn {
    min-height: 36px;
  }

  .term-select {
    min-height: 36px;
  }

  .now-block {
    display: block;
  }

  .result-card {
    position: sticky;
    top: calc(52px + 1.25rem);
    gap: 0.9rem;
  }

  .card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
  }

  .card-actions .btn {
    min-height: 40px;
  }

  .mobile-bar {
    display: none;
  }
}

/* ---------- pointer ---------- */

@media (hover: hover) and (pointer: fine) {
  .opt:hover,
  .hit:hover {
    background: var(--parchment);
  }

  .school-chip:hover {
    background: var(--pearl);
  }

  .link-btn:hover,
  .add-btn:hover {
    text-decoration: underline;
  }

  .remove-btn:hover,
  .move-btn:hover {
    color: var(--ink);
  }
}

/* ---------- print ---------- */

@media print {
  .site-head,
  .site-foot,
  .skip,
  .dock,
  .mobile-bar,
  .school-chip,
  .school-pop,
  .notice,
  .card-actions,
  .cell-actions,
  .panel-foot,
  .plan-hint,
  .typeahead {
    display: none;
  }

  body {
    background: var(--canvas);
  }

  .calc-grid {
    display: block;
  }

  .result-card,
  .calc-page .panel {
    position: static;
    padding: 0;
    border: 0;
  }

  .now-block {
    display: block;
  }
}

/* Reserve three rows so deferred JS does not shift the page (CLS). */
#taken-rows {
  min-height: 186px;
}
