/* Poetry Generator. Two themes, set on <html data-theme> by theme.js before first paint. */

:root {
  --bg: #0d0b16;
  --panel: #16132437;
  --card: #171426;
  --line: #2b2542;
  --ink: #ece9f6;
  --dim: #a79fc4;
  --muted: #8b83a8;
  --accent: #c4b5fd;
  --accent-ink: #1b1330;
  --ok: #6ee7a8;
  --warn: #fbbf24;
  --bad: #fb7185;
  --unk: #7f8ea3;
  --shadow: 0 1px 0 #ffffff0a inset, 0 12px 32px #00000055;
}

:root[data-theme="light"] {
  --bg: #faf9fd;
  --panel: #ffffff;
  --card: #ffffff;
  --line: #e2ddf0;
  --ink: #201b32;
  --dim: #574f70;
  --muted: #6f678a;
  --accent: #6d4aff;
  --accent-ink: #ffffff;
  --ok: #0f8a52;
  --warn: #a16207;
  --bad: #c02a45;
  --unk: #64748b;
  --shadow: 0 1px 2px #0000000d, 0 8px 24px #2a1f5510;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; }
.small { font-size: 0.86rem; }
.muted { color: var(--muted); }
.hidden { display: none !important; }

a { color: var(--accent); }

/* --- top bar --------------------------------------------------------------- */

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 20px;
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.backlink { text-decoration: none; color: var(--dim); white-space: nowrap; }
.backlink:hover { color: var(--accent); }
.sep { color: var(--muted); }
.topactions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.credits { color: var(--dim); font-size: 0.86rem; white-space: nowrap; }
.topup {
  font-size: 0.82rem; text-decoration: none; color: var(--accent);
  border: 1px solid var(--line); border-radius: 8px; padding: 4px 9px;
}

button { font: inherit; cursor: pointer; }

.ghost {
  background: transparent; color: var(--dim);
  border: 1px solid var(--line); border-radius: 8px; padding: 5px 11px;
}
.ghost:hover { color: var(--ink); border-color: var(--accent); }

.primary {
  background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: 10px; padding: 11px 20px; font-weight: 650;
}
.primary:disabled { opacity: 0.45; cursor: not-allowed; }

.mini {
  background: transparent; color: var(--dim);
  border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px;
  font-size: 0.84rem;
}
.mini:hover { color: var(--ink); border-color: var(--accent); }

.big {
  background: var(--accent); color: var(--accent-ink);
  border: 0; border-radius: 10px; padding: 10px 18px; font-weight: 600;
}
.ghostbig {
  background: transparent; color: var(--ink);
  border: 1px solid var(--line);
}
.ghostbig:hover { border-color: var(--accent); }

/* --- layout ---------------------------------------------------------------- */

main { max-width: 900px; margin: 0 auto; padding: 24px 20px 60px; }

.hero h1 { font-size: clamp(1.6rem, 3.6vw, 2.3rem); line-height: 1.2; margin: 18px 0 12px; }
.lede { color: var(--dim); margin: 0 0 10px; }
.herobtns { display: flex; gap: 10px; flex-wrap: wrap; margin: 18px 0 8px; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 14px; padding: 18px; margin: 22px 0;
  box-shadow: var(--shadow);
}

.field { margin: 0 0 14px; min-width: 0; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.94rem; }
.labelrow { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }

textarea, input[type="text"], select {
  width: 100%; background: var(--bg); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  font: inherit; resize: vertical;
}
textarea:focus, input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.row { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 14px; }

.dropzone { border: 1px dashed transparent; border-radius: 12px; transition: border-color .15s; }
.dropzone.over { border-color: var(--accent); }
.droprow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 6px; }

.moderow { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 0 0 14px; }
.modelabel { font-weight: 600; font-size: 0.9rem; }
.mode {
  background: transparent; color: var(--dim);
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 13px; font-size: 0.88rem;
}
.mode.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.runrow { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: 6px; }

.warnline {
  border-left: 3px solid var(--warn); padding: 8px 12px; margin: 10px 0;
  background: color-mix(in srgb, var(--warn) 8%, transparent);
  border-radius: 0 8px 8px 0; font-size: 0.9rem; color: var(--dim);
}
.gate {
  border-left: 3px solid var(--accent); padding: 8px 12px; margin: 10px 0;
  background: color-mix(in srgb, var(--accent) 9%, transparent);
  border-radius: 0 8px 8px 0; font-size: 0.9rem;
}
.gateaction { font-weight: 650; cursor: pointer; }

/* --- verdict badges -------------------------------------------------------- */

.verdict {
  font-size: 0.82rem; font-weight: 650; padding: 4px 11px; border-radius: 999px;
  border: 1px solid var(--line); white-space: nowrap;
}
.verdict.ok   { color: var(--ok);   border-color: color-mix(in srgb, var(--ok) 45%, transparent);
                background: color-mix(in srgb, var(--ok) 12%, transparent); }
.verdict.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent);
                background: color-mix(in srgb, var(--warn) 12%, transparent); }
.verdict.bad  { color: var(--bad);  border-color: color-mix(in srgb, var(--bad) 45%, transparent);
                background: color-mix(in srgb, var(--bad) 12%, transparent); }
.verdict.unk  { color: var(--unk);  border-color: color-mix(in srgb, var(--unk) 45%, transparent);
                background: color-mix(in srgb, var(--unk) 12%, transparent); }

/* --- the poem itself ------------------------------------------------------- */

.poemzone { margin: 6px 0 18px; }

.stanza { margin: 0 0 18px; }

.pline {
  display: grid; grid-template-columns: 2.2rem 1fr auto auto;
  gap: 10px; align-items: baseline;
  padding: 3px 6px; border-radius: 7px;
}
.pline:hover { background: color-mix(in srgb, var(--accent) 7%, transparent); }
.pline.flagged { background: color-mix(in srgb, var(--bad) 8%, transparent); }
.pline.refrain { background: color-mix(in srgb, var(--accent) 10%, transparent); }

.plno { color: var(--muted); font-size: 0.78rem; text-align: right;
        font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.pltext { font-size: 1.04rem; line-height: 1.55; min-width: 0; overflow-wrap: break-word; }
.plsyl {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem; color: var(--muted); white-space: nowrap;
}
.plsyl.range { color: var(--warn); }
.plrhyme {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem; font-weight: 700; width: 1.4rem; text-align: center;
  color: var(--accent);
}
.plrhyme.unver { color: var(--unk); }

/* The volta marker sits between lines rather than on one. */
.voltamark {
  display: flex; align-items: center; gap: 10px;
  margin: 10px 0 10px 2.2rem; color: var(--accent); font-size: 0.8rem; font-weight: 650;
}
.voltamark::after { content: ""; flex: 1; height: 1px; background: color-mix(in srgb, var(--accent) 40%, transparent); }

/* The stress row drawn under a line, one mark per syllable. */
.stressrow {
  grid-column: 2 / 3; display: flex; gap: 3px; flex-wrap: wrap;
  margin: 1px 0 4px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.7rem; letter-spacing: 0.5px;
}
.sm { display: inline-block; min-width: 0.72rem; text-align: center; border-radius: 3px; }
.sm.strong { color: var(--ink); font-weight: 800; }
.sm.weak   { color: var(--muted); }
.sm.free   { color: var(--unk); opacity: 0.75; }
.sm.unk    { color: var(--unk); opacity: 0.55; }
.sm.clash  { color: var(--bad); font-weight: 800;
             background: color-mix(in srgb, var(--bad) 16%, transparent); }

/* --- findings -------------------------------------------------------------- */

.findings { display: flex; flex-direction: column; gap: 8px; }

.finding {
  border-left: 3px solid var(--line); padding: 8px 12px; border-radius: 0 8px 8px 0;
  font-size: 0.92rem; background: var(--panel);
}
.finding.high   { border-left-color: var(--bad);
                  background: color-mix(in srgb, var(--bad) 7%, transparent); }
.finding.medium { border-left-color: var(--warn);
                  background: color-mix(in srgb, var(--warn) 7%, transparent); }
.finding.note   { border-left-color: var(--unk);
                  background: color-mix(in srgb, var(--unk) 7%, transparent); }
.fcode {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.72rem; color: var(--muted); text-transform: uppercase;
  letter-spacing: 0.6px; display: block; margin-bottom: 2px;
}

/* --- reconciliation banner ------------------------------------------------- */

.recon { margin: 4px 0 16px; display: flex; flex-direction: column; gap: 8px; }
.reconrow {
  display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap;
  border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px;
  font-size: 0.9rem; background: var(--panel);
}
.reconrow.mismatch { border-color: color-mix(in srgb, var(--bad) 50%, transparent);
                     background: color-mix(in srgb, var(--bad) 8%, transparent); }
.reconlabel { font-weight: 650; min-width: 6.5rem; }
.reconclaim { color: var(--dim); }
.reconscan  { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* --- facts, blocks, history ------------------------------------------------ */

.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
         gap: 10px; margin: 6px 0 18px; }
.fact { border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: var(--panel); }
.factlabel { display: block; font-size: 0.74rem; text-transform: uppercase;
             letter-spacing: 0.6px; color: var(--muted); }
.factval { font-weight: 650; font-size: 1rem; }

.resulthead { display: flex; align-items: flex-start; justify-content: space-between;
              gap: 12px; flex-wrap: wrap; }
.resulthead h2 { margin: 0 0 4px; font-size: 1.25rem; }
.reading { color: var(--dim); margin: 0 0 6px; font-size: 0.94rem; }

.block { margin: 20px 0 0; }
.block h3 { font-size: 1rem; margin: 0 0 8px; }
.count { color: var(--muted); font-weight: 400; font-size: 0.85rem; }

.item { border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
        margin: 0 0 8px; background: var(--panel); font-size: 0.93rem; }
.item .why { color: var(--muted); font-size: 0.87rem; display: block; margin-top: 3px; }

.exportrow { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 18px; }

.historylist { display: flex; flex-direction: column; gap: 8px; }
.histrow { display: flex; gap: 10px; align-items: baseline; justify-content: space-between;
           border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
           flex-wrap: wrap; background: var(--panel); }
.histmain { min-width: 0; }
.histtitle { font-weight: 600; }
.histmeta { color: var(--muted); font-size: 0.83rem; }
.histbtns { display: flex; gap: 6px; }

.checker { border: 1px solid var(--line); border-radius: 12px; padding: 14px;
           margin: 0 0 16px; background: var(--panel); }
.checkerhead { display: flex; align-items: center; justify-content: space-between;
               gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.checkerhead h2 { font-size: 1rem; margin: 0; }
.ambnote { font-size: 0.87rem; color: var(--dim); margin: 8px 0 0; }

.progress .progresshead { display: flex; justify-content: space-between; gap: 10px;
                          align-items: baseline; flex-wrap: wrap; }
.steps { margin: 10px 0 0; padding-left: 20px; color: var(--muted); font-size: 0.92rem; }
.steps li.done { color: var(--ok); }
.steps li.now { color: var(--ink); font-weight: 600; }

.raw { white-space: pre-wrap; overflow-x: auto; background: var(--bg);
       border: 1px solid var(--line); border-radius: 10px; padding: 12px;
       font-size: 0.84rem; max-height: 60vh; }

.how ol { padding-left: 20px; }
.how li { margin: 0 0 10px; }

.foot { border-top: 1px solid var(--line); padding: 20px; text-align: center; color: var(--muted); }
.foot p { margin: 4px 0; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: flex;
          flex-direction: column; gap: 8px; z-index: 50; max-width: min(92vw, 380px); }
.toast { border: 1px solid var(--line); border-radius: 10px; padding: 10px 13px;
         background: var(--card); box-shadow: var(--shadow); font-size: 0.9rem; }
.toast.err { border-color: color-mix(in srgb, var(--bad) 50%, transparent); }
.toast.ok  { border-color: color-mix(in srgb, var(--ok) 50%, transparent); }

@media (max-width: 560px) {
  .pline { grid-template-columns: 1.8rem 1fr auto; }
  .plrhyme { grid-row: 1; }
}

@media print {
  .topbar, .foot, .exportrow, .herobtns, #form, #historyZone, #how, .toasts { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border: 0; box-shadow: none; }
}

/* --- docs pages (api.html, tokens.html) ------------------------------------ */

.doc { max-width: 860px; }
.doc h1 { font-size: clamp(1.5rem, 3.2vw, 2rem); margin: 18px 0 12px; }
.doc h2 { font-size: 1.2rem; margin: 30px 0 10px; padding-top: 14px;
          border-top: 1px solid var(--line); }
.doc h3 { font-size: 1.02rem; margin: 22px 0 8px; }
.doc p { color: var(--dim); }
.doc code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
            font-size: 0.88em; background: color-mix(in srgb, var(--accent) 10%, transparent);
            border-radius: 5px; padding: 1px 5px; }

.codegroup { margin: 12px 0 18px; border: 1px solid var(--line);
             border-radius: 12px; overflow: hidden; background: var(--card); }
.tabs { display: flex; flex-wrap: wrap; gap: 0; border-bottom: 1px solid var(--line);
        background: var(--panel); }
.tab { background: transparent; border: 0; border-bottom: 2px solid transparent;
       color: var(--muted); padding: 8px 13px; font-size: 0.85rem; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 650; }

.codegroup pre { margin: 0; padding: 14px; overflow-x: auto; background: var(--bg); }
.codegroup pre code { background: none; padding: 0; font-size: 0.83rem; line-height: 1.55; }

.sample { margin: 12px 0 18px; padding: 14px; overflow-x: auto;
          border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.sample code { display: block; white-space: pre; background: none; padding: 0;
               font-size: 0.83rem; line-height: 1.55; }

.tokenbox { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
            font-size: 0.85rem; word-break: break-all; border: 1px solid var(--line);
            border-radius: 10px; padding: 12px; background: var(--bg); margin: 10px 0; }
.btnrow { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
