:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2230;
  --muted: #667085;
  --border: #d9dee7;
  --accent: #2f6fed;
  --accent-text: #ffffff;
  --error: #c62828;
  --stage: #eef1f5;
  --line: #1c2230;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1218;
    --panel: #171b24;
    --text: #e6e9ef;
    --muted: #98a2b3;
    --border: #2a303c;
    --accent: #5b8def;
    --accent-text: #0f1218;
    --error: #ff6b6b;
    --stage: #12151c;
    --line: #e6e9ef;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
header h1 { margin: 0; font-size: 18px; }
.sub { color: var(--muted); }

main { flex: 1; display: flex; min-height: 0; }

.panel {
  width: 420px;
  flex-shrink: 0;
  padding: 16px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.panel h2 { margin: 0; font-size: 15px; }
#editor, #viewHeader { display: flex; flex-direction: column; gap: 12px; }
a { color: var(--accent); }
.panel h2 small { color: var(--muted); font-weight: normal; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; color: var(--muted); font-weight: 500; padding: 4px 2px; }
td { padding: 2px; }
td input { width: 100%; min-width: 0; }
td input[type="checkbox"] { width: auto; }

input, button {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 7px;
}
input[type="number"] { width: 70px; }
#apiKey { flex: 1; min-width: 0; }
#maxVolume { width: 110px; }
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); padding: 9px; font-weight: 600; }
button.primary:disabled { opacity: 0.6; cursor: wait; }
.del { padding: 2px 8px; }

.row { display: flex; gap: 8px; align-items: center; }
.error { color: var(--error); margin: 0; }

dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; font-variant-numeric: tabular-nums; }

.stage { flex: 1; position: relative; min-width: 0; background: var(--stage); }
#viewer { position: absolute; inset: 0; }
#viewer canvas { display: block; width: 100%; height: 100%; }

#tip {
  position: absolute;
  pointer-events: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12px;
  white-space: pre;
}

.steps {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 16px;
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
}
.steps label { flex: 1; display: flex; gap: 8px; align-items: center; }
.steps input { flex: 1; }

@media (max-width: 800px) {
  main { flex-direction: column; }
  .panel { width: auto; border-right: none; border-bottom: 1px solid var(--border); max-height: 50vh; }
  .stage { min-height: 50vh; }
}
