:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --surface-2: #ece7dc;
  --ink: #1d2422;
  --ink-2: #5b6461;
  --line: #d9d2c4;
  --accent: #1f3a34;
  --accent-ink: #f4f1ea;
  --tag: #c8662b;
  --danger: #a3341f;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(30, 30, 20, .06), 0 4px 14px rgba(30, 30, 20, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141816; --surface: #1c211f; --surface-2: #262c29; --ink: #ece8df; --ink-2: #a3aaa6;
    --line: #333a37; --accent: #9fd0bf; --accent-ink: #10201b; --tag: #e8955f; --danger: #f08a73;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141816; --surface: #1c211f; --surface-2: #262c29; --ink: #ece8df; --ink-2: #a3aaa6;
  --line: #333a37; --accent: #9fd0bf; --accent-ink: #10201b; --tag: #e8955f; --danger: #f08a73;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }

.topbar {
  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-ink);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; letter-spacing: .01em; }
.brand svg { width: 22px; height: 22px; }
#nav { display: flex; gap: 6px; }
#nav a, #nav button {
  background: transparent; border: 1px solid color-mix(in srgb, var(--accent-ink) 35%, transparent);
  color: var(--accent-ink); border-radius: 999px; padding: 5px 12px; font-size: 14px; text-decoration: none; cursor: pointer;
}

main { max-width: 720px; margin: 0 auto; padding: 16px; }
h1 { font-size: 26px; line-height: 1.2; margin: 4px 0 4px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--ink-2); margin: 26px 0 8px; }
.muted { color: var(--ink-2); }
.small { font-size: 14px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 16px; }
.stack > * + * { margin-top: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); text-decoration: none; cursor: pointer; font-weight: 600; white-space: nowrap;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; }
.linkbtn { background: none; border: 0; padding: 4px 6px; color: var(--ink-2); cursor: pointer; font-size: 14px; text-decoration: underline; }

label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 4px; }
input[type=text], input[type=number], input[type=password], input[type=search], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); font-size: 16px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--tag); outline-offset: 1px; }

.search { position: relative; }
.search input { padding-left: 42px; min-height: 52px; font-size: 17px; border-radius: 14px; box-shadow: var(--shadow); }
.search svg { position: absolute; left: 14px; top: 50%; translate: 0 -50%; width: 18px; height: 18px; color: var(--ink-2); }

.boxlist { list-style: none; margin: 0; padding: 0; }
.boxlist li + li { border-top: 1px solid var(--line); }
.boxrow { display: flex; align-items: center; gap: 12px; padding: 12px 14px; text-decoration: none; }
.boxrow:hover { background: var(--surface-2); }
.boxrow .meta { min-width: 0; flex: 1; }
.boxrow .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.boxrow .where { font-size: 13px; color: var(--ink-2); }
.chev { color: var(--ink-2); }

.num {
  flex: none; min-width: 46px; height: 46px; padding: 0 8px; border-radius: 10px;
  display: grid; place-items: center; font-weight: 800; font-size: 19px; font-variant-numeric: tabular-nums;
  background: var(--surface-2); border: 2px solid var(--ink);
}
.num.big { min-width: 92px; height: 92px; font-size: 44px; border-width: 3px; border-radius: 16px; }
.num.big small { display: block; font-size: 11px; letter-spacing: .14em; font-weight: 700; margin-bottom: -6px; }

.boxhead { display: flex; gap: 16px; align-items: center; }
.crumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.crumb { font-size: 14px; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); }
.crumb.tag { background: color-mix(in srgb, var(--tag) 16%, transparent); color: var(--tag); font-weight: 600; }

.items { list-style: none; margin: 0; padding: 0; }
.items li { display: flex; gap: 10px; padding: 10px 14px; }
.items li + li { border-top: 1px solid var(--line); }
.qty { color: var(--ink-2); font-variant-numeric: tabular-nums; }

.group-title { display: flex; align-items: baseline; gap: 8px; margin: 22px 0 8px; }
.group-title h2 { margin: 0; }
.shelf-label { padding: 8px 14px; font-size: 13px; font-weight: 700; color: var(--ink-2); background: var(--surface-2); border-top: 1px solid var(--line); }
.card > .shelf-label:first-child { border-top: 0; border-radius: var(--radius) var(--radius) 0 0; }

.empty { text-align: center; padding: 28px 16px; color: var(--ink-2); }
.linkbox { display: flex; gap: 8px; }
.linkbox input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }

.loc-room + .loc-room { margin-top: 14px; }
.loc-room header { display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.loc-room header strong { flex: 1; font-size: 17px; }
.loc-shelf { display: flex; align-items: center; gap: 8px; padding: 8px 14px; }
.loc-shelf + .loc-shelf { border-top: 1px dashed var(--line); }
.loc-shelf span { flex: 1; }
.loc-add { display: flex; gap: 8px; padding: 10px 14px; border-top: 1px solid var(--line); }
.loc-add input { min-height: 40px; }
.loc-add .btn { min-height: 40px; }

.error { color: var(--danger); font-size: 14px; min-height: 1em; }
#toast {
  position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); translate: -50% 20px;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; translate: -50% 0; }

.login { max-width: 380px; margin: 40px auto; }
