/* =====================================================================
   KnowMyGPA — shared stylesheet
   Design language: clean, modern, trustworthy (Stripe / Linear).
   Mobile-first. Tokens drive light + dark themes.
   ===================================================================== */

/* ---------- Design tokens ---------- */
:root {
  --bg: #ffffff;
  --surface: #f8fafc;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-2: #64748b;
  --accent: #4f46e5;
  --accent-contrast: #ffffff;
  --accent-soft: rgba(79, 70, 229, 0.08);
  --success: #10b981;
  --warning: #f59e0b;
  --error: #ef4444;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;
  --sp-8: 64px;

  --r-input: 8px;
  --r-card: 12px;
  --r-hero: 16px;

  --sh-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --sh-md: 0 4px 6px rgba(0, 0, 0, 0.07);
  --sh-lg: 0 10px 15px rgba(0, 0, 0, 0.1);

  --maxw: 1080px;
  --maxw-prose: 720px;
  --header-h: 64px;
}

:root[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --border: #334155;
  --text: #f1f5f9;
  --text-2: #94a3b8;
  --accent: #818cf8;
  --accent-contrast: #0f172a;
  --accent-soft: rgba(129, 140, 248, 0.12);
  --sh-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --sh-md: 0 4px 6px rgba(0, 0, 0, 0.35);
  --sh-lg: 0 10px 20px rgba(0, 0, 0, 0.45);
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3 {
  line-height: 1.2;
  letter-spacing: -0.02em;
  margin: 0 0 var(--sp-4);
  font-weight: 700;
}

h1 {
  font-size: 2.25rem;
}
h2 {
  font-size: 1.5rem;
}
h3 {
  font-size: 1.25rem;
}

p {
  margin: 0 0 var(--sp-4);
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

img,
svg {
  display: block;
  max-width: 100%;
}

small {
  font-size: 0.875rem;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.container {
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding-left: var(--sp-5);
  padding-right: var(--sp-5);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--sp-3);
  top: -60px;
  background: var(--accent);
  color: var(--accent-contrast);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--r-input);
  z-index: 100;
  transition: top 0.15s ease;
}
.skip-link:focus {
  top: var(--sp-3);
}

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: saturate(180%) blur(8px);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.site-header.is-stuck {
  border-bottom-color: var(--border);
  box-shadow: var(--sh-sm);
}
.header-inner {
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  height: var(--header-h);
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 700;
  font-size: 1.125rem;
  letter-spacing: -0.02em;
  color: var(--text);
}
.brand:hover {
  text-decoration: none;
}
.brand img {
  width: 28px;
  height: 28px;
}
.brand .dot {
  color: var(--accent);
}

.nav {
  display: none;
  margin-left: auto;
  align-items: center;
  gap: var(--sp-5);
}
.nav a {
  color: var(--text-2);
  font-size: 0.9375rem;
  font-weight: 500;
}
.nav a:hover,
.nav a[aria-current="page"] {
  color: var(--text);
  text-decoration: none;
}

.header-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.nav + .header-actions {
  margin-left: var(--sp-5);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--r-input);
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.icon-btn:hover {
  background: var(--surface-2);
}
.icon-btn svg {
  width: 20px;
  height: 20px;
}

/* theme toggle: show the icon for the action the user can take */
.theme-toggle .icon-moon {
  display: block;
}
.theme-toggle .icon-sun {
  display: none;
}
:root[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}
:root[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

.nav-toggle {
  display: inline-flex;
}

/* mobile nav drawer */
@media (max-width: 819px) {
  .nav {
    position: fixed;
    inset: var(--header-h) 0 auto 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    margin: 0;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--sh-lg);
    padding: var(--sp-2) var(--sp-5) var(--sp-4);
    transform: translateY(-12px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
  }
  .nav.is-open {
    display: flex;
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
  }
  .nav a {
    padding: var(--sp-3) 0;
    border-bottom: 1px solid var(--border);
    font-size: 1rem;
  }
  .nav a:last-child {
    border-bottom: 0;
  }
}

@media (min-width: 820px) {
  .nav {
    display: flex;
  }
  .nav-toggle {
    display: none;
  }
}

/* ---------- Hero + breadcrumb ---------- */
.hero {
  padding: var(--sp-6) 0 var(--sp-5);
}
.breadcrumb {
  font-size: 0.8125rem;
  color: var(--text-2);
  margin-bottom: var(--sp-4);
}
.breadcrumb ol {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin: 0;
  padding: 0;
}
.breadcrumb li::after {
  content: "/";
  margin-left: var(--sp-2);
  color: var(--border);
}
.breadcrumb li:last-child::after {
  content: "";
}
.breadcrumb a {
  color: var(--text-2);
}
.hero h1 {
  max-width: 18ch;
}
.hero .subhead {
  font-size: 1.125rem;
  color: var(--text-2);
  max-width: var(--maxw-prose);
  margin-bottom: var(--sp-6);
}

/* ---------- Calculator card ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-hero);
  box-shadow: var(--sh-md);
  padding: var(--sp-5);
  max-width: 640px;
}
.card.is-centered {
  margin-left: auto;
  margin-right: auto;
}
@media (min-width: 600px) {
  .card {
    padding: var(--sp-6);
  }
}

.calc-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.calc-head h2 {
  font-size: 1.125rem;
  margin: 0;
}

/* rows */
.rows {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.row {
  display: grid;
  gap: var(--sp-2);
  align-items: end;
}
/* default GPA layout: name | grade | credits | remove */
.row.row-gpa {
  grid-template-columns: 1fr;
}
.row .field-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: var(--sp-1);
  display: block;
}
.rows-head {
  display: none;
}

@media (min-width: 560px) {
  .row.row-gpa {
    grid-template-columns: 1fr 7.5rem 7rem 2.5rem;
  }
  .row.row-weighted {
    grid-template-columns: 1fr 6.5rem 7.5rem 6rem 2.5rem;
  }
  .row.row-cumulative {
    grid-template-columns: 1fr 7rem 7rem 2.5rem;
  }
  .row.row-grade {
    grid-template-columns: 1fr 7rem 7rem 2.5rem;
  }
  /* labels become a single header row on wider screens */
  .rows-head {
    display: grid;
    gap: var(--sp-2);
    padding: 0 0 var(--sp-1);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-2);
  }
  .rows-head.row-gpa {
    grid-template-columns: 1fr 7.5rem 7rem 2.5rem;
  }
  .rows-head.row-weighted {
    grid-template-columns: 1fr 6.5rem 7.5rem 6rem 2.5rem;
  }
  .rows-head.row-cumulative {
    grid-template-columns: 1fr 7rem 7rem 2.5rem;
  }
  .rows-head.row-grade {
    grid-template-columns: 1fr 7rem 7rem 2.5rem;
  }
  .row .field-label {
    display: none;
  }
}

/* ---------- Inputs ---------- */
.input,
.select {
  width: 100%;
  height: 44px;
  padding: 0 var(--sp-3);
  font: inherit;
  font-size: 0.9375rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--r-input);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}
.input::placeholder {
  color: var(--text-2);
  opacity: 0.7;
}
.input:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}
.input[type="number"]::-webkit-outer-spin-button,
.input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.input.input-num {
  text-align: center;
  font-family: var(--font-mono);
}
.select {
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right var(--sp-3) center;
  background-size: 16px;
  padding-right: var(--sp-7);
  cursor: pointer;
}

/* number stepper */
.stepper {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--r-input);
  background: var(--bg);
  overflow: hidden;
  height: 44px;
}
.stepper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.stepper input {
  width: 100%;
  border: 0;
  text-align: center;
  font: inherit;
  font-size: 0.9375rem;
  color: var(--text);
  background: transparent;
  -moz-appearance: textfield;
  appearance: textfield;
}
.stepper input:focus {
  outline: none;
}
.stepper input::-webkit-outer-spin-button,
.stepper input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.stepper-btn {
  border: 0;
  background: var(--surface-2);
  color: var(--text);
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.12s ease;
}
.stepper-btn:hover {
  background: var(--border);
}
.stepper-btn:active {
  transform: translateY(1px);
}

/* remove row button */
.row-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 44px;
  border: 0;
  background: transparent;
  color: var(--text-2);
  border-radius: var(--r-input);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease, opacity 0.12s ease;
}
.row-remove:hover {
  background: color-mix(in srgb, var(--error) 12%, transparent);
  color: var(--error);
}
.row-remove svg {
  width: 18px;
  height: 18px;
}
@media (min-width: 560px) and (hover: hover) {
  .row .row-remove {
    opacity: 0;
  }
  .row:hover .row-remove,
  .row:focus-within .row-remove {
    opacity: 1;
  }
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 44px;
  padding: 0 var(--sp-5);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  border-radius: var(--r-input);
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.15s ease,
    border-color 0.15s ease, box-shadow 0.15s ease;
}
.btn svg {
  width: 18px;
  height: 18px;
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
}
.btn-primary:hover {
  text-decoration: none;
  transform: translateY(-1px);
  box-shadow: var(--sh-md);
}
.btn-secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
.btn-secondary:hover {
  text-decoration: none;
  border-color: var(--accent);
  color: var(--accent);
}
.btn-block {
  width: 100%;
}
.btn-add {
  margin-top: var(--sp-4);
  border-style: dashed;
}

/* ---------- Results panel ---------- */
.results {
  margin-top: var(--sp-5);
  padding-top: var(--sp-5);
  border-top: 1px solid var(--border);
  text-align: center;
}
.result-label {
  font-size: 0.875rem;
  color: var(--text-2);
  margin-bottom: var(--sp-1);
}
.result-value {
  font-family: var(--font-mono);
  font-size: 3rem;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.03em;
  color: var(--text);
}
.result-value.is-good {
  color: var(--success);
}
.result-value.is-ok {
  color: var(--warning);
}
.result-value.is-low {
  color: var(--error);
}
.result-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--sp-2) var(--sp-5);
  margin-top: var(--sp-4);
}
.stat {
  font-size: 0.875rem;
  color: var(--text-2);
}
.stat b {
  color: var(--text);
  font-weight: 600;
  font-family: var(--font-mono);
}
.calc-hint {
  margin: var(--sp-3) 0 0;
  font-size: 0.875rem;
  color: var(--text-2);
}
.calc-message {
  margin-top: var(--sp-4);
  padding: var(--sp-3) var(--sp-4);
  border-radius: var(--r-input);
  font-size: 0.9375rem;
  background: var(--surface-2);
  color: var(--text);
}
.calc-message.is-good {
  background: color-mix(in srgb, var(--success) 12%, transparent);
}
.calc-message.is-ok {
  background: color-mix(in srgb, var(--warning) 14%, transparent);
}
.calc-message.is-low {
  background: color-mix(in srgb, var(--error) 12%, transparent);
}
.weight-note {
  margin-top: var(--sp-3);
  font-size: 0.8125rem;
  color: var(--warning);
}

/* simple field stack (final-grade page) */
.field-stack {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}
.field label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: var(--sp-2);
}
.field .hint {
  font-size: 0.8125rem;
  color: var(--text-2);
  font-weight: 400;
}

/* ---------- Content sections ---------- */
.section {
  padding: var(--sp-7) 0;
  border-top: 1px solid var(--border);
}
.section:first-of-type {
  border-top: 0;
}
.prose {
  max-width: var(--maxw-prose);
}
.prose p,
.prose li {
  color: var(--text);
}
.prose ul {
  padding-left: var(--sp-5);
}

.formula {
  display: block;
  font-family: var(--font-mono);
  font-size: 0.9375rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-input);
  padding: var(--sp-4);
  margin: var(--sp-4) 0;
  overflow-x: auto;
  white-space: pre-wrap;
  color: var(--text);
}
.example {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: var(--sp-4) var(--sp-5);
  margin: var(--sp-5) 0;
}
.example h3 {
  margin-top: 0;
  font-size: 1rem;
}

/* scale table */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-card);
}
table.scale {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9375rem;
}
table.scale th,
table.scale td {
  text-align: left;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
}
table.scale thead th {
  background: var(--surface);
  font-weight: 600;
  color: var(--text-2);
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
table.scale tbody tr:last-child td {
  border-bottom: 0;
}
table.scale td:first-child {
  font-family: var(--font-mono);
  font-weight: 600;
}

/* FAQ (native details) */
.faq-list {
  max-width: var(--maxw-prose);
}
.faq {
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  background: var(--surface);
  margin-bottom: var(--sp-3);
  overflow: hidden;
}
.faq > summary {
  list-style: none;
  cursor: pointer;
  padding: var(--sp-4) var(--sp-5);
  font-weight: 600;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}
.faq > summary::-webkit-details-marker {
  display: none;
}
.faq > summary::after {
  content: "";
  flex: none;
  width: 12px;
  height: 12px;
  border-right: 2px solid var(--text-2);
  border-bottom: 2px solid var(--text-2);
  transform: rotate(45deg);
  transition: transform 0.18s ease;
}
.faq[open] > summary::after {
  transform: rotate(-135deg);
}
.faq > .faq-body {
  padding: 0 var(--sp-5) var(--sp-5);
  color: var(--text-2);
}
.faq > .faq-body p:last-child {
  margin-bottom: 0;
}

/* related cards */
.related-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-4);
}
@media (min-width: 560px) {
  .related-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (min-width: 900px) {
  .related-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}
.related-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: var(--sp-5);
  color: var(--text);
  transition: transform 0.12s ease, border-color 0.15s ease,
    box-shadow 0.15s ease;
}
.related-card:hover {
  text-decoration: none;
  transform: translateY(-2px);
  border-color: var(--accent);
  box-shadow: var(--sh-md);
}
.related-card .ic {
  display: inline-flex;
  width: 40px;
  height: 40px;
  align-items: center;
  justify-content: center;
  border-radius: var(--r-input);
  background: var(--accent-soft);
  color: var(--accent);
  margin-bottom: var(--sp-3);
}
.related-card .ic svg {
  width: 22px;
  height: 22px;
}
.related-card h3 {
  font-size: 1rem;
  margin-bottom: var(--sp-1);
}
.related-card p {
  margin: 0;
  font-size: 0.875rem;
  color: var(--text-2);
}

/* ---------- Footer ---------- */
.site-footer {
  margin-top: var(--sp-8);
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.footer-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-6);
  padding: var(--sp-7) 0 var(--sp-6);
}
@media (min-width: 700px) {
  .footer-grid {
    grid-template-columns: 1.4fr 1fr 1fr;
  }
}
.footer-grid h4 {
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-2);
  margin: 0 0 var(--sp-4);
}
.footer-grid ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}
.footer-grid a {
  color: var(--text-2);
  font-size: 0.9375rem;
}
.footer-grid a:hover {
  color: var(--text);
}
.footer-about p {
  color: var(--text-2);
  font-size: 0.9375rem;
  max-width: 32ch;
}
.footer-bottom {
  border-top: 1px solid var(--border);
  padding: var(--sp-4) 0;
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  align-items: center;
  justify-content: space-between;
  font-size: 0.875rem;
  color: var(--text-2);
}
.footer-social {
  display: flex;
  gap: var(--sp-3);
}
.footer-social a {
  color: var(--text-2);
}
.footer-social svg {
  width: 20px;
  height: 20px;
}

/* ---------- Utilities ---------- */
.mt-0 {
  margin-top: 0;
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
