:root {
  --bg: #f3f0e8;
  --surface: #fffdf8;
  --surface-2: #f8f5ee;
  --ink: #1d2433;
  --muted: #5c6477;
  --line: rgba(29, 36, 51, 0.13);
  --accent: #2c4bb0;
  --accent-ink: #ffffff;
  --accent-soft: rgba(44, 75, 176, 0.1);
  --warn: #9a3b2a;
  --track: #dcd7cb;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 24, 40, 0.06), 0 8px 24px rgba(20, 24, 40, 0.08);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151d;
    --surface: #182030;
    --surface-2: #1d2639;
    --ink: #e7eaf3;
    --muted: #9ba4b9;
    --line: rgba(255, 255, 255, 0.1);
    --accent: #8ea6ff;
    --accent-ink: #0f1422;
    --accent-soft: rgba(142, 166, 255, 0.14);
    --warn: #f0a08f;
    --track: #2c364b;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 10px 30px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 var(--sans);
}
a { color: var(--accent); }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.15; margin: 0 0 0.5em; }
p { margin: 0 0 0.8em; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* header */
.site-header {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 10px clamp(16px, 4vw, 40px);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  position: relative; z-index: 2;
}
.brand { display: block; line-height: 0; }
#logo { width: 230px; height: 46px; display: block; }
@media (prefers-color-scheme: dark) { #logo { filter: invert(0.9) hue-rotate(180deg); } }
.site-header nav { display: flex; gap: 4px; flex-wrap: wrap; }
.site-header nav a {
  text-decoration: none; color: var(--muted); font-weight: 600; font-size: 15px;
  padding: 8px 12px; border-radius: 999px;
}
.site-header nav a:hover { color: var(--ink); background: var(--surface-2); }
.site-header nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }

main { max-width: 1480px; margin: 0 auto; padding: 0 clamp(16px, 4vw, 40px) 40px; }

.hero { padding: clamp(24px, 5vw, 48px) 0 clamp(16px, 3vw, 28px); max-width: 760px; }
.hero h1 { font-size: clamp(32px, 5vw, 54px); letter-spacing: -0.01em; }
.hero p { font-size: clamp(16px, 1.6vw, 19px); color: var(--muted); }
.notice { background: var(--accent-soft); color: var(--ink) !important; padding: 10px 14px; border-radius: 10px; font-size: 15px !important; }

/* workspace */
.workspace {
  display: grid;
  grid-template-columns: minmax(330px, 410px) minmax(0, 1fr);
  grid-template-areas: "panel stage" "panel reading";
  gap: 24px 32px;
  align-items: start;
}
.panel {
  grid-area: panel;
  position: sticky; top: 12px;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 4px 20px 20px;
  scrollbar-width: thin;
}
.stage { grid-area: stage; min-width: 0; }
.reading-col { grid-area: reading; min-width: 0; }

.step { padding: 18px 0 6px; border-bottom: 1px solid var(--line); }
.step:last-child { border-bottom: 0; }
.step h2 { font-size: 20px; display: flex; align-items: center; gap: 10px; }
.step-num {
  display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 50%;
  background: var(--ink); color: var(--surface); font: 700 14px var(--sans);
}
.hint { font-size: 13.5px; color: var(--muted); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip {
  font: 500 14px var(--sans); color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line);
  padding: 6px 11px; border-radius: 999px; cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
}
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.field { display: block; font-weight: 600; font-size: 14px; margin: 10px 0 6px; }
textarea, input[type="text"], select {
  width: 100%; font: 15px/1.45 var(--sans); color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 11px;
}
textarea { resize: vertical; }
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.matched { font-size: 13.5px; min-height: 1.4em; margin-top: 8px; color: var(--muted); }
.tag {
  display: inline-block; font-size: 12.5px; font-weight: 600; color: var(--accent);
  background: var(--accent-soft); padding: 1px 8px; border-radius: 999px; margin: 1px 0;
}
.tag.neg { color: var(--warn); background: rgba(154, 59, 42, 0.1); }

/* sliders */
.group { border: 0; padding: 0; margin: 0 0 12px; }
.group legend { font: 700 12px var(--sans); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); padding: 8px 0 4px; }
.trait { padding: 6px 0 4px; }
.ends { display: flex; justify-content: space-between; font-size: 14px; gap: 8px; }
.ends span { transition: color 0.12s, font-weight 0.12s; color: var(--muted); }
.trait.lean-l .l, .trait.lean-r .r { color: var(--ink); font-weight: 650; }
.trait .q { font-size: 12.5px; color: var(--muted); margin: 2px 0 0; opacity: 0.85; }
input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 6px; border-radius: 3px; margin: 9px 0 4px;
  background:
    linear-gradient(90deg, transparent calc(50% - 1px), var(--muted) calc(50% - 1px), var(--muted) calc(50% + 1px), transparent calc(50% + 1px)),
    var(--fill, linear-gradient(transparent, transparent)),
    linear-gradient(var(--track), var(--track));
  cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 20px; height: 20px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--accent); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--accent); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
}
input[type="range"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; }

.row { display: flex; gap: 8px; margin: 12px 0 6px; flex-wrap: wrap; }
.row.three > * { flex: 1 1 90px; }
.mini { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: var(--muted); }
.mini select { padding: 7px 8px; font-size: 14px; }
.mini.inline { flex-direction: row; align-items: center; gap: 6px; }
.mini.inline select { width: auto; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  font: 600 14.5px var(--sans); color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 14px; cursor: pointer; white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, transform 0.05s;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.55; cursor: progress; }
.link-btn { background: none; border: 0; color: var(--accent); font: 600 13px var(--sans); cursor: pointer; padding: 0; margin-left: 6px; text-decoration: underline; }
.icon-btn { background: none; border: 0; font-size: 28px; line-height: 1; color: var(--muted); cursor: pointer; padding: 0 6px; }

/* stage */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  margin-bottom: 12px;
}
.tb-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tb-group.end { margin-left: auto; }
.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; }
.toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; }
.toggle input { width: 16px; height: 16px; accent-color: var(--accent); }
.paper-wrap {
  position: relative; line-height: 0;
  border-radius: 6px; overflow: hidden;
  box-shadow: 0 2px 4px rgba(20, 20, 30, 0.12), 0 18px 40px rgba(20, 20, 30, 0.16);
  background: #fbf8f0;
}
.paper-wrap canvas { width: 100%; height: auto; display: block; }
#overlay { position: absolute; inset: 0; pointer-events: none; }
.progress { height: 3px; background: transparent; margin-top: 6px; border-radius: 2px; overflow: hidden; }
#progress-bar { height: 100%; width: 0; background: var(--accent); opacity: 0.55; }

/* reading */
.reading { margin-top: 8px; }
.reading > h2 { font-size: 28px; }
.you-are { color: var(--muted); }
.portrait { font-family: var(--serif); font-size: 21px; line-height: 1.45; max-width: 60ch; }
.portrait b { font-weight: 650; }
.features { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; margin: 18px 0 14px; }
.feature {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px 12px; font-size: 14.5px;
}
.feature header { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.feature h3 { font-size: 17px; margin: 0; }
.feature .value { font-size: 12.5px; font-weight: 700; color: var(--accent); white-space: nowrap; }
.feature .band { margin-bottom: 8px; }
.feature .shape { font-family: var(--serif); font-size: 15px; color: var(--muted); }
.because { display: block; font-size: 12.5px; color: var(--muted); }
.meter { position: relative; height: 4px; border-radius: 2px; background: linear-gradient(90deg, var(--track), var(--track)); margin: 2px 0 10px; }
.meter::after { content: ""; position: absolute; left: 50%; top: -3px; width: 1px; height: 10px; background: var(--muted); opacity: 0.6; }
.meter span { position: absolute; top: 50%; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); transform: translate(-50%, -50%); box-shadow: 0 0 0 3px var(--surface); }

.cta {
  display: block; margin-top: 24px; padding: 20px 22px; border-radius: var(--radius);
  background: var(--ink); color: var(--surface); text-decoration: none;
}
.cta strong { display: block; font-family: var(--serif); font-size: 22px; margin-bottom: 4px; }
.cta span { opacity: 0.85; }
.cta:hover { filter: brightness(1.08); }

/* dialog */
dialog {
  border: 0; border-radius: 18px; padding: 20px; width: min(680px, calc(100vw - 24px));
  background: var(--surface); color: var(--ink); box-shadow: 0 30px 80px rgba(0, 0, 0, 0.4);
}
dialog::backdrop { background: rgba(10, 14, 24, 0.55); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; }
.dialog-head h2 { margin: 0; font-size: 24px; }
#card-preview { width: 100%; height: auto; border-radius: 10px; margin: 14px 0; background: #1d2433; display: block; }
.share-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.link-row { display: flex; gap: 8px; }
.link-row input { flex: 1; font-size: 13.5px; }
.status { font-size: 14px; color: var(--muted); min-height: 1.3em; margin-top: 10px; }

/* footer */
.site-footer {
  max-width: 1480px; margin: 0 auto; padding: 24px clamp(16px, 4vw, 40px) 40px;
  font-size: 14px; color: var(--muted); border-top: 1px solid var(--line);
}
.site-footer p { max-width: 90ch; }

/* generic content pages */
.prose { max-width: 820px; }
.prose h2 { font-size: 30px; margin-top: 1.4em; }
.prose h3 { font-size: 21px; margin-top: 1.2em; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}

@media (max-width: 960px) {
  .workspace { grid-template-columns: minmax(0, 1fr); grid-template-areas: "stage" "panel" "reading"; }
  .panel { position: static; max-height: none; overflow: visible; }
  #logo { width: 190px; height: 40px; }
}
@media (max-width: 560px) {
  .toolbar { gap: 6px; }
  .btn { padding: 8px 11px; }
  .site-header { flex-wrap: wrap; justify-content: center; }
  .portrait { font-size: 18px; }
}

/* ---- compare page ---- */
.small { font-size: 13.5px; }
.compare-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 24px; align-items: start; }
.compare-grid h2 { font-size: 24px; }
.drop {
  border: 2px dashed var(--line); border-radius: var(--radius); padding: 28px 16px; text-align: center;
  color: var(--muted); background: var(--surface-2); transition: border-color 0.15s, background 0.15s;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop p { margin: 6px 0 12px; }
.row.center { justify-content: center; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }
.tips { margin: 14px 0 8px; font-size: 14.5px; }
.tips summary { font-weight: 650; cursor: pointer; }
.tips ol { padding-left: 1.3em; margin: 8px 0; }
.tips li { margin-bottom: 4px; }
.editor { width: 100%; height: auto; display: block; border-radius: 8px; background: #fff; touch-action: none; cursor: crosshair; }
#measured-canvas { cursor: default; }
.controls { display: grid; gap: 10px; margin: 12px 0 4px; }
.controls input[type="text"] { font-weight: 400; }
.legend { font-size: 12.5px; color: var(--muted); display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; }
.sw { display: inline-block; width: 14px; height: 10px; border-radius: 2px; vertical-align: middle; margin-right: 2px; }
.sw.z1 { background: rgba(90,140,230,0.45); } .sw.z2 { background: rgba(240,190,60,0.6); } .sw.z3 { background: rgba(230,100,140,0.45); }
.sw.bl { height: 3px; background: rgb(200,40,60); } .sw.sl { width: 3px; height: 12px; background: rgb(30,140,90); transform: skewX(-20deg); } .sw.wd { height: 3px; background: rgb(120,70,190); }

.results { margin-top: 32px; }
.results > h2 { font-size: 28px; margin-top: 36px; }
.score-box { display: flex; gap: 24px; align-items: center; }
.score-num { display: flex; flex-direction: column; align-items: center; min-width: 110px; }
#score { font: 700 54px/1 var(--serif); color: var(--accent); }
.score-body { flex: 1; }
.score-body p { margin: 10px 0 0; font-size: 17px; }
.score-track { height: 10px; border-radius: 5px; background: var(--track); overflow: hidden; }
#score-meter { height: 100%; background: linear-gradient(90deg, #c76b4f, #d9b44a 50%, #4f9c6f); width: 0; transition: width 0.6s; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.ftable { width: 100%; border-collapse: collapse; font-size: 14.5px; }
.ftable th, .ftable td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.ftable thead th { font-size: 12.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.ftable tbody th { font-weight: 650; width: 22%; }
.ftable td.num { font-weight: 700; color: var(--accent); text-align: right; white-space: nowrap; }
.ftable tr.manual { background: var(--surface-2); }
.ftable tr:last-child th, .ftable tr:last-child td { border-bottom: 0; }

.track { position: relative; height: 4px; border-radius: 2px; background: var(--track); margin: 10px 6px 6px; min-width: 120px; }
.track::after { content: ""; position: absolute; left: 50%; top: -3px; width: 1px; height: 10px; background: var(--muted); opacity: 0.6; }
.mk { position: absolute; top: 50%; width: 13px; height: 13px; transform: translate(-50%, -50%); z-index: 1; }
.mk.real { border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--surface); }
.mk.gen { background: transparent; border: 2.5px solid #c76b4f; transform: translate(-50%, -50%) rotate(45deg); width: 11px; height: 11px; }
.mk-legend { white-space: nowrap; margin-left: 10px; font-size: 13.5px; }
.mk-legend .mk { position: relative; display: inline-block; top: auto; transform: none; vertical-align: -1px; margin-right: 4px; }
.mk-legend .mk.gen { transform: rotate(45deg); }

.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 440px), 1fr)); gap: 14px; }
.check { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 12px 14px 14px; margin: 0; }
.check legend { font-weight: 650; font-family: var(--serif); font-size: 17px; padding: 0 4px; }
.opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.opt { display: flex; flex-direction: column; gap: 4px; align-items: stretch; font-size: 13px; font-weight: 600; cursor: pointer; border: 2px solid transparent; border-radius: 10px; padding: 4px; }
.opt input { position: absolute; opacity: 0; pointer-events: none; }
.opt canvas { width: 100%; height: auto; border-radius: 6px; background: #fbf8f0; }
.opt:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.opt:has(input:focus-visible) { outline: 2px solid var(--accent); }
.opt.skip { justify-content: center; align-items: center; color: var(--muted); border: 1px dashed var(--line); min-height: 60px; }

.trait-summary p { font-size: 16px; }
.trait-compare { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px 24px; margin-top: 10px; }
.trait-cmp { padding: 6px 0; }
.trait-cmp .ends span { color: var(--ink); }
.trait-cmp.weak { opacity: 0.5; }
.trait-cmp p { margin: 0; }
.actions { margin-top: 28px; }

@media (max-width: 900px) {
  .compare-grid { grid-template-columns: minmax(0, 1fr); }
  .score-box { flex-direction: column; align-items: stretch; text-align: center; }
}

/* ---- rules page ---- */
.prose.wide { max-width: none; }
.toc { display: flex; flex-wrap: wrap; gap: 6px 18px; padding: 14px 18px; margin-bottom: 8px; }
.toc a { font-weight: 600; text-decoration: none; }
.traits-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 520px), 1fr)); gap: 8px 28px; }
.trait-group h3 { font-size: 15px; font-family: var(--sans); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-top: 1em; }
.trait-card { padding: 10px 0; border-bottom: 1px solid var(--line); }
.trait-card h4 { font-size: 17px; margin: 0 0 2px; font-family: var(--serif); }
.trait-card p { margin: 0 0 4px; }
.rules-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 520px), 1fr)); gap: 16px; }
.area-title { grid-column: 1 / -1; font-size: 24px; margin: 18px 0 0; }
.rule h4 { font-size: 20px; margin: 0 0 4px; font-family: var(--serif); }
.rule .pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0; }
.rule figure { margin: 0; }
.rule canvas { width: 100%; height: auto; border-radius: 8px; background: #fbf8f0; display: block; }
.rule figcaption { font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 4px; }
.bands { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: 14.5px; margin: 8px 0 12px; }
.bands dt { font-weight: 650; }
.bands dd { margin: 0; color: var(--muted); }
.drivers { list-style: none; padding: 0; margin: 4px 0 0; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 14px; }
.dir.up { color: #3b8a5c; } .dir.down { color: #c0573f; }
#rule-form { grid-column: 1 / -1; }
.forms { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: 16px; margin-top: 10px; }
.forms figcaption { font-weight: 400; color: var(--ink); font-size: 14.5px; }
.forms .drivers { font-size: 13px; }

/* own sentence above the paper, word-selection actions */
.own-text { margin-bottom: 12px; }
.own-text .field { margin-top: 0; font-family: var(--serif); font-size: 18px; }
.own-text textarea { font-size: 16px; background: var(--surface); }
.text-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin-top: 6px; min-height: 1.4em; }
.text-actions .link-btn { margin-left: 0; }
.text-actions .count { margin-left: auto; font-size: 12.5px; color: var(--muted); }
.chip-actions { display: flex; align-items: center; gap: 10px; margin: -6px 0 12px; font-size: 13px; color: var(--muted); }
.chip-actions .link-btn { margin-left: 0; }
