:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #16181d;
  --muted: #5f6672;
  --line: #e3e6eb;
  --accent: #1f5eff;
  --good: #1a9e5c;
  --ok: #c79a00;
  --warn: #e0691b;
  --bad: #d12f2f;
  --track: #eceef2;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1115;
    --card: #171a21;
    --text: #e8eaef;
    --muted: #9aa3b2;
    --line: #262b35;
    --accent: #5b8cff;
    --good: #35c47a;
    --ok: #e2b93b;
    --warn: #f0853d;
    --bad: #f05656;
    --track: #232834;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115;
  --card: #171a21;
  --text: #e8eaef;
  --muted: #9aa3b2;
  --line: #262b35;
  --accent: #5b8cff;
  --good: #35c47a;
  --ok: #e2b93b;
  --warn: #f0853d;
  --bad: #f05656;
  --track: #232834;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
.wrap { max-width: 920px; margin: 0 auto; padding: 40px 16px 60px; }
.wrap.narrow { max-width: 460px; }

.nav { display: flex; align-items: center; gap: 18px; margin: -16px 0 28px; font-size: 14px; }
.nav .brand { font-weight: 700; color: var(--text); text-decoration: none; }
.nav .spacer { flex: 1; }
.nav a { color: var(--muted); text-decoration: none; }
.nav a.active { color: var(--text); font-weight: 600; }
.nav a:hover { color: var(--accent); }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); cursor: pointer; }
.link:hover { color: var(--accent); }

.btn {
  padding: 10px 18px; font-size: 15px; font-weight: 600; border: 0; border-radius: 10px;
  background: var(--accent); color: #fff; cursor: pointer; white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn.ghost:hover:not(:disabled) { border-color: var(--accent); }
.btn.danger { color: var(--bad); }
.toolbar { display: flex; align-items: center; gap: 12px; margin-top: 20px; }

/* The hidden attribute must beat display rules like .form { display: grid }, or hidden forms show. */
[hidden] { display: none !important; }

.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.form input {
  padding: 11px 14px; font-size: 16px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--text); width: 100%;
}
.form input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.form .btn { justify-self: start; }
.inline-form { margin-top: 12px; }
.grid2 { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; }
.provider { display: grid; gap: 12px; }
.provider h2 { display: flex; align-items: center; gap: 10px; margin-bottom: 0; }
.provider .src { margin: 0; }
.provider .src a { color: var(--accent); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.actions .result { font-size: 14px; color: var(--muted); }
.pill { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; padding: 2px 9px; border-radius: 99px; background: var(--track); color: var(--muted); }
.pill.on { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.notice { margin-top: 24px; padding: 14px 16px; border-radius: var(--radius); background: color-mix(in srgb, var(--good) 10%, var(--card)); border: 1px solid color-mix(in srgb, var(--good) 40%, var(--line)); color: var(--good); }
code { font-size: 0.92em; background: var(--track); padding: 1px 5px; border-radius: 4px; }
.hero h1 { margin: 0 0 8px; font-size: 32px; letter-spacing: -0.02em; }
.lede { color: var(--muted); margin: 0 0 24px; max-width: 640px; }
.lede a { color: var(--accent); }

.bar { display: flex; gap: 8px; }
.bar input {
  flex: 1; min-width: 0; padding: 14px 16px; font-size: 17px;
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text);
}
.bar input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.bar button {
  padding: 14px 22px; font-size: 16px; font-weight: 600; border: 0; border-radius: var(--radius);
  background: var(--accent); color: #fff; cursor: pointer; white-space: nowrap;
}
.bar button:disabled { opacity: 0.6; cursor: wait; }
.opts { display: flex; flex-wrap: wrap; gap: 18px; margin: 10px 2px 0; color: var(--muted); font-size: 14px; }
.opts label { display: inline-flex; align-items: center; gap: 6px; }
.opts a { color: var(--accent); }

.status { margin-top: 24px; padding: 14px 16px; border-radius: var(--radius); background: var(--card); border: 1px solid var(--line); color: var(--muted); }
.status::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 10px; border-radius: 50%; border: 2px solid var(--accent); border-top-color: transparent; animation: spin 0.8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }
.error { margin-top: 24px; padding: 14px 16px; border-radius: var(--radius); background: color-mix(in srgb, var(--bad) 10%, var(--card)); border: 1px solid color-mix(in srgb, var(--bad) 40%, var(--line)); color: var(--bad); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 24px; margin-top: 20px; }
.card h2 { margin: 0 0 14px; font-size: 18px; }
.card h3 { margin: 14px 0 6px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.card ul { margin: 0; padding-left: 20px; }
.card li { margin: 4px 0; }
.muted { color: var(--muted); font-size: 14px; }

.top { display: flex; gap: 28px; align-items: center; }
.gauge { text-align: center; flex: 0 0 auto; }
.ring {
  width: 132px; height: 132px; border-radius: 50%; display: grid; place-items: center;
  background: conic-gradient(var(--tone, var(--accent)) calc(var(--pct, 0) * 1%), var(--track) 0);
}
.ring .num {
  width: 104px; height: 104px; border-radius: 50%; background: var(--card); display: grid; place-items: center;
  font-size: 40px; font-weight: 700; letter-spacing: -0.03em; color: var(--tone, var(--text));
}
.gauge-label { margin-top: 6px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.verdict { flex: 1; min-width: 0; }
.grade { font-size: 24px; font-weight: 700; color: var(--tone, var(--text)); }
.verdict p { margin: 6px 0; }
.meta { color: var(--muted); font-size: 14px; word-break: break-word; }
.blend { margin-top: 10px; font-size: 14px; color: var(--muted); display: flex; gap: 14px; flex-wrap: wrap; }
.blend span b { color: var(--text); }

.tone-good { --tone: var(--good); }
.tone-ok { --tone: var(--ok); }
.tone-warn { --tone: var(--warn); }
.tone-bad { --tone: var(--bad); }

.signals { display: grid; gap: 14px; }
.sig { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; }
.sig-head { display: flex; align-items: center; gap: 12px; }
.sig-head .name { font-weight: 600; flex: 1; }
.sig-head .w { color: var(--muted); font-size: 12px; }
.sig-head .val { font-weight: 700; min-width: 34px; text-align: right; color: var(--tone, var(--text)); }
.track { height: 8px; border-radius: 99px; background: var(--track); margin: 10px 0 8px; overflow: hidden; }
.fill { height: 100%; width: 0; border-radius: 99px; background: var(--tone, var(--accent)); transition: width 0.6s ease; }
.sig .detail { font-size: 14px; color: var(--muted); margin: 0; }
.sig details { margin-top: 8px; font-size: 14px; }
.sig summary { cursor: pointer; color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { background: var(--track); border-radius: 99px; padding: 2px 10px; font-size: 13px; }
.chip b { font-weight: 600; }
.ex { margin: 6px 0; padding: 8px 12px; border-left: 3px solid var(--line); color: var(--muted); font-size: 14px; }
.ex mark { background: color-mix(in srgb, var(--warn) 30%, transparent); color: inherit; border-radius: 3px; padding: 0 2px; }
.explain { font-size: 13px; color: var(--muted); margin: 6px 0 0; }

.quote { font-size: 17px; margin: 0 0 10px; }
.review h2 { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.review .rscore { font-size: 22px; font-weight: 700; color: var(--tone, var(--text)); }
.review .w { color: var(--muted); font-size: 12px; font-weight: 400; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.evidence li { margin: 8px 0; }
.evidence q { display: block; font-style: italic; }
.evidence small { color: var(--muted); }

.pages { width: 100%; border-collapse: collapse; font-size: 14px; }
.pages th, .pages td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.pages th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.pages td.n { text-align: right; font-variant-numeric: tabular-nums; }
.pages a { color: var(--accent); text-decoration: none; word-break: break-all; }
.pages .t { display: block; color: var(--muted); font-size: 12px; }

.foot { margin-top: 36px; color: var(--muted); font-size: 13px; }

@media (max-width: 640px) {
  .wrap { padding-top: 24px; }
  .hero h1 { font-size: 26px; }
  .bar { flex-direction: column; }
  .top { flex-direction: column; align-items: stretch; text-align: center; }
  .two { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
  .nav { flex-wrap: wrap; gap: 12px; }
  .card { padding: 18px 16px; }
}

/* How-it-works page */
.doc .card p { margin: 0 0 12px; line-height: 1.55; }
.doc .card p:last-child { margin-bottom: 0; }
.doc .card li { margin: 6px 0; line-height: 1.5; }
.doc a { color: var(--accent); }
.facts { width: 100%; border-collapse: collapse; font-size: 14px; margin: 6px 0 14px; }
.facts th, .facts td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; line-height: 1.5; }
.facts th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.facts td.n { white-space: nowrap; font-variant-numeric: tabular-nums; }
.facts td:last-child { color: var(--muted); font-size: 13px; }
.grades td:last-child { color: var(--text); font-size: 14px; }
.pill.good { background: color-mix(in srgb, var(--good) 18%, transparent); color: var(--good); }
.pill.ok { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.pill.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.pill.bad { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }
@media (max-width: 640px) {
  .facts thead { display: none; }
  .facts tr { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .facts td { display: block; border: 0; padding: 2px 0; }
  .facts td.n::before { content: "weight "; color: var(--muted); font-weight: 400; }
  .grades td.n::before { content: ""; }
}

/* Text checker */
:root {
  --hl-ai: #c2298a;
  --hl-phrase: #e5484d;
  --hl-boilerplate: #f08c00;
  --hl-vocab: #8e4ec6;
  --hl-structure: #3e63dd;
  --hl-filler: #d9a400;
  --hl-repeat: #0f9d8a;
  --hl-detail: #2f9e5b;
}
.wrap.wide { max-width: 1180px; }
.editor { padding: 0; overflow: hidden; }
.editor.drag { outline: 2px dashed var(--accent); outline-offset: -6px; }
/* The textarea sits on top of a layer that holds the same text, invisible, with the highlights.
   Both must wrap identically, so every property that affects text layout is set on the pair. */
.live { position: relative; }
.live textarea, .backdrop {
  margin: 0; border: 0; padding: 22px 24px; width: 100%; box-sizing: border-box;
  font-family: inherit; font-size: 17px; line-height: 1.7; letter-spacing: normal; word-spacing: normal; tab-size: 4;
  white-space: pre-wrap; overflow-wrap: break-word; word-break: normal; text-align: left;
}
.backdrop { position: absolute; inset: 0; overflow: hidden; color: transparent; user-select: none; }
.live textarea {
  position: relative; display: block; min-height: 340px; resize: none; overflow: hidden;
  background: transparent; color: var(--text); outline: 0;
}
.editor-foot { display: flex; align-items: center; flex-wrap: wrap; gap: 14px; padding: 12px 16px; border-top: 1px solid var(--line); }
.editor-foot .spacer { flex: 1; }
.btn.file { cursor: pointer; }
.btn.file:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }

.split { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 20px; align-items: start; }
.side { position: sticky; top: 16px; display: grid; gap: 14px; }
.side .card { margin-top: 0; padding: 18px; }
.main-col .card { margin-top: 0; }
.side #exportMsg { margin: 0; }
.side-actions { display: flex; gap: 10px; }
.side-actions .btn { flex: 1; }
.mini-top { display: flex; align-items: center; gap: 14px; }
.ring.small { width: 84px; height: 84px; flex: 0 0 auto; }
.ring.small .num { width: 64px; height: 64px; font-size: 26px; }
.score-card .grade { font-size: 19px; line-height: 1.25; }
.score-card .gauge-label { margin-top: 2px; }
.score-card p { margin: 10px 0 0; font-size: 14px; }
.score-card .blend { flex-direction: column; gap: 4px; }

.legend { display: grid; gap: 4px; }
.lg {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 8px; border: 0; border-radius: 8px;
  background: transparent; color: var(--text); font: inherit; font-size: 14px; text-align: left; cursor: pointer;
}
.lg:hover:not(:disabled) { background: var(--track); }
.lg[aria-pressed="false"] { opacity: 0.45; text-decoration: line-through; }
.lg.none { color: var(--muted); cursor: default; }
.lg .lg-label { flex: 1; }
.lg .lg-label small { color: var(--good); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; margin-left: 4px; }
.lg .lg-n { font-weight: 700; font-variant-numeric: tabular-nums; }
.lg.none .lg-n { font-weight: 400; }
.sw { width: 14px; height: 14px; border-radius: 4px; flex: 0 0 auto; background: color-mix(in srgb, var(--c) 45%, transparent); border: 1px solid var(--c); }
.t-ai > .sw { background: transparent; border-width: 0 0 3px; border-radius: 0; height: 12px; }
.hint { margin: 12px 0 0; font-size: 12.5px; }

.t-ai { --c: var(--hl-ai); }
.t-phrase { --c: var(--hl-phrase); }
.t-boilerplate { --c: var(--hl-boilerplate); }
.t-vocab { --c: var(--hl-vocab); }
.t-structure { --c: var(--hl-structure); }
.t-filler { --c: var(--hl-filler); }
.t-repeat { --c: var(--hl-repeat); }
.t-detail { --c: var(--hl-detail); }

/* Later rules win where highlights overlap: a phrase colour shows over the sentence it sits in. */
.hl { border-radius: 3px; padding: 2px 0; -webkit-box-decoration-break: clone; box-decoration-break: clone; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
.hl.t-filler { background: color-mix(in srgb, var(--hl-filler) 20%, transparent); }
.hl.t-repeat { background: color-mix(in srgb, var(--hl-repeat) 24%, transparent); }
.hl.t-detail { background: color-mix(in srgb, var(--hl-detail) 26%, transparent); }
.hl.t-structure { background: color-mix(in srgb, var(--hl-structure) 26%, transparent); }
.hl.t-vocab { background: color-mix(in srgb, var(--hl-vocab) 30%, transparent); }
.hl.t-boilerplate { background: color-mix(in srgb, var(--hl-boilerplate) 34%, transparent); }
.hl.t-phrase { background: color-mix(in srgb, var(--hl-phrase) 32%, transparent); }
.hl.t-ai { box-shadow: inset 0 -3px 0 var(--hl-ai); }

.tip {
  position: fixed; z-index: 20; width: min(340px, calc(100vw - 16px)); padding: 12px 14px; border-radius: 10px;
  background: var(--card); border: 1px solid var(--line); box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18); font-size: 14px; line-height: 1.45; pointer-events: none;
}
.tip-row { display: flex; gap: 10px; }
.tip-row + .tip-row { margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--line); }
.tip-row .sw { margin-top: 3px; }
.tip-row p { margin: 2px 0 0; color: var(--muted); }
.tip-row .fix { color: var(--text); }

@media (max-width: 860px) {
  .split { grid-template-columns: 1fr; }
  .side { position: static; }
  .live textarea, .backdrop { padding: 18px 16px; }
  .live textarea { min-height: 260px; }
}
@media print {
  .nav, .hero, .side-actions, .hint, .foot, .editor-foot, .opts, .tip { display: none !important; }
  .wrap { padding: 0; max-width: none; }
  .split { grid-template-columns: 1fr; }
  .side { position: static; order: -1; }
  body { background: #fff; }
}
