/* gtnh-agent demo layout. Palette and buttons come from ../_shared/demo.css. */
:root {
  --warn: #f0abfc;
  --ok: var(--accent);
  --bad: var(--danger);
}
html { -webkit-text-size-adjust: 100%; }
body { padding: 14px 16px 12px; overflow-x: hidden; }
#root { max-width: 1400px; margin: 0 auto; }
h1, h2 { margin: 0; font-weight: 650; letter-spacing: -0.02em; }
p { margin: 0; }
code { font-family: var(--mono); font-size: 0.92em; color: var(--text-2); }
button { font: inherit; }
[hidden] { display: none !important; }

/* ---- Poster ---- */
.poster { min-height: 420px; align-content: center; }
.poster .lede { color: var(--text-2); max-width: 62ch; font-size: 14.5px; }
.mini-pipe { list-style: none; margin: 4px 0; padding: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; max-width: 640px; }
.mini-pipe li { font: 500 11px/1 var(--mono); letter-spacing: 0.06em; text-transform: uppercase; color: var(--accent-hi); border: 1px solid var(--line); background: var(--surface-2); border-radius: var(--radius-pill); padding: 6px 9px; }
.mini-pipe li + li::before { content: '→'; color: var(--muted); margin-right: 6px; margin-left: -2px; }

/* ---- App bar ---- */
.bar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: flex-start; justify-content: space-between; margin-bottom: 12px; }
.bar-l { flex: 1 1 360px; min-width: 0; }
.bar .note { font-size: 12.5px; color: var(--text-2); margin-top: 3px; max-width: 78ch; }
.bar-r { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.seg.small button { padding: 5px 9px; font-size: 11px; }
.btn { min-height: 36px; }

/* ---- Three columns, collapsing ---- */
.grid { display: grid; grid-template-columns: 236px minmax(0, 1fr) minmax(300px, 360px); gap: 14px; align-items: start; }
.col { min-width: 0; }
@media (max-width: 1120px) {
  .grid { grid-template-columns: 220px minmax(0, 1fr); }
  .side { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 14px; }
}
@media (max-width: 760px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .side { grid-template-columns: minmax(0, 1fr); }
}

/* ---- Scenario picker: a list on wide screens, a select on narrow ones ---- */
.scen .label { display: block; margin-bottom: 6px; }
.scen-select { width: 100%; display: none; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius); padding: 9px 10px; font: 13px/1.3 var(--mono); }
.scen-list { max-height: 640px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); padding: 6px; outline-offset: -2px; }
.scen-list h3 { font: 500 11px/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin: 10px 6px 5px; }
.scen-list h3:first-child { margin-top: 4px; }
.scen-opt { display: block; width: 100%; text-align: left; background: none; border: 0; border-radius: 7px; color: var(--text-2); font: 12px/1.25 var(--mono); padding: 6px 8px; cursor: pointer; }
.scen-opt:hover { background: var(--surface-2); color: var(--text); }
.scen-opt[aria-selected="true"] { background: rgba(167, 139, 250, 0.16); color: var(--accent-hi); }
.scen-opt .ran { float: right; color: var(--muted); font-size: 11px; }
@media (max-width: 760px) {
  .scen-select { display: block; }
  .scen-list { display: none; }
}

/* ---- Scenario head and run controls ---- */
.scen-head { display: grid; gap: 6px; }
.scen-name { color: var(--accent-hi); font-size: 14px; }
.scen-desc { color: var(--text); font-size: 14px; }
.scen-expect { font-size: 11.5px; overflow-wrap: anywhere; }
.runrow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 4px; }
.human { display: inline-flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.human .tag { font: 12px/1.3 var(--mono); color: var(--warn); }
.btn.warn { border-color: var(--warn); color: var(--warn); }
.btn.warn:hover { background: rgba(240, 171, 252, 0.1); }
.try { font-size: 12px; }
.link { background: none; border: 0; padding: 0; color: var(--accent); font: 12px var(--mono); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.link:hover { color: var(--accent-hi); }

/* ---- Cycle summary ---- */
.summary { margin: 12px 0 8px; font: 12px/1.45 var(--mono); color: var(--text-2); display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; min-height: 1.45em; }
.summary .st { font-weight: 600; }
.st.s-succeeded { color: var(--ok); }
.st.s-paused { color: var(--warn); }
.st.s-rejected, .st.s-failed, .st.s-verification_failed, .st.s-error { color: var(--bad); }
.summary .line { color: var(--text); overflow-wrap: anywhere; }

/* ---- Stage list ---- */
.stages { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; counter-reset: st; }
.stage { border: 1px solid var(--line); border-left-width: 3px; border-radius: 8px; background: var(--surface); padding: 8px 10px 8px 12px; transition: opacity 0.25s, transform 0.25s, border-color 0.25s; }
.stage.pending { opacity: 0; transform: translateY(4px); }
.stage[data-s="ok"] { border-left-color: var(--ok); }
.stage[data-s="warn"] { border-left-color: var(--warn); }
.stage[data-s="bad"] { border-left-color: var(--bad); }
.stage[data-s="skip"] { border-left-color: var(--line); }
.stage[data-s="skip"] .st-body { color: var(--muted); }
.st-top { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; flex-wrap: wrap; }
.st-name { font: 500 11px/1.3 var(--mono); letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); }
.st-name b { color: var(--text-2); font-weight: 600; margin-right: 6px; }
.chip { font: 600 12px/1.3 var(--mono); padding: 2px 8px; border-radius: var(--radius-pill); background: var(--surface-2); color: var(--text-2); overflow-wrap: anywhere; }
.stage[data-s="ok"] .chip { color: var(--accent-hi); background: rgba(167, 139, 250, 0.13); }
.stage[data-s="warn"] .chip { color: var(--warn); background: rgba(240, 171, 252, 0.11); }
.stage[data-s="bad"] .chip { color: #fda4af; background: rgba(244, 63, 94, 0.14); }
.st-body { margin-top: 4px; font: 12px/1.45 var(--mono); color: var(--text-2); overflow-wrap: anywhere; }
.st-body div + div { margin-top: 1px; }
.st-body .pass { color: var(--accent-hi); }
.st-body .fail { color: #fda4af; }
.st-right { display: inline-flex; gap: 6px; align-items: baseline; min-width: 0; }
.json-t { background: none; border: 1px solid var(--line); border-radius: var(--radius-pill); color: var(--muted); font: 11px/1 var(--mono); padding: 3px 7px; cursor: pointer; flex: none; }
.json-t:hover, .json-t[aria-expanded="true"] { color: var(--accent-hi); border-color: var(--accent); }
.stage pre { margin: 6px 0 0; max-height: 260px; overflow: auto; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px; font: 11px/1.45 var(--mono); color: var(--text-2); white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---- World map ---- */
.world-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 6px 8px; margin-bottom: 8px; }
.world-head .seg { flex: none; }
#map { width: 100%; height: auto; display: block; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; touch-action: manipulation; }
#map .grid-l { stroke: #1d1a29; stroke-width: 1; }
#map .axis { stroke: #2d2840; stroke-width: 1; }
#map text { font: 9px var(--mono); fill: var(--muted); }
.map-cap { font-size: 11.5px; color: var(--text-2); margin-top: 6px; min-height: 2.9em; overflow-wrap: anywhere; }
.legend { font-size: 10.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 3px 10px; margin-top: 4px; }
.legend i { display: inline-block; width: 9px; height: 9px; margin-right: 4px; vertical-align: -1px; border-radius: 2px; }
.k-p { background: var(--accent); border-radius: 50% !important; }
.k-h { border: 1.5px solid var(--text-2); }
.k-b { background: #4a4360; }
.k-x { border: 1.5px solid var(--accent-hi); }
.k-d { background: var(--danger); }
.k-m { background: #c4b5fd; transform: rotate(45deg) scale(0.85); }
.k-t { border: 1.5px dashed var(--warn); border-radius: 50% !important; }

/* ---- History ---- */
.hist { margin-top: 14px; }
@media (max-width: 1120px) { .hist { margin-top: 0; } }
.history { list-style: none; margin: 8px 0 0; padding: 0; max-height: 210px; overflow: auto; display: grid; gap: 2px; }
.history li button { width: 100%; text-align: left; background: none; border: 0; border-radius: 6px; padding: 5px 6px; color: var(--text-2); font: 12px/1.35 var(--mono); cursor: pointer; display: grid; grid-template-columns: 2.6em minmax(0, 1fr); gap: 6px; }
.history li button:hover { background: var(--surface-2); }
.history li button[aria-current="true"] { background: rgba(167, 139, 250, 0.12); }
.history .n { color: var(--muted); }
.history .who { color: var(--accent-hi); }
.history .msg { overflow-wrap: anywhere; }
.history li.human-entry .msg { color: var(--warn); }
.history .empty { color: var(--muted); font: 12px var(--mono); padding: 4px 6px; }
.db { font-size: 10.5px; margin-top: 8px; overflow-wrap: anywhere; }

/* ---- Self-test overlay ---- */
.overlay { position: fixed; inset: 0; background: rgba(11, 10, 16, 0.82); display: grid; place-items: center; padding: 16px; z-index: 10; }
.test { width: min(860px, 100%); max-height: calc(100vh - 32px); display: grid; grid-template-rows: auto auto auto minmax(0, 1fr) auto auto; gap: 8px; }
.test-head { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.test h2 { font-size: 17px; }
.small-t { font-size: 12px; }
.test-scroll { overflow: auto; min-height: 120px; border: 1px solid var(--line); border-radius: 8px; }
.test-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.test-table th, .test-table td { text-align: left; padding: 4px 8px; border-bottom: 1px solid var(--line); vertical-align: top; overflow-wrap: anywhere; }
.test-table th { color: var(--muted); font-weight: 500; position: sticky; top: 0; background: var(--surface); }
.test-table td.ok { color: var(--accent-hi); white-space: nowrap; }
.test-table td:last-child { width: 4.5em; white-space: nowrap; }
.test-table td.no { color: #fda4af; white-space: nowrap; }
@media (max-width: 560px) { .test-table th:nth-child(2), .test-table td:nth-child(2) { display: none; } }

.demo-foot a { color: var(--accent); }
@media (prefers-reduced-motion: reduce) {
  .stage.pending { opacity: 1; transform: none; }
}
