:root {
  color-scheme: light;
  --paper: #f5f3ec;
  --paper-deep: #e8e6dc;
  --ink: #162022;
  --ink-soft: #273235;
  --line: #cacbc2;
  --white: #ffffff;
  --mint: #64e4bd;
  --mint-dark: #08775f;
  --coral: #ff7653;
  --yellow: #ffd166;
  --error: #b52f28;
  font-family: "Geist", "Avenir Next", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--paper); color: var(--ink); overflow-x: hidden; }
button, input, textarea { font: inherit; letter-spacing: 0; }
button { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

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

.app-shell { width: 100%; min-height: 100vh; overflow-x: hidden; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 58px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto 40px;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  color: var(--white);
  background: var(--ink);
  border-bottom: 1px solid #344044;
}
.brand-lockup { display: flex; min-width: 0; align-items: center; gap: 11px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  flex: 0 0 32px;
  border: 1px solid var(--mint);
  color: var(--mint);
  font: 700 11px/1 ui-monospace, SFMono-Regular, Menlo, monospace;
}
.brand-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; font-weight: 700; }
.engine-state { display: flex; align-items: center; gap: 8px; white-space: nowrap; color: #dce8e4; font: 600 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--yellow); box-shadow: 0 0 0 3px rgba(255, 209, 102, .12); }
.engine-state.ready .status-dot { background: var(--mint); box-shadow: 0 0 0 3px rgba(100, 228, 189, .12); }
.icon-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid #465255;
  border-radius: 6px;
  color: var(--white);
  background: transparent;
  cursor: pointer;
}
.icon-button:hover, .icon-button:focus-visible { border-color: var(--mint); color: var(--mint); outline: none; }
.icon-button svg { width: 17px; height: 17px; }

.workspace {
  display: grid;
  grid-template-columns: minmax(410px, .88fr) minmax(0, 1.12fr);
  min-height: calc(100vh - 58px);
}
.config-panel {
  padding: 22px 24px 20px;
  background:
    linear-gradient(rgba(22, 32, 34, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(22, 32, 34, .035) 1px, transparent 1px),
    var(--paper);
  background-size: 24px 24px;
  border-right: 1px solid var(--line);
}
.panel-intro { max-width: 610px; }
.kicker, .result-kicker {
  margin: 0 0 7px;
  color: var(--mint-dark);
  font: 700 11px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace;
  text-transform: uppercase;
}
#scenario-label { text-transform: none; }
h1 { max-width: 700px; margin: 0; font-size: 36px; line-height: 1.02; font-weight: 740; letter-spacing: 0; }
.lede { max-width: 600px; margin: 9px 0 0; color: #536063; font-size: 13px; line-height: 1.45; }

.assumption-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 18px 0 14px;
}
.assumption-grid label { min-width: 0; }
.assumption-grid label > span:first-child, .csv-label > span:first-child {
  display: block;
  margin: 0 0 5px;
  color: #566164;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}
.budget-field { grid-column: auto; }
.input-with-unit {
  display: grid;
  grid-template-columns: minmax(48px, 1fr) auto;
  align-items: center;
  height: 38px;
  overflow: hidden;
  border: 1px solid #b8bbb3;
  border-radius: 6px;
  background: rgba(255, 255, 255, .78);
}
.input-with-unit:focus-within { border-color: var(--mint-dark); box-shadow: 0 0 0 2px rgba(8, 119, 95, .12); }
.input-with-unit input { width: 100%; min-width: 0; height: 100%; padding: 0 9px; border: 0; outline: 0; background: transparent; color: var(--ink); font: 700 13px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.input-with-unit b { padding: 0 9px; color: #667174; font: 600 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: nowrap; }

.csv-label { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.csv-label code { color: #697476; font-size: 9px; white-space: nowrap; }
#workload-csv {
  width: 100%;
  height: 154px;
  resize: vertical;
  padding: 11px 12px;
  border: 1px solid #aeb4ac;
  border-radius: 6px;
  outline: 0;
  background: #fcfbf7;
  color: #233033;
  font: 500 10px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  tab-size: 2;
}
#workload-csv:focus { border-color: var(--mint-dark); box-shadow: 0 0 0 2px rgba(8, 119, 95, .12); }
.config-actions, .result-actions { display: grid; gap: 8px; }
.config-actions { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); margin-top: 10px; }
.button {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.1;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}
.button:hover { transform: translateY(-1px); }
.button:focus-visible { outline: 2px solid var(--yellow); outline-offset: 2px; }
.button svg { width: 16px; height: 16px; flex: 0 0 auto; }
.button-primary { color: var(--ink); background: var(--mint); border-color: #44cfa5; }
.button-primary:hover { background: #78eac8; }
.button-secondary { color: var(--ink); background: transparent; border-color: #8e9793; }
.button-secondary:hover { background: var(--white); }
.input-note, .error-message { margin: 9px 0 0; font-size: 10px; line-height: 1.45; }
.input-note { color: #6a7475; }
.error-message { padding: 9px 10px; border-left: 3px solid var(--error); color: #7b1f1a; background: #fff0ed; }

.result-panel {
  position: relative;
  min-width: 0;
  padding: 22px;
  overflow: hidden;
  color: var(--white);
  background:
    radial-gradient(circle at 90% 5%, rgba(100, 228, 189, .09), transparent 31%),
    linear-gradient(135deg, rgba(255, 118, 83, .035), transparent 42%),
    var(--ink);
}
.result-panel:focus { outline: none; }
.empty-result { min-height: calc(100vh - 102px); display: grid; place-content: center; justify-items: center; gap: 28px; color: #a9b6b7; text-align: center; }
.empty-result p { max-width: 380px; margin: 0; font-size: 13px; line-height: 1.55; }
.empty-diagram { width: 300px; display: grid; grid-template-columns: 1fr 58px 1fr; grid-template-rows: 36px 36px; gap: 12px; align-items: center; }
.empty-node { display: grid; place-items: center; height: 36px; border: 1px solid #465356; color: #d4dddd; font: 700 10px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.empty-node:first-child { grid-row: 1 / 3; }
.empty-node.wasm { border-color: rgba(100, 228, 189, .5); color: var(--mint); }
.empty-node.x86 { border-color: rgba(255, 118, 83, .5); color: var(--coral); }
.empty-line { grid-row: 1 / 3; height: 1px; background: #536064; }

.result-content { max-width: 980px; margin: 0 auto; }
.result-mast { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 18px; padding-bottom: 16px; border-bottom: 1px solid #3b484b; }
.result-kicker { color: var(--mint); }
.result-brand { display: block; margin-bottom: 4px; color: #8fa0a2; font: 700 9px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; }
.result-model { margin: 0; color: #bec8c9; font: 600 10px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }
.cost-lockup { text-align: right; }
.cost-lockup span, .proof-strip span, .explanation-band span { display: block; margin-bottom: 5px; color: #8fa0a2; font-size: 9px; font-weight: 800; text-transform: uppercase; }
.cost-lockup strong { color: var(--white); font: 760 28px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }

.proof-strip { display: grid; grid-template-columns: .85fr 1.25fr 1fr; border-bottom: 1px solid #3b484b; }
.proof-strip > div { min-width: 0; padding: 13px 14px 13px 0; }
.proof-strip > div + div { padding-left: 14px; border-left: 1px solid #3b484b; }
.proof-strip strong { display: block; color: #edf2f1; font-size: 11px; line-height: 1.35; }
.budget-proof strong { color: var(--mint); }
.budget-proof.over strong { color: var(--coral); }

.result-actions { grid-template-columns: max-content max-content minmax(170px, 1fr); margin: 12px 0; }
.button-ink { color: var(--ink); background: var(--white); }
.button-ghost { color: var(--white); border-color: #627074; background: transparent; }
.button-ghost:hover { background: #2b373a; }
.button-export { justify-self: end; color: var(--ink); background: var(--yellow); border-color: #edbd46; }

.lane-board { display: grid; grid-template-columns: 1.45fr 1fr; gap: 10px; }
.runtime-lane { min-width: 0; border: 1px solid #405053; background: rgba(6, 13, 14, .3); }
.runtime-lane > header { height: 40px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 12px; border-bottom: 1px solid #405053; }
.runtime-lane > header div { min-width: 0; display: flex; align-items: center; gap: 8px; }
.runtime-lane h2 { margin: 0; font-size: 11px; line-height: 1; white-space: nowrap; }
.runtime-lane > header strong { color: #aebabb; font: 600 9px/1 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: nowrap; }
.lane-signal { width: 8px; height: 8px; border-radius: 50%; background: var(--mint); box-shadow: 0 0 0 3px rgba(100, 228, 189, .1); }
.lane-x86 .lane-signal { background: var(--coral); box-shadow: 0 0 0 3px rgba(255, 118, 83, .1); }
.ticket-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.lane-x86 .ticket-list { grid-template-columns: 1fr; }
.task-ticket { min-width: 0; min-height: 61px; padding: 9px 11px; border-right: 1px solid #344245; border-bottom: 1px solid #344245; }
.task-ticket:nth-child(even) { border-right: 0; }
.lane-x86 .task-ticket { border-right: 0; }
.task-ticket:last-child { border-bottom: 0; }
.task-ticket-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.task-ticket strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; color: #f1f5f4; font-size: 10px; white-space: nowrap; }
.coefficient { flex: 0 0 auto; color: var(--mint); font: 700 8px/1 ui-monospace, SFMono-Regular, Menlo, monospace; }
.lane-x86 .coefficient { color: var(--coral); }
.task-ticket-meta { margin-top: 6px; display: flex; align-items: center; justify-content: space-between; gap: 8px; color: #a0adaf; font: 500 8px/1.25 ui-monospace, SFMono-Regular, Menlo, monospace; }
.task-ticket-reason { margin: 5px 0 0; overflow: hidden; text-overflow: ellipsis; color: #748487; font-size: 8px; white-space: nowrap; }

.explanation-band { display: grid; grid-template-columns: 1fr 1fr; gap: 22px; margin-top: 12px; padding-top: 12px; border-top: 1px solid #3b484b; }
.explanation-band p { margin: 0; color: #acb8ba; font-size: 9px; line-height: 1.45; }
.export-status { min-height: 14px; margin: 8px 0 0; color: var(--mint); font: 600 9px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; }

@media (max-width: 960px) {
  .topbar { grid-template-columns: minmax(0, 1fr) 40px; }
  .engine-state { display: none; }
  .workspace { display: block; }
  .config-panel { min-height: calc(100svh - 58px); border-right: 0; border-bottom: 1px solid var(--line); }
  .result-panel { min-height: 100svh; padding-top: 18px; }
  .empty-result { min-height: calc(100svh - 44px); }
}

@media (max-width: 620px) {
  .topbar { padding: 0 12px; }
  .brand-name { font-size: 13px; }
  .config-panel { padding: 18px 14px 16px; }
  h1 { font-size: 30px; line-height: 1.05; }
  .lede { font-size: 12px; }
  .assumption-grid { margin-top: 15px; }
  .assumption-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .budget-field { grid-column: 1 / -1; }
  .csv-label { align-items: flex-start; }
  .csv-label code { max-width: 190px; text-align: right; white-space: normal; line-height: 1.25; }
  #workload-csv { height: 166px; font-size: 9px; }
  .config-actions { grid-template-columns: 1fr; }
  .button { min-height: 44px; }
  .result-panel { padding: 16px 12px 20px; }
  .result-mast { grid-template-columns: 1fr; gap: 10px; }
  .cost-lockup { text-align: left; }
  .cost-lockup strong { font-size: 26px; }
  .proof-strip { grid-template-columns: 1fr 1fr; }
  .proof-strip > div { padding: 11px 9px 11px 0; }
  .proof-strip > div + div { padding-left: 9px; }
  .proof-strip > div:nth-child(3) { grid-column: 1 / -1; padding-left: 0; border-left: 0; border-top: 1px solid #3b484b; }
  .proof-strip strong { font-size: 10px; }
  .result-actions { grid-template-columns: 1fr 1fr; }
  .button-export { grid-column: 1 / -1; width: 100%; justify-self: stretch; }
  .lane-board { grid-template-columns: 1fr; }
  .ticket-list, .lane-x86 .ticket-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .lane-x86 .task-ticket:nth-child(even) { border-right: 0; }
  .lane-x86 .task-ticket:nth-child(odd) { border-right: 1px solid #344245; }
  .explanation-band { grid-template-columns: 1fr; gap: 10px; }
}

@media (max-width: 390px) {
  .brand-mark { width: 30px; height: 30px; flex-basis: 30px; }
  .brand-name { font-size: 12px; }
  h1 { font-size: 28px; }
  .result-actions { grid-template-columns: 1fr; }
  .button-export { grid-column: auto; }
  .ticket-list, .lane-x86 .ticket-list { grid-template-columns: 1fr; }
  .task-ticket, .task-ticket:nth-child(even), .lane-x86 .task-ticket:nth-child(odd) { border-right: 0; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
