:root {
  color-scheme: light;
  --ink: #172824;
  --muted: #63736b;
  --quiet: #87938b;
  --line: #d9e1db;
  --paper: #f4f6f1;
  --white: #fff;
  --green: #18786f;
  --green-dark: #145d57;
  --green-pale: #e2eee8;
  --orange: #d58a49;
  --red: #bb5c4b;
  font-family: Inter, "Segoe UI", "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

* { box-sizing: border-box; }
body { min-width: 320px; margin: 0; color: var(--ink); background: var(--paper); }
button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid rgba(24, 120, 111, .28); outline-offset: 2px; }
[hidden] { display: none !important; }

.site-header {
  height: 64px;
  display: flex;
  align-items: center;
  gap: 22px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.brand { display: inline-flex; align-items: center; gap: 9px; }
.brand-mark { width: 34px; height: 34px; }
.brand-mark svg { width: 100%; height: 100%; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 15px; line-height: 1.2; }
.brand small { margin-top: 2px; color: var(--quiet); font-size: 8px; letter-spacing: 1px; }
.header-state { display: inline-flex; align-items: center; gap: 8px; margin-left: 10px; color: var(--muted); font-size: 13px; }
.state-dot { width: 7px; height: 7px; border-radius: 50%; background: #aab5ac; }
.header-state[data-state="running"] .state-dot { background: #d58a49; animation: pulse 1s ease-in-out infinite alternate; }
.header-state[data-state="done"] .state-dot { background: #4d9878; }
.admin-link { margin-left: auto; color: var(--muted); font-size: 11px; }
.admin-link:hover { color: var(--green-dark); }
@keyframes pulse { to { opacity: .35; } }

main {
  position: relative;
  height: calc(100vh - 104px);
  min-height: 620px;
  display: flex;
  flex-direction: column;
  padding: 0 24px 0;
}
.group-strip {
  flex: 0 0 auto;
  min-height: 76px;
  display: flex;
  align-items: center;
  gap: 24px;
  border-bottom: 1px solid var(--line);
}
.group-label { flex: 0 0 auto; display: flex; align-items: center; }
.section-index { color: var(--green); font-size: 13px; font-weight: 800; letter-spacing: 1px; }
.group-label .section-index { font-size: 14px; }
.group-label strong { font-size: 11px; font-weight: 600; }
.group-tabs { flex: 1; display: flex; align-items: stretch; gap: 7px; min-width: 0; overflow-x: auto; padding: 4px; }
.group-message { align-self: center; color: var(--muted); font-size: 11px; }
.group-tab {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  min-width: 120px;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid #d6dfd8;
  border-radius: 4px;
  color: #4e6258;
  background: #fff;
  font-size: 14px;
  white-space: nowrap;
}
.group-tab > span, .group-tab::after { grid-area: 1 / 1; }
/* Reserve the selected label width so switching tabs does not shift the strip. */
.group-tab::after { content: attr(data-label); font-weight: 700; visibility: hidden; }
.group-tab:disabled { cursor: not-allowed; opacity: .6; }
.group-tab:hover { border-color: #86aa9c; }
.group-tab.active { border-color: var(--green); color: #fff; background: var(--green); font-weight: 700; }
.settings-toggle {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  margin-left: auto;
  padding: 0 11px;
  border: 1px solid #d3ddd5;
  border-radius: 4px;
  color: #40584d;
  background: #fff;
  font-size: 10px;
}
.settings-toggle:hover, .settings-toggle[aria-expanded="true"] { border-color: #88aa9b; background: #f5f8f5; }
.settings-toggle svg, .button svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

.connection-drawer {
  position: absolute;
  z-index: 5;
  top: 77px;
  left: 24px;
  width: min(680px, calc(100% - 48px));
  margin: 0;
  padding: 18px 20px 20px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  box-shadow: 0 16px 38px rgba(23, 40, 36, .13);
}
.connection-drawer .config-grid { grid-template-columns: minmax(0, 1.15fr) minmax(0, .95fr); }
.drawer-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 13px; }
.drawer-heading h1 { margin: 4px 0 0; font-size: 18px; }
.local-badge { display: inline-flex; align-items: center; gap: 7px; color: var(--muted); font-size: 10px; }
.local-badge > span { width: 7px; height: 7px; border-radius: 50%; background: #57a17c; }
.setup-panel { margin: 0; }
.config-grid { display: grid; grid-template-columns: minmax(180px, 1fr) minmax(180px, .9fr) minmax(200px, 1.1fr) minmax(210px, 1.1fr); align-items: start; gap: 14px; }
.field { min-width: 0; display: grid; gap: 6px; color: #34473f; font-size: 10px; font-weight: 700; }
.field > input, .field input, .field select {
  width: 100%;
  min-width: 0;
  height: 36px;
  padding: 0 9px;
  border: 1px solid #ced9d1;
  border-radius: 4px;
  color: var(--ink);
  background: white;
  font-size: 11px;
  font-weight: 400;
}
.field input::placeholder { color: #a1aba4; }
.field small { min-height: 14px; color: var(--quiet); font-size: 9px; font-weight: 400; line-height: 1.5; }
.secret-input, .model-input { display: flex; min-width: 0; gap: 6px; }
.secret-input input, .model-input input, .model-input select { flex: 1; }
.text-button { flex: 0 0 46px; border: 1px solid var(--line); border-radius: 4px; color: var(--green-dark); background: #f8faf7; font-size: 10px; }
.button { min-height: 36px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 0 11px; border: 1px solid transparent; border-radius: 4px; font-size: 10px; font-weight: 700; }
.button:disabled { cursor: not-allowed; opacity: .45; }
.button-primary { color: #fff; background: var(--green); }
.button-primary:hover:not(:disabled) { background: var(--green-dark); }
.button-secondary { border-color: #ced9d1; color: #40584d; background: #fff; }
.button-secondary:hover:not(:disabled) { border-color: #89aa9b; background: #f4f8f5; }
.model-input .button { flex: 0 0 auto; }
.field-message { min-height: 14px; }
.field-message.warn { color: #a16232; }
.config-actions { min-width: 0; display: flex; flex-direction: column; justify-content: center; padding-top: 16px; }
.cost-note { margin: 0; color: var(--quiet); font-size: 9px; line-height: 1.6; }

.workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(240px, 288px) minmax(0, 1fr);
  gap: 0;
  width: calc(100% + 48px);
  margin-right: -24px;
  margin-left: -24px;
  padding-top: 0;
}
.history-panel, .effect-panel { min-width: 0; min-height: 0; border: 1px solid var(--line); border-radius: 5px; background: #fff; }
.history-panel { display: flex; flex-direction: column; overflow: hidden; }
.history-heading, .effect-heading {
  min-height: 63px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid #e3e9e4;
}
.history-heading h2, .effect-heading h2 { margin: 3px 0 0; font-size: 14px; line-height: 1.3; }
.history-heading { min-height: 48px; }
.history-heading h2 { margin: 0; color: var(--green); font-size: 14px; }
.history-list { flex: 1; overflow-y: auto; padding: 8px 0; }
.history-item {
  width: 100%;
  display: grid;
  gap: 4px;
  margin-bottom: 3px;
  padding: 10px 12px;
  border: 1px solid #62c6b7;
  border-radius: 8px;
  color: var(--ink);
  background: #effcf9;
  text-align: left;
}
.history-item:hover { border-color: #31aa98; background: #e9faf6; }
.history-item.active { border-color: #27a693; background: #e8f8f4; box-shadow: inset 3px 0 0 #249985; }
.history-time { font-size: 13px; font-weight: 750; font-variant-numeric: tabular-nums; }
.history-meta { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11px; }
.history-duration { color: #56877b; font-size: 10px; font-variant-numeric: tabular-nums; }
.history-verdict { color: #168e70; }
.history-verdict.dumbed { color: var(--red); }
.history-verdict.unknown { color: #a27537; }
.history-empty { display: grid; min-height: 140px; place-content: center; gap: 7px; padding: 14px; color: var(--quiet); text-align: center; }
.history-message { font-size: 13px; }
.history-empty strong { color: #506057; font-size: 11px; }
.history-empty span { font-size: 9px; line-height: 1.6; }

.effect-panel { overflow-x: hidden; overflow-y: auto; display: flex; flex-direction: column; }
.effect-heading { flex: 0 0 auto; }
.effect-heading .section-index { font-size: 14px; }
.effect-heading h2 { font-size: 16px; }
.effect-badge { padding: 5px 8px; border: 1px solid #e4e8dd; border-radius: 3px; color: #5a6e61; background: #f4f7f0; font-size: 9px; white-space: nowrap; }
.reference-stage { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; justify-content: center; overflow: hidden; margin: 0; border: 1px solid #e3e7dc; border-radius: 4px; background: #fbfcfa; }
.reference-message { margin: 0; padding: 24px; color: var(--muted); font-size: 13px; line-height: 1.6; text-align: center; }
.scene-note { position: absolute; z-index: 1; top: 13px; left: 14px; display: flex; align-items: center; gap: 7px; color: #466353; font-size: 9px; font-weight: 700; }
.reference-placeholder { display: grid; justify-items: center; gap: 8px; color: #456b5d; text-align: center; }
.reference-placeholder strong { font-size: 24px; }
.reference-placeholder span { color: var(--muted); font-size: 11px; }
.art-note-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--orange); }
.pelican-scene { width: 100%; max-height: calc(100% - 55px); display: block; }
.wheel-spin, .pedal-spin { transform-box: fill-box; transform-origin: center; animation: wheel-turn 3s linear infinite; }
@keyframes wheel-turn { to { transform: rotate(360deg); } }
.reference-caption { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 11px 15px; border-top: 1px solid rgba(38, 81, 72, .12); background: rgba(255,255,255,.68); }
.reference-caption strong { font-size: 11px; }
.reference-caption span { color: var(--muted); font-size: 9px; }

.activity-section { min-height: 0; display: flex; flex: 0 0 auto; flex-direction: column; padding: 12px; }
.activity-status { margin: 0 0 8px; color: var(--muted); font-size: 10px; }
.activity-status[data-kind="run-info"] { display: flex; flex-wrap: wrap; column-gap: 14px; row-gap: 4px; color: #728096; font-size: 13px; line-height: 1.4; }
.live-output { min-height: 120px; max-height: 290px; overflow: auto; margin: 0; padding: 14px; border: 1px solid #d9e1db; border-radius: 4px; color: #d9e6de; background: #1d302e; font: 10px/1.65 "Cascadia Code", Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.verdict-panel { display: flex; align-items: center; gap: 12px; margin-top: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 4px; background: #fbfcfa; }
.verdict-symbol { width: 34px; height: 34px; display: grid; flex: 0 0 34px; place-items: center; border-radius: 50%; color: var(--green-dark); background: var(--green-pale); font-size: 16px; font-weight: 800; }
.verdict-panel[data-verdict="dumbed"] .verdict-symbol { color: #a34c3b; background: #f8e8e2; }
.verdict-panel[data-verdict="unknown"] .verdict-symbol { color: #896432; background: #f5edda; }
.verdict-copy h3 { margin: 3px 0; font-size: 13px; }
.verdict-copy p { margin: 0; color: var(--muted); font-size: 9px; line-height: 1.6; }
.full-result { min-height: 0; min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) clamp(245px, 27%, 320px); row-gap: 12px; column-gap: 0; flex: 0 0 auto; margin-top: 15px; }
.result-sidebar { min-width: 0; min-height: 0; display: flex; flex-direction: column; gap: 12px; overflow: visible; }
.result-sidebar > .button { align-self: flex-start; flex: 0 0 auto; }
.result-sidebar > .button[hidden] { display: none; }
.art-judgement { min-width: 0; padding: 14px; border: 1px solid var(--line); border-radius: 4px; background: #fbfcfa; }
.art-judgement-heading { display: flex; flex-direction: column; gap: 9px; }
.art-judgement-heading h3 { margin: 0; font-size: 18px; line-height: 1.3; }
.art-judgement-heading p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.6; }
.result-meta { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; margin-top: 8px; color: #728096; font-size: 13px; line-height: 1.4; }
.result-meta > span { white-space: nowrap; }
.art-judgement-criteria { margin: 0 0 14px; padding-bottom: 12px; border-bottom: 1px solid var(--line); font-size: 12px; line-height: 1.55; }
.art-judgement-criteria strong { color: var(--green-dark); font-size: 13px; }
.art-judgement-criteria p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.art-judgement[data-verdict="pass"] .art-judgement-heading h3 { color: #168e70; }
.art-judgement[data-verdict="fail"] .art-judgement-heading h3 { color: var(--red); }
.art-judgement[data-verdict="review"] .art-judgement-heading h3 { color: #896432; }
.art-judgement-checks { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-top: 12px; }
.art-check { padding: 7px 8px; border-radius: 3px; color: #53645b; background: #edf1ef; font-size: 13px; }
.art-check.pass { color: #256a56; background: #e6f3ed; }
.art-check.fail { color: #963f32; background: #f8e9e5; }
.art-check.uncertain { color: #896432; background: #f5edda; }
.preview-frame { height: clamp(480px, calc(100vh - 250px), 900px); min-height: 0; min-width: 0; flex: 0 0 auto; display: flex; flex-direction: column; overflow: hidden; border: 1px solid var(--line); border-radius: 4px; background: #fff; }
.preview-toolbar { height: 46px; flex: 0 0 46px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 14px; border-bottom: 1px solid var(--line); background: #fbfcfa; }
.preview-tab { align-self: stretch; display: inline-flex; align-items: center; padding: 0 10px; border-bottom: 2px solid var(--green); color: var(--green-dark); font-size: 14px; font-weight: 700; white-space: nowrap; }
.preview-actions { display: flex; align-items: center; gap: 4px; }
.preview-actions button { min-width: 44px; height: 30px; padding: 0 7px; border: 0; border-radius: 3px; color: var(--muted); background: transparent; font-size: 11px; }
#expandPreview { font-size: 13px; }
.preview-actions button:hover:not(:disabled) { color: var(--green-dark); background: var(--green-pale); }
.preview-actions button:disabled { opacity: .45; cursor: default; }
.preview-viewport { position: relative; flex: 1 1 auto; min-height: 0; min-width: 0; overflow: hidden; background: #fff; }
.preview-frame .preview-viewport iframe { width: 100%; height: 100%; min-height: 0; display: block; border: 0; background: #fff; }
.preview-viewport #previewStatus { margin: 0; padding: 24px; color: var(--muted); font-size: 12px; }
.preview-footer { height: 34px; flex: 0 0 34px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 14px; border-top: 1px solid var(--line); color: var(--quiet); background: #fbfcfa; font-size: 13px; }
.activity-section:has(.full-result:not([hidden])) { flex: 1 1 auto; }
.activity-section:has(.full-result:not([hidden])) {
  padding-top: 0;
  padding-right: 0;
  padding-bottom: 0;
  padding-left: 0;
}
.activity-section:has(.full-result:not([hidden])) .full-result { flex: 1 1 auto; margin-top: 0; }
.activity-section:has(.full-result:not([hidden])) .preview-frame { height: auto; min-height: 0; }
.preview-frame:fullscreen, .activity-section:has(.full-result:not([hidden])) .preview-frame:fullscreen { width: 100vw; height: 100vh; max-height: none; border: 0; border-radius: 0; }
.effect-panel:has(.activity-section:not([hidden])) .reference-stage { display: none; }
.error-box { max-width: 1000px; margin: 12px auto; padding: 11px 14px; border: 1px solid #e9c5bc; border-radius: 4px; color: #873f33; background: #fbefec; font-size: 10px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.site-footer { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 26px; border-top: 1px solid var(--line); color: var(--quiet); background: #fff; font-size: 9px; }
.site-footer > span { color: var(--green); font-size: 8px; font-weight: 800; letter-spacing: 1px; }

@media (min-width: 1100px) {
  .workspace { grid-template-columns: 280px minmax(0, 1fr); }
}
@media (max-width: 860px) {
  main { height: auto; min-height: calc(100vh - 104px); display: block; padding: 0 16px 14px; }
  .connection-drawer { position: static; width: auto; margin: 14px auto; box-shadow: none; }
  .group-strip { flex-wrap: wrap; gap: 12px; padding: 12px 0; }
  .group-label { flex: 1 1 100%; }
  .settings-toggle { margin-left: auto; }
  .group-tabs { flex: 1; }
  .group-tab { min-width: 110px; flex: 0 0 auto; padding: 0 12px; }
  .config-grid { grid-template-columns: 1fr 1fr; }
  .config-actions { padding-top: 0; }
  .workspace { min-height: 0; grid-template-columns: 220px minmax(0, 1fr); }
  .workspace { width: calc(100% + 32px); margin-right: -16px; margin-left: -16px; }
  .history-panel, .effect-panel { min-height: 570px; }
  .reference-stage { min-height: 380px; }
  .reference-caption { align-items: flex-start; flex-direction: column; gap: 4px; }
}
@media (max-width: 1000px) {
  .full-result { display: flex; flex-direction: column; }
  .activity-section:has(.full-result:not([hidden])) .preview-frame { height: 520px; flex: 0 0 520px; }
  .result-sidebar { overflow: visible; }
  .art-judgement-checks { display: flex; flex-wrap: wrap; }
}
@media (max-width: 620px) {
  .site-header { height: 58px; gap: 12px; padding: 0 14px; }
  .brand-mark { width: 30px; height: 30px; }
  .header-state { margin-left: 0; }
  .admin-link { font-size: 10px; }
  main { min-height: calc(100vh - 98px); padding: 0 12px 18px; }
  .group-strip { gap: 10px; }
  .group-label { display: flex; align-items: center; }
  .group-tabs { width: 100%; flex: 1 1 100%; order: 2; }
  .settings-toggle { order: 1; }
  .group-tab { min-height: 36px; }
  .connection-drawer { padding: 14px; }
  .config-grid { grid-template-columns: 1fr; }
  .workspace { width: calc(100% + 24px); grid-template-columns: 1fr; gap: 10px; margin-right: -12px; margin-left: -12px; }
  .history-panel { min-height: 210px; max-height: 250px; }
  .history-list { display: flex; gap: 4px; overflow-x: auto; overflow-y: hidden; }
  .history-item { width: 180px; min-width: 180px; align-self: flex-start; margin: 0; }
  .history-empty { min-width: 100%; }
  .effect-panel { min-height: 530px; overflow: visible; }
  .reference-stage { min-height: 390px; }
  .reference-caption { padding: 9px 11px; }
  .activity-section { padding: 8px; }
  .preview-frame, .activity-section:has(.full-result:not([hidden])) .preview-frame { height: 620px; min-height: 620px; flex: 0 0 620px; }
  .activity-section:has(.full-result:not([hidden])) { flex: 0 0 auto; }
  .activity-section:has(.full-result:not([hidden])) .full-result { flex: 0 0 auto; }
  .site-footer { align-items: flex-start; flex-direction: column; padding: 12px 14px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
