:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1f2a44;
  --muted: #5d6779;
  --line: #dfe3ea;
  --brand: #1f2a44;
  --on-brand: #ffffff;
  --mine: #e8edf6;
  --warn-bg: #fff6e0;
  --warn-text: #6b4a00;
  --error-bg: #fdecea;
  --error-text: #8a1c12;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161f;
    --surface: #1b212d;
    --text: #e8ebf1;
    --muted: #a3acbc;
    --line: #333c4d;
    --brand: #c4d0ea;
    --on-brand: #12161f;
    --mine: #2a3347;
    --warn-bg: #3a2f12;
    --warn-text: #f2d48a;
    --error-bg: #3f1b18;
    --error-text: #f6b5ae;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
}

.top { padding: 16px; max-width: 1080px; margin: 0 auto; }
.top h1 { font-size: 20px; margin: 0 0 8px; }

.notice {
  margin: 0;
  padding: 8px 12px;
  background: var(--warn-bg);
  color: var(--warn-text);
  border-radius: 6px;
  font-size: 14px;
}

main { padding: 0 16px 32px; max-width: 1080px; margin: 0 auto; }

.steps {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  padding: 0;
  list-style: none;
  counter-reset: step;
  color: var(--muted);
  font-size: 14px;
}

.steps li { display: flex; align-items: center; gap: 6px; counter-increment: step; }

.steps li::before {
  content: counter(step);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 50%;
  font-size: 12px;
}

.steps li:not(:last-child)::after {
  content: "";
  width: 24px;
  height: 1px;
  margin-left: 2px;
  background: var(--line);
}

.steps [aria-current] { color: var(--text); font-weight: 600; }

.steps [aria-current]::before {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--on-brand);
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.narrow {
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

h2 { font-size: 17px; margin: 8px 0 0; }

label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
small { color: var(--muted); font-weight: 400; overflow-wrap: anywhere; }

input, select, textarea {
  font: inherit;
  color: inherit;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  width: 100%;
  font-weight: 400;
}

textarea { resize: vertical; }

fieldset { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 4px 16px; }
legend { font-weight: 500; padding: 0; margin-bottom: 4px; }

.choice { flex-direction: row; align-items: center; gap: 6px; font-weight: 400; }
.choice input { width: auto; }

.field-list { display: flex; flex-direction: column; gap: 12px; }
#review-empty .field-list { margin-top: 12px; }
#review-messages { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
#review-messages p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
summary { cursor: pointer; font-weight: 500; }

button {
  font: inherit;
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: transparent;
  color: inherit;
  cursor: pointer;
  min-height: 40px;
}

button:disabled { opacity: 0.6; cursor: wait; }
.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  align-items: start;
}

.thread-card { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.thread {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 55vh;
  min-height: 160px;
  overflow-y: auto;
}

.hint { color: var(--muted); margin: 0; }

.bubble {
  padding: 10px 12px;
  border-radius: 8px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-width: 90%;
}

.bubble.user { background: var(--mine); align-self: flex-end; }
.bubble.assistant { border: 1px solid var(--line); align-self: flex-start; }

.bubble.thinking { color: var(--muted); }

.bubble.thinking::after {
  content: "…";
  margin-left: 2px;
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  50% { opacity: 0.2; }
}

@media (prefers-reduced-motion: reduce) {
  .bubble.thinking::after { animation: none; }
}

.composer { display: flex; flex-direction: column; gap: 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

.summary { margin: 12px 0 0; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 12px; }
.summary dt { color: var(--muted); font-size: 14px; }
.summary dd { margin: 0; overflow-wrap: anywhere; }
.summary dd.empty { color: var(--muted); }

.error {
  position: sticky;
  top: 8px;
  z-index: 1;
  margin: 0 0 12px;
  padding: 8px 12px;
  background: var(--error-bg);
  color: var(--error-text);
  border-radius: 6px;
}

@media (max-width: 760px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .side { order: -1; }
  .side > label { flex-direction: row; align-items: center; gap: 12px; white-space: nowrap; }
  .thread { max-height: 45vh; }
}
