:root {
  --bg: #f4f3ee;
  --card: #ffffff;
  --ink: #1d2320;
  --muted: #6b726d;
  --line: #e3e1d8;
  --accent: #2f6b3a;
  --accent-ink: #ffffff;
  --accent-soft: #e3efe4;
  --danger: #b3261e;
  --warn: #b26a00;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 4px 16px rgb(0 0 0 / 6%);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121513;
    --card: #1c201d;
    --ink: #e9ece9;
    --muted: #9aa39c;
    --line: #2c322e;
    --accent: #7cc48a;
    --accent-ink: #0e1a10;
    --accent-soft: #233528;
    --danger: #f2b8b5;
    --warn: #f0b44c;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
[hidden] { display: none !important; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: max(24px, env(safe-area-inset-top)) 20px 24px; }
.login-card { width: 100%; max-width: 360px; display: grid; gap: 14px; text-align: center; }
.login-card img { justify-self: center; border-radius: 18px; }
.login-card h1 { margin: 0 0 8px; font-size: 28px; }
.login-card label { display: grid; gap: 6px; text-align: left; font-size: 15px; color: var(--muted); }
input, select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; font-size: 17px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
.error { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 15px; }
.primary { background: var(--accent); color: var(--accent-ink); border-radius: 12px; min-height: 46px; padding: 0 18px; font-weight: 600; }
.danger { color: var(--danger); font-weight: 600; min-height: 44px; padding: 0 8px; }

/* Header */
.bar { position: sticky; top: 0; z-index: 5; background: var(--bg); padding-top: env(safe-area-inset-top); }
.top {
  display: flex; align-items: center; gap: 10px;
  padding: 8px max(16px, env(safe-area-inset-right)) 8px max(16px, env(safe-area-inset-left));
}
.top h1 { margin: 0; font-size: 26px; letter-spacing: -0.02em; flex: 1; }
.status { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.status.live::before { background: var(--accent); }
.status.waiting::before { background: var(--warn); }
.icon-btn { width: 44px; height: 44px; border-radius: 22px; font-size: 24px; line-height: 44px; }
.icon-btn:active { background: var(--line); }
.menu {
  position: absolute; right: 12px; top: calc(env(safe-area-inset-top) + 56px);
  background: var(--card); border-radius: 14px; box-shadow: var(--shadow), 0 0 0 1px var(--line);
  display: grid; min-width: 220px; overflow: hidden;
}
.menu button { text-align: left; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.menu button:last-child { border-bottom: 0; color: var(--danger); }
.menu button:active { background: var(--accent-soft); }

/* Add bar (at the top so the iPhone keyboard never covers it) */
.add {
  display: grid; grid-template-columns: 1fr minmax(0, 9.5em) 46px; gap: 8px;
  padding: 4px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
}
.add select { font-size: 15px; padding: 10px 8px; color: var(--muted); }
.add-btn { padding: 0; font-size: 26px; font-weight: 500; }
.suggest {
  list-style: none; margin: -4px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left)); padding: 0;
  background: var(--card); border-radius: 12px; box-shadow: var(--shadow), 0 0 0 1px var(--line); overflow: hidden;
}
.suggest button { width: 100%; text-align: left; padding: 12px 14px; display: flex; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); }
.suggest li:last-child button { border-bottom: 0; }
.suggest button:active { background: var(--accent-soft); }
.suggest small { color: var(--muted); font-size: 13px; }

/* List */
.list { padding: 0 max(16px, env(safe-area-inset-right)) calc(env(safe-area-inset-bottom) + 32px) max(16px, env(safe-area-inset-left)); }
.group { margin: 0 0 14px; }
.group h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 14px 4px 6px; font-weight: 600; }
.group ul { list-style: none; margin: 0; padding: 0; background: var(--card); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.item { display: flex; align-items: center; min-height: 52px; border-bottom: 1px solid var(--line); }
.item:last-child { border-bottom: 0; }
.check {
  flex: none; width: 52px; height: 52px; display: grid; place-items: center;
}
.check::before {
  content: ""; width: 24px; height: 24px; border-radius: 50%; border: 2px solid var(--muted);
}
.item.ticked .check::before {
  background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M6 12.5l4 4 8-9' fill='none' stroke='white' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/18px no-repeat;
  border-color: var(--accent);
}
.item .name { flex: 1; text-align: left; padding: 14px 14px 14px 0; min-width: 0; overflow-wrap: anywhere; }
.item.ticked .name { color: var(--muted); text-decoration: line-through; }
.basket h2 { display: flex; justify-content: space-between; }
.empty { text-align: center; color: var(--muted); padding: 56px 24px; }
.empty strong { display: block; color: var(--ink); font-size: 19px; margin-bottom: 6px; }

/* Edit sheet */
.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px;
  background: var(--card); color: var(--ink); border-radius: 18px 18px 0 0;
}
.sheet::backdrop { background: rgb(0 0 0 / 35%); }
.sheet form { display: grid; gap: 14px; padding: 20px 20px calc(env(safe-area-inset-bottom) + 20px); }
.sheet h2 { margin: 0; font-size: 20px; }
.sheet label { display: grid; gap: 6px; color: var(--muted); font-size: 15px; }
.sheet-actions { display: flex; align-items: center; gap: 8px; }
.sheet-actions .grow { flex: 1; }
#editCancel { min-height: 46px; padding: 0 12px; color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 24px); transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 22px; font-size: 15px; z-index: 20;
  max-width: calc(100% - 32px);
}
#exportText { font: 15px/1.4 ui-monospace, Menlo, monospace; resize: none; }
