:root {
  --red: #da291c;
  --red-ink: #b31f14;
  --yellow: #ffc72c;
  --bg: #f6f4f1;
  --surface: #ffffff;
  --ink: #1d1b19;
  --muted: #6d6862;
  --line: #e4e0da;
  --chip: #f1eee9;
  --good: #1f7a3a;
  --mid: #8a6a00;
  --warn-bg: #fff4d6;
  --warn-ink: #7a5600;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141312;
    --surface: #1e1c1a;
    --ink: #f3f0ec;
    --muted: #a39d96;
    --line: #34302c;
    --chip: #2a2724;
    --good: #5cc27a;
    --mid: #e0b84a;
    --warn-bg: #3a2f10;
    --warn-ink: #ffd877;
    --red-ink: #ff6b5e;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: env(safe-area-inset-bottom);
}

.top {
  position: sticky; top: 0; z-index: 5;
  background: var(--red); color: #fff;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 8px; background: none; border: 0; color: #fff; font: inherit; font-size: 17px; font-weight: 700; padding: 0; letter-spacing: -.01em; }
.brand-mark { display: block; width: 30px; height: 30px; border-radius: 8px; box-shadow: 0 2px 6px rgba(0,0,0,.18); }
.wordmark { letter-spacing: -.02em; font-weight: 800; }
.top nav { display: flex; gap: 4px; background: rgba(0,0,0,.18); padding: 3px; border-radius: 999px; }
.top nav button { background: none; border: 0; color: #fff; padding: 6px 14px; border-radius: 999px; font: inherit; font-size: 14px; }
.top nav button.active { background: var(--yellow); color: #27251f; font-weight: 600; }

main { max-width: 520px; margin: 0 auto; padding: 16px; }
.view { display: flex; flex-direction: column; gap: 14px; }
[hidden] { display: none !important; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.eyebrow { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.muted { color: var(--muted); font-size: 14px; }

.hero {
  display: flex; flex-direction: column; align-items: center; gap: 8px; text-align: center; cursor: pointer;
  padding: 36px 20px 30px; border-radius: 20px; color: #fff;
  background: radial-gradient(120% 90% at 50% 0%, #ef4a3c 0%, var(--red) 55%, #a81d12 100%);
  box-shadow: 0 10px 24px -12px rgba(170, 30, 20, .6);
  transition: transform .12s ease;
}
.hero:active { transform: scale(.985); }
.hero-icon { display: grid; place-items: center; width: 68px; height: 68px; border-radius: 20px; background: var(--yellow); color: #27251f; margin-bottom: 4px; }
.hero strong { font-size: 22px; letter-spacing: -.01em; }
.hero small { font-size: 14px; opacity: .88; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-top: 6px; }
.section-head h2 { font-size: 15px; margin: 0; letter-spacing: -.01em; }
.section-head .link { align-self: auto; font-size: 14px; }


.flow-bar { display: flex; align-items: center; margin-bottom: -6px; }
.back { background: none; border: 0; color: var(--red-ink); font: inherit; font-size: 15px; font-weight: 600; padding: 6px 0; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); list-style: none; margin: 0 0 2px; padding: 0; counter-reset: step; }
.steps li { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
/* connector to the previous step */
.steps li + li::before {
  content: ""; position: absolute; top: 13px; right: 50%; width: 100%; height: 3px; border-radius: 2px;
  background: var(--line); z-index: 0;
}
.steps li.done + li::before { background: var(--good); }
.steps i {
  position: relative; z-index: 1; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%;
  font-style: normal; font-size: 13px; font-weight: 800; background: var(--surface); border: 2px solid var(--line); color: var(--muted);
}
.steps li.done { color: var(--good); }
.steps li.done i { background: var(--good); border-color: var(--good); color: transparent; }
.steps li.done i::after { content: "✓"; position: absolute; color: #fff; font-size: 14px; }
.steps li.now { color: var(--ink); }
.steps li.now i { background: var(--red); border-color: var(--red); color: #fff; box-shadow: 0 0 0 4px color-mix(in srgb, var(--red) 22%, transparent); }

.status { min-height: 1.2em; margin: 0; color: var(--muted); font-size: 14px; text-align: center; }
.status.error { color: var(--red-ink); }
.warn { background: var(--warn-bg); color: var(--warn-ink); padding: 10px 12px; border-radius: 10px; font-size: 14px; margin: 0; }

.receipt-line { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; border-left: 4px solid var(--yellow); }
.receipt-line strong { font-size: 17px; }

.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
input {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px; width: 100%;
}
textarea {
  font: inherit; font-size: 15px; line-height: 1.45; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; width: 100%; resize: none; overflow: hidden; min-height: 44px;
}
textarea:focus, input:focus { outline: 2px solid var(--yellow); outline-offset: 0; border-color: transparent; }
#r-code { font-family: ui-monospace, Menlo, monospace; font-size: 14px; }

.ratings { display: flex; flex-direction: column; gap: 8px; }
.rating-row { display: flex; flex-direction: column; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px 12px; }
.rating-label { font-weight: 700; font-size: 14px; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg button {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 11px 4px; border-radius: 10px; font: inherit; font-size: 14px; line-height: 1.15;
  transition: background .12s, border-color .12s, color .12s;
}
.seg button:active { transform: scale(.97); }
.seg button.on[data-tone="good"] { background: var(--good); border-color: var(--good); color: #fff; }
.seg button.on[data-tone="mid"] { background: var(--yellow); border-color: var(--yellow); color: #27251f; }
.seg button.on[data-tone="bad"] { background: var(--red); border-color: var(--red); color: #fff; }

.grade {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px;
  font-weight: 800; font-size: 24px; background: var(--chip); color: var(--ink); flex: none;
}
.grade.A { background: #1f7a3a; color: #fff; }
.grade.B { background: #5b9a2f; color: #fff; }
.grade.C { background: var(--yellow); color: #27251f; }
.grade.D { background: #e67e22; color: #fff; }
.grade.F { background: var(--red); color: #fff; }
.grade.xl { width: 72px; height: 72px; font-size: 40px; border-radius: 18px; }

.result { display: flex; align-items: center; gap: 14px; }
.score-big { font-size: 22px; font-weight: 700; }
.code-card { text-align: center; border: 2px dashed var(--good); padding: 20px 14px; }
.chip-btn { margin-top: 12px; background: var(--chip); color: var(--ink); border: 0; border-radius: 999px; padding: 8px 16px; font: inherit; font-size: 14px; font-weight: 600; }
.submit-bar { position: sticky; bottom: 0; margin: 4px -16px 0; padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); background: linear-gradient(to bottom, transparent, var(--bg) 30%); display: flex; flex-direction: column; gap: 6px; }
.code-value { font-family: ui-monospace, Menlo, monospace; font-size: 30px; font-weight: 700; letter-spacing: .06em; margin: 6px 0; user-select: all; }
details summary { font-weight: 600; cursor: pointer; }
details p { margin: 10px 0 0; color: var(--muted); font-size: 15px; }

button.primary, button.secondary {
  font: inherit; font-weight: 600; border-radius: 12px; padding: 13px 16px; width: 100%;
}
button.primary { background: var(--red); color: #fff; border: 0; }
button.primary:disabled { opacity: .45; }
button.primary.big { padding: 16px; font-size: 17px; }
button.secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
button.link { background: none; border: 0; color: var(--red-ink); font: inherit; font-size: 15px; font-weight: 600; padding: 0; align-self: flex-start; }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.stat b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12px; color: var(--muted); }

.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.history li { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; display: flex; gap: 12px; align-items: center; }
.history li { align-items: flex-start; }
.history .meta { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.history .sub { font-size: 13px; color: var(--muted); }
.quote { margin: 2px 0 0; font-size: 14px; color: var(--ink); opacity: .85; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.pill.ok { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); font-family: ui-monospace, Menlo, monospace; }
.pill.bad { background: var(--warn-bg); color: var(--warn-ink); }
.empty { justify-content: center; color: var(--muted); padding: 32px 0 !important; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #27251f; color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 14px; z-index: 10;
}

.gate { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(0,0,0,.45); }
.gate[hidden] { display: none; }
.gate-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }

@media (max-width: 420px) {
  .top { gap: 8px; }
  .wordmark { display: none; }
}

.draft { display: flex; flex-direction: column; gap: 10px; border-left: 4px solid var(--good); }
.draft-head { display: flex; align-items: center; justify-content: space-between; }
.draft .chip-btn { margin: 0; }
.draft .chip-btn:disabled { opacity: .5; }
.draft.loading textarea { opacity: .45; }
.draft-status { margin: 0; font-size: 13px; }
.draft-status.error { color: var(--red-ink); }
.fineprint { margin: 0; text-align: center; font-size: 12px; color: var(--muted); }
.upload {
  display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; column-gap: 12px; align-items: center; cursor: pointer;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-top: -4px;
}
.upload:active { transform: scale(.985); }
.upload svg { grid-row: span 2; color: var(--red); }
.upload span { font-weight: 700; }
.upload small { color: var(--muted); font-size: 13px; }
.pill.run { background: var(--chip); color: var(--ink); }

.guide-step { display: flex; flex-direction: column; gap: 10px; }
.gs-head { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.gs-head b { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50%; background: var(--red); color: #fff; font-size: 13px; flex: none; }
.gs-code { display: grid; grid-template-columns: repeat(5, 1fr) .45fr; gap: 6px; }
.gs-code span { font-family: ui-monospace, Menlo, monospace; font-size: 16px; font-weight: 700; text-align: center; padding: 9px 0; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; user-select: all; }
.guide-step .chip-btn { margin: 0; align-self: flex-start; }
a.link-btn { display: block; text-align: center; text-decoration: none; border-radius: 12px; padding: 14px 16px; font-weight: 600; background: var(--red); color: #fff; }
.small { font-size: 13px; margin: 0; }
.sheet { margin: 0; display: grid; grid-template-columns: 1fr auto; border-top: 1px solid var(--line); }
.sheet dt, .sheet dd { margin: 0; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.sheet dt { color: var(--muted); padding-right: 12px; }
.sheet dd { font-weight: 700; text-align: right; max-width: 52vw; }
.gs-copy { display: flex; flex-direction: column; gap: 6px; background: var(--bg); border-radius: 10px; padding: 10px 12px; }
.gs-text { margin: 0; font-size: 15px; }
