:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --text: #1d2321;
  --muted: #6b726f;
  --line: #e1dfd8;
  --accent: #2f5d50;
  --accent-text: #ffffff;
  --take: #8a4b2a;
  --warn-bg: #fff4d6;
  --warn: #7a5600;
  --bad: #a1271d;
  --radius: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151918;
    --card: #1f2523;
    --text: #e9ecea;
    --muted: #9aa39f;
    --line: #313937;
    --accent: #5fa58f;
    --accent-text: #0d1311;
    --take: #d08b62;
    --warn-bg: #3a3014;
    --warn: #f2cd6b;
    --bad: #ff7a6e;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
main { max-width: 760px; margin: 0 auto; padding: 16px; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0.4rem 0 0.8rem; }
h2 { font-size: 1.1rem; margin: 1.6rem 0 0.6rem; }
code { font: 600 0.85em ui-monospace, Menlo, monospace; background: var(--line); padding: 1px 6px; border-radius: 6px; white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.error { color: var(--bad); }
.notice { background: var(--warn-bg); color: var(--warn); padding: 8px 12px; border-radius: 10px; font-size: 0.9rem; }

header.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--accent); color: var(--accent-text);
}
header.top a { color: var(--accent-text); text-decoration: none; font-weight: 600; }
header.top nav { display: flex; gap: 16px; }
.brand { font-size: 1.05rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--bad); }
.btn.big { min-height: 52px; width: 100%; font-size: 1.05rem; }
.btn.link { border: 0; background: none; color: var(--muted); text-decoration: underline; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 8px 0; }
.btn.huge { flex-direction: column; min-height: 140px; font-size: 1.35rem; border-radius: 20px; border: 0; }
.btn.huge span { font-size: 2.4rem; line-height: 1; }
.btn.huge small { font-size: 0.75rem; font-weight: 500; }
.btn.huge.place { background: var(--accent); color: var(--accent-text); }
.btn.huge.take { background: var(--take); color: #fff; }

input, select, textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--text); font: inherit; font-size: 16px; /* 16px stops iOS zoom */
}
textarea { resize: vertical; }
label { display: grid; gap: 4px; font-weight: 600; font-size: 0.9rem; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; min-height: 36px; }
label.check input { width: auto; min-height: 0; }
.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; }
.row input, .row select { flex: 1; min-width: 0; }
.row .code-input { flex: 0 0 7rem; text-transform: uppercase; font-family: ui-monospace, Menlo, monospace; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.card h2 { margin-top: 0; }
.titlebar { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

body.login main { min-height: 100vh; display: grid; place-items: center; }
body.login form { width: 100%; max-width: 380px; }

.searchbox { display: flex; gap: 8px; margin: 4px 0 12px; }
.searchbox input { flex: 1; }

.items { display: grid; gap: 10px; }
.itemcard {
  display: flex; gap: 12px; align-items: center;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px; color: var(--text); text-decoration: none;
}
.itemcard img, .itemcard .noimg { width: 72px; height: 72px; flex: none; object-fit: cover; border-radius: 10px; background: var(--line); }
.itemcard .body { display: grid; gap: 4px; min-width: 0; }
.itemcard .name { overflow: hidden; text-overflow: ellipsis; }
.itemcard .where { color: var(--muted); font-size: 0.875rem; }
.status-processing { opacity: 0.75; }
.status-processing .name::after { content: ''; display: inline-block; width: 10px; height: 10px; margin-left: 8px; border: 2px solid var(--muted); border-top-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.result .desc { margin: 4px 4px 8px; color: var(--muted); }
.pill { display: inline-block; justify-self: start; font-size: 0.75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--line); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad); color: #fff; }

.tree { list-style: none; padding-left: 0; margin: 0; }
.tree .tree { padding-left: 1.2rem; border-left: 2px solid var(--line); margin: 4px 0 4px 4px; }
.tree li { padding: 4px 0; }
.tree a { font-weight: 600; text-decoration: none; }
details.add summary { color: var(--accent); cursor: pointer; font-size: 0.9rem; padding: 4px 0; }
details.add form { margin: 6px 0 10px; }

.crumbs { font-size: 0.875rem; color: var(--muted); }
.itemhead { display: grid; gap: 12px; }
.itemhead .photo { width: 100%; max-height: 60vh; object-fit: contain; border-radius: var(--radius); background: var(--line); }
@media (min-width: 640px) { .itemhead { grid-template-columns: 260px 1fr; align-items: start; } }
.dupes { background: var(--warn-bg); color: var(--warn); border-radius: var(--radius); padding: 4px 16px; }
.dupes a { color: inherit; font-weight: 700; }
.dupes ul { padding-left: 1.1rem; }
.dupes li { margin: 6px 0; }
.history { padding-left: 1.1rem; }
.history li { margin: 4px 0; }

.feed { list-style: none; padding: 0; display: grid; gap: 8px; }
.feed a { display: flex; gap: 10px; align-items: center; color: var(--text); text-decoration: none; }
.feed img, .feed .noimg { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--line); flex: none; }
.logout { margin-top: 2rem; display: grid; justify-items: center; gap: 4px; }
