/* Rival Scope — theme via [data-theme] on <html>, set by theme.js before paint. */

:root[data-theme="light"] {
  --bg: #f6f7f9; --panel: #ffffff; --ink: #17222e; --muted: #5b6b7c;
  --line: #dde3ea; --accent: #1f6feb; --accent-ink: #ffffff;
  --red: #c02b2b; --red-bg: #fdf1f1; --yellow: #a06a00; --yellow-bg: #fdf7ea;
  --ok: #1d7a4a; --ok-bg: #eef8f1;
  --code-bg: #eef1f5; --shadow: 0 1px 3px rgba(20, 30, 50, 0.08);
}
:root[data-theme="dark"] {
  --bg: #101620; --panel: #18202c; --ink: #e6ebf2; --muted: #93a3b5;
  --line: #2a3646; --accent: #6cb1ff; --accent-ink: #0c1520;
  --red: #f08080; --red-bg: #2a1c1e; --yellow: #e0b45c; --yellow-bg: #282215;
  --ok: #6fce9e; --ok-bg: #16281e;
  --code-bg: #222c3a; --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.55;
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.82em; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

/* --- Header ------------------------------------------------------------ */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.9rem 1.4rem; border-bottom: 1px solid var(--line); background: var(--panel);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 0.7rem; }
.brand h1 { font-size: 1.15rem; margin: 0; }
.logo { color: var(--accent); font-size: 1.3rem; }
.backlink { color: var(--muted); text-decoration: none; font-size: 0.85rem; margin-right: 0.4rem; }
.backlink:hover { color: var(--ink); }
.session { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.credits { color: var(--ok); font-weight: 600; font-size: 0.9rem; }

button { font: inherit; cursor: pointer; }
.btn {
  background: var(--panel); border: 1px solid var(--line); color: var(--ink);
  padding: 0.4rem 0.95rem; font-size: 0.9rem; border-radius: 8px; text-decoration: none;
  display: inline-block;
}
.btn:hover { border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.primary {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
  font-weight: 600; padding: 0.5rem 1.2rem;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary:disabled { opacity: 0.55; cursor: default; }
.linklike { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; font-size: inherit; }

/* --- Layout ------------------------------------------------------------ */
main { max-width: 1000px; margin: 0 auto; padding: 1.5rem 1.2rem 3rem; }
.hero h2 { margin: 0.4rem 0 0.5rem; font-size: 1.5rem; }
.hero p { max-width: 52rem; }
.hero-actions { margin: 1rem 0 0.4rem; }
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 1.1rem 1.3rem; margin-top: 1.4rem;
}
.panel h3 { margin-top: 0; }
label { display: block; font-size: 0.88rem; color: var(--muted); margin: 0.9rem 0 0.25rem; }
textarea, input[type="text"] {
  width: 100%; font: inherit; color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; outline: none; padding: 0.6rem 0.75rem;
}
textarea { resize: vertical; }
textarea:focus, input[type="text"]:focus { border-color: var(--accent); }
.filerow { margin: 0.4rem 0 0; font-size: 0.82rem; }
.filelabel { display: inline; color: var(--muted); margin: 0; }
input[type="file"] { font-size: 0.8rem; color: var(--muted); }
.optrow { display: grid; grid-template-columns: 1fr 1.4fr; gap: 0.9rem; }
@media (max-width: 720px) { .optrow { grid-template-columns: 1fr; } }
.runrow { display: flex; align-items: center; gap: 0.9rem; margin-top: 1.2rem; flex-wrap: wrap; }
.meter { font-size: 0.8rem; color: var(--muted); }

/* --- Prescan ------------------------------------------------------------ */
.prescan { margin-top: 0.9rem; }
.prescan h3 { font-size: 0.9rem; margin: 0 0 0.4rem; }
.comp-chip {
  display: inline-block; background: var(--code-bg); border: 1px solid var(--line);
  border-radius: 999px; padding: 0.15rem 0.7rem; font-size: 0.84rem; margin: 0 0.35rem 0.35rem 0;
}

/* --- Progress ------------------------------------------------------------ */
.steps { list-style: none; margin: 0.8rem 0 0; padding: 0; display: grid; gap: 0.45rem; }
.step { display: flex; align-items: center; gap: 0.6rem; font-size: 0.92rem; color: var(--muted); }
.step-ic { width: 0.85rem; height: 0.85rem; border-radius: 50%; border: 2px solid var(--line); flex: none; }
.step.live { color: var(--ink); }
.step.live .step-ic { border-color: var(--accent); animation: pulse 1.2s infinite; }
.step.done { color: var(--ink); }
.step.done .step-ic { background: var(--ok); border-color: var(--ok); }
@keyframes pulse { 50% { transform: scale(1.25); } }

/* --- Result ------------------------------------------------------------ */
.res-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.res-head h3 { margin: 0; font-size: 1.3rem; }
.verdict { color: var(--muted); font-style: italic; max-width: 50rem; }
.sec { margin: 1.6rem 0 0.6rem; font-size: 1.02rem; }
.count { color: var(--muted); font-weight: 400; }
.attract-badge {
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
  border-radius: 999px; padding: 0.25rem 0.75rem; white-space: nowrap;
}
.attract-high { background: var(--ok-bg); color: var(--ok); }
.attract-moderate { background: var(--yellow-bg); color: var(--yellow); }
.attract-low { background: var(--red-bg); color: var(--red); }

.reconcile {
  margin-top: 0.9rem; border: 1px solid var(--yellow); background: var(--yellow-bg);
  color: var(--yellow); border-radius: 10px; padding: 0.6rem 0.9rem; font-size: 0.9rem;
}
.reconcile p { margin: 0; }

.score-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.7rem; }
@media (max-width: 860px) { .score-row { grid-template-columns: 1fr 1fr; } }
.score-card { background: var(--bg); border: 1px solid var(--line); border-top-width: 4px; border-radius: 10px; padding: 0.7rem 0.8rem; }
.score-card.band-good { border-top-color: var(--ok); }
.score-card.band-mid { border-top-color: var(--yellow); }
.score-card.band-bad { border-top-color: var(--red); }
.sc-num { font-size: 1.4rem; font-weight: 700; }
.band-good .sc-num { color: var(--ok); }
.band-mid .sc-num { color: var(--yellow); }
.band-bad .sc-num { color: var(--red); }
.sc-label { font-weight: 700; font-size: 0.86rem; margin-top: 0.1rem; }
.sc-note { margin: 0.35rem 0 0; font-size: 0.8rem; color: var(--muted); }

/* --- Positioning map ----------------------------------------------------- */
.pos-wrap { overflow-x: auto; }
.pos-svg { width: 100%; max-width: 660px; height: auto; display: block; margin: 0 auto; }
.pos-axis { stroke: var(--muted); stroke-width: 1.5; fill: none; }
.pos-grid { stroke: var(--line); stroke-width: 0.75; stroke-dasharray: 3 4; }
.pos-dot { fill: var(--muted); opacity: 0.85; }
.pos-dot.you { fill: var(--accent); opacity: 1; }
.pos-label { fill: var(--muted); font-size: 12px; }
.pos-label.you { fill: var(--accent); font-weight: 700; }
.pos-axis-label { fill: var(--ink); font-size: 12.5px; font-weight: 600; }
.gapline { font-size: 0.93rem; }

/* --- Four actions --------------------------------------------------------- */
.fa-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
@media (max-width: 720px) { .fa-grid { grid-template-columns: 1fr; } }
.fa-cell { border: 1px solid var(--line); border-radius: 10px; padding: 0.7rem 0.9rem; background: var(--bg); }
.fa-cell h4 { margin: 0 0 0.35rem; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; }
.fa-cell ul { margin: 0; padding-left: 1.1rem; font-size: 0.9rem; display: grid; gap: 0.25rem; }
.fa-cell p { margin: 0; font-size: 0.88rem; }
.fa-eliminate h4 { color: var(--red); }
.fa-reduce h4 { color: var(--yellow); }
.fa-raise h4 { color: var(--accent); }
.fa-create h4 { color: var(--ok); }

/* --- Opportunities --------------------------------------------------------- */
#oppList { display: grid; gap: 0.7rem; }
.flag-card { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 0.8rem 1rem; }
.flag-card.sev-high { border-left: 4px solid var(--red); }
.flag-card.sev-medium { border-left: 4px solid var(--yellow); }
.flag-card.sev-low { border-left: 4px solid var(--line); }
.fc-head { display: flex; gap: 0.8rem; align-items: baseline; flex-wrap: wrap; }
.fc-sev { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; border-radius: 999px; padding: 0.1rem 0.55rem; }
.fc-sev.high { background: var(--red-bg); color: var(--red); }
.fc-sev.medium { background: var(--yellow-bg); color: var(--yellow); }
.fc-sev.low { background: var(--code-bg); color: var(--muted); }
.fc-cat { font-weight: 700; font-size: 0.92rem; }
.fc-problem { margin: 0.4rem 0; font-size: 0.93rem; }
.fc-suggestion { margin: 0.4rem 0 0; font-size: 0.9rem; color: var(--ok); }
.fc-suggestion strong { color: inherit; }

/* --- Moves & statement ------------------------------------------------------ */
.moves { margin: 0.4rem 0 0; padding-left: 1.3rem; display: grid; gap: 0.4rem; }
.moves li { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem 0.8rem; font-size: 0.92rem; }
.stmt-label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0.9rem 0 0.2rem; }
.stmt blockquote {
  margin: 0; padding: 0.7rem 0.9rem; border-radius: 10px; font-size: 0.92rem;
  border: 1px solid var(--line); background: var(--code-bg); overflow-wrap: break-word;
}
.stmt-reco { background: var(--ok-bg) !important; }

/* --- Exports, raw, history --------------------------------------------------- */
.exports { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 1.4rem; }
.raw { background: var(--code-bg); border: 1px solid var(--line); border-radius: 10px; padding: 1rem; overflow-x: auto; font-size: 0.82rem; white-space: pre-wrap; }
.hist { list-style: none; margin: 0.6rem 0 0; padding: 0; display: grid; gap: 0.4rem; }
.hist-btn {
  width: 100%; text-align: left; background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 0.5rem 0.8rem; font-size: 0.88rem; color: var(--ink);
}
.hist-btn:hover { border-color: var(--accent); }
.hist-row { display: flex; gap: 0.4rem; align-items: stretch; flex-wrap: wrap; }
.hist-row .hist-btn { flex: 1 1 16rem; }
.hist-tools { display: flex; gap: 0.3rem; flex-wrap: wrap; align-items: center; }
.hist-row.pinned .hist-btn { border-color: var(--accent); border-left-width: 4px; }
.btn.small { padding: 0.35rem 0.6rem; font-size: 0.78rem; }

/* --- Map exports, checklist, low-confidence flag, diff ------------------------ */
.mapexports { display: flex; gap: 0.45rem; flex-wrap: wrap; margin: 0.5rem 0 0; }
.score-card.low-conf { border-style: dashed; }
.sc-flag {
  margin: 0.3rem 0 0; font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--yellow);
}
.checks { list-style: none; margin: 0.5rem 0 0; padding: 0; display: grid; gap: 0.35rem; }
.check-item {
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem 0.7rem;
}
.check-item label { display: flex; gap: 0.55rem; align-items: baseline; cursor: pointer; font-weight: 400; }
.check-item input { margin: 0; flex: none; }
.check-text { flex: 1 1 auto; font-size: 0.92rem; }
.check-src { flex: none; font-size: 0.72rem; color: var(--muted); }
.check-item.done .check-text { text-decoration: line-through; color: var(--muted); }
.difftable { width: 100%; border-collapse: collapse; margin: 0.5rem 0 0.4rem; font-size: 0.88rem; }
.difftable th, .difftable td {
  text-align: left; padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--line);
}
.difftable th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); }
.difftable tr.better td:last-child { color: var(--ok); font-weight: 700; }
.difftable tr.worse td:last-child { color: var(--red); font-weight: 700; }
.difftable tr.flat td:last-child { color: var(--muted); }

/* --- Footer & toasts ------------------------------------------------------ */
.foot {
  border-top: 1px solid var(--line); padding: 1rem 1.4rem; display: flex;
  justify-content: space-between; gap: 1rem; font-size: 0.85rem; color: var(--muted); flex-wrap: wrap;
}
.foot a { color: var(--muted); margin-left: 0.8rem; }
.toasts { position: fixed; bottom: 1rem; right: 1rem; display: grid; gap: 0.5rem; z-index: 50; max-width: min(420px, 90vw); }
.toast {
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--ok);
  border-radius: 10px; padding: 0.6rem 0.9rem; font-size: 0.88rem; box-shadow: var(--shadow);
  transition: opacity 0.5s;
}
.toast.err { border-left-color: var(--red); }
.toast.gone { opacity: 0; }
.toast a { color: var(--accent); margin-left: 0.4rem; }

/* --- Print: just the analysis -------------------------------------------------- */
@media print {
  .top, .foot, form, .hero, #how, #historyPanel, .toasts, .exports, .mapexports,
  #progressPanel, #diffPanel { display: none !important; }
  body { background: #fff; color: #000; }
  .panel { box-shadow: none; page-break-inside: auto; }
  .flag-card, .score-card, .fa-cell, .check-item, .pos-wrap, .stmt { break-inside: avoid; }
  .pos-svg { max-width: 100%; height: auto; }
  .check-item input { -webkit-appearance: checkbox; appearance: checkbox; }
}
