/* ClassCalc v3 stylesheet.
   Six colour tokens, two typefaces, one animation. Cyan, amber and coral
   appear only where they signal a state (healthy, tight, short). Everything
   else is moon on ink at some opacity. No shadows, no gradients. */

:root {
  --ink: #070B12;
  --surface: #0E1622;
  --moon: #E8EDF2;
  --cyan: #37E8FF;
  --amber: #FFB020;
  --coral: #FF4D5E;

  /* Derived from moon, never a separate grey. */
  --muted: rgba(232, 237, 242, 0.62);
  --faint: rgba(232, 237, 242, 0.38);
  --rule: rgba(232, 237, 242, 0.12);
  --rule-strong: rgba(232, 237, 242, 0.24);

  --sans: "IBM Plex Sans", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "IBM Plex Mono", Consolas, "Liberation Mono", Menlo, monospace;

  /* Type scale */
  --fs-pct-hero: clamp(4.5rem, 24vw, 8.5rem);
  --fs-pct-card: 2.75rem;
  --fs-stat: 1.75rem;
  --fs-h1: clamp(1.75rem, 7vw, 2.75rem);
  --fs-h2: 1.375rem;
  --fs-h3: 1.0625rem;
  --fs-body: 1.0625rem;
  --fs-input: 1.5rem;
  --fs-small: 0.875rem;
  --fs-line: 0.9375rem;

  /* Rhythm, 4px unit */
  --s-1: 4px;
  --s-2: 8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-6: 24px;
  --s-8: 32px;
  --s-10: 40px;
  --s-16: 64px;

  --radius: 4px;
  --radius-card: 6px;
  --measure: 66rem;

  /* State colour, overridden per [data-status] */
  --state: var(--cyan);

  --tween: 320ms;
  --ease: cubic-bezier(0.2, 0, 0, 1);
}

/* ---------------------------------------------------------------- base */

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

html {
  background: var(--ink);
  color-scheme: dark;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--ink);
  color: var(--moon);
  font-family: var(--sans);
  font-size: var(--fs-body);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

h1, h2, h3, p, dl, dd, dt, ol, ul, figure { margin: 0; }

a { color: var(--moon); text-decoration-thickness: 1px; text-underline-offset: 0.15em; }
a:hover { text-decoration-thickness: 2px; }

button, input { font: inherit; color: inherit; }

::selection { background: var(--moon); color: var(--ink); }

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

.mono, .num, .pct, .hours, .stats dd, .steps li::before, .visit-counter .mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.sr-only {
  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(--s-4);
  top: -100px;
  padding: var(--s-2) var(--s-3);
  background: var(--moon);
  color: var(--ink);
  border-radius: var(--radius);
  z-index: 100;
}
.skip-link:focus { top: var(--s-4); }

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

.wrap {
  width: 100%;
  max-width: calc(var(--measure) + 2 * var(--s-4));
  margin: 0 auto;
  padding-left: max(var(--s-4), env(safe-area-inset-left));
  padding-right: max(var(--s-4), env(safe-area-inset-right));
}

.site-header {
  padding-top: var(--s-6);
  padding-bottom: var(--s-2);
}

.wordmark {
  font-weight: 600;
  font-size: 1.125rem;
  letter-spacing: -0.01em;
  color: var(--cyan);
  text-decoration: none;
}

main > section {
  padding: var(--s-10) 0;
  border-top: 1px solid var(--rule);
}
main > section.hero {
  border-top: 0;
  padding-top: var(--s-6);
  padding-bottom: var(--s-10);
}

h1 {
  font-size: var(--fs-h1);
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.02em;
  max-width: 18ch;
  text-wrap: balance;
}

h2 {
  font-size: var(--fs-h2);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin-bottom: var(--s-4);
}

h3 {
  font-size: var(--fs-h3);
  font-weight: 600;
  line-height: 1.3;
}

.lede {
  margin-top: var(--s-4);
  color: var(--muted);
  max-width: 62ch;
}

.prose p { max-width: 62ch; }
.prose p + p { margin-top: var(--s-3); }

.note {
  font-size: var(--fs-small);
  color: var(--muted);
  max-width: 62ch;
}

/* -------------------------------------------------------------- fields */

.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-3);
}

.field label {
  display: block;
  font-size: var(--fs-small);
  font-weight: 500;
  color: var(--muted);
  margin-bottom: var(--s-1);
}

.field input {
  display: block;
  width: 100%;
  min-height: 56px;
  padding: var(--s-2) var(--s-3);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  color: var(--moon);
  outline-offset: 2px;
}
.field input.num {
  font-family: var(--mono);
  font-size: var(--fs-input);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}
.field input::placeholder { color: var(--faint); }
.field input:focus { border-color: var(--rule-strong); }
.field input[aria-invalid="true"] { border-color: var(--coral); }

/* Hide the spinner; the values are typed. */
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; }

.form-error {
  margin-top: var(--s-2);
  font-size: var(--fs-small);
  color: var(--coral);
}
.form-error[hidden] { display: none; }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 var(--s-4);
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-weight: 500;
  font-size: 1rem;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  background: none;
  -webkit-tap-highlight-color: transparent;
}
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.4; cursor: default; }

.btn-primary {
  background: var(--cyan);
  color: var(--ink);
  border-color: var(--cyan);
}
.btn-primary:hover { background: var(--moon); border-color: var(--moon); }

.btn-ghost {
  background: transparent;
  color: var(--moon);
  border-color: var(--rule-strong);
}
.btn-ghost:hover { border-color: var(--moon); }

.btn-small {
  min-height: 36px;
  padding: 0 var(--s-3);
  font-size: var(--fs-small);
}

.btn-block { width: 100%; }

.actions {
  display: flex;
  gap: var(--s-2);
  flex-wrap: wrap;
}
.actions .btn { flex: 1 1 auto; }

/* ---------------------------------------------------------------- hero */

.calc { margin-top: var(--s-8); }

.hero .form-error:not([hidden]) + .result { margin-top: var(--s-4); }

.result {
  --state: var(--cyan);
  margin-top: var(--s-8);
}
.result[data-status="healthy"] { --state: var(--cyan); }
.result[data-status="tight"] { --state: var(--amber); }
.result[data-status="short"] { --state: var(--coral); }
.result[data-status="empty"] { --state: var(--faint); }

.pct {
  color: var(--state);
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.04em;
  display: flex;
  align-items: baseline;
}
.pct-unit {
  font-size: 0.4em;
  margin-left: 0.08em;
  letter-spacing: 0;
  color: var(--muted);
}
.pct-hero {
  font-size: var(--fs-pct-hero);
  /* Reserve the line so the font swap cannot move anything below it. */
  min-height: var(--fs-pct-hero);
}
.pct-card { font-size: var(--fs-pct-card); letter-spacing: -0.03em; }

.result[data-status="empty"] .pct-unit { color: var(--faint); }

.status-line {
  margin-top: var(--s-3);
  font-size: 1.125rem;
  line-height: 1.4;
  max-width: 34ch;
  text-wrap: balance;
}
.hero .status-line { font-size: 1.1875rem; }

.hours {
  margin-top: var(--s-2);
  color: var(--muted);
  font-size: 1rem;
}

/* Progress bar with the target drawn on it. */
.bar {
  position: relative;
  margin-top: var(--s-4);
  padding-bottom: 1.4rem; /* room for the label under the tick */
}
.bar-track {
  position: relative;
  height: 6px;
  background: var(--rule);
  border-radius: 3px;
  overflow: visible;
}
.bar-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: var(--state);
  border-radius: 3px;
  transition: width var(--tween) var(--ease);
}
.bar-tick {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 2px;
  margin-left: -1px;
  background: var(--moon);
}
.bar-label {
  position: absolute;
  top: 14px;
  transform: translateX(-100%);
  font-size: 0.75rem;
  color: var(--muted);
  white-space: nowrap;
  padding-right: 6px;
}

.trust {
  margin-top: var(--s-6);
  font-size: var(--fs-small);
  color: var(--muted);
}

.field-name { margin-top: var(--s-4); }
.field-name[hidden] { display: none; }

.hero .actions { margin-top: var(--s-4); }

/* -------------------------------------------------------------- target */

.segmented {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--s-1);
  padding: var(--s-1);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
}
.seg {
  min-height: 44px;
  border: 0;
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font-family: var(--mono);
  font-weight: 500;
  font-size: 1rem;
  cursor: pointer;
}
.seg[data-target="custom"] { font-family: var(--sans); }
.seg .unit { font-size: 0.75em; margin-left: 1px; }
.seg[aria-checked="true"] {
  background: var(--moon);
  color: var(--ink);
}
.seg:focus-visible { outline-offset: -2px; }

.field-custom { margin-top: var(--s-3); max-width: 12rem; }
.field-custom[hidden] { display: none; }

.bands {
  margin-top: var(--s-4);
  display: flex;
  flex-wrap: wrap;
  gap: var(--s-1) var(--s-4);
  font-size: var(--fs-small);
  color: var(--muted);
}
.bands div { display: flex; gap: var(--s-2); }
.bands dt { font-family: var(--mono); color: var(--moon); }

/* --------------------------------------------------------------- cards */

.empty {
  color: var(--muted);
  max-width: 62ch;
}
.empty[hidden] { display: none; }

.subject-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--s-3);
}
.subject-grid:empty { display: none; }

#add-another { margin-top: var(--s-4); }
#add-another[hidden] { display: none; }

.card {
  --state: var(--cyan);
  background: var(--surface);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--state);
  border-radius: var(--radius-card);
  padding: var(--s-4);
}
.card[data-status="healthy"] { --state: var(--cyan); }
.card[data-status="tight"] { --state: var(--amber); }
.card[data-status="short"] { --state: var(--coral); }
.card[data-status="empty"] { --state: var(--faint); }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--s-3);
  margin-bottom: var(--s-3);
}
.card-name {
  overflow-wrap: anywhere;
  padding-top: 6px;
}
.card-tools { display: flex; gap: var(--s-1); flex-shrink: 0; }

.card .pct-card { margin-top: var(--s-1); }
.card .bar { margin-top: var(--s-3); padding-bottom: var(--s-1); }
.card .status-line { font-size: 1.0625rem; margin-top: var(--s-2); }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-3);
  margin-top: var(--s-4);
  padding-top: var(--s-3);
  border-top: 1px solid var(--rule);
}
.stats dt {
  font-size: var(--fs-small);
  font-weight: 500;
  color: var(--muted);
}
.stats dd {
  font-size: var(--fs-stat);
  font-weight: 500;
  line-height: 1.2;
  margin-top: var(--s-1);
}

.consequence {
  margin-top: var(--s-3);
  font-size: var(--fs-line);
  color: var(--muted);
  max-width: 40ch;
}
.consequence .mono { color: var(--moon); }
.consequence:empty { display: none; }

.card-view[hidden], .card-edit[hidden] { display: none; }
.card-edit .field + .fields { margin-top: var(--s-3); }
.card-edit .actions { margin-top: var(--s-3); }
.card-edit label input { margin-top: var(--s-1); }

/* ------------------------------------------------------------- overall */

.overall .result { margin-top: 0; }
.overall .result-main { display: flex; align-items: baseline; gap: var(--s-4); flex-wrap: wrap; }
.overall .hours { margin-top: 0; }
.overall .note { margin-top: var(--s-3); }
.overall .btn { margin-top: var(--s-4); }
#share-overall[hidden] { display: none; }

/* --------------------------------------------------------------- prose */

.steps {
  list-style: none;
  padding: 0;
  counter-reset: step;
  display: grid;
  gap: var(--s-4);
}
.steps li {
  counter-increment: step;
  display: grid;
  grid-template-columns: 2.25rem 1fr;
  gap: var(--s-3);
}
.steps li::before {
  content: counter(step);
  grid-row: 1 / 3;
  font-size: 1.5rem;
  font-weight: 500;
  line-height: 1.2;
  color: var(--muted);
}
.steps h3, .steps p { grid-column: 2; }
.steps p { margin-top: var(--s-1); color: var(--muted); max-width: 55ch; }

.faq details {
  border-top: 1px solid var(--rule);
  padding: var(--s-3) 0;
}
.faq details:last-of-type { border-bottom: 1px solid var(--rule); }
.faq summary {
  cursor: pointer;
  font-weight: 500;
  list-style: none;
  display: flex;
  justify-content: space-between;
  gap: var(--s-3);
  min-height: 32px;
  align-items: center;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: "+";
  font-family: var(--mono);
  color: var(--muted);
  flex-shrink: 0;
}
.faq details[open] summary::after { content: "\2013"; }
.faq details p { margin-top: var(--s-2); color: var(--muted); }

/* -------------------------------------------------------------- footer */

.site-footer {
  padding-top: var(--s-8);
  padding-bottom: var(--s-10);
  border-top: 1px solid var(--rule);
  margin-top: var(--s-8);
  font-size: var(--fs-small);
  color: var(--muted);
}
.site-footer a { color: var(--moon); }
.footer-note { margin-bottom: var(--s-2); }
.visit-counter { margin-top: var(--s-2); }
.visit-counter[hidden] { display: none; }

/* --------------------------------------------------------------- toast */

.toast {
  position: fixed;
  left: var(--s-4);
  right: var(--s-4);
  bottom: max(var(--s-4), env(safe-area-inset-bottom));
  margin: 0 auto;
  max-width: 28rem;
  padding: var(--s-3) var(--s-4);
  background: var(--moon);
  color: var(--ink);
  border-radius: var(--radius);
  font-size: var(--fs-small);
  font-weight: 500;
  z-index: 60;
}
.toast .mono { font-family: var(--mono); }

/* --------------------------------------------------------------- modal */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: var(--s-4);
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(7, 11, 18, 0.88);
}
.modal-body {
  position: relative;
  width: 100%;
  max-width: 22rem;
  max-height: calc(100vh - 2 * var(--s-4));
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: var(--radius-card);
  padding: var(--s-4);
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--s-3);
}
.modal-head h2 { margin: 0; font-size: 1.125rem; }
.share-preview {
  margin-top: var(--s-3);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--ink);
}
.share-preview canvas {
  display: block;
  width: 100%;
  height: auto;
  max-height: 52vh;
  object-fit: contain;
}
.modal-actions {
  display: flex;
  gap: var(--s-2);
  margin-top: var(--s-3);
}
.modal-actions .btn { flex: 1; }
.modal-actions .btn[hidden] { display: none; }
.modal .note { margin-top: var(--s-2); }

/* -------------------------------------------------------------- motion */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

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

@media (min-width: 760px) {
  .site-header { padding-top: var(--s-8); }
  main > section { padding: var(--s-16) 0; }
  main > section.hero { padding-top: var(--s-8); }

  .hero .status-line { max-width: 40ch; }
  .hero .actions .btn { flex: 0 1 auto; min-width: 12rem; }

  .subject-grid { grid-template-columns: 1fr 1fr; }
  .card { padding: var(--s-6); }

  .steps { grid-template-columns: repeat(3, 1fr); gap: var(--s-8); }

  .bands { gap: var(--s-1) var(--s-6); }
}

/* Wide: the hero becomes two columns, words left and the calculator right,
   so the page uses the width instead of stacking down a narrow spine. */
@media (min-width: 1000px) {
  .hero {
    display: grid;
    grid-template-columns: minmax(0, 5fr) minmax(0, 6fr);
    column-gap: var(--s-16);
    align-items: start;
  }
  .hero h1 { max-width: 14ch; }
  .hero .lede { max-width: 40ch; }
  .hero-words { position: sticky; top: var(--s-8); }
  .calc { margin-top: 0; }
  .hero .result { margin-top: var(--s-6); }
  .pct-hero { font-size: 7.5rem; min-height: 7.5rem; }

  .subject-grid { grid-template-columns: repeat(3, 1fr); }
  .overall:not([hidden]) { display: grid; grid-template-columns: 1fr auto; column-gap: var(--s-8); align-items: center; }
  .overall h2 { grid-column: 1 / -1; }
  .overall .note { grid-column: 1; }
  .overall .btn { grid-column: 2; grid-row: 2 / 4; margin-top: 0; }

  .faq { columns: 2; column-gap: var(--s-8); }
  .faq h2 { column-span: all; }
  .faq details { break-inside: avoid; }
}
