:root {
  --teal: #15bcbc;
  --teal-dark: #0e8f8f;
  --teal-soft: #e6f7f7;
  --navy: #0b2366;
  --navy-2: #1a3a8f;
  --ink: #1d2433;
  --muted: #5d6677;
  --line: #dfe4ea;
  --card: #ffffff;
  --good: #1f8a3b;
  --bad: #c0392b;
  --radius: 12px;
  --shadow: 0 6px 24px rgba(11, 35, 102, 0.12);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 64px; }
body {
  margin: 0;
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
  color: var(--ink);
  background: var(--teal);
  line-height: 1.45;
}
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 20px; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--navy); color: #fff; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.brand { color: #fff; text-decoration: none; font-weight: 800; font-size: 22px; letter-spacing: .5px; }
.brand span { color: var(--teal); }
.topbar nav a { color: #dce6ff; text-decoration: none; margin-left: 22px; font-size: 15px; }
.topbar nav a:hover { color: #fff; }

/* ---------- hero / quick ---------- */
.hero { padding: 48px 0 40px; text-align: center; }
.hero h1 { font-size: clamp(30px, 5vw, 48px); margin: 0 0 8px; color: #0d1b3d; }
.lede { font-size: 19px; margin: 0 auto 28px; max-width: 720px; color: #0d2a3a; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; }
.quick-card { text-align: left; }
.quick-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 14px; align-items: end; }
.quick-results {
  display: grid; grid-template-columns: 1.1fr 2fr; gap: 20px; align-items: center;
  margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--line);
}
.big-stat { background: var(--navy); color: #fff; border-radius: 10px; padding: 18px 20px; }
.big-stat .stat-label, .big-stat .stat-sub { color: #bcd0ff; }
.big-stat .stat-value { display: block; font-size: 40px; font-weight: 800; margin: 4px 0; }
.mini-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.mini-stats > div { background: var(--teal-soft); border-radius: 10px; padding: 12px 14px; }
.mini-stats strong { display: block; font-size: 22px; margin-top: 2px; }
.stat-label { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.stat-sub { font-size: 13px; }
.scroll-cue {
  display: inline-block; margin-top: 26px; color: #fff; background: var(--navy);
  padding: 12px 22px; border-radius: 999px; text-decoration: none; font-weight: 700;
}
.scroll-cue:hover { background: var(--navy-2); }

.equation { margin-top: 14px; font-size: 14px; color: var(--muted); }
.equation summary { cursor: pointer; color: var(--navy-2); font-weight: 700; }
code { background: #f2f4f8; padding: 2px 6px; border-radius: 4px; font-size: 13px; }

/* ---------- forms ---------- */
label { display: block; font-size: 14px; font-weight: 700; color: #26324a; }
label small { font-weight: 400; color: var(--muted); }
input, select {
  width: 100%; padding: 10px 11px; font-size: 15px; font-family: inherit;
  border: 1px solid #c9d1dc; border-radius: 8px; background: #fff; color: var(--ink);
  display: block; margin-top: 6px;
}
input:focus, select:focus { outline: 2px solid var(--teal); border-color: var(--teal); }
.grid { display: grid; gap: 14px; }
.g3 { grid-template-columns: repeat(3, 1fr); }
.g4 { grid-template-columns: repeat(4, 1fr); }
.g6 { grid-template-columns: repeat(6, 1fr); }
[hidden] { display: none !important; }

/* ---------- detailed ---------- */
.detailed { background: #f3f6f8; padding: 56px 0; }
.section-title { font-size: 32px; margin: 0 0 6px; color: var(--navy); }
.intro { color: var(--muted); max-width: 820px; margin: 0 0 24px; font-size: 16px; }
.step { margin-bottom: 18px; }
.step h3 { margin: 0 0 16px; font-size: 19px; display: flex; align-items: center; gap: 10px; color: var(--navy); }
.num {
  display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  background: var(--teal); color: #fff; font-size: 15px;
}
.note { color: var(--muted); font-size: 14px; margin: 14px 0 0; }

.variety { border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 14px; background: #fbfcfd; }
.variety-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.v-title { color: var(--navy); }
.icon-btn { border: none; background: transparent; font-size: 18px; color: var(--muted); cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: #eef1f5; color: var(--bad); }
.quality { margin-top: 14px; border-top: 1px dashed var(--line); padding-top: 12px; }
.quality summary { cursor: pointer; font-weight: 700; color: var(--navy-2); margin-bottom: 12px; }

.btn {
  font: inherit; font-weight: 700; border-radius: 8px; padding: 12px 22px; cursor: pointer;
  border: 2px solid var(--navy); transition: background .15s, color .15s;
}
.btn.primary { background: var(--navy); color: #fff; font-size: 17px; padding: 14px 40px; }
.btn.primary:hover { background: var(--navy-2); }
.btn.ghost { background: #fff; color: var(--navy); }
.btn.ghost:hover { background: var(--teal-soft); }
.btn.small { padding: 8px 14px; font-size: 14px; }
.actions { display: flex; align-items: center; gap: 16px; margin: 8px 0 26px; }
.status { color: var(--muted); font-size: 14px; }
.status.error { color: var(--bad); font-weight: 700; }

/* ---------- results ---------- */
.results { border-top: 6px solid var(--teal); }
.results-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.results-head h3 { margin: 0; font-size: 22px; color: var(--navy); }
.muted { color: var(--muted); }
.stat-row { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 12px; margin: 18px 0 8px; }
.be-note { font-size: 14px; color: var(--muted); margin: 0 0 22px; }
.be-note b { color: var(--ink); }
.stat { background: var(--teal-soft); border-radius: 10px; padding: 14px 16px; }
.stat .stat-value { display: block; font-size: 26px; font-weight: 800; margin-top: 4px; }
.hero-stat { background: var(--navy); color: #fff; }
.hero-stat .stat-label { color: #bcd0ff; }
.hero-stat .stat-value { font-size: 34px; }
.pos { color: var(--good); }
.neg { color: var(--bad); }
.hero-stat .pos { color: #7ef0a0; }
.hero-stat .neg { color: #ff9c8f; }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; }
h4 { margin: 18px 0 10px; color: var(--navy); font-size: 16px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
.kv td { padding: 8px 4px; border-bottom: 1px solid var(--line); }
.kv td:last-child { text-align: right; font-weight: 700; white-space: nowrap; }
.kv tr.total td { border-top: 2px solid var(--navy); border-bottom: none; font-size: 16px; }
.table-scroll { overflow-x: auto; }
.vtable th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 8px 6px; border-bottom: 2px solid var(--line); }
.vtable td { padding: 10px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.arrow { color: var(--muted); padding: 0 4px; }
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; background: #eef1f5; font-size: 12px; font-weight: 700; }
.pill.up { background: #dcf5e3; color: var(--good); }

.bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 90px; gap: 10px; align-items: center; font-size: 14px; }
.bar-track { background: #eef1f5; height: 14px; border-radius: 7px; position: relative; overflow: hidden; }
.bar-fill { position: absolute; top: 0; bottom: 0; border-radius: 7px; }
.bar-val { text-align: right; font-weight: 700; }

.warnings { color: #8a5a00; font-size: 14px; padding-left: 18px; }
.fine { color: var(--muted); font-size: 12px; margin-top: 16px; }

/* ---------- about / footer ---------- */
.about { padding: 50px 0; }
.about .section-title { color: #0d1b3d; }
.about-grid ul { padding-left: 18px; margin: 0 0 10px; }
.about-grid li { margin-bottom: 6px; }
.about-grid h4 { margin-top: 0; }
.footer { background: var(--navy); color: #dce6ff; padding: 22px 0; font-size: 14px; text-align: center; }
.tip { position: relative; border-bottom: 1px dotted #dce6ff; cursor: help; color: #fff; }
.tiptext {
  visibility: hidden; opacity: 0; position: absolute; bottom: 140%; left: 50%; transform: translateX(-50%);
  background: #333; color: #fff; padding: 6px 10px; border-radius: 6px; white-space: nowrap; transition: opacity .2s;
}
.tip:hover .tiptext, .tip:focus .tiptext { visibility: visible; opacity: 1; }

/* ---------- responsive ---------- */
@media (max-width: 1000px) {
  .quick-grid { grid-template-columns: repeat(4, 1fr); }
  .g6 { grid-template-columns: repeat(3, 1fr); }
  .stat-row { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
  .topbar nav a { margin-left: 12px; font-size: 13px; }
  .quick-grid, .g3, .g4, .g6 { grid-template-columns: 1fr 1fr; }
  .quick-results, .split { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 110px 1fr 80px; }
}
@media (max-width: 440px) {
  .topbar nav { display: none; }
  .g3, .g4, .g6, .stat-row { grid-template-columns: 1fr; }
}

/* ---------- One-page print / PDF (print-mode is added by app.js before printing) ---------- */
.print-only { display: none; }
body.print-mode .topbar, body.print-mode .hero, body.print-mode .about, body.print-mode .footer,
body.print-mode #detailForm, body.print-mode #detailed > .wrap > .section-title,
body.print-mode #detailed > .wrap > .intro, body.print-mode .results-head button { display: none !important; }
body.print-mode { background: #fff; }
body.print-mode .detailed { background: #fff; padding: 0; }
body.print-mode .detailed > .wrap { max-width: none; padding: 0; }
body.print-mode #results { width: 740px; margin: 0; padding: 12px 14px; box-shadow: none; border: 1px solid var(--line); border-top: 6px solid var(--teal); }
body.print-mode .print-only { display: block; }
body.print-mode .stat-row { grid-template-columns: 1.4fr 1fr 1fr !important; margin: 10px 0 4px; }
body.print-mode .split { grid-template-columns: 1fr 1fr !important; gap: 18px; }
body.print-mode .bar-row { grid-template-columns: 110px 1fr 70px !important; }
body.print-mode h4 { margin: 10px 0 6px; }
body.print-mode .kv td, body.print-mode .vtable td, body.print-mode .btable td { padding-top: 4px; padding-bottom: 4px; }
body.print-mode .breakdown { padding: 6px 10px; margin: 0; break-inside: avoid; }
body.print-mode #rBreakdown { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 8px; }
body.print-mode #rBreakdown > h4 { grid-column: 1 / -1; margin-bottom: 0; }
body.print-mode .btable { font-size: 12px; margin-top: 4px; }
body.print-mode .btable th { padding: 3px 4px; font-size: 10px; }
body.print-mode .btable td { padding: 3px 4px; }
body.print-mode .breakdown summary { font-size: 13px; list-style: none; }
body.print-mode .table-scroll { overflow: visible; }
body.print-mode .vtable { font-size: 13px; }
@page { size: letter; margin: 0.35in; }
@media print {
  html, body { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .topbar, .hero, .footer, .about, #detailForm, .results-head button { display: none !important; }
  body, .detailed { background: #fff !important; }
  #results { break-inside: avoid; page-break-inside: avoid; }
}

/* ---------- v2.1 layout ---------- */
.note.top { margin: 0 0 14px; }
.vgrid { display: flex; flex-direction: column; gap: 12px; }
.vrow {
  display: grid; grid-template-columns: 130px 1.4fr 1fr 1fr 1fr; gap: 14px; align-items: end;
  padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: #fbfcfd;
}
.vrow-label { align-self: center; display: flex; flex-direction: column; color: var(--navy); }
.vrow-label small { color: var(--muted); font-weight: 400; font-size: 12px; }
.preview { margin-top: 16px; max-width: 640px; }
.preview th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 6px; border-bottom: 2px solid var(--line); }
.preview td { padding: 8px 6px; border-bottom: 1px solid var(--line); }
.elig { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: #eef1f5; color: #3b4658; }
.chip.good { background: #dcf5e3; color: #17692d; }
.chip.bad { background: #fde7e4; color: #9c2b1f; }
.bar-zero { position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: #b8c0cc; }
.status code { background: #fde7e4; }
@media (max-width: 1000px) { .vrow { grid-template-columns: 1fr 1fr; } .vrow-label { grid-column: 1 / -1; flex-direction: row; gap: 8px; align-items: baseline; } }
@media (max-width: 440px) { .vrow { grid-template-columns: 1fr; } }
.vrow.is-none { opacity: .55; }
.vrow.is-none input { background: #f2f4f7; }
select option[disabled] { color: #8a93a3; }
.elig-label { font-size: 12px; font-weight: 700; color: var(--muted); align-self: center; margin-right: 2px; }
.grade-status { background: #f4f7fb; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; margin-bottom: 14px; font-size: 14px; }
.gs-head { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-top: 4px; }
.gs-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 4px 0; }
.pill.no { background: #fde7e4; color: #9c2b1f; }
.breakdown { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; margin-bottom: 10px; }
.breakdown summary { cursor: pointer; font-weight: 700; color: var(--navy); }
.btable { margin-top: 10px; }
.btable th { text-align: left; font-size: 12px; text-transform: uppercase; color: var(--muted); padding: 6px; border-bottom: 2px solid var(--line); }
.btable td { padding: 7px 6px; border-bottom: 1px solid var(--line); }
.btable td:not(:first-child), .btable th:not(:first-child) { text-align: right; white-space: nowrap; }
.btable tr.qrow td { background: #fff8e1; font-weight: 700; }
.btable tr.total td { font-weight: 800; border-top: 2px solid var(--navy); border-bottom: none; }
.small { font-size: 12px; font-weight: 400; }
select.is-default { color: var(--muted); font-style: italic; background: #f7f9fb; }
select.is-default option { color: var(--ink); font-style: normal; }
