:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --text: #1d2330;
  --muted: #5d6676;
  --line: #dde1e8;
  --accent: #2856c7;
  --accent-text: #ffffff;
  --accent-soft: #e8eefc;
  --ok: #1d7a46;
  --warn: #9a5b00;
  --warn-soft: #fff4e0;
  --err: #b42318;
  --err-soft: #fdecea;
  --code: #f0f2f5;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171c; --card: #1c2027; --text: #e6e9ef; --muted: #9aa3b2; --line: #2e343e;
    --accent: #7aa2ff; --accent-text: #0d1424; --accent-soft: #22304f; --ok: #5cc98a; --warn: #f0b45a; --warn-soft: #3a2c12;
    --err: #ff8a80; --err-soft: #3b1d1b; --code: #242a33; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #14171c; --card: #1c2027; --text: #e6e9ef; --muted: #9aa3b2; --line: #2e343e;
  --accent: #7aa2ff; --accent-text: #0d1424; --accent-soft: #22304f; --ok: #5cc98a; --warn: #f0b45a; --warn-soft: #3a2c12;
  --err: #ff8a80; --err-soft: #3b1d1b; --code: #242a33; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0 auto; max-width: 1180px; padding: 16px;
  background: var(--bg); color: var(--text);
  font: 15px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}
a { color: var(--accent); }
h2 { font-size: 1.2rem; margin: 0 0 .4rem; }
h3 { font-size: 1.05rem; margin: 0 0 .6rem; }
h4 { font-size: .98rem; margin: 1.2rem 0 .4rem; }
p { margin: .4rem 0; }
.muted { color: var(--muted); }
small { font-size: .85em; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .86em; }
code { background: var(--code); padding: 1px 5px; border-radius: 4px; }
pre { background: var(--code); padding: 12px; border-radius: 8px; overflow: auto; white-space: pre-wrap; word-break: break-word; max-height: 520px; }
pre code { background: none; padding: 0; }

.top { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.brand strong { font-size: 1.15rem; margin-right: 8px; }
.usage { font-size: .85rem; color: var(--muted); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 14px; }
.note { font-size: .85rem; color: var(--muted); margin-top: 10px; }
.tag { font-size: .72rem; font-weight: 600; background: var(--accent-soft); color: var(--accent); padding: 2px 8px; border-radius: 99px; vertical-align: middle; }
.tag.warn { background: var(--warn-soft); color: var(--warn); }

label { display: block; font-size: .9rem; font-weight: 600; }
label > input:not([type=checkbox]):not([type=radio]), label > select, label > textarea { display: block; margin-top: 4px; }
label.inline { margin-top: .8rem; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.req, .opt { font-weight: 400; font-size: .78rem; color: var(--muted); }
.req { color: var(--err); }
.settings-grid { display: grid; grid-template-columns: 180px 220px 1fr; gap: 12px; align-items: end; }
.settings-grid .remember { grid-column: 1 / -1; display: flex; gap: 6px; align-items: center; font-weight: 400; }
.remember input, .checks input, .dir input { width: auto; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-top: 12px; }
.form-grid .wide { grid-column: 1 / -1; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

button, .button {
  font: inherit; font-weight: 600; cursor: pointer; border-radius: 8px; padding: 8px 16px;
  border: 1px solid var(--line); background: var(--card); color: var(--text); text-decoration: none; display: inline-block;
}
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button:disabled { opacity: .55; cursor: wait; }
.ghost { background: transparent; }
.small { padding: 4px 10px; font-size: .85rem; }
.next { margin-top: 14px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; overflow-x: auto; }
.tabs button { border: none; border-bottom: 3px solid transparent; border-radius: 0; background: none; padding: 10px 14px; color: var(--muted); white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }

.steps { margin: 0; padding-left: 1.3rem; }
.steps li { margin: 2px 0; }
.steps li.running::after { content: " …進行中"; color: var(--accent); }
.steps li.done::marker { color: var(--ok); }
.steps li.done::after { content: " ✓"; color: var(--ok); }
.steps li.error { color: var(--err); }
.steps li.wait { color: var(--muted); }
.material { margin-top: 10px; }
details { margin-top: 10px; }
summary { cursor: pointer; color: var(--muted); font-size: .88rem; }
details.prompt pre { font-size: .8rem; }

.error { background: var(--err-soft); color: var(--err); border-radius: 8px; padding: 10px 12px; margin: 8px 0; white-space: pre-wrap; word-break: break-word; }
.loading { color: var(--muted); }
.loading::before { content: ""; display: inline-block; width: .8em; height: .8em; margin-right: 8px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }

.report-head { border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 12px; }
.summary { background: var(--accent-soft); border-radius: 8px; padding: 10px 14px; margin: 8px 0; }
.agent { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.agent .state { font-weight: 400; font-size: .82rem; color: var(--muted); }
.md h3 { font-size: 1rem; margin-top: 1rem; }
.md table, .step-card table { border-collapse: collapse; width: 100%; font-size: .9rem; }
.table-wrap { overflow-x: auto; margin: .5rem 0; }
th, td { border: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: top; }
th { background: var(--code); }
a.cite { font-size: .75em; vertical-align: super; text-decoration: none; background: var(--accent-soft); padding: 0 4px; border-radius: 4px; margin-left: 1px; }
.est { font-size: .72em; vertical-align: super; color: var(--warn); background: var(--warn-soft); padding: 0 4px; border-radius: 4px; }
a.src { font-size: .78rem; margin-left: 6px; background: var(--accent-soft); padding: 1px 6px; border-radius: 99px; text-decoration: none; word-break: break-all; }
.sources { padding-left: 1.2rem; font-size: .9rem; }
.sources li { margin: 3px 0; word-break: break-word; }
blockquote { margin: .6rem 0; padding: .2rem 12px; border-left: 3px solid var(--line); color: var(--muted); }
.frontmatter { border-left: 3px solid var(--accent); }

.checks, .dirs { display: grid; gap: 8px; }
.checks label, .dir { display: flex; flex-direction: row; align-items: flex-start; gap: 8px; font-weight: 400; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
.dir:has(input:checked), .checks label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.proposal-head h2 { font-size: 1.3rem; margin-top: .4rem; }
.lead { font-weight: 600; }

.skill-list { display: grid; gap: 10px; margin-top: 10px; }
.skill { display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.skill p { font-size: .88rem; margin: .3rem 0 0; }
.skill .button { white-space: nowrap; flex: none; }
.viewer { display: grid; grid-template-columns: 260px 1fr; gap: 16px; padding: 0; overflow: hidden; }
.file-tree { border-right: 1px solid var(--line); padding: 14px; font-size: .88rem; max-height: 80vh; overflow: auto; }
.file-tree ul { list-style: none; margin: 4px 0 12px; padding-left: 8px; }
.file-tree button { border: none; background: none; padding: 3px 6px; font-weight: 400; text-align: left; width: 100%; border-radius: 6px; font-size: .86rem; word-break: break-all; }
.file-tree button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.file-view { padding: 14px 18px 18px 0; min-width: 0; }
.file-bar { display: flex; gap: 8px; align-items: center; border-bottom: 1px solid var(--line); padding-bottom: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.file-bar .spacer { flex: 1; }
pre.raw { max-height: none; }
.foot { font-size: .8rem; margin: 20px 0 8px; }

@media (max-width: 760px) {
  body { padding: 12px 16px; }
  .settings-grid { grid-template-columns: 1fr; }
  .viewer { grid-template-columns: 1fr; }
  .file-tree { border-right: none; border-bottom: 1px solid var(--line); max-height: 240px; }
  .file-view { padding: 0 14px 14px; }
  .skill { flex-direction: column; }
}
