:root {
  --bg: #f4f3f0; --card: #fff; --line: #dcd9d2; --ink: #23221f; --mute: #8a867d;
  --accent: #2f5d50; --accent-ink: #fff; --err: #b3261e;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #171716; --card: #222120; --line: #3a3835; --ink: #ecebe7; --mute: #9b978e; --accent: #7fb8a4; --accent-ink: #10201b; --err: #f2867f; color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "PingFang TC", "Noto Sans TC", sans-serif; }
[hidden] { display: none !important; }
button, select, textarea, input, .btn { font: inherit; color: inherit; }
button, .btn { cursor: pointer; border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 8px 12px; text-align: center; text-decoration: none; }
button:disabled { opacity: .5; cursor: not-allowed; }
.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.ghost { background: transparent; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.err { color: var(--err); margin: 0; }

.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(340px, 100%); padding: 24px; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }

.app { max-width: 1180px; margin: 0 auto; padding: 16px; }
.top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-size: 17px; }
.tabs { display: flex; gap: 4px; }
.tabs button { border-radius: 8px 8px 0 0; border-bottom: none; background: transparent; color: var(--mute); padding: 8px 16px; }
.tabs button.on { background: var(--card); color: var(--ink); font-weight: 600; }
.panel { display: grid; grid-template-columns: 360px 1fr; gap: 18px; background: var(--card); border: 1px solid var(--line); border-radius: 0 12px 12px 12px; padding: 16px; }
.left, .right { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.lbl { font-weight: 600; font-size: 14px; }
.drop { border: 1.5px dashed var(--line); border-radius: 10px; padding: 18px 10px; text-align: center; color: var(--mute); cursor: pointer; font-size: 14px; }
.drop.over { border-color: var(--accent); color: var(--accent); }
.refs { display: flex; gap: 8px; flex-wrap: wrap; }
.refs:empty { display: none; }
.ref { position: relative; width: 64px; height: 64px; }
.ref img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.ref button { position: absolute; top: -7px; right: -7px; width: 22px; height: 22px; padding: 0; border-radius: 50%; font-size: 12px; line-height: 1; background: var(--ink); color: var(--bg); border: none; }
textarea { min-height: 150px; resize: vertical; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); }
.row { display: flex; align-items: center; gap: 8px; font-size: 14px; }
select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.go { padding: 12px; font-size: 16px; }

.result { min-height: 420px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); display: grid; place-items: center; overflow: hidden; }
.result img { max-width: 100%; max-height: 72vh; display: block; }
.result.empty, .result.busy { color: var(--mute); }
.result.fail { color: var(--err); }
#status { padding: 16px; text-align: center; white-space: pre-wrap; }
.detail { margin: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); font-size: 13px; white-space: pre-wrap; word-break: break-word; max-height: 220px; overflow: auto; }
.actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.history { display: flex; gap: 8px; overflow-x: auto; }
.history img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 2px solid transparent; cursor: pointer; flex: none; }
.history img.cur { border-color: var(--accent); }
.hint { margin: 0; color: var(--mute); font-size: 12px; }

@media (max-width: 760px) {
  .app { padding: 10px 10px 84px; }
  .panel { grid-template-columns: 1fr; padding: 12px; }
  .right { order: -1; }
  .result { min-height: 0; }
  .history:empty + .hint { display: none; }
  .result.empty { display: none; }
  .result.busy, .result.fail { min-height: 120px; }
  .go { position: fixed; left: 10px; right: 10px; bottom: calc(10px + env(safe-area-inset-bottom)); z-index: 5; box-shadow: 0 4px 16px rgba(0,0,0,.2); }
  .actions .btn { padding: 8px 4px; font-size: 14px; }
}
