/* =========================================================
   The rereading tax (agent-costs.html) — builds on style.css, adlc.css (role colours) and
   adlc-phase.css (scene, beats, caption). Conversation kinds: instructions = --pm, replies =
   --agent, command output = --gate, screenshots = --human. History reread from earlier work is
   a neutral grey (--carried), so "waste" never reads as an error colour.
   ========================================================= */

:root { --carried: #9aa1ae; }
:root[data-theme="dark"] { --carried: #555d6e; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --carried: #555d6e; }
}

.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;
}

.muted { color: var(--text-muted); }

/* ---------- Hero ---------- */

.ac-hero { padding-bottom: 12px; }
.ac-hero .lede + .lede { margin-top: 14px; }
.ac-hero .lede a { color: var(--accent-strong); }
.ac-hero .story-card { margin-top: 22px; }

.story-card {
  display: flex;
  gap: 14px;
  align-items: center;
  max-width: 680px;
  margin: 0 0 22px;
  padding: 14px 18px;
  border: 1px solid color-mix(in srgb, var(--human) 35%, var(--border));
  border-radius: var(--radius-md);
  background: color-mix(in srgb, var(--human) 8%, var(--bg-elevated));
  font-size: 15.5px;
  line-height: 1.5;
}

.story-card .ic-lg { width: 40px; height: 40px; flex: none; color: var(--human); }
.story-card .muted { display: block; font-size: 12.5px; margin-top: 4px; }

.toc {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toc a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 6px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
}

.toc a:hover { color: var(--accent-strong); border-color: var(--accent); }

.toc span {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font: 600 12px var(--font-display);
}

/* ---------- Sections ---------- */

.ac-section { padding: 28px 0 20px; scroll-margin-top: 16px; }
.ac-section:last-of-type { padding-bottom: 100px; }

.sec-head { display: flex; gap: 14px; align-items: flex-start; margin-bottom: 16px; }
.sec-head h2 { margin: 0; font-family: var(--font-display); font-size: clamp(22px, 3vw, 28px); line-height: 1.2; }
.sec-head p { margin: 4px 0 0; color: var(--text-muted); }

.sec-n {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font: 600 17px var(--font-display);
}

/* ---------- Scene drawings (inline SVG built by js/agent-costs.js) ---------- */

.ac-svg { display: block; width: 100%; height: auto; overflow: visible; }
.ac-svg text { fill: var(--text); font-family: var(--font-sans); }
.ac-svg .lbl { fill: var(--text-muted); font: 500 13px var(--font-mono); letter-spacing: 0.04em; }
.ac-svg .num { fill: var(--text-muted); font: 500 14px var(--font-mono); }
.ac-svg .big { font-family: var(--font-display); font-weight: 700; }
.ac-svg .q { font-size: 15px; font-weight: 600; }
.ac-svg .lane-t { font-size: 16px; font-weight: 600; }
.ac-svg .frame { fill: none; stroke: var(--border); stroke-width: 2; }
.ac-svg .axis { stroke: var(--border); stroke-width: 2; }
.ac-svg .track { fill: var(--code-bg); }

.k-instr { fill: var(--pm); background: var(--pm); }
.k-reply { fill: var(--agent); background: var(--agent); }
.k-tool { fill: var(--gate); background: var(--gate); }
.k-shot { fill: var(--human); background: var(--human); }
.k-summary { fill: color-mix(in srgb, var(--agent) 22%, var(--bg-elevated)); stroke: var(--agent); stroke-width: 1.5; }
.ac-legend i.k-summary { background: color-mix(in srgb, var(--agent) 22%, var(--bg-elevated)); border: 1.5px solid var(--agent); }
.k-cached { background: color-mix(in srgb, var(--carried) 45%, transparent); }
.ac-svg .faint { opacity: 0.35; }

.beam { fill: var(--human); }
.beam-glow { fill: var(--human); fill-opacity: 0.12; }

.bar-own { fill: var(--agent); background: var(--agent); }
.bar-new { fill: color-mix(in srgb, var(--agent) 55%, var(--bg-elevated)); }
.bar-base { fill: color-mix(in srgb, var(--gate) 70%, var(--bg-elevated)); background: color-mix(in srgb, var(--gate) 70%, var(--bg-elevated)); }
.bar-carried { fill: var(--carried); background: var(--carried); }
.ac-svg .bar-own.hl { fill: var(--human); }
.ac-svg .bar-own.dim, .ac-svg .bar-new.dim { opacity: 0.35; }

/* Scene 2: triangles */
.tri { fill: color-mix(in srgb, var(--agent) 14%, transparent); stroke: var(--agent); stroke-width: 2.5; stroke-linejoin: round; }
.tri.copy { fill-opacity: 1; stroke-width: 2; }
.tri.c0 { fill: color-mix(in srgb, var(--agent) 30%, transparent); stroke: var(--agent); }
.tri.c1 { fill: color-mix(in srgb, var(--gate) 30%, transparent); stroke: var(--gate); }
.tri.c2 { fill: color-mix(in srgb, var(--human) 30%, transparent); stroke: var(--human); }
.tri.c3 { fill: color-mix(in srgb, var(--pm) 30%, transparent); stroke: var(--pm); }
.ac-svg .copy-n { font: 700 20px var(--font-display); }

/* Scene 3: cache, timer, compaction */
.ac-svg rect.cached { fill: var(--carried); opacity: 0.45; }
.ac-svg rect.flash { stroke: var(--fail); stroke-width: 3; }
.cache-bar { fill: var(--carried); }
.ac-svg .cache-t { fill: var(--text-muted); font: 600 13px var(--font-mono); paint-order: stroke; stroke: var(--bg-elevated); stroke-width: 4px; }
.ac-svg .edit-t { fill: var(--fail); font: 600 14px var(--font-mono); paint-order: stroke; stroke: var(--bg-elevated); stroke-width: 4px; }
.ac-svg .sum-t { font-size: 14px; font-weight: 600; }
.ac-svg .lost-t { fill: var(--text); font-size: 13px; font-weight: 600; }
.lost-chip { fill: var(--bg-elevated); stroke: var(--pm); stroke-width: 2; }
.price { fill: var(--fail); transition: fill 0.3s ease; }
.price.cheap { fill: var(--gate); }
.timer-face { fill: var(--code-bg); stroke: var(--border); stroke-width: 2; }
.timer-arc { fill: none; stroke: var(--human); stroke-width: 8; stroke-linecap: round; }
.timer-arc.expired { stroke: var(--fail); }

/* Scene 4: lanes */
.ac-svg .sep { stroke: var(--text-muted); stroke-dasharray: 3 4; }
.ac-svg .sep-t { fill: var(--text-muted); font: 500 11px var(--font-mono); }
.meter-long { fill: var(--carried); }
.meter-fresh { fill: color-mix(in srgb, var(--gate) 70%, var(--bg-elevated)); }
.ac-svg .verdict { fill: var(--gate); font: 700 24px var(--font-display); }

/* Scene 5: rocks, rereads, subagent */
.ac-svg .halo { paint-order: stroke; stroke: var(--bg-elevated); stroke-width: 6px; }
.ac-svg .rock-t { fill: #0b0d12; font: 600 14px var(--font-mono); }
.bubble { fill: color-mix(in srgb, var(--agent) 7%, transparent); stroke: var(--agent); stroke-width: 2; stroke-dasharray: 6 5; }
.file { fill: var(--bg-elevated); stroke: var(--gate); stroke-width: 1.5; }
.ac-svg .para { stroke: var(--human); stroke-width: 2; }
.ac-svg .para-t { fill: var(--bg); font-size: 12px; font-weight: 600; }

@media (min-width: 601px) and (max-width: 960px) {
  .ac-svg .lbl { font-size: 17px; }
  .ac-svg .num { font-size: 18px; }
  .ac-svg .lane-t { font-size: 20px; }
  .ac-svg .q { font-size: 19px; }
  .ac-svg .sep-t { font-size: 14px; }
  .ac-svg .cache-t, .ac-svg .edit-t { font-size: 17px; }
}

/* Phone layouts use a 400-unit-wide viewBox drawn at ~330 px, so SVG text is scaled down by about
   a fifth: set it larger to land near 12–14 px on screen. Same breakpoint as narrowMq in the script. */
@media (max-width: 600px) {
  .ac-svg .lbl { font-size: 15px; }
  .ac-svg .num { font-size: 16px; }
  .ac-svg .lane-t { font-size: 18px; }
  .ac-svg .q { font-size: 18px; }
  .ac-svg .sep-t { font-size: 13px; }
  .ac-svg .cache-t, .ac-svg .edit-t { font-size: 15px; }
  .ac-svg .para-t, .ac-svg .lost-t, .ac-svg .rock-t { font-size: 14px; }
}

.ac-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.ac-legend i {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 6px;
  border-radius: 3px;
  vertical-align: -1px;
}

/* ---------- Simulator ---------- */

.ac-sim {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  gap: 28px;
  padding: 22px;
}

.habits { margin: 0; padding: 0; border: 0; min-width: 0; }

.habit {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px 12px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.habit:hover { border-color: var(--accent); }
.habit:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.habit:has(input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.habit input { flex: none; width: 18px; height: 18px; margin: 3px 0 0; accent-color: var(--accent); }
.habit b { display: block; font-size: 15px; }
.habit span span { display: block; font-size: 13px; color: var(--text-muted); line-height: 1.45; }
.habit.rev { border-style: dashed; margin-top: 14px; }
.habit.rev:has(input:checked) { border-color: var(--human); background: color-mix(in srgb, var(--human) 9%, transparent); }

.bill { position: sticky; top: 16px; align-self: start; display: flex; flex-direction: column; }
.lbl-h { font: 500 12px var(--font-mono); letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-muted); }
.bill-cost { font: 700 clamp(44px, 8vw, 64px)/1.05 var(--font-display); letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.bill-save { min-height: 1.5em; font: 600 18px var(--font-display); color: color-mix(in srgb, var(--gate) 75%, var(--text)); }
.bill-save.up { color: var(--fail); }

.bill-stack {
  display: flex;
  height: 34px;
  margin: 14px 0 0;
  border-radius: 8px;
  overflow: hidden;
  background: var(--code-bg);
}

.bill-stack span { display: block; height: 100%; transition: width 0.45s cubic-bezier(0.2, 0.8, 0.2, 1); }
.bill-ghost { height: 5px; margin-top: 6px; border-radius: 3px; background: var(--border); }
.p-reread { background: var(--carried); }
.p-new { background: var(--gate); }
.p-out { background: var(--agent); }
.p-rev { background: var(--human); }

.bill-bugs { margin: 14px 0 0; font-size: 14.5px; font-weight: 600; }
.bill-bugs.bad { color: var(--fail); }
.bill-note { margin: 10px 0 0; font-size: 12.5px; color: var(--text-muted); line-height: 1.5; }

/* ---------- Ten habits ---------- */

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

.hab-group {
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
}

.hab-group h3 { margin: 0 0 10px; font: 600 13px var(--font-mono); letter-spacing: 0.04em; text-transform: uppercase; color: var(--accent-strong); }
.hab-group ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.hab-group li { display: flex; gap: 10px; align-items: flex-start; }
.hab-group b { display: block; font-size: 15px; }
.hab-group li span:not(.hab-n) { display: block; font-size: 13.5px; color: var(--text-muted); line-height: 1.45; }

.hab-n {
  flex: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font: 600 12.5px var(--font-display);
}

.ac-takeaway { margin: 28px 0 0; font: 600 clamp(19px, 3vw, 24px)/1.3 var(--font-display); }
.ac-next { margin-top: 20px; }

@media (max-width: 760px) {
  .ac-sim { grid-template-columns: 1fr; padding: 18px 16px; }
  .bill { position: static; }
}

@media (max-width: 560px) {
  .sec-head { gap: 10px; }
  .story-card { align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  .bill-stack span, .habit, .price { transition: none; }
}
