:root {
  --bg: #12110f;
  --card: #1e1c18;
  --card-2: #2a261f;
  --line: #3c3832;
  --ink: #f4f0e6;
  --muted: #c9c0b2;
  --faint: #a39888;
  --amber: #e8a04a;
  --amber-ink: #23180a;
  --teal: #8fd0b4;
  --rose: #f0a090;
  --sans: "Segoe UI", "Avenir Next", "Helvetica Neue", sans-serif;
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  --mono: ui-monospace, "SFMono-Regular", "Cascadia Code", Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100%;
  padding: 18px 22px 14px;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  background:
    radial-gradient(1000px 420px at 8% -10%, #2c261c 0%, transparent 58%),
    radial-gradient(820px 380px at 110% -8%, #1a2c27 0%, transparent 52%),
    var(--bg);
}

::selection { background: var(--amber); color: var(--amber-ink); }

:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  margin-bottom: 14px;
}

.kicker {
  margin: 0 0 6px;
  color: var(--amber);
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(32px, 4vw, 44px);
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 0.95;
}

.lede {
  margin: 8px 0 0;
  max-width: 62ch;
  color: var(--muted);
}

.session {
  margin: 0;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  white-space: nowrap;
}

main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}

.stages {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
  position: relative;
}

.stages::before {
  content: "";
  position: absolute;
  top: 26px;
  left: 7%;
  right: 7%;
  height: 1px;
  background: var(--line);
}

.stage {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 104px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
}

.stage h2 {
  margin: 8px 0 4px;
  font-size: 15px;
  font-weight: 600;
}

.num {
  position: relative;
  z-index: 1;
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--bg);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.detail {
  margin: 0;
  min-height: 2.6em;
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.flag {
  margin: auto 0 0;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.stage.is-ok { border-color: #3e6b59; }
.stage.is-ok .num { background: var(--teal); color: #10211a; border-color: transparent; }
.stage.is-ok .flag { color: var(--teal); }
.stage.is-err { border-color: #8a4638; }
.stage.is-err .num { background: var(--rose); color: #2a100c; border-color: transparent; }
.stage.is-err .flag { color: var(--rose); }
.stage.is-run { border-color: var(--amber); }
.stage.is-run .num { background: var(--amber); color: var(--amber-ink); border-color: transparent; }
.stage.is-run .flag { color: var(--amber); }
.stage.is-skip { border-style: dashed; opacity: 0.72; }

.grid {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  min-height: 0;
}

.panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
}

.panel-h {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.panel-h h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.hint-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hint {
  margin: 0;
  color: var(--faint);
  font-size: 12px;
}

.hint-row .ghost { padding: 4px 10px; font-size: 13px; }

kbd {
  padding: 0 4px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 32px;
  margin-bottom: 10px;
}

.presets button,
.ghost,
.primary,
.agent,
.hist {
  font: inherit;
  cursor: pointer;
}

.presets button {
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
}

.presets button[aria-pressed="true"] {
  border-color: transparent;
  background: var(--amber);
  color: var(--amber-ink);
}

textarea,
.response {
  flex: 1;
  min-height: 0;
  margin: 0;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.5;
}

textarea {
  width: 100%;
  resize: none;
}

.shape {
  margin: 8px 0 0;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 12px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
}

.row.end { justify-content: flex-end; }

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.check input {
  width: 16px;
  height: 16px;
  accent-color: var(--amber);
}

.primary {
  padding: 10px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--amber);
  color: var(--amber-ink);
  font-weight: 600;
}

.primary:hover { filter: brightness(1.06); }
.primary:disabled { opacity: 0.6; cursor: default; }

.primary:focus-visible,
.presets button[aria-pressed="true"]:focus-visible {
  outline-color: var(--ink);
}

.ghost {
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
}

.ghost:disabled { opacity: 0.45; cursor: default; }

.statusline {
  min-height: 1.3em;
  margin: 0 0 8px;
  color: var(--faint);
  font-size: 14px;
}

.statusline.is-ok { color: var(--teal); }
.statusline.is-err { color: var(--rose); }
.statusline.is-run { color: var(--amber); }

.response.is-empty {
  display: grid;
  place-items: center;
  color: var(--faint);
}

.response.is-err { border-color: #8a4638; }

.strip {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 12px 16px;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
}

.strip-col {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.strip h3 {
  flex: none;
  margin: 0;
  color: var(--faint);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.strip ul {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.empty {
  padding: 6px 2px;
  color: var(--muted);
  font-size: 13px;
}

.agent,
.hist {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: auto;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: inherit;
  text-align: left;
}

.agent:hover,
.hist:hover { background: var(--card-2); }

.agent .id,
.hist .code {
  font-family: var(--mono);
  font-size: 12px;
}

.agent .meta,
.hist .name {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent.is-off .id { color: var(--faint); text-decoration: line-through; }
.hist.is-err .code { color: var(--rose); }
.hist.is-ok .code { color: var(--teal); }

footer {
  margin-top: 12px;
  color: var(--faint);
  font-size: 12px;
}

footer p { margin: 0; }

footer code {
  color: var(--muted);
  font-family: var(--mono);
}

.dot { padding: 0 2px; }

@media (max-height: 840px) and (min-width: 801px) {
  body { padding: 12px 22px 8px; }
  h1 { font-size: 36px; }
  .lede { margin-top: 4px; }
  .top { margin-bottom: 8px; }
  main { gap: 10px; }
  .stage { min-height: 88px; }
  .panel { padding: 10px 12px; }
  .response { font-size: 12.5px; line-height: 1.4; }
  footer { margin-top: 8px; }
}

@media (max-width: 800px) {
  html, body { height: auto; }
  body { display: block; padding: 14px; }
  .top { flex-direction: column; align-items: flex-start; }
  main { display: block; }
  .stages { grid-template-columns: 1fr; }
  .stages::before { display: none; }
  .stage {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-areas: "num name flag" "num detail flag";
    column-gap: 10px;
    min-height: 0;
    align-items: center;
  }
  .flag { margin: 0; }
  .num { grid-area: num; }
  .stage h2 { grid-area: name; margin: 0; }
  .detail { grid-area: detail; min-height: 0; }
  .flag { grid-area: flag; margin: 0; }
  .grid { grid-template-columns: 1fr; }
  textarea, .response { min-height: 180px; }
  .strip { grid-template-columns: 1fr; align-items: stretch; }
  .strip .ghost { justify-self: start; }
}

@media (max-width: 420px) {
  .presets button { font-size: 12px; }
  .row { align-items: stretch; flex-direction: column; }
  .primary, .row.end .ghost { width: 100%; }
  .hint { display: none; }
  .hint-row .ghost { padding: 6px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
