/* styles.css — Short Story Generator */

:root {
  --bg: #f6f4ef;
  --panel: #fffdf9;
  --panel2: #f0ece3;
  --ink: #1d1b18;
  --muted: #6b665d;
  --line: #ddd7cb;
  --accent: #9a6b34;
  --accent-ink: #fff;
  --warn: #9a4a2f;
  --ok: #3f6b45;
  --radius: 10px;
  --maxw: 820px;
}
:root[data-theme="dark"] {
  --bg: #16151a;
  --panel: #1e1d24;
  --panel2: #26242d;
  --ink: #ece8e1;
  --muted: #9b958c;
  --line: #33313b;
  --accent: #c99a5c;
  --accent-ink: #1a1820;
  --warn: #d9855f;
  --ok: #7fae83;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 Charter, "Iowan Old Style", Georgia, "Times New Roman", serif;
  -webkit-text-size-adjust: 100%;
}

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 0 20px 64px; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line);
  background: var(--panel); flex-wrap: wrap;
}
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.back { color: var(--muted); text-decoration: none; font-size: 14px; }
.back:hover { color: var(--ink); }
.account { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.credits { font-variant-numeric: tabular-nums; }
.topup { color: var(--accent); text-decoration: none; font-size: 14px; }
.topup:hover { text-decoration: underline; }

/* ---- typography ---- */
h1 { font-size: 34px; line-height: 1.15; margin: 28px 0 10px; letter-spacing: -0.01em; }
h2 { font-size: 22px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0 0 4px; }
.lede { font-size: 18px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13.5px; }
.section-head {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.09em;
  color: var(--muted); margin: 0 0 12px; font-weight: 600;
}
.intro { margin-bottom: 20px; }

/* ---- panels ---- */
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 20px; margin: 0 0 18px;
}

/* ---- form ---- */
.field { display: block; margin: 0 0 14px; }
.field .label {
  display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px;
  letter-spacing: 0.01em;
}
textarea, input[type="text"], select {
  width: 100%; padding: 10px 12px; font: inherit; font-size: 15px;
  color: var(--ink); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px;
}
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
select { appearance: none; background-image: none; cursor: pointer; }
textarea:focus, input:focus, select:focus {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.third { flex: 1 1 180px; }

/* ---- buttons ---- */
.btn {
  font: inherit; font-size: 15px; padding: 9px 16px; cursor: pointer;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--panel2); color: var(--ink);
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.small { font-size: 13.5px; padding: 6px 11px; }
.btn.toggle { border-radius: 999px; }
.btn.toggle.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.shape-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 14px 0; }
.shape-row .label { font-size: 13px; font-weight: 600; color: var(--muted); }
.run-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 14px; }

/* ---- scan + tone notes ---- */
.scan-notes ul.scan, .guard-list { margin: 0 0 14px; padding-left: 18px; }
.scan-notes li { font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.tone-note {
  background: var(--panel2); border-radius: 8px; padding: 12px 14px; margin: 0 0 14px;
  font-size: 14px;
}
.tone-note p { margin: 0 0 6px; }
.tone-note p:last-child { margin-bottom: 0; }
.tone-over { color: var(--accent); font-size: 13.5px; }

/* ---- guard ---- */
.guard-zone {
  border: 1px solid var(--warn); border-left-width: 4px;
  border-radius: 8px; padding: 14px; margin: 0 0 14px; background: var(--panel2);
}
.guard-head { font-size: 15px; margin-bottom: 8px; }
.guard-item { font-size: 14px; margin-bottom: 6px; }
.tier-tag {
  display: inline-block; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.06em; padding: 1px 6px; margin-right: 8px;
  border-radius: 4px; background: var(--warn); color: #fff;
}

/* ---- cost ---- */
.cost { font-size: 14px; margin: 10px 0 4px; }
.cost-figure { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.cost-note, .cost-balance { color: var(--muted); }
.shortfall:not(:empty) {
  font-size: 14px; color: var(--warn); margin-bottom: 8px;
}

/* ---- progress ---- */
.progress-head {
  display: flex; justify-content: space-between; font-size: 13px;
  color: var(--muted); margin-bottom: 12px;
}
.elapsed { font-variant-numeric: tabular-nums; }
ul.stages { list-style: none; margin: 0; padding: 0; }
.stage { display: flex; align-items: center; gap: 10px; font-size: 14px; padding: 3px 0; color: var(--muted); }
.stage-dot {
  width: 9px; height: 9px; border-radius: 50%;
  border: 1.5px solid var(--line); flex: 0 0 auto;
}
.stage.active { color: var(--ink); }
.stage.active .stage-dot { border-color: var(--accent); background: var(--accent); }
.stage.done .stage-dot { border-color: var(--ok); background: var(--ok); }

.retry-note:not(:empty) {
  font-size: 14px; color: var(--muted); padding: 10px 14px;
  border-left: 3px solid var(--accent); margin: 0 0 14px;
}

/* ---- the story ---- */
.story-title { font-size: 27px; line-height: 1.2; margin: 0 0 16px; letter-spacing: -0.01em; }
.story-body p { margin: 0 0 1.15em; }
.story-body p:first-child::first-line { font-variant-caps: small-caps; }
.result { margin-bottom: 26px; }

/* ---- craft ---- */
.craft-panel { border-top: 1px solid var(--line); padding-top: 18px; margin-bottom: 8px; }
.craft-item { margin-bottom: 14px; }
.craft-label {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--accent); font-weight: 700;
}
.craft-text { margin: 0; font-size: 15px; }
.craft-text.empty, .empty { color: var(--muted); font-style: italic; }

/* ---- details blocks ---- */
.detail-block { border-top: 1px solid var(--line); padding: 12px 0 4px; }
.detail-block summary {
  cursor: pointer; font-size: 13px; text-transform: uppercase;
  letter-spacing: 0.07em; color: var(--muted); font-weight: 600;
}
.detail-block[open] summary { margin-bottom: 12px; }

dl.measured { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 0; font-size: 14px; }
dl.measured dt { color: var(--muted); }
dl.measured dd { margin: 0; font-variant-numeric: tabular-nums; }

ul.findings { list-style: none; margin: 0; padding: 0; }
.finding { display: flex; gap: 10px; font-size: 14px; padding: 5px 0; align-items: baseline; }
.sev-tag {
  font-size: 10px; letter-spacing: 0.06em; padding: 1px 5px; border-radius: 3px;
  flex: 0 0 auto; background: var(--panel2); color: var(--muted);
}
.sev-warn .sev-tag { background: var(--warn); color: #fff; }

/* ---- actions ---- */
.actions { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 16px; border-top: 1px solid var(--line); margin-top: 10px; }

/* ---- history ---- */
ul.history { list-style: none; margin: 0; padding: 0; }
.history-item {
  display: flex; justify-content: space-between; gap: 12px; align-items: baseline;
  padding: 8px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.history-item:last-child { border-bottom: 0; }
.history-open {
  background: none; border: 0; padding: 0; font: inherit; font-size: 16px;
  color: var(--ink); cursor: pointer; text-align: left;
}
.history-open:hover { color: var(--accent); text-decoration: underline; }
.history-meta { font-size: 13px; color: var(--muted); }

/* ---- footer ---- */
.foot {
  border-top: 1px solid var(--line); padding: 20px;
  text-align: center; color: var(--muted); font-size: 14px;
}
.foot a { color: var(--muted); }
.foot p { max-width: var(--maxw); margin: 0 auto 8px; }

/* ---- utility ---- */
.is-hidden { display: none !important; }
[hidden] { display: none !important; }

@media (max-width: 560px) {
  h1 { font-size: 27px; }
  .story-title { font-size: 22px; }
  .wrap { padding: 0 14px 44px; }
  .panel { padding: 15px; }
  .third { flex: 1 1 100%; }
}
