/* Ward console — dark-first operator console. Sidebar + work area; playground = editors left, learn/result panel right. */
:root {
  --bg: #0A0F1A;
  --panel: #0F1624;
  --panel-2: #151D2E;
  --line: #222D42;
  --fg: #E6EBF2;
  --muted: #9AA8BC;
  --faint: #6B7A90;
  --accent: #16C784;
  --accent-ink: #03150D;
  --accent-soft: rgba(22, 199, 132, 0.14);
  --warn: #F5B544;
  --warn-soft: rgba(245, 181, 68, 0.15);
  --bad: #FB8A8A;
  --bad-soft: rgba(251, 138, 138, 0.14);
  --code-bg: #0B111D;
  --code-key: #9CB3D6;
  --code-str: #A6E9C9;
  --focus: #5CC8FF;
  --font-ui: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  --radius: 10px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #F3F5F8; --panel: #FFFFFF; --panel-2: #F1F4F8; --line: #E1E6EE;
    --fg: #0F172A; --muted: #475569; --faint: #64748B;
    --accent: #0B7D57; --accent-ink: #FFFFFF; --accent-soft: #E6F7F0;
    --warn: #A15C07; --warn-soft: #FEF3C7; --bad: #B91C1C; --bad-soft: #FEE2E2;
    --code-bg: #F8FAFC; --code-key: #3B5B8C; --code-str: #0B6B4A; --focus: #1D6FD8;
    color-scheme: light;
  }
}
:root[data-theme="light"] {
  --bg: #F3F5F8; --panel: #FFFFFF; --panel-2: #F1F4F8; --line: #E1E6EE;
  --fg: #0F172A; --muted: #475569; --faint: #64748B;
  --accent: #0B7D57; --accent-ink: #FFFFFF; --accent-soft: #E6F7F0;
  --warn: #A15C07; --warn-soft: #FEF3C7; --bad: #B91C1C; --bad-soft: #FEE2E2;
  --code-bg: #F8FAFC; --code-key: #3B5B8C; --code-str: #0B6B4A; --focus: #1D6FD8;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
code, .mono { font-family: var(--font-mono); font-size: 0.92em; }
h1, h2, h3 { text-wrap: balance; margin: 0; }

/* ── Shell ── */
.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  gap: 16px;
  padding-block: 16px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.side {
  position: sticky;
  top: calc(16px + env(safe-area-inset-top, 0px));
  align-self: start;
  height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 16px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px; }
.brand-mark { width: 30px; height: 30px; flex: none; }
.brand-mark svg { width: 100%; height: 100%; display: block; }
.theme-switch {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px;
  padding: 3px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel-2);
}
.theme-switch button {
  display: flex; align-items: center; justify-content: center; gap: 5px;
  min-height: 32px; padding: 0 6px; border: 0; border-radius: 7px; background: transparent;
  color: var(--muted); font-size: 12px; cursor: pointer;
}
.theme-switch button svg { width: 14px; height: 14px; flex: none; }
.theme-switch button:hover { color: var(--fg); }
.theme-switch button[aria-pressed="true"] { background: var(--panel); color: var(--fg); font-weight: 600; box-shadow: 0 0 0 1px var(--line); }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; line-height: 1.1; }
.brand-sub { font-size: 11.5px; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  min-height: 38px; padding: 0 10px; border-radius: 8px;
  color: var(--muted); text-decoration: none;
}
.nav a:hover { background: var(--panel-2); color: var(--fg); }
.nav a[aria-current="page"] { background: var(--panel-2); color: var(--fg); font-weight: 600; }
.nav svg { width: 17px; height: 17px; flex: none; }
.nav .nav-off { display: flex; align-items: center; gap: 10px; min-height: 38px; padding: 0 10px; color: var(--faint); }
.nav .soon { margin-left: auto; font-size: 11px; color: var(--faint); }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 10px; }
.mode-card {
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; display: flex; flex-direction: column; gap: 4px;
}
.mode-card .label { font-size: 12px; color: var(--muted); }
.mode-card .value { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); flex: none; }
.dot.live { background: var(--accent); }
.dot.demo { background: var(--warn); }

.main { min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  min-height: 48px; padding: 0 4px;
}
.crumb { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.crumb svg { width: 17px; height: 17px; color: var(--muted); }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Controls ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 38px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--fg);
  cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--panel-2); text-decoration: none; }
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:hover { background: var(--accent); filter: brightness(1.06); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--fg); background: var(--panel-2); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }
.btn-lg { min-height: 44px; padding: 0 20px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
  white-space: nowrap;
}
.chip.ok { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.chip.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; min-width: 0; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-height: 48px; padding: 0 14px 0 16px; border-bottom: 1px solid var(--line);
}
.panel-head h2 { font-size: 14px; font-weight: 600; }
.panel-head .tools { display: flex; gap: 4px; flex-wrap: wrap; }
.panel-body { padding: 16px; }

/* ── Playground ── */
.play { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 16px; align-items: start; }
.editors { display: flex; flex-direction: column; min-height: 640px; }
.editor-block { display: flex; flex-direction: column; min-height: 0; }
.editor-block + .editor-block { border-top: 1px solid var(--line); }
.editor {
  display: grid; grid-template-columns: 44px minmax(0, 1fr);
  background: var(--code-bg); margin: 12px; border-radius: 8px; border: 1px solid var(--line);
  overflow: hidden; height: 340px;
}
.editor.short { height: 200px; }
.editor textarea { height: 100%; resize: none; }
.gutter {
  padding: 12px 8px 12px 0; text-align: right; color: var(--faint);
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.6;
  white-space: pre; user-select: none; overflow: hidden; border-right: 1px solid var(--line);
}
.editor textarea {
  width: 100%; border: 0; outline: none; resize: vertical; background: transparent;
  padding: 12px 14px; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.6;
  color: var(--fg); white-space: pre; overflow: auto; tab-size: 2;
}
.editor:focus-within { border-color: var(--focus); }
.editor-status { display: flex; justify-content: space-between; gap: 10px; padding: 0 16px 12px; font-size: 12px; color: var(--muted); }
.editor-status .err { color: var(--bad); }
.runbar {
  margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 12px 14px; border-top: 1px solid var(--line);
}
.runbar-left { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.select {
  min-height: 34px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel-2);
  padding: 0 10px; font-family: var(--font-mono); font-size: 12.5px;
}
.kbd { font-family: var(--font-mono); font-size: 11.5px; color: var(--faint); }

.side-panel { min-height: 640px; }
.learn { padding: 24px 22px; display: flex; flex-direction: column; gap: 26px; }
.eyebrow { font-size: 11.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.learn h1 { font-size: 34px; letter-spacing: -0.025em; line-height: 1.1; margin-top: 6px; }
.learn p.lede { color: var(--muted); margin: 10px 0 0; max-width: 56ch; }
.lessons { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.lesson {
  text-align: left; cursor: pointer; border: 1px solid var(--line); border-radius: 12px;
  background: var(--panel-2); padding: 14px; display: flex; flex-direction: column; gap: 8px;
  min-height: 132px; color: var(--fg);
}
.lesson:hover { border-color: var(--faint); }
.lesson .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.lesson .t { font-weight: 600; font-size: 14.5px; }
.lesson .b { color: var(--muted); font-size: 13px; }
.lesson .src { margin-top: auto; font-size: 11.5px; color: var(--faint); }
.trace-mini { display: flex; gap: 3px; align-items: flex-end; height: 22px; }
.trace-mini span { width: 6px; border-radius: 2px; background: var(--faint); opacity: 0.6; }
.usecases { display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.usecase {
  display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; text-align: left;
  padding: 13px 14px; background: transparent; border: 0; border-bottom: 1px solid var(--line); cursor: pointer; color: var(--fg);
}
.usecase:last-child { border-bottom: 0; }
.usecase:hover { background: var(--panel-2); }
.usecase .t { font-weight: 600; }
.usecase .b { color: var(--muted); font-size: 13px; }

/* Result */
.result { padding: 20px 22px; display: flex; flex-direction: column; gap: 20px; }
.result-top { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.verdict { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.verdict-word {
  font-size: 30px; font-weight: 700; letter-spacing: -0.02em; padding: 4px 14px; border-radius: 10px;
}
.verdict-word.APPROVE { background: var(--accent-soft); color: var(--accent); }
.verdict-word.STEP_UP { background: var(--warn-soft); color: var(--warn); }
.verdict-word.DECLINE { background: var(--bad-soft); color: var(--bad); }
.verdict-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 240px; }
.verdict-text .z { font-weight: 600; }
.verdict-text .d { color: var(--muted); }
.facts {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px;
  background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden;
}
.fact { background: var(--panel); padding: 11px 13px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.fact .k { font-size: 12px; color: var(--muted); }
.fact .v { font-weight: 600; font-family: var(--font-mono); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.fact .s { font-size: 12px; color: var(--muted); }
.gates { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.gate {
  display: grid; grid-template-columns: 26px minmax(110px, 160px) minmax(0, 1fr) auto; gap: 10px; align-items: center;
  padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 13px;
}
.gate:last-child { border-bottom: 0; }
.gate .n { font-family: var(--font-mono); font-size: 11.5px; color: var(--faint); }
.gate .name { font-weight: 500; }
.gate .detail { color: var(--muted); min-width: 0; overflow-wrap: anywhere; }
.gate.flag { background: var(--warn-soft); }
.gate.fail { background: var(--bad-soft); }
.steps { display: flex; flex-wrap: wrap; gap: 6px; }
.step {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 6px;
  border: 1px solid var(--line); font-family: var(--font-mono); font-size: 11.5px; color: var(--muted);
}
.step b { font-weight: 600; }
.step.APPROVE b { color: var(--accent); }
.step.STEP_UP b { color: var(--warn); }
.step.DECLINE b { color: var(--bad); }
.step.final { border-color: var(--fg); color: var(--fg); }
details.raw { border: 1px solid var(--line); border-radius: 10px; }
details.raw summary { cursor: pointer; padding: 10px 12px; color: var(--muted); font-size: 13px; }
details.raw pre { margin: 0; padding: 12px 14px; border-top: 1px solid var(--line); overflow: auto; max-height: 360px; font-family: var(--font-mono); font-size: 12px; background: var(--code-bg); }
.note { font-size: 12.5px; color: var(--muted); }
.note.warn { color: var(--warn); }
.error-box { border: 1px solid var(--bad); background: var(--bad-soft); color: var(--fg); border-radius: 10px; padding: 12px 14px; }
.section-title { font-size: 13px; font-weight: 600; }
.loading { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 24px 22px; }
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Pages ── */
.page { display: flex; flex-direction: column; gap: 16px; max-width: 980px; }
.page h1 { font-size: 28px; letter-spacing: -0.02em; }
.page .lede { color: var(--muted); margin: 6px 0 0; max-width: 62ch; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.card .n { font-family: var(--font-mono); font-size: 12px; color: var(--faint); }
.card h3 { font-size: 15px; }
.card p { margin: 0; color: var(--muted); font-size: 13.5px; }
pre.code {
  margin: 0; padding: 14px 16px; background: var(--code-bg); border: 1px solid var(--line); border-radius: 10px;
  font-family: var(--font-mono); font-size: 12.5px; line-height: 1.6; overflow-x: auto; white-space: pre;
}
.k { color: var(--code-key); }
.s { color: var(--code-str); }
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 500; }
.field .hint { font-size: 12.5px; color: var(--muted); }
.input {
  min-height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--code-bg);
  font-family: var(--font-mono); font-size: 13px; width: 100%;
}
.input:focus { outline: 2px solid var(--focus); outline-offset: 0; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.stat .k { font-size: 12.5px; color: var(--muted); }
.stat .v { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
table.list { width: 100%; border-collapse: collapse; font-size: 13px; }
table.list th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
table.list td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
.toast {
  position: fixed; right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: var(--fg); color: var(--bg); padding: 10px 14px; border-radius: 8px; font-weight: 500; font-size: 13px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}

/* ── Responsive ── */
@media (max-width: 1120px) {
  .play { grid-template-columns: minmax(0, 1fr); }
  .editors, .side-panel { min-height: 0; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; flex-direction: column; gap: 12px; }
  .nav { flex-direction: row; overflow-x: auto; }
  .nav a { flex: none; }
  .side-foot { margin-top: 0; }
  .grid-3, .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .lessons, .grid-3, .stats { grid-template-columns: minmax(0, 1fr); }
  .gate { grid-template-columns: 22px minmax(0, 1fr) auto; }
  .gate .detail { grid-column: 2 / -1; grid-row: 2; }
  .gate .chip { grid-column: 3; grid-row: 1; }
  .learn h1 { font-size: 28px; }
}
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; }
}
