:root {
  --bg: #f4f2ec;
  --card: #ffffff;
  --ink: #111111;
  --muted: #6b6860;
  --line: #d9d5ca;
  --red: #c8201c;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111111;
    --card: #1b1b1a;
    --ink: #f1efe8;
    --muted: #9a968c;
    --line: #2e2d2a;
    --red: #ff4a42;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.45 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  padding: env(safe-area-inset-top) 16px calc(24px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
main { max-width: 640px; margin: 0 auto; }
[hidden] { display: none !important; }
.red { color: var(--red); }

h1 {
  font: 800 26px/1 ui-monospace, "SF Mono", Menlo, monospace;
  letter-spacing: -0.02em;
  margin: 20px 0;
}
header { display: flex; align-items: center; justify-content: space-between; }

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; border-radius: 10px; padding: 12px 18px; }
button:disabled { opacity: 0.4; cursor: default; }
.primary { background: var(--ink); color: var(--bg); font-weight: 700; }
.ghost { background: transparent; font-size: 22px; padding: 6px 10px; color: var(--muted); }
.small { font-size: 14px; padding: 7px 12px; background: transparent; border: 1px solid var(--line); }

input[type=password], textarea {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  resize: vertical;
}
#login-form { display: grid; gap: 12px; margin-top: 32px; }
#login-form label { font-weight: 600; }
.error { color: var(--red); margin: 8px 0 0; font-size: 14px; }

/* capture */
.capture {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  display: grid;
  gap: 12px;
}
.shoot {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  min-height: 120px;
  border: 2px dashed var(--line);
  border-radius: 12px;
  font-weight: 700; font-size: 18px;
  cursor: pointer;
}
.shoot:active { background: var(--bg); }
.shoot-icon {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--ink);
  box-shadow: inset 0 0 0 4px var(--card), inset 0 0 0 12px var(--red);
}
.thumbs { display: flex; gap: 8px; overflow-x: auto; }
.thumbs:empty { display: none; }
.thumb { position: relative; flex: none; }
.thumb img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; display: block; }
.thumb button {
  position: absolute; top: -6px; right: -6px;
  width: 24px; height: 24px; padding: 0; border-radius: 50%;
  background: var(--ink); color: var(--bg); font-size: 14px; line-height: 24px;
}
.row { display: flex; gap: 10px; align-items: center; justify-content: space-between; }
.row .primary { flex: 1; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { padding: 11px 14px; font-size: 15px; cursor: pointer; }
.seg input:checked + label { background: var(--ink); color: var(--bg); font-weight: 700; }
.seg input:focus-visible + label { outline: 2px solid var(--red); outline-offset: -2px; }

/* items */
.items { display: grid; gap: 12px; margin-top: 18px; }
.item {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--ink);
  border-radius: var(--radius);
  padding: 14px;
  min-width: 0;
}
.item.processing { border-left-color: var(--muted); }
.item.error { border-left-color: var(--red); }
.item-head { display: flex; align-items: baseline; gap: 10px; }
.item-head h2 { font-size: 17px; margin: 0; flex: 1; overflow-wrap: anywhere; }
.meta { color: var(--muted); font-size: 13px; }
.status { font-size: 13px; font-weight: 700; }
.processing .status::after { content: ""; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }
.item .thumbs { margin-top: 10px; }
.item .thumbs img { width: 56px; height: 56px; }
.answer { margin-top: 10px; overflow-wrap: anywhere; }
.answer h3, .answer h4 { color: var(--red); margin: 14px 0 4px; font-size: 16px; }
.answer p { margin: 6px 0; }
.answer pre, .answer code { font: 14px/1.4 ui-monospace, Menlo, monospace; }
.answer pre { background: var(--bg); padding: 10px; border-radius: 8px; overflow-x: auto; }
.answer ul, .answer ol { padding-left: 22px; margin: 6px 0; }
.item-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
details summary { cursor: pointer; color: var(--muted); font-size: 14px; margin-top: 10px; }
.empty { color: var(--muted); text-align: center; padding: 24px 0; }
