:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1c2330;
  --muted: #667085;
  --line: #dde1e8;
  --accent: #2f6fdf;
  --accent-text: #ffffff;
  --chip: #eef2f8;
  --warn: #b54708;
  --err: #c0362c;
  --ok: #18794e;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418;
    --panel: #1a1f26;
    --text: #e6e9ef;
    --muted: #98a2b3;
    --line: #2c333d;
    --accent: #5b8def;
    --accent-text: #0b1220;
    --chip: #232a34;
    --warn: #f79009;
    --err: #f97066;
    --ok: #47cd89;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111418; --panel: #1a1f26; --text: #e6e9ef; --muted: #98a2b3; --line: #2c333d;
  --accent: #5b8def; --accent-text: #0b1220; --chip: #232a34; --warn: #f79009; --err: #f97066; --ok: #47cd89;
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
}
header { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 16px 16px 8px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand svg { color: var(--text); flex: none; }
h1 { font-size: 20px; margin: 0; letter-spacing: .01em; line-height: 1.2; }
.tagline { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.header-side { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.env { font-size: 12.5px; color: var(--muted); background: var(--chip); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; }
a.ghost { text-decoration: none; }
h2 { font-size: 16px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

main { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; padding: 8px 16px; }
@media (max-width: 820px) { main { grid-template-columns: minmax(0, 1fr); } }

.controls, .stage, .history { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.controls { display: flex; flex-direction: column; gap: 10px; align-self: start; }

.tasks { display: flex; flex-wrap: wrap; gap: 6px; }
.tasks button {
  border: 1px solid var(--line); background: var(--chip); color: var(--text);
  border-radius: 999px; padding: 5px 11px; font-size: 13.5px; cursor: pointer;
}
.tasks button[aria-selected="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.hint { margin: 0; font-size: 13px; color: var(--muted); }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; }
.field.row { flex-direction: row; align-items: center; gap: 10px; flex-wrap: wrap; }
.field.row input[type="range"] { flex: 1; min-width: 120px; }
select, input[type="text"], textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 8px;
}
.model-note { font-size: 12.5px; min-height: 1em; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13.5px; }

.images { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13.5px; }
button, .button { font: inherit; cursor: pointer; }
.ghost {
  border: 1px solid var(--line); background: transparent; color: var(--text);
  border-radius: 6px; padding: 5px 10px; font-size: 13.5px; display: inline-block;
}
.ghost:hover { border-color: var(--accent); }
.primary {
  border: 0; background: var(--accent); color: var(--accent-text); font-weight: 600;
  border-radius: 8px; padding: 10px; font-size: 15px;
}
.primary:disabled { opacity: .55; cursor: progress; }
.status { font-size: 13px; min-height: 1.3em; white-space: pre-wrap; }
.status.err { color: var(--err); }
.status.warn { color: var(--warn); }

.stage { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
/* インタラクトの画面は、広い画面では結果の横、狭い画面では下に出す */
.stage-row { display: flex; gap: 10px; align-items: stretch; }
.stage-row > .canvas-wrap { flex: 1 1 60%; min-width: 0; }
.interact { flex: 1 1 40%; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.interact[hidden] { display: none; }
.interact-canvas { width: 100%; aspect-ratio: 1; max-height: 70vh; border-radius: 8px; max-width: none; }
.interact-info { min-height: 1.3em; }
@media (max-width: 700px) { .stage-row { flex-direction: column; } .interact-canvas { max-height: 45vh; } }
.canvas-wrap { position: relative; width: 100%; background: var(--chip); border-radius: 8px; overflow: hidden; }
canvas { display: block; max-width: 100%; max-height: 70vh; width: auto; height: auto; margin: 0 auto; touch-action: manipulation; }
.canvas-wrap.clickable canvas { cursor: crosshair; }
/* テンプレートを枠で切り出している間は、ドラッグでページがスクロールしないように */
.canvas-wrap.selecting canvas { cursor: crosshair; touch-action: none; }
.tpl-preview { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.tpl-preview canvas { max-width: 120px; max-height: 90px; width: auto; height: auto; margin: 0; border-radius: 4px; border: 1px solid var(--line); }
.row.wrap { flex-wrap: wrap; }
.offscreen { position: absolute; left: -9999px; top: 0; width: 2px; height: 2px; opacity: 0; pointer-events: none; }
.video-controls { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.live {
  border: 1px solid var(--accent); background: transparent; color: var(--accent); font-weight: 600;
  border-radius: 8px; padding: 8px 12px; font-size: 14px;
}
.live.on { background: var(--err); border-color: var(--err); color: #fff; }
.view-toggle { font-size: 13px; }
.actions { display: flex; flex-direction: column; gap: 8px; }
.actions .primary { align-self: stretch; }
.view-toggle select { width: auto; }
.video-controls select { width: auto; padding: 4px 6px; }
#camera-select { width: auto; max-width: 100%; }

.result { font-size: 14px; display: flex; flex-direction: column; gap: 10px; }
.result:empty { display: none; }
.result-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.result-head b { font-size: 15px; }
.badge { font-size: 12px; border-radius: 999px; padding: 2px 9px; border: 1px solid var(--line); background: var(--chip); color: var(--muted); }
.badge.browser { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); color: var(--accent); }
.badge.server { border-color: color-mix(in srgb, var(--ok) 45%, var(--line)); color: var(--ok); }
.stats { display: flex; gap: 8px; flex-wrap: wrap; }
.stat { display: flex; flex-direction: column; min-width: 78px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.stat small { font-size: 11.5px; color: var(--muted); }
.stat b { font-size: 17px; font-variant-numeric: tabular-nums; }
.breakdown { display: flex; flex-direction: column; gap: 4px; }
.bd-bar { display: flex; height: 8px; border-radius: 4px; overflow: hidden; background: var(--chip); }
.bd-bar i { display: block; height: 100%; min-width: 2px; }
.bd-legend, .chips { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 12.5px; color: var(--muted); }
.bd-legend i, .chip i { display: inline-block; width: 9px; height: 9px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.chips { gap: 6px; }
.chip { color: var(--text); background: var(--chip); border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; font-size: 13px; }
.chip b { margin-left: 3px; font-variant-numeric: tabular-nums; }
.sub { font-size: 13px; color: var(--muted); }
.legend { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.legend i { flex: 1; max-width: 260px; height: 10px; border-radius: 5px; }
.answer { margin: 0; padding: 10px 12px; border-left: 3px solid var(--accent); background: var(--bg); border-radius: 0 8px 8px 0; white-space: pre-wrap; line-height: 1.7; }
.bar.top span:first-child { font-weight: 600; }
.bar { display: grid; grid-template-columns: minmax(80px, 180px) 1fr 52px; gap: 8px; align-items: center; margin: 3px 0; font-size: 13.5px; }
.bar .track { height: 8px; background: var(--chip); border-radius: 4px; overflow: hidden; }
.bar .fill { height: 100%; background: var(--accent); }
.bar .num { text-align: right; font-variant-numeric: tabular-nums; }
.dets { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 13px; color: var(--muted); }

.history { margin: 0 16px 24px; display: flex; flex-direction: column; gap: 8px; }
.history-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.server-box { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 13px; }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
th { color: var(--muted); font-weight: 500; }

.cats { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; padding: 3px; background: var(--chip); border: 1px solid var(--line); border-radius: 10px; }
.cats button { border: 0; background: transparent; color: var(--muted); border-radius: 7px; padding: 6px 4px; font-size: 13px; }
.cats button[aria-selected="true"] { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.15); }
.advanced { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }
.advanced summary { cursor: pointer; font-size: 13.5px; color: var(--muted); }
.advanced[open] summary { margin-bottom: 8px; }
.advanced .field { margin-bottom: 6px; }
.progress { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.progress progress { flex: 1; height: 8px; accent-color: var(--accent); }
.about { margin: 0 16px 24px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; font-size: 13.5px; }
.about ul { margin: 8px 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }
.row-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.chip small { color: var(--muted); margin-left: 3px; }

.result-tools { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.result-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.export-box { display: flex; gap: 6px; flex-wrap: wrap; }
.history-head h2 small { font-weight: 400; font-size: 13px; }
td small { color: var(--muted); margin-left: 2px; }
.bench { margin: 0 16px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.bench p { margin: 0; }
.bench-models { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.bench-models fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px 8px; margin: 0; display: flex; flex-direction: column; gap: 3px; }
.bench-models legend { font-size: 12.5px; color: var(--muted); padding: 0 4px; }
.bench-models .check { font-size: 13px; }
.local ul { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 3px; }
#local-result { list-style: none; padding-left: 0; }
.local code { font-size: 12px; overflow-wrap: anywhere; }
.bench .primary { padding: 8px 18px; }
#bench-profile { display: flex; flex-direction: column; gap: 12px; }
#bench-profile:empty { display: none; }
.prof { display: flex; flex-direction: column; gap: 4px; overflow-x: auto; }
.prof table { border-collapse: collapse; width: max-content; }
.prof th, .prof td { padding: 2px 10px 2px 0; text-align: left; border-bottom: 1px solid var(--line); }
.prof .num { text-align: right; }

#judge { width: 100%; font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; }
.num-s { width: 4.2em; padding: 1px 4px; }
