:root {
  color-scheme: dark;
  --bg: #0b0d10;
  --surface: #11151a;
  --surface-hover: #171d24;
  --border: #252b34;
  --text: #dce2e8;
  --muted: #7b8592;
  --dim: #4c5663;
  --accent: #b7f05b;
  --mono: Consolas, "Cascadia Code", "SFMono-Regular", "SimSun", monospace;
  --body: "SimSun", "Songti SC", serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-width: 320px; min-height: 100%; background: var(--bg); }
body { color: var(--text); font: 14px/1.5 var(--body); }
button, input, select, textarea { font-family: var(--mono); font-size: 12px; color: inherit; }
button, input, select, textarea { border: 1px solid var(--border); border-radius: 4px; }
button, select { min-height: 32px; }
button { background: transparent; padding: 6px 12px; cursor: pointer; line-height: 1.3; letter-spacing: .035em; }
button:hover:not(:disabled) { border-color: #4b5664; background: var(--surface-hover); }
button:active:not(:disabled) { background: #202731; }
button:disabled { color: var(--dim); cursor: not-allowed; opacity: .65; }
input, select, textarea { background: var(--bg); padding: 8px 10px; outline: none; }
input, select { min-height: 36px; }
select { padding-right: 28px; max-width: 100%; cursor: pointer; }
textarea { width: 100%; font-size: 14px; line-height: 1.7; tab-size: 2; resize: none; }
input::placeholder, textarea::placeholder { color: var(--dim); opacity: 1; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible,
a:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
textarea:focus-visible { outline-offset: -2px; }
input[type="checkbox"] { width: 14px; height: 14px; min-height: 0; margin: 0; accent-color: var(--accent); cursor: pointer; }
input[type="number"] { font-variant-numeric: tabular-nums; }
::selection { color: var(--bg); background: var(--accent); }
* { scrollbar-width: thin; scrollbar-color: #333d49 transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #333d49; border: 2px solid var(--surface); border-radius: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-corner { background: transparent; }
h1, h2, h3, p { margin: 0; }
pre { margin: 0; font-family: var(--mono); }

.shell { min-height: 100dvh; }
.appbar {
  height: 58px; padding: 0 24px; display: flex; align-items: center;
  gap: 36px; border-bottom: 1px solid var(--border); background: var(--bg);
}
.brand { flex: none; color: var(--text); font: 700 19px/1 var(--mono); letter-spacing: -.055em; }
.brand-dot { color: var(--accent); }
.tabs { display: flex; align-self: stretch; gap: 28px; }
.nav-tab {
  min-height: 0; height: 100%; padding: 0 1px; border: 0; border-bottom: 2px solid transparent;
  border-radius: 0; color: var(--muted); font-size: 11px; letter-spacing: .065em;
  display: flex; align-items: center; gap: 7px;
}
.nav-tab:hover:not(:disabled) { color: var(--text); background: transparent; border-bottom-color: var(--dim); }
.nav-tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.service-status {
  margin-left: auto; flex: none; display: inline-flex; align-items: center; gap: 9px;
  color: var(--muted); font: 11px/1.3 var(--mono); padding: 7px 0;
}
.status-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--dim); flex: none; }
.service-status.ready { color: var(--text); }
.service-status.ready .status-dot { background: var(--accent); }
.count {
  display: inline-flex; align-items: center; justify-content: center; min-width: 20px;
  height: 19px; padding: 0 5px; border: 1px solid var(--border); border-radius: 3px;
  color: var(--muted); font: 10px/1 var(--mono); font-variant-numeric: tabular-nums;
}

main { min-width: 0; }
.view { display: flex; flex-direction: column; height: calc(100dvh - 58px); min-height: 560px; }
.toolbar {
  height: 52px; min-height: 52px; padding: 0 24px; display: flex; align-items: center;
  justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--border);
}
.toolbar select { height: 30px; min-height: 30px; padding-top: 4px; padding-bottom: 4px; border-color: transparent; background-color: transparent; }
.toolbar select:hover { border-color: var(--border); }
.toolbar-actions { display: flex; align-items: center; gap: 8px; min-width: 0; }
.toolbar button { min-height: 28px; padding: 5px 10px; font-size: 10px; }
.primary { background: var(--accent); color: #172107; border-color: var(--accent); font-weight: 700; }
.primary:hover:not(:disabled) { background: #c8f784; border-color: #c8f784; }
.primary:active:not(:disabled) { background: #a5dd49; border-color: #a5dd49; }
.primary:disabled { background: #252e1d; border-color: #334026; color: #758368; opacity: 1; }
.text-button { border: 0; padding: 3px 0; min-height: 24px; color: var(--muted); font-size: 10px; }
.text-button:hover:not(:disabled) { color: var(--text); background: transparent; }

.playground-grid {
  display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(250px, .85fr) minmax(290px, .95fr);
  gap: 16px; flex: 1; min-height: 0; padding: 20px 24px 24px;
}
.panel { min-width: 0; border: 1px solid var(--border); border-radius: 5px; background: var(--surface); overflow: hidden; }
.panel-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  min-height: 44px; height: 44px; padding: 0 16px; border-bottom: 1px solid var(--border);
  flex: none;
}
.panel-head h1, .panel-head h2 { color: var(--muted); font: 11px/1 var(--mono); letter-spacing: .09em; }
.input-stack { display: grid; grid-template-rows: minmax(200px, 1fr) 166px; gap: 16px; min-width: 0; min-height: 0; }
.state-panel, .query-panel, .options-panel, .output-panel { display: flex; flex-direction: column; min-height: 0; }
.code-editor { display: flex; flex: 1; min-height: 0; overflow: hidden; background: var(--surface); }
.line-numbers {
  flex: none; width: 43px; padding: 16px 9px 16px 0; text-align: right;
  color: #47515d; font: 14px/1.7 var(--mono); white-space: pre;
  overflow: hidden; user-select: none;
}
#state-input {
  flex: 1; min-width: 0; min-height: 0; padding: 16px 15px 16px 0;
  border: 0; border-radius: 0; background: transparent; white-space: pre; overflow: auto;
}
#question-input { flex: 1; min-height: 0; border: 0; border-radius: 0; padding: 14px 16px; background: transparent; }
.options-list { display: flex; flex-direction: column; gap: 12px; padding: 14px; overflow-y: auto; min-height: 0; flex: 1; }
.option-row, .option-card { border: 1px solid var(--border); border-radius: 4px; padding: 10px; background: var(--bg); flex: none; }
.option-top, .option-header { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.option-id { font-weight: 600; color: var(--accent); font-size: 12px; min-width: 0; width: 100%; }
.option-row input, .option-card input { height: 30px; min-height: 30px; padding: 4px 7px; background: transparent; border-color: transparent; }
.option-row input:hover, .option-card input:hover { border-color: var(--border); }
.option-row textarea, .option-card textarea, .option-description {
  min-height: 68px; padding: 7px; font-size: 13px; line-height: 1.55;
  background: transparent; border-color: transparent; resize: vertical;
}
.option-row textarea:hover, .option-card textarea:hover { border-color: var(--border); }
.remove-option, .option-remove { width: 26px; min-height: 26px; flex: none; border-color: transparent; padding: 0; font-size: 17px; color: var(--dim); }
.remove-option:hover:not(:disabled), .option-remove:hover:not(:disabled) { color: var(--text); }
.add-option { margin: 0 14px 14px; min-height: 34px; color: var(--muted); font-size: 11px; background: transparent; border-style: dashed; }
.add-option:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.empty-output { display: flex; flex: 1; align-items: center; justify-content: center; min-height: 180px; }
.code-symbol { color: #303943; font: 28px/1 var(--mono); letter-spacing: .14em; }
#output-result { flex: 1; min-height: 0; overflow: auto; padding: 22px 18px 16px; }
.result-main { display: flex; align-items: baseline; gap: 10px; justify-content: space-between; margin-bottom: 26px; }
.result-choice { color: var(--accent); font: 600 26px/1.25 var(--mono); overflow-wrap: anywhere; }
.tag { display: inline-flex; align-items: center; flex: none; padding: 3px 6px; border: 1px solid var(--border); border-radius: 3px; color: var(--muted); font: 9px/1.1 var(--mono); letter-spacing: .035em; }
.tag.live, .tag.success, .tag.running { color: var(--accent); border-color: #42532d; }
.probability-list { display: flex; flex-direction: column; gap: 13px; }
.probability-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; font: 11px/1.4 var(--mono); }
.probability-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.probability-value { color: var(--text); font-variant-numeric: tabular-nums; }
.probability-track { height: 3px; grid-column: 1 / -1; border-radius: 1px; background: #252d37; overflow: hidden; }
.probability-bar { height: 100%; min-width: 0; background: #52606e; }
.probability-row.selected .probability-bar, .probability-row.winner .probability-bar { background: var(--accent); }
.probability-row.selected .probability-name, .probability-row.winner .probability-name { color: var(--text); }
.result-meta { display: flex; justify-content: space-between; gap: 12px; padding: 22px 0 14px; color: var(--muted); font: 10px/1.5 var(--mono); }
.result-meta span { overflow-wrap: anywhere; }
.code-output { border-top: 1px solid var(--border); padding-top: 16px; font-size: 11px; line-height: 1.65; color: #a4afb9; white-space: pre-wrap; overflow-wrap: anywhere; }
.run-controls { padding: 14px; border-top: 1px solid var(--border); margin-top: auto; flex: none; }
.run-button { display: flex; width: 100%; min-height: 39px; align-items: center; justify-content: center; gap: 12px; font-size: 12px; letter-spacing: .08em; }
.run-button span { font-size: 17px; line-height: 1; opacity: .65; }
.error-box { margin: 14px; padding: 11px 12px; border: 1px solid #65615a; border-radius: 4px; color: #d5cfc5; font: 12px/1.6 var(--mono); overflow-wrap: anywhere; }

.runner-grid { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 16px; padding: 20px 24px 24px; flex: 1; min-height: 0; }
.runner-config { overflow-y: auto; }
.column-list { display: flex; flex-direction: column; gap: 0; padding: 10px 16px 12px; }
.column-item { display: flex; align-items: center; gap: 10px; padding: 7px 0; min-width: 0; color: #bdc6d0; font: 12px/1.5 var(--mono); cursor: pointer; }
.column-item span { overflow-wrap: anywhere; }
.column-item:has(input:disabled) { color: var(--dim); cursor: default; }
.column-item input { flex: none; }
.config-row { display: flex; flex-direction: column; gap: 7px; padding: 0 16px 16px; }
.config-row label { color: var(--muted); font-size: 12px; }
.config-row input, .config-row select { width: 100%; }
.route-head { margin-top: 8px; border-top: 1px solid var(--border); }
.routes-list { padding: 10px 16px 16px; }
.route-row { padding: 9px 0; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; }
.route-row:last-child { border-bottom: 0; }
button.route-row {
  flex-direction: row; align-items: center; justify-content: space-between;
  gap: 12px; width: 100%; min-height: 38px; border: 0;
  border-bottom: 1px solid var(--border); border-radius: 0; text-align: left;
}
button.route-row:hover:not(:disabled) { background: transparent; border-bottom-color: var(--border); }
button.route-row:hover .route-id { color: var(--accent); }
button.route-row .count { flex: none; }
.route-id { color: var(--text); font: 11px/1.5 var(--mono); overflow-wrap: anywhere; }
.route-label, .route-description { color: var(--muted); font: 12px/1.5 var(--mono); overflow-wrap: anywhere; }
.data-panel { display: flex; flex-direction: column; min-height: 0; }
.records-controls { display: flex; align-items: center; gap: 10px; }
.records-controls select { min-height: 25px; height: 25px; padding: 2px 24px 2px 8px; font-size: 10px; border-color: transparent; background: transparent; max-width: 180px; }
.progress-track { height: 2px; background: transparent; flex: none; }
#progress-fill { width: 0; height: 100%; background: var(--accent); transition: width .12s linear; }
.data-empty { display: flex; flex: 1; min-height: 260px; align-items: center; justify-content: center; }
.drop-import { width: min(280px, 80%); min-height: 126px; border-style: dashed; color: var(--muted); font-size: 13px; line-height: 2.4; }
.drop-import span { font-family: var(--body); font-size: 12px; }
.drop-import:hover:not(:disabled) { border-color: var(--accent); color: var(--text); }
.data-empty.drag-over { background: #151c11; }
.data-empty.drag-over .drop-import { border-color: var(--accent); color: var(--accent); }
.dataset-name { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font: 10px/1.5 var(--mono); }
.table-wrap { overflow: auto; min-height: 0; flex: 1; }
table { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: auto; font: 11px/1.5 var(--mono); }
th { position: sticky; top: 0; z-index: 1; background: #151a21; color: var(--muted); font-weight: 400; text-align: left; white-space: nowrap; }
td, th { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
td { max-width: 320px; min-width: 76px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #bbc5cf; }
tbody tr:hover td { background: var(--surface-hover); }
td:first-child, th:first-child { padding-left: 16px; }
td.status-success, td.success, .status-success, .cell-success { color: var(--accent); }
td.status-error, td.error, .status-error, .cell-error { color: #d5cfc5; }
.cell-pending { color: var(--dim); }
.row-number { color: var(--dim); width: 58px; min-width: 58px; font-variant-numeric: tabular-nums; }
.data-value { max-width: 320px; min-width: 100px; }
.time-value { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 90px; }
.route-chip { min-height: 24px; padding: 3px 6px; font-size: 10px; letter-spacing: 0; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.route-chip.success { color: var(--accent); border-color: #38482a; }
.route-chip.running { color: var(--text); border-color: #52606e; }
.route-chip.error { color: #d5cfc5; border-color: #65615a; }
.route-chip:disabled { border-color: transparent; color: var(--dim); opacity: 1; }
.row-running td { background: #171d22; }
.row-running .row-number { color: var(--text); }
.data-pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; min-height: 42px; padding: 6px 14px; border-top: 1px solid var(--border); color: var(--muted); font: 10px/1.5 var(--mono); flex: none; }
.data-pager button { width: 26px; min-height: 25px; padding: 2px; font-size: 13px; }
.batch-summary { display: flex; flex-wrap: wrap; gap: 18px 30px; padding: 15px 18px; border-top: 1px solid var(--border); flex: none; color: var(--muted); font: 10px/1.6 var(--mono); }
.summary-item { display: flex; flex-direction: column; gap: 4px; font-family: var(--mono); }
.summary-label { color: var(--muted); font-size: 9px; letter-spacing: .04em; }
.summary-value { color: var(--text); font-size: 16px; font-variant-numeric: tabular-nums; }
.summary-value.success { color: var(--accent); }

.trace-grid { display: grid; grid-template-columns: 300px minmax(0, 1fr); flex: 1; min-height: 0; margin: 20px 24px 24px; }
.trace-index { min-height: 0; overflow: hidden; display: flex; flex-direction: column; border-right: 1px solid var(--border); }
#trace-list { flex: 1; min-height: 0; overflow-y: auto; }
.trace-item { display: block; width: 100%; padding: 14px 16px; text-align: left; border: 0; border-bottom: 1px solid var(--border); border-radius: 0; font: 11px/1.5 var(--mono); }
.trace-item:hover:not(:disabled) { border-bottom-color: var(--border); }
.trace-item.active { background: #1a2115; box-shadow: inset 2px 0 var(--accent); }
.trace-item-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; min-width: 0; }
.trace-item-top > :first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.trace-item-meta { display: flex; justify-content: space-between; gap: 12px; margin-top: 6px; color: var(--muted); font-size: 10px; }
.trace-item.error .trace-item-top { color: #d5cfc5; }
.trace-item.success .trace-item-top > :last-child { color: var(--accent); }
.trace-item.running .trace-item-top > :last-child { color: var(--muted); }
.trace-detail { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.trace-json { padding: 20px; overflow: auto; flex: 1; min-height: 0; color: #b8c4ce; font: 12px/1.7 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; }

.toast { position: fixed; z-index: 20; right: 24px; bottom: 24px; max-width: min(440px, calc(100vw - 32px)); padding: 12px 16px; background: #1b222b; border: 1px solid #3b4654; border-radius: 4px; color: var(--text); font: 12px/1.6 var(--mono); overflow-wrap: anywhere; box-shadow: 0 8px 24px #0005; }

@media (min-width: 1600px) {
  .playground-grid { grid-template-columns: minmax(0, 1.15fr) minmax(280px, .75fr) minmax(340px, .95fr); }
  .input-stack { grid-template-rows: minmax(240px, 1fr) 190px; }
  .options-list { gap: 14px; padding: 18px; }
  .add-option { margin: 0 18px 18px; }
}

@media (max-width: 1100px) {
  .appbar { gap: 28px; padding: 0 18px; }
  .tabs { gap: 22px; }
  .toolbar { padding-left: 18px; padding-right: 18px; }
  .playground-grid { gap: 12px; padding: 16px 18px 18px; grid-template-columns: minmax(0, 1fr) minmax(220px, .85fr) minmax(240px, .95fr); }
  .panel-head { padding-left: 13px; padding-right: 13px; }
  .runner-grid { padding: 16px 18px 18px; grid-template-columns: 230px minmax(0, 1fr); gap: 12px; }
  .trace-grid { margin: 16px 18px 18px; grid-template-columns: 260px minmax(0, 1fr); }
}

@media (max-width: 999px) {
  .view { height: auto; min-height: calc(100dvh - 58px); }
  .playground-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: stretch; flex: none; }
  .input-stack { grid-column: 1 / -1; grid-template-columns: minmax(0, 1.25fr) minmax(0, .75fr); grid-template-rows: 320px; gap: 12px; }
  .options-panel, .output-panel { min-height: 400px; max-height: 620px; }
  .options-list { max-height: 485px; }
  .runner-grid { min-height: 600px; grid-template-columns: 220px minmax(0, 1fr); }
  .data-panel { min-height: 560px; }
  .table-wrap { max-height: calc(100dvh - 260px); min-height: 320px; }
  .trace-grid { height: calc(100dvh - 150px); min-height: 470px; flex: none; }
  .dataset-name { max-width: 170px; }
}

@media (max-width: 640px) {
  .appbar { height: 58px; padding: 0 12px; gap: 18px; }
  .brand { font-size: 16px; }
  .tabs { gap: 16px; }
  .nav-tab { font-size: 9px; letter-spacing: 0; gap: 4px; }
  .nav-tab .count { height: 16px; min-width: 16px; padding: 0 3px; font-size: 8px; }
  .service-status { padding: 5px 7px; font-size: 9px; gap: 6px; min-height: 28px; }
  .status-dot { width: 5px; height: 5px; }
  .toolbar { padding: 0 12px; gap: 8px; }
  .toolbar-actions { gap: 6px; }
  .toolbar button { padding: 5px 7px; font-size: 9px; }
  .toolbar select { max-width: 160px; font-size: 12px; padding-left: 0; }
  .playground-grid { display: flex; flex-direction: column; gap: 12px; padding: 12px; }
  .input-stack { display: flex; flex-direction: column; gap: 12px; }
  .state-panel { height: 320px; flex: none; }
  .query-panel { height: 150px; flex: none; }
  .options-panel { min-height: 250px; max-height: none; }
  .options-list { max-height: 460px; }
  .output-panel { min-height: 330px; max-height: 650px; }
  #output-result { min-height: 220px; }
  .runner-grid { grid-template-columns: minmax(0, 1fr); padding: 12px; gap: 12px; min-height: 0; }
  .runner-config { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .runner-config > .panel-head, .column-list, .routes-list { grid-column: 1 / -1; }
  .column-list { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 12px; }
  .config-row { padding-left: 14px; padding-right: 14px; }
  .routes-list { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 14px; }
  .route-row { min-width: 0; }
  .route-row:nth-last-child(-n+2) { border-bottom: 0; }
  .data-panel { min-height: 420px; }
  .table-wrap { min-height: 280px; max-height: 520px; }
  .dataset-name { display: none; }
  .records-controls { gap: 5px; }
  .records-controls select { max-width: 130px; }
  .batch-summary { gap: 14px 22px; padding: 14px; }
  .summary-value { font-size: 14px; }
  .trace-grid { display: flex; flex-direction: column; margin: 12px; min-height: 600px; height: calc(100dvh - 135px); }
  .trace-index { height: 220px; flex: none; border-right: 0; border-bottom: 1px solid var(--border); }
  .trace-detail { flex: 1; min-height: 300px; }
  .trace-item { padding: 10px 14px; }
  .trace-json { padding: 14px; font-size: 11px; }
  .toast { right: 16px; bottom: 16px; }
}

@media (max-width: 400px) {
  .appbar { gap: 12px; }
  .tabs { gap: 10px; }
  .brand { font-size: 14px; }
  .service-status { padding: 5px; border-color: transparent; }
  .service-status .status-dot { display: none; }
  .nav-tab .count { display: none; }
  .toolbar button { padding: 5px 6px; }
  .toolbar-actions { gap: 4px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
