:root {
  --bg: #f2f3f5;
  --surface: #ffffff;
  --text: #1c2330;
  --muted: #6b7280;
  --border: #e3e6eb;
  --accent: #0f7b6c;
  --accent-soft: #e2f3ef;
  --accent-text: #ffffff;
  --danger: #c0392b;
  --warn-bg: #fff6e0;
  --warn-border: #f0c36d;
  --ok-bg: #e6f5f1;
  --ok-border: #8fd1c2;
  --tabbar-h: 58px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #1a1f27;
    --text: #e6e9ee;
    --muted: #9aa3b2;
    --border: #2c333e;
    --accent: #2bb39d;
    --accent-soft: #15302a;
    --accent-text: #0b1512;
    --danger: #e5675a;
    --warn-bg: #33290f;
    --warn-border: #7a6223;
    --ok-bg: #123029;
    --ok-border: #2a6f61;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
body.login { padding-bottom: 0; }
a { color: var(--accent); }
code { font-size: 0.85em; }
h2 { font-size: 1.05rem; margin: 20px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.error { color: var(--danger); font-size: 0.85rem; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.3rem; margin: 0; letter-spacing: -0.01em; }

main { max-width: 640px; margin: 0 auto; padding: 12px 16px; }

/* bottom tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: space-around;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: 0.7rem; font-weight: 500;
}
.tabbar a .ico { font-size: 1.3rem; filter: grayscale(1); opacity: 0.7; }
.tabbar a.on { color: var(--accent); }
.tabbar a.on .ico { filter: none; opacity: 1; }

/* banners & cards */
.banner { padding: 10px 14px; border-radius: 12px; margin-bottom: 12px; border: 1px solid; font-size: 0.9rem; }
.banner.warn { background: var(--warn-bg); border-color: var(--warn-border); }
.banner.ok { background: var(--ok-bg); border-color: var(--ok-border); }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 16px; margin-bottom: 12px; }
.empty { text-align: center; padding: 32px 16px; color: var(--muted); }

/* buttons */
button, .button {
  font: inherit; font-size: 0.9rem; font-weight: 600; cursor: pointer;
  min-height: 38px; padding: 8px 14px; border-radius: 10px;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-text);
  text-decoration: none; display: inline-flex; align-items: center; justify-content: center; white-space: nowrap;
}
button.big, .button.big { min-height: 48px; font-size: 1rem; }
button.full, .button.full { width: 100%; }
.ghost { background: transparent; color: var(--accent); }
.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button.link { background: none; border: 0; color: var(--accent); padding: 0; min-height: 0; font-weight: 500; }
form { margin: 0; }

/* search cards */
.cards { list-style: none; padding: 0; margin: 0; }
.card.search.paused { opacity: 0.55; }
.row-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.row-top .title { font-weight: 700; font-size: 1.05rem; color: var(--text); text-decoration: none; margin-right: auto; }
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip { background: var(--accent-soft); color: var(--text); border-radius: 999px; padding: 3px 10px; font-size: 0.8rem; }
.tag { font-size: 0.72rem; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.meta { font-size: 0.82rem; color: var(--muted); }
.actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 12px; }
.actions form, .actions .button, .actions button { width: 100%; }
.actions button, .actions .button { padding: 8px 4px; font-size: 0.8rem; }

/* form */
.search-form { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 0.88rem; }
label small { font-weight: 400; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 500; }
label.check input { width: 22px; height: 22px; accent-color: var(--accent); }
input:not([type=checkbox]), select, textarea {
  font: inherit; font-size: 16px; /* >=16px stops iOS zooming in */
  width: 100%; padding: 11px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  -webkit-appearance: none; appearance: none;
}
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%;
  background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px;
}
textarea { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
details > summary { cursor: pointer; font-weight: 600; font-size: 0.9rem; color: var(--accent); padding: 4px 0; }
details[open] > summary { margin-bottom: 12px; }
details label { margin-bottom: 12px; }
.buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.buttons button { min-height: 48px; font-size: 1rem; }
.buttons.sticky {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 8px);
  background: var(--surface); padding-top: 8px;
}

/* category picker */
.category-picker { display: flex; flex-direction: column; gap: 10px; }
.subcats { border: 1px solid var(--border); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.subcats-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; font-size: 0.88rem; }
.sub-list { max-height: 300px; overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: 10px; }
.sub-group-title { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 5px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.sub-group[hidden] { display: none; }
.sub-summary { line-height: 1.35; }
.sub { flex-direction: row; font-weight: 500; font-size: 0.82rem; }
.sub input { position: absolute; opacity: 0; pointer-events: none; }
.sub span { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg); }
.sub input:checked + span { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.sub[hidden] { display: none; }

/* result / match lists */
.results { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.results li a { display: flex; gap: 12px; align-items: center; padding: 8px; border-radius: 14px; border: 1px solid var(--border); background: var(--surface); text-decoration: none; color: var(--text); }
.results li.match a { border-color: var(--ok-border); }
.results li.nomatch { opacity: 0.45; }
.results img, .results .noimg { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; flex-shrink: 0; background: var(--border); }
.results .t { font-weight: 600; font-size: 0.95rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* log */
.log { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.log li { background: var(--surface); border: 1px solid var(--border); border-left-width: 4px; border-radius: 12px; padding: 10px 12px; }
.log li.ok { border-left-color: var(--accent); }
.log li.fail { border-left-color: var(--danger); }
.log pre { white-space: pre-wrap; word-break: break-word; margin: 6px 0 0; font: inherit; font-size: 0.88rem; }

/* menu / more page */
.menu { list-style: none; padding: 0; }
.menu li { border-bottom: 1px solid var(--border); }
.menu li:last-child { border-bottom: 0; }
.menu li a, .menu li button.link { display: block; width: 100%; text-align: left; padding: 14px 0; color: var(--text); text-decoration: none; font-size: 1rem; }
.menu.card { padding: 0 16px; }
.steps { padding-left: 20px; margin: 0 0 12px; }
.steps li { margin-bottom: 8px; }

/* login */
body.login main { min-height: 70vh; display: flex; align-items: center; }
.login-card { width: 100%; display: flex; flex-direction: column; gap: 14px; }

@media (min-width: 700px) {
  .actions { grid-template-columns: repeat(4, auto); justify-content: start; }
}
