:root{
  --bg: #f6f5f1;
  --surface: #fffdf8;
  --ink: #14161a;
  --ink-2: #3a3f46;
  --ink-3: #6b7079;
  --ink-4: #9aa0a6;
  --rule: #e4e2da;
  --rule-strong: #cfccbf;
  --grid: #ebe8df;
  --accent: oklch(0.62 0.12 210);
  --accent-soft: oklch(0.92 0.04 210);
  --warn: oklch(0.70 0.14 75);
  --ok:   oklch(0.62 0.13 155);
  --err:  oklch(0.58 0.18 25);

  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Inter", system-ui, sans-serif;
  --serif: "Fraunces", serif;
}

*,*::before,*::after{ box-sizing: border-box; }
html,body{ margin:0; padding:0; }
body{
  font-family: var(--mono);
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.003em;
}

button{ font-family: inherit; color: inherit; }

/* ---------- Page shell ---------- */
.page{
  min-height: 100vh;
  background: var(--bg);
}

.masthead{
  border-bottom: 1px solid var(--rule-strong);
  background: var(--bg);
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: blur(6px);
}
.masthead-inner{
  max-width: 1600px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 32px;
}
.brand{
  display: flex; align-items: baseline; gap: 14px;
}
.brand-mark{
  font-family: var(--serif);
  font-weight: 500;
  font-size: 22px;
  letter-spacing: -0.02em;
}
.brand-mark .dot{ color: var(--accent); }
.brand-sub{
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.masthead-meta{
  display:flex; gap: 20px; align-items:center;
  font-family: var(--mono); font-size: 11px; color: var(--ink-3);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.masthead-meta .pill{
  display:inline-flex; align-items:center; gap: 6px;
  padding: 5px 12px; border: 1px solid var(--rule);
  border-radius: 999px; background: var(--surface);
}
.live-dot{
  width: 6px; height: 6px; border-radius: 999px;
  background: var(--ok);
  box-shadow: 0 0 0 0 oklch(0.62 0.13 155 / 0.5);
  animation: pulse 1.8s infinite;
}
@keyframes pulse{
  0%{ box-shadow: 0 0 0 0 oklch(0.62 0.13 155 / 0.45); }
  70%{ box-shadow: 0 0 0 6px oklch(0.62 0.13 155 / 0); }
  100%{ box-shadow: 0 0 0 0 oklch(0.62 0.13 155 / 0); }
}

/* ---------- Layout ---------- */
.container{ max-width: 1600px; margin: 0 auto; padding: 10px 32px 24px; }
.cols{ display: grid; grid-template-columns: 340px 1fr; gap: 16px; align-items: stretch; }
.cols > :first-child{ display: flex; flex-direction: column; align-self: flex-start; }
@media (max-width: 1080px){ .cols{ grid-template-columns: 1fr; } }

.panel{
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 6px;
  position: relative;
  overflow: hidden;
}
.panel-head{
  display:flex; align-items:center; justify-content: space-between;
  padding: 16px 20px 10px;
}
.panel-head .title{
  font-family: var(--mono); font-size: 13px; font-weight: 600;
  color: var(--ink); letter-spacing: -0.005em;
  text-transform: none;
}
.panel-head .meta{
  font-family: var(--mono); font-size: 10px; color: var(--ink-4);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.panel-body{ padding: 18px 20px 20px; }
.corner-l, .corner-r{ display: none; }

/* ---------- Upload ---------- */
.upload{
  border: 1.5px dashed var(--rule-strong);
  border-radius: 6px;
  padding: 14px 22px;
  text-align: center;
  background: var(--surface);
  transition: border-color .15s, background .15s;
  cursor: pointer;
}
.upload:hover,.upload.drag{
  border-color: var(--accent);
  background: var(--accent-soft);
}
.upload .glyph{
  width: 40px; height: 40px; margin: 0 auto 12px;
  border-radius: 999px;
  border: 1px solid var(--rule-strong); position: relative;
  display:flex; align-items:center; justify-content:center;
  font-family: var(--mono); font-size: 16px;
  color: var(--ink-3);
  background: var(--bg);
}
.upload .lead{ font-family: var(--mono); font-weight: 500; font-size: 12px; letter-spacing: 0.04em; margin-bottom: 3px; }
.upload .sub{ font-family: var(--mono); color: var(--ink-3); font-size: 11px; letter-spacing: 0.03em; }
.upload .mono{ font-family: var(--mono); font-size: 10px; color: var(--ink-4); margin-top: 10px; text-transform: uppercase; letter-spacing: 0.1em;}

.sample-row{ display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 14px; }
.sample-tile{
  aspect-ratio: 1/1;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: var(--surface);
  padding: 3px;
  cursor: pointer;
  position: relative;
  transition: border-color .15s, box-shadow .15s;
  overflow: hidden;
}
.sample-tile:hover{ border-color: var(--accent); }
.sample-tile.selected{ border-color: var(--ink); box-shadow: 0 0 0 1px var(--ink); }
.sample-tile .num{
  position:absolute; top:2px; left:3px; font-family: var(--mono);
  font-size: 9px; color: var(--ink-4);
}
.sample-tile svg{ width: 100%; height: 100%; display: block; }

.preview{
  width: 100%;
  flex: 1;
  min-height: 100px;
  background: var(--bg);
  display:flex; align-items:center; justify-content:center;
  position: relative;
}
.preview .badge{
  position:absolute; top: 10px; left: 10px;
  font-family: var(--mono); font-size: 10px;
  background: rgba(255,255,255,0.92); padding: 3px 8px; border-radius: 3px;
  color: var(--ink-2);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.preview svg{ max-width: 60%; max-height: 90%; width: auto; height: 100%; }

/* ---------- Buttons ---------- */
.btn{
  display: inline-flex; align-items: center; justify-content:center; gap: 8px;
  padding: 11px 16px;
  border: 1px solid var(--ink);
  background: var(--ink); color: #fff;
  font-family: var(--mono); font-weight: 500; font-size: 13px;
  cursor: pointer;
  transition: transform .06s ease, background .15s;
  border-radius: 6px;
  letter-spacing: -0.005em;
}
.btn:hover{ background: #2b2f35; }
.btn:active{ transform: translateY(1px); }
.btn:disabled{ opacity: 0.4; cursor: not-allowed; }
.btn.primary{ background: var(--accent); border-color: var(--accent); }
.btn.primary:hover{ filter: brightness(1.05); }
.btn.ghost{ background: transparent; color: var(--ink); }
.btn.ghost:hover{ background: var(--surface); }
.btn.block{ width: 100%; }
.btn .kbd{
  font-family: var(--mono); font-size: 10px;
  border: 1px solid currentColor; padding: 1px 5px;
  opacity: 0.6; border-radius: 2px;
}

/* ---------- Stepper variants ---------- */
.stage-grid{ display:grid; gap:14px; }

/* Variant A: horizontal stepper */
.stepper{
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0;
  background: var(--surface);
}
.step{
  padding: 20px 22px;
  border-right: 1px solid var(--rule);
  position: relative;
}
.step:last-child{ border-right: none; }
.step .num{
  font-family: var(--mono); font-size: 11px; color: var(--ink-4);
  letter-spacing: 0.08em;
}
.step .name{ font-weight: 600; margin-top: 2px; font-size: 15px; }
.step .desc{ color: var(--ink-3); font-size: 12px; margin-top: 2px; }
.step .bar{
  margin-top: 12px; height: 4px; background: var(--rule);
  position: relative; overflow: hidden;
}
.step .bar .fill{
  position: absolute; inset: 0; width: 0%;
  background: var(--accent);
  transition: width 0.1s linear;
}
.step.done .bar .fill{ background: var(--ok); width: 100% !important; }
.step.active .bar::after{
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, oklch(1 0 0 / 0.6), transparent);
  animation: shimmer 1.2s linear infinite;
}
@keyframes shimmer{ 0%{ transform: translateX(-100%);} 100%{ transform: translateX(100%);} }
.step .stat{
  display:flex; justify-content: space-between; align-items:center;
  margin-top: 10px;
  font-family: var(--mono); font-size: 11px; color: var(--ink-3);
}
.step .stat .dotstate{ display:inline-flex; align-items:center; gap: 6px; }
.dotstate .d{
  width: 7px; height: 7px; border-radius: 999px;
  background: var(--ink-4);
}
.step.idle .dotstate .d{ background: var(--ink-4); }
.step.active .dotstate .d{
  background: var(--accent);
  box-shadow: 0 0 0 0 oklch(0.62 0.12 210 / 0.6);
  animation: pulse-teal 1.1s infinite;
}
.step.done .dotstate .d{ background: var(--ok); }
@keyframes pulse-teal{
  0%{ box-shadow: 0 0 0 0 oklch(0.62 0.12 210 / 0.5); }
  70%{ box-shadow: 0 0 0 7px oklch(0.62 0.12 210 / 0); }
  100%{ box-shadow: 0 0 0 0 oklch(0.62 0.12 210 / 0); }
}
.step.active{ background:
  linear-gradient(90deg, var(--accent-soft) 0 3px, transparent 3px),
  var(--surface);
}

/* Variant B: network diagram */
.network{
  position: relative;
  height: 280px;
  background: var(--surface);
}
.node{
  position: absolute;
  width: 136px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--rule-strong);
  border-radius: 6px;
  transform: translate(-50%, -50%);
  transition: border-color .2s, box-shadow .2s;
}
.node .n{ font-family: var(--mono); font-size: 10px; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.08em;}
.node .t{ font-weight: 600; font-size: 13px; margin-top: 2px;}
.node .s{ font-family: var(--mono); font-size: 10px; color: var(--ink-4); margin-top: 6px;}
.node.io{ background: var(--bg); border-style: dashed; }
.node.active{ box-shadow: 0 0 0 3px var(--accent-soft); border-color: var(--accent); }
.node.done{ border-color: var(--ok); }
.network svg.edges{ position:absolute; inset:0; width:100%; height:100%; pointer-events:none; }

/* Variant C: vertical timeline */
.timeline{
  display:grid; grid-template-columns: 40px 1fr;
  background: var(--surface);
}
.tl-axis{
  border-right: 1px solid var(--rule);
  position: relative;
  background:
    repeating-linear-gradient(0deg, transparent 0 23px, var(--rule) 23px 24px);
}
.tl-steps{ display: flex; flex-direction: column; }
.tl-step{
  padding: 14px 16px; border-bottom: 1px solid var(--rule); position: relative;
}
.tl-step:last-child{ border-bottom: none; }
.tl-step .dot{
  position: absolute; left: -21px; top: 18px;
  width: 12px; height: 12px; background: var(--surface);
  border: 2px solid var(--ink-4); border-radius: 999px;
}
.tl-step.active .dot{
  border-color: var(--accent); background: var(--accent);
  animation: pulse-teal 1.1s infinite;
}
.tl-step.done .dot{ border-color: var(--ok); background: var(--ok); }
.tl-step .head{ display:flex; justify-content:space-between; align-items: baseline; }
.tl-step .head .nm{ font-weight: 600; }
.tl-step .head .tm{ font-family: var(--mono); font-size: 11px; color: var(--ink-3); }
.tl-step .desc{ color: var(--ink-3); font-size: 12px; margin-top: 3px; }
.tl-step .payload{
  margin-top: 10px; font-family: var(--mono); font-size: 11px;
  background: var(--bg); padding: 8px 10px; border: 1px solid var(--rule);
  color: var(--ink-2); word-break: break-all;
}

/* ---------- Metrics tiles ---------- */
.hero-metrics{
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
}
.metric{
  padding: 18px 18px 16px;
  border-right: 1px solid var(--rule);
  position: relative;
}
.metric:last-child{ border-right: none; }
.metric .lbl{
  font-family: var(--mono); font-size: 10px; color: var(--ink-3);
  text-transform: uppercase; letter-spacing: 0.1em;
}
.metric .val{
  font-family: var(--serif);
  font-size: 30px; line-height: 1.05; letter-spacing: -0.02em;
  margin-top: 4px;
  font-weight: 400;
}
.metric .val .unit{
  font-family: var(--mono); font-size: 12px;
  color: var(--ink-3); margin-left: 4px; letter-spacing: 0;
  font-weight: 500;
}
.metric .delta{
  margin-top: 6px; font-family: var(--mono); font-size: 11px;
}
.metric .delta.neg{ color: var(--ok); }
.metric .delta.pos{ color: var(--err); }
.metric .spark{ margin-top: 10px; height: 22px; }

/* metric detail table */
.detail-table{ width: 100%; border-collapse: collapse; font-family: var(--mono); font-size: 12px; }
.detail-table th, .detail-table td{
  padding: 8px 14px; text-align: left;
  border-bottom: 1px solid var(--rule);
}
.detail-table th{
  font-weight: 500; color: var(--ink-3);
  text-transform: uppercase; font-size: 10px; letter-spacing: 0.1em;
  background: var(--bg);
}
.detail-table th.num{ text-align: right; }
.detail-table td.num{ text-align: right; font-variant-numeric: tabular-nums; }
.detail-table tr:last-child td{ border-bottom: none; }
.detail-table .lane{
  display:inline-block; width: 6px; height: 6px;
  border-radius: 999px; margin-right: 8px;
  vertical-align: middle;
}

/* results panel */
.result-grid{ display: grid; grid-template-columns: 160px 1fr; gap: 14px 18px; align-items: start; }
.result-grid .k{
  font-family: var(--mono); font-size: 10px; color: var(--ink-3);
  text-transform: uppercase; letter-spacing: 0.1em;
  padding-top: 3px;
}
.result-grid .v{ font-size: 14px; }
.mono-block{
  font-family: var(--mono); font-size: 12px;
  background: var(--bg); padding: 12px 14px; border: 1px solid var(--rule);
  border-radius: 4px;
  color: var(--ink-2); word-break: break-all; line-height: 1.6;
}
.ocr-out{
  font-family: var(--mono); font-size: 12px; letter-spacing: 0.04em;
  font-weight: 400; line-height: 1.6; max-height: 120px;
  overflow-y: auto; display: block; word-break: break-word;
}
.check{
  display: inline-flex; align-items:center; gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--ok); color: var(--ok);
  font-family: var(--mono); font-size: 10px;
  text-transform: uppercase; letter-spacing: 0.08em;
  background: oklch(0.62 0.13 155 / 0.08);
  border-radius: 999px;
}
.check.err{ border-color: var(--err); color: var(--err); background: oklch(0.58 0.18 25 / 0.08); }

/* bytes bar */
.bytes{ display:grid; grid-template-columns: 80px 1fr 80px; gap: 10px; align-items:center;}
.bytes .lane-lbl{ font-family: var(--mono); font-size: 11px; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.08em; }
.bytes .lane-val{ font-family: var(--mono); font-size: 11px; text-align: right; font-variant-numeric: tabular-nums; }
.bar-track{
  height: 10px; background: var(--bg); border: 1px solid var(--rule);
  border-radius: 999px;
  position: relative; overflow: hidden;
}
.bar-fill{ position:absolute; inset: 0 auto 0 0; background: var(--ink); transition: width .4s ease; }
.bar-fill.accent{ background: var(--accent); }
.bar-stripe{ background: var(--ink-2); }
.bar-stripe.accent{ background: var(--accent); }

/* headings */
h1,h2,h3{ margin: 0; font-weight: 600; letter-spacing: -0.01em; }
.section-h{
  display:flex; align-items: baseline; justify-content: space-between;
  margin: 4px 0 10px;
}
.section-h .lead{
  font-family: var(--serif); font-weight: 500;
  font-size: 22px; letter-spacing: -0.015em;
}
.section-h .sub{ font-family: var(--mono); font-size: 11px; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.08em;}

/* split columns */
.two-col{ display:grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: stretch; }
@media (max-width: 900px){ .two-col{ grid-template-columns: 1fr; } }

/* tweaks */
.tweaks-panel{
  position: fixed; right: 20px; bottom: 20px; width: 280px;
  background: var(--surface); border: 1px solid var(--rule-strong);
  border-radius: 8px;
  box-shadow: 0 20px 48px -18px rgba(0,0,0,0.18);
  z-index: 40;
  transition: transform .2s ease, opacity .2s ease;
  overflow: hidden;
}
.tweaks-panel.hidden{ opacity: 0; transform: translateY(14px); pointer-events: none; }
.tweaks-head{
  padding: 10px 14px; border-bottom: 1px solid var(--rule);
  display:flex; align-items:center; justify-content: space-between;
  font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em;
}
.tweaks-body{ padding: 14px; display:flex; flex-direction: column; gap: 14px;}
.tweak-row{ display:flex; flex-direction:column; gap: 6px; }
.tweak-row .tlbl{ font-family: var(--mono); font-size: 10px; color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.1em; }
.seg{
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  border: 1px solid var(--rule-strong);
  border-radius: 4px;
  overflow: hidden;
}
.seg button{
  border: none; background: var(--surface); padding: 8px;
  font-family: var(--mono); font-size: 11px;
  cursor: pointer; border-right: 1px solid var(--rule);
}
.seg button:last-child{ border-right: none; }
.seg button.on{ background: var(--ink); color: #fff; }

/* footer */
.foot{
  max-width: 1600px; margin: 30px auto 40px;
  padding: 16px 32px; border-top: 1px solid var(--rule);
  display:flex; justify-content: space-between;
  font-family: var(--mono); font-size: 10px; color: var(--ink-4);
  text-transform: uppercase; letter-spacing: 0.1em;
}

/* tag */
.tag{
  display: inline-flex; align-items:center; gap: 6px;
  font-family: var(--mono); font-size: 10px;
  padding: 3px 9px; border: 1px solid var(--rule);
  border-radius: 999px;
  color: var(--ink-3); text-transform: uppercase; letter-spacing: 0.08em;
  background: var(--surface);
}
.tag.accent{ border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.reset-link{
  background: none; border: none; padding: 0;
  font-family: var(--mono); font-size: 11px; color: var(--ink-3);
  text-decoration: underline; cursor: pointer;
}
.reset-link:hover{ color: var(--ink); }

.muted{ color: var(--ink-3); }
.hairline{ height:1px; background: var(--rule); margin: 14px 0; }

/* status banner */
.status-banner{
  display: flex; gap: 12px; align-items:center;
  padding: 12px 16px; background: var(--surface);
  border: 1px solid var(--rule); border-left: 3px solid var(--accent);
  border-radius: 6px;
  font-family: var(--mono); font-size: 12px;
}
.status-banner.ok{ border-left-color: var(--ok); }
.status-banner.idle{ border-left-color: var(--ink-4); }

/* token animation */
@keyframes tokflow{
  0%{ offset-distance: 0%; opacity: 0; }
  10%{ opacity: 1; }
  90%{ opacity: 1; }
  100%{ offset-distance: 100%; opacity: 0; }
}
