:root {
  --accent: #2e7d4f;
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6a64;
  --line: #e4e2db;
  --danger: #b3261e;
  --radius: 14px;
  --tap: 52px;
  color-scheme: light dark;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141413;
    --surface: #1f1f1d;
    --text: #f0efe9;
    --muted: #a3a29b;
    --line: #34332f;
    --danger: #ff8a80;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { margin: 0; background: var(--bg); color: var(--text); }
body { min-height: 100dvh; -webkit-tap-highlight-color: transparent; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; }

.muted { color: var(--muted); font-size: 0.92rem; line-height: 1.4; }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }

/* ---------- buttons ---------- */

.btn {
  min-height: 44px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-weight: 600;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:disabled { opacity: 0.55; cursor: default; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 0.88rem; }
.btn.wide { width: 100%; min-height: var(--tap); font-size: 1.05rem; }

.icon-btn {
  width: 44px; height: 44px;
  display: grid; place-items: center;
  border: 0; border-radius: 999px;
  background: transparent; color: var(--muted);
}

/* ---------- sign in ---------- */

.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(380px, 100%);
  display: grid; gap: 14px; justify-items: center; text-align: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 28px 22px;
}
.login-card p { margin: 0; color: var(--muted); }
.login-card input { width: 100%; }
.login-card .btn { width: 100%; }

input[type="password"], input[type="search"], input:not([type]), select {
  min-height: 48px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 16px; /* prevents iOS zoom on focus */
}
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- header ---------- */

.top {
  position: sticky; top: 0; z-index: 10;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  padding: env(safe-area-inset-top) 0 0;
  border-bottom: 1px solid var(--line);
}
.titlebar { display: flex; align-items: center; gap: 10px; padding: 6px 8px 0 16px; }
.titlebar h1 { font-size: 1.35rem; letter-spacing: -0.01em; }
.sync { margin-left: auto; font-size: 0.8rem; color: var(--muted); }
.sync[data-status="pending"] { color: var(--accent); }
.sync[data-status="offline"], .sync[data-status="error"] { color: var(--danger); }

.stores {
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  padding: 8px 16px; scroll-padding: 16px;
}
.stores::-webkit-scrollbar { display: none; }
.store-tab {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 40px; padding: 0 14px;
  border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); font-weight: 600; white-space: nowrap;
}
.store-tab[aria-pressed="true"] { background: var(--c); border-color: var(--c); color: #fff; }
.badge {
  min-width: 22px; height: 22px; padding: 0 6px;
  display: inline-grid; place-items: center;
  border-radius: 999px; font-size: 0.78rem;
  background: color-mix(in srgb, var(--c) 18%, transparent); color: var(--c);
}
.store-tab[aria-pressed="true"] .badge { background: rgba(255, 255, 255, 0.25); color: #fff; }

.modes {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  margin: 0 16px 10px; padding: 4px;
  background: var(--line); border-radius: 999px;
}
.modes button {
  min-height: 38px; border: 0; border-radius: 999px;
  background: transparent; font-weight: 600; color: var(--muted);
}
.modes button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }

/* ---------- content ---------- */

main {
  max-width: 640px; margin: 0 auto;
  padding: 12px 16px calc(120px + env(safe-area-inset-bottom));
}

.addbar { margin-bottom: 14px; }
.addbar input { width: 100%; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px;
  margin-bottom: 18px;
}
.section-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.section-head h2 { font-size: 1rem; }
.count { color: var(--muted); font-weight: 600; font-size: 0.9rem; }

.group-title {
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin: 18px 4px 8px; font-weight: 700;
  display: flex; gap: 8px; align-items: baseline;
}
.group-title.big { font-size: 1rem; text-transform: none; letter-spacing: 0; color: var(--text); margin-top: 26px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 36px; padding: 0 8px 0 14px;
  border-radius: 999px; border: 0;
  background: color-mix(in srgb, var(--accent) 14%, var(--surface));
  color: var(--text); font-weight: 500;
}
.chip span { font-size: 1.15rem; color: var(--muted); width: 20px; }

.rows {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
}
.rows:empty { display: none; }

.row {
  width: 100%; min-height: var(--tap);
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px; text-align: left;
  border: 0; border-top: 1px solid var(--line); background: transparent;
}
.rows > .row:first-child { border-top: 0; }
.row-text { display: grid; gap: 2px; flex: 1; min-width: 0; }
.row-name { font-weight: 500; }
.row-sub { font-size: 0.82rem; color: var(--muted); }
.row-icon {
  flex: 0 0 auto; width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 999px; border: 1.5px solid var(--line);
  color: var(--accent); font-size: 1.15rem; font-weight: 700;
}
.row.on { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.row.on .row-icon { background: var(--accent); border-color: var(--accent); color: #fff; font-size: 0.95rem; }

/* press-and-hold to star */
.row, .chip { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; touch-action: manipulation; }
.row.holding, .chip.holding {
  background: color-mix(in srgb, #e0a100 22%, transparent);
  transition: background 0.5s ease;
}
.usual-star { color: #e0a100; font-size: 0.9em; }
.hint { font-size: 0.82rem; color: var(--muted); margin: -8px 4px 4px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 20;
  max-width: calc(100% - 32px);
  padding: 12px 18px; border-radius: 999px;
  background: var(--text); color: var(--bg);
  font-weight: 600; font-size: 0.95rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

.new-item { padding: 0; overflow: hidden; margin-top: 14px; }
.new-item .row { border-top: 0; }
.cat-pick {
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  padding: 8px 14px 12px; color: var(--muted); font-size: 0.9rem;
}
.cat-pick select { min-height: 40px; }

/* ---------- shop ---------- */

.progress { margin: 2px 4px 6px; }
.progress-text { font-size: 0.95rem; color: var(--muted); margin-bottom: 8px; }
.progress-text strong { color: var(--text); font-size: 1.1rem; }
.progress-track { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width 0.25s ease; }

.shop-group.all-done .group-title { opacity: 0.6; }

.shop-row {
  width: 100%; min-height: 58px;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 16px; text-align: left;
  border: 0; border-top: 1px solid var(--line); background: transparent;
  font-size: 1.08rem;
}
.rows > .shop-row:first-child { border-top: 0; }
.box {
  flex: 0 0 auto; width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 8px; border: 2px solid var(--line);
  color: #fff; font-weight: 800; font-size: 0.95rem;
  transition: background 0.15s, border-color 0.15s;
}
.shop-row.checked .box { background: var(--accent); border-color: var(--accent); }
.shop-row.checked .shop-name { text-decoration: line-through; text-decoration-thickness: 2px; color: var(--muted); }

.empty { text-align: center; padding: 48px 12px; display: grid; gap: 10px; justify-items: center; }
.empty p { margin: 0; }
.empty-title { font-weight: 600; font-size: 1.1rem; }

.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.bottombar .btn { max-width: 608px; margin: 0 auto; display: block; }

/* ---------- dialogs ---------- */

dialog.sheet {
  width: min(560px, calc(100% - 24px));
  max-height: calc(100dvh - 48px);
  border: 1px solid var(--line); border-radius: 20px;
  background: var(--surface); color: var(--text);
  padding: 20px;
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog.sheet h2 { font-size: 1.2rem; }
dialog.sheet h3 { font-size: 1rem; margin: 20px 0 6px; }
dialog.sheet p { margin: 10px 0; }
.actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.actions.left { justify-content: flex-start; margin-top: 8px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }

#settingsFilter { width: 100%; margin: 6px 0 10px; }
.star {
  width: 36px; height: 40px; border: 0; background: transparent;
  font-size: 1.3rem; color: var(--muted); padding: 0;
}
.star.on { color: #e0a100; }
.edit-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  grid-template-areas: "star name hide" ". cat .";
  gap: 6px; align-items: center;
  padding: 8px 0; border-top: 1px solid var(--line);
}
.edit-row .star { grid-area: star; }
.edit-row .edit-name { grid-area: name; }
.edit-row .edit-cat { grid-area: cat; }
.edit-row [data-act="hide"] { grid-area: hide; }
.edit-row input, .edit-row select { min-height: 40px; min-width: 0; width: 100%; }
.edit-row.hidden-item input, .edit-row.hidden-item select { opacity: 0.5; }
