/* =========================================================================
   ClearPen — readability grader styles
   Editorial ink-on-paper palette. Mobile-first. The .editor-backdrop and
   .editor-input MUST share identical box metrics and typography or the inline
   highlights will drift — keep their font, padding, border, line-height in sync.
   ========================================================================= */
:root {
  --bg: #f4f3ef;
  --surface: #ffffff;
  --ink: #1c1b18;
  --ink-soft: #51504b;
  --ink-faint: #77756f;
  --line: #e2e0d8;
  --paper: #fbfaf6;
  --accent: #2f6f4f;        /* clear green */
  --accent-deep: #1f4e37;
  --link: #1f5fa0;
  --link-deep: #144175;
  --good: #1e7d43;
  --good-bg: #e7f5ec;
  --warn: #b3261e;

  /* highlight colors — must read as distinct categories */
  --hl-passive: #fbe3a2;     /* amber */
  --hl-passive-line: #cf9b1e;
  --hl-adverb: #cfe6f7;      /* blue */
  --hl-adverb-line: #5a9bcb;
  --hl-weak: #e7dcf5;        /* purple — filler/wordy */
  --hl-weak-line: #9a78c4;
  --hl-long: #d9ead0;        /* green — long words */
  --hl-long-line: #79a861;
  --hl-hard: #f7d9c0;        /* orange — hard sentence */
  --hl-vhard: #f3bfae;       /* red-orange — very hard sentence */

  --radius: 12px;
  --shadow: 0 1px 3px rgba(28, 27, 24, .07), 0 4px 16px rgba(28, 27, 24, .05);
  --max: 820px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --editor-font: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --editor-size: 1.05rem;
  --editor-lh: 1.7;
  --editor-pad: 1rem;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px; line-height: 1.6; color: var(--ink); background: var(--bg);
}
body.has-sticky-bar { padding-bottom: 84px; }
img, svg { max-width: 100%; height: auto; }
a { color: var(--link); }
a:hover { color: var(--link-deep); }

.skip-link { position: absolute; left: -9999px; top: 0; background: var(--accent); color: #fff; padding: .5rem 1rem; z-index: 100; border-radius: 0 0 8px 0; font-weight: 700; }
.skip-link:focus { left: 0; }

/* ---------- header / nav ---------- */
.site-header { background: var(--ink); color: #fff; padding: .65rem 1rem; }
.site-header .inner { max-width: var(--max); margin: 0 auto; display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .5rem; color: #fff; text-decoration: none; font-weight: 800; font-size: 1.08rem; letter-spacing: .2px; }
.brand .pen { color: #9fd9bb; }
.brand svg { width: 26px; height: 26px; flex: none; }
.site-nav { margin-left: auto; display: flex; gap: .25rem .9rem; flex-wrap: wrap; }
.site-nav a { color: #d7d5cd; text-decoration: none; font-size: .85rem; font-weight: 600; padding: .25rem 0; }
.site-nav a:hover, .site-nav a[aria-current="page"] { color: #9fd9bb; }

/* ---------- layout ---------- */
main { max-width: var(--max); margin: 0 auto; padding: 1.25rem 1rem 2.5rem; }
.hero { padding: .5rem 0 .25rem; }
.hero h1 { font-size: 1.7rem; line-height: 1.2; margin: .25rem 0 .5rem; letter-spacing: -.3px; }
.hero .lede { color: var(--ink-soft); font-size: 1.04rem; margin: 0 0 .5rem; }
.hero .meta-line { color: var(--ink-faint); font-size: .82rem; margin: 0; }
@media (min-width: 700px) { .hero h1 { font-size: 2.15rem; } }

article.prose h2 { font-size: 1.4rem; margin: 2rem 0 .6rem; letter-spacing: -.2px; }
article.prose h3 { font-size: 1.12rem; margin: 1.4rem 0 .4rem; }
article.prose p, article.prose li { color: #2a2925; }
article.prose ul, article.prose ol { padding-left: 1.3rem; }
article.prose table { border-collapse: collapse; width: 100%; margin: 1rem 0; font-size: .95rem; }
article.prose th, article.prose td { border: 1px solid var(--line); padding: .5rem .65rem; text-align: left; }
article.prose th { background: #eeece4; }
article.prose td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- privacy badge ---------- */
.privacy-badge {
  display: inline-flex; align-items: center; gap: .45rem;
  background: var(--good-bg); border: 1.5px solid #bfe3cc; border-radius: 999px;
  padding: .4rem .85rem; font-size: .82rem; font-weight: 700; color: var(--good);
  margin: .6rem 0 .4rem; line-height: 1.3;
}
.privacy-badge svg { flex: none; }

/* ---------- editor / grader ---------- */
#grader { margin: 1rem 0 0; }
.editor-toolbar { display: flex; gap: .5rem; flex-wrap: wrap; margin: 0 0 .5rem; }
.btn { display: inline-block; border: none; cursor: pointer; text-decoration: none; font-weight: 700; font-size: .95rem; border-radius: 10px; padding: .7rem 1.05rem; min-height: 44px; }
.btn-sm { padding: .5rem .8rem; font-size: .85rem; min-height: 38px; }
.btn-secondary { background: var(--accent); color: #fff; }
.btn-secondary:hover { background: var(--accent-deep); }
.btn-ghost { background: var(--surface); color: var(--ink-soft); border: 1.5px solid var(--line); }
.btn-ghost:hover { border-color: var(--ink-faint); }

.editor-wrap {
  position: relative; background: var(--paper);
  border: 1.5px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.editor-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47, 111, 79, .18); }

/* Backdrop and textarea share EXACT metrics so highlights align. */
.editor-backdrop, .editor-input {
  margin: 0; border: 0; width: 100%;
  min-height: 240px; max-height: 60vh;
  padding: var(--editor-pad);
  font-family: var(--editor-font); font-size: var(--editor-size);
  line-height: var(--editor-lh); letter-spacing: 0;
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: break-word;
  tab-size: 4;
}
.editor-backdrop {
  position: absolute; inset: 0; overflow: auto;
  color: transparent; pointer-events: none; user-select: none;
  z-index: 1;
}
.backdrop-inner { color: transparent; }
.editor-input {
  position: relative; z-index: 2;
  background: transparent; color: var(--ink);
  resize: vertical; outline: none; display: block;
  -webkit-text-fill-color: var(--ink);
  caret-color: var(--ink);
}
.editor-input::placeholder { color: var(--ink-faint); -webkit-text-fill-color: var(--ink-faint); }

mark { border-radius: 3px; padding: .02em 0; color: transparent; -webkit-text-fill-color: transparent; box-decoration-break: clone; -webkit-box-decoration-break: clone; }
mark.hl-passive { background: var(--hl-passive); box-shadow: inset 0 -2px 0 var(--hl-passive-line); }
mark.hl-adverb { background: var(--hl-adverb); box-shadow: inset 0 -2px 0 var(--hl-adverb-line); }
mark.hl-weak { background: var(--hl-weak); box-shadow: inset 0 -2px 0 var(--hl-weak-line); }
mark.hl-long { background: var(--hl-long); box-shadow: inset 0 -2px 0 var(--hl-long-line); }
mark.hl-hard { background: var(--hl-hard); }
mark.hl-vhard { background: var(--hl-vhard); }

/* ---------- legend / filters ---------- */
.legend { display: flex; flex-wrap: wrap; gap: .4rem .5rem; margin: .7rem 0 0; }
.legend-item { display: inline-flex; align-items: center; gap: .35rem; font-size: .8rem; font-weight: 600; color: var(--ink-soft); background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: .25rem .6rem .25rem .45rem; cursor: pointer; user-select: none; }
.legend-item input { position: absolute; opacity: 0; width: 0; height: 0; }
.legend-swatch { width: 14px; height: 14px; border-radius: 4px; flex: none; }
.legend-item.hl-passive .legend-swatch { background: var(--hl-passive); border: 1px solid var(--hl-passive-line); }
.legend-item.hl-adverb .legend-swatch { background: var(--hl-adverb); border: 1px solid var(--hl-adverb-line); }
.legend-item.hl-weak .legend-swatch { background: var(--hl-weak); border: 1px solid var(--hl-weak-line); }
.legend-item.hl-long .legend-swatch { background: var(--hl-long); border: 1px solid var(--hl-long-line); }
.legend-item.hl-hard .legend-swatch { background: var(--hl-hard); border: 1px solid #d99a6a; }
.legend-item.hl-vhard .legend-swatch { background: var(--hl-vhard); border: 1px solid #d07a5e; }
.legend-item:has(input:not(:checked)) { opacity: .42; text-decoration: line-through; }
.legend-item input:focus-visible + .legend-swatch { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- score cards ---------- */
.results { margin-top: 1.4rem; }
.score-cards { display: grid; grid-template-columns: 1fr; gap: .7rem; }
@media (min-width: 560px) { .score-cards { grid-template-columns: repeat(3, 1fr); } }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: .9rem 1rem; display: flex; flex-direction: column; gap: .12rem; }
.card-label { font-size: .76rem; font-weight: 700; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .5px; }
.card-value { font-size: 2.1rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.5px; line-height: 1.05; }
.card-sub { font-size: .85rem; color: var(--ink-soft); font-weight: 600; }
.card-help { font-size: .76rem; color: var(--ink-faint); margin-top: .15rem; }
.card-primary { background: var(--ink); border-color: var(--ink); }
.card-primary .card-label { color: #a8a69d; }
.card-primary .card-value { color: #9fd9bb; }
.card-primary .card-sub { color: #d7d5cd; }
.card-primary .card-help { color: #8d8b83; }
.card-accent .card-value { color: var(--accent-deep); }
.card-good { background: var(--good-bg); border-color: #bfe3cc; }
.card-good .card-value { color: var(--good); }
.empty-note { color: var(--ink-faint); background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius); padding: 1.2rem; text-align: center; font-size: .95rem; grid-column: 1 / -1; }

/* ---------- secondary stats ---------- */
.stat-grid { margin-top: 1.4rem; }
.stat-grid h3, .dist-block h3, .tips-block h3 { font-size: 1.05rem; margin: 0 0 .6rem; }
.stat-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; }
@media (min-width: 560px) { .stat-cards { grid-template-columns: repeat(4, 1fr); } }
.stat-cell { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .7rem; display: flex; flex-direction: column; gap: .1rem; }
.stat-val { font-size: 1.15rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-key { font-size: .74rem; color: var(--ink-faint); font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.footnote { font-size: .76rem; color: var(--ink-faint); margin: .5rem 0 0; }

/* ---------- distribution chart ---------- */
.dist-block { margin-top: 1.5rem; }
.dist-lede { color: var(--ink-soft); font-size: .9rem; margin: 0 0 .7rem; }
.dist-chart { display: grid; grid-template-columns: repeat(5, 1fr); gap: .5rem; align-items: end; height: 130px; padding: 0 .25rem; }
.dist-col { display: flex; flex-direction: column; align-items: center; gap: .3rem; height: 100%; }
.dist-bar-wrap { width: 100%; height: 100%; display: flex; align-items: flex-end; }
.dist-bar { width: 100%; min-height: 3px; border-radius: 6px 6px 0 0; position: relative; transition: height .25s ease; }
.dist-vshort { background: #bfe3cc; }
.dist-short { background: #9fd9bb; }
.dist-med { background: var(--accent); }
.dist-long { background: #d99a6a; }
.dist-vlong { background: #cf6f52; }
.dist-count { position: absolute; top: -1.2rem; left: 0; right: 0; text-align: center; font-size: .78rem; font-weight: 800; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
.dist-axis { font-size: .74rem; color: var(--ink-faint); font-weight: 700; font-variant-numeric: tabular-nums; }
.dist-axis-label { text-align: center; font-size: .72rem; color: var(--ink-faint); margin: .2rem 0 0; text-transform: uppercase; letter-spacing: .4px; }
.dist-flag { font-size: .88rem; color: var(--ink-soft); background: #fdeee2; border-left: 4px solid #d99a6a; padding: .55rem .8rem; border-radius: 0 8px 8px 0; margin: .9rem 0 0; }

/* ---------- tips ---------- */
.tips-block { margin-top: 1.5rem; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; }
.tips-list { margin: 0; padding-left: 1.1rem; }
.tips-list li { margin: .5rem 0; color: #2a2925; font-size: .95rem; }
.tips-list strong { color: var(--ink); }

/* ---------- partner panel ---------- */
.partner-panel { margin-top: 1.5rem; border-radius: var(--radius); background: linear-gradient(135deg, var(--ink), #2c2a25); color: #ece9e0; padding: 1.1rem 1.2rem; box-shadow: var(--shadow); }
.partner-panel h3 { margin: .3rem 0 .4rem; color: #9fd9bb; font-size: 1.08rem; }
.partner-panel p { margin: .3rem 0; font-size: .92rem; color: #cfccc3; }
.partner-links { margin: .8rem 0 .25rem; display: grid; gap: .6rem; }
@media (min-width: 560px) { .partner-links { grid-template-columns: 1fr 1fr; } }
.partner-card { display: block; background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.14); border-radius: 10px; padding: .8rem .9rem; text-decoration: none; }
.partner-card:hover { background: rgba(255,255,255,.12); }
.partner-name { display: block; font-weight: 800; color: #fff; font-size: .98rem; }
.partner-blurb { display: block; font-size: .82rem; color: #cfccc3; margin-top: .2rem; }
.disclosure { font-size: .74rem !important; color: #a8a69d !important; }

/* ---------- sticky score bar ---------- */
.sticky-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; display: grid; grid-template-columns: repeat(3, 1fr); background: var(--ink); border-top: 3px solid var(--accent); padding: .5rem .5rem calc(.5rem + env(safe-area-inset-bottom)); cursor: pointer; box-shadow: 0 -4px 18px rgba(28, 27, 24, .3); }
.sb-cell { display: flex; flex-direction: column; align-items: center; gap: .04rem; min-width: 0; }
.sb-num { color: #9fd9bb; font-size: 1.45rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.sb-label { color: #a8a69d; font-size: .62rem; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; text-align: center; }
@media (min-width: 700px) { .sticky-bar { max-width: var(--max); margin: 0 auto; border-radius: 14px 14px 0 0; } }

/* ---------- FAQ ---------- */
.faq details { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; margin: .5rem 0; }
.faq summary { font-weight: 700; cursor: pointer; padding: .8rem 1rem; }
.faq details p { padding: 0 1rem .8rem; margin: 0; color: #2a2925; }

/* ---------- callouts & link cards ---------- */
.callout { background: var(--surface); border: 1px solid var(--line); border-left: 5px solid var(--accent); border-radius: 10px; padding: .8rem 1rem; margin: 1rem 0; font-size: .95rem; }
.tool-links { display: grid; grid-template-columns: 1fr; gap: .6rem; margin: 1rem 0; padding: 0; list-style: none; }
@media (min-width: 560px) { .tool-links { grid-template-columns: 1fr 1fr; } }
.tool-links a { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .8rem 1rem; text-decoration: none; font-weight: 700; color: var(--accent-deep); box-shadow: var(--shadow); }
.tool-links a:hover { border-color: var(--accent); }
.tool-links .sub { display: block; font-weight: 400; font-size: .83rem; color: var(--ink-faint); margin-top: .15rem; }

/* ---------- footer ---------- */
.site-footer { background: var(--ink); color: #a8a69d; margin-top: 2rem; padding: 1.5rem 1rem 2rem; font-size: .84rem; }
body.has-sticky-bar .site-footer { padding-bottom: 6rem; }
.site-footer .inner { max-width: var(--max); margin: 0 auto; }
.site-footer a { color: #d7d5cd; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: .4rem 1.2rem; margin-bottom: .9rem; }
.site-footer nav a { text-decoration: none; font-weight: 600; }
.site-footer nav a:hover { color: #9fd9bb; }
.site-footer .fine { margin: .35rem 0; line-height: 1.5; }

/* ---------- 404 ---------- */
.page-404 { text-align: center; padding: 4rem 1rem; }
.page-404 .big { font-size: 5rem; font-weight: 800; color: var(--ink); margin: 0; }

/* ---------- reduced motion ---------- */
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } .dist-bar { transition: none; } }

/* ---------- print ---------- */
@media print {
  .site-header, .site-footer, .sticky-bar, .editor-toolbar, .legend, .partner-panel { display: none !important; }
  body { background: #fff; padding-bottom: 0; }
  .editor-wrap { box-shadow: none; }
}
