:root {
  color-scheme: light dark;
  --paper: #f8f7f3;
  --raised: var(--paper);
  --desk: #e9e8e3;
  --ink: #1d1d1b;
  --muted: #6b6a65;
  --faint: #c4c3bd;
  --line: rgba(29, 29, 27, 0.13);
  --field: #edece7;
  --press: rgba(29, 29, 27, 0.06);
  --accent: #2b7a4b;
  --on-accent: #ffffff;
  --danger: #b8372b;
  --scrim: rgba(20, 20, 18, 0.32);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #161615;
    --raised: #222220;
    --desk: #0b0b0a;
    --ink: #ecebe7;
    --muted: #9d9c96;
    --faint: #4a4945;
    --line: rgba(236, 235, 231, 0.13);
    --field: #242422;
    --press: rgba(236, 235, 231, 0.07);
    --accent: #62c08a;
    --on-accent: #0f2418;
    --danger: #ff7266;
    --scrim: rgba(0, 0, 0, 0.55);
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--desk);
}
body {
  font: 17px/1.35 var(--font);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* The visible viewport (shrinks with the on-screen keyboard; set from app.js), else 100dvh. */
.app {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--vv-top, 0px);
  height: var(--vv-height, 100dvh);
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--paper);
}
@media (min-width: 640px) {
  .app { border-inline: 1px solid var(--line); }
}

/* Header */
.bar {
  flex: none;
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr) 48px;
  align-items: center;
  gap: 4px;
  padding: env(safe-area-inset-top) max(6px, env(safe-area-inset-right)) 0 max(6px, env(safe-area-inset-left));
  min-height: calc(56px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
}
.icon {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--ink);
}
.icon svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon .dot-fill { fill: currentColor; stroke: none; }
.icon:active:not(:disabled) { background: var(--press); }
.icon:disabled { color: var(--faint); }
.check { justify-self: end; color: var(--accent); }
.check svg { stroke-width: 2.2; }

.title { min-width: 0; }
.title h1 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.title-button {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 0 6px;
  border: 0;
  background: none;
  font-weight: inherit;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.title-button:disabled { color: var(--ink); }
.rename {
  display: block;
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 0;
  border-radius: 10px;
  background: var(--field);
  font-size: 20px;
  font-weight: 600;
  text-align: center;
}
.rename:focus-visible { outline-offset: 0; }

.offline {
  flex: none;
  margin: 0;
  padding: 5px 16px;
  font-size: 14px;
  text-align: center;
  color: var(--muted);
  background: var(--field);
}

/* Pages: one per list, side by side; native swipe through scroll snapping. */
.pager {
  flex: 1;
  min-height: 0;
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.pager::-webkit-scrollbar { display: none; }
.pager > section {
  flex: 0 0 100%;
  min-width: 0;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}
.pager > section:focus-visible { outline-offset: -2px; }

.items { list-style: none; margin: 0; padding: 0 0 12px; }
.items li {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 16px;
  min-height: 52px;
  padding: 14px 20px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}
.items li::after {
  content: "";
  position: absolute;
  left: 20px;
  right: 0;
  bottom: 0;
  border-bottom: 1px solid var(--line);
}
.items li:active { background: var(--press); }
@media (hover: hover) {
  .items li:hover { background: var(--press); }
}
.items li:focus-visible { outline-offset: -2px; }
.item-label { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.item-qty-label {
  flex: none;
  max-width: 40%;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  text-align: right;
  overflow-wrap: anywhere;
}
.items li[data-done="true"],
.items li[data-done="true"] > span {
  color: var(--muted);
  text-decoration-line: line-through;
  text-decoration-thickness: 1.5px;
}
.empty {
  margin: 0;
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}

/* New-list page */
.new-list-page { padding-top: 8px; padding-bottom: 28px; }
.stack { margin: 0 auto 24px; padding: 0 20px; }
.stack label {
  display: flex;
  align-items: flex-end;
  min-height: 44px; /* it is a tap target too: it focuses its field */
  padding-bottom: 8px;
  font-size: 15px;
  font-weight: 600;
  color: var(--muted);
}
.row { display: flex; gap: 8px; }
.hint { margin: 10px 0 0; font-size: 15px; color: var(--muted); }
.text {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  background: var(--field);
  font-size: 17px;
}
.text::placeholder, .field input::placeholder { color: var(--muted); opacity: 1; }
.text:focus-visible { outline-offset: 0; }
.button {
  flex: none;
  min-width: 44px;
  height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 12px;
  background: var(--ink);
  color: var(--paper);
  font-weight: 600;
}
.button.quiet { background: var(--field); color: var(--ink); }
.button.danger { background: var(--danger); color: var(--paper); }
.button:active { opacity: 0.75; }

/* Bottom: suggestions above the add bar, page dots below it. */
.dock {
  flex: none;
  display: flex;
  flex-direction: column;
  padding: 8px max(12px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(12px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
}
.add { display: flex; gap: 8px; align-items: center; }
.field {
  flex: 1;
  min-width: 0;
  display: flex;
  height: 44px;
  border-radius: 22px;
  background: var(--field);
}
.field input {
  min-width: 0;
  height: 44px;
  border: 0;
  background: none;
  font-size: 17px;
}
.field:focus-within { box-shadow: inset 0 0 0 1.5px var(--muted); }
.field input:focus-visible { outline: none; }
.item-name { flex: 1; padding: 0 12px 0 18px; }
.field .item-qty {
  flex: 0 0 84px;
  padding: 0 16px 0 12px;
  border-left: 1px solid var(--line);
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.add-button {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--on-accent);
}
.add-button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; }
.add-button:active { opacity: 0.8; }

.suggestions {
  order: -1;
  display: flex;
  gap: 6px;
  margin: -4px calc(-1 * max(12px, env(safe-area-inset-left))) 2px;
  padding: 0 max(12px, env(safe-area-inset-left));
  overflow-x: auto;
  scrollbar-width: none;
}
.suggestions::-webkit-scrollbar { display: none; }
.suggestion {
  flex: none;
  height: 44px;
  padding: 0;
  border: 0;
  background: none;
}
.suggestion span {
  display: block;
  max-width: 220px;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper);
  font-size: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.suggestion:active span { background: var(--press); }
.suggestion:focus-visible { outline: none; }
.suggestion:focus-visible span { outline: 2px solid var(--ink); outline-offset: 1px; }

.dots { display: flex; justify-content: center; height: 44px; overflow: hidden; }
.dot {
  flex: 0 1 44px;
  min-width: 0;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
}
.dot::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
  transition: transform 0.15s ease-out;
}
.dot.plus::before {
  width: 10px;
  height: 10px;
  border-radius: 0;
  background:
    linear-gradient(currentColor 0 0) center / 100% 1.6px no-repeat,
    linear-gradient(currentColor 0 0) center / 1.6px 100% no-repeat;
}
.dot[aria-current="true"] { color: var(--ink); }
.dot[aria-current="true"]::before { transform: scale(1.3); }
.dot:focus-visible { outline-offset: -8px; border-radius: 50%; }

/* Header menu */
.menu {
  inset: auto;
  top: calc(var(--vv-top, 0px) + env(safe-area-inset-top) + 50px);
  left: max(8px, env(safe-area-inset-left), calc(50vw - 292px));
  margin: 0;
  min-width: 240px;
  padding: 6px 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--raised);
  color: var(--ink);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.16);
}
.menu button {
  display: block;
  width: 100%;
  min-height: 44px;
  padding: 0 18px;
  border: 0;
  background: none;
  text-align: left;
}
.menu button + button { border-top: 1px solid var(--line); }
.menu button:active { background: var(--press); }
.menu button:focus-visible { outline-offset: -2px; }
.danger { color: var(--danger); }

/* Dialogs */
.sheet {
  width: min(400px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: var(--paper);
  color: var(--ink);
}
.sheet::backdrop { background: var(--scrim); }
.sheet-body { padding: 22px 20px 18px; }
.sheet h2 { margin: 0 0 8px; font-size: 19px; font-weight: 600; overflow-wrap: anywhere; }
.sheet p { margin: 0 0 16px; font-size: 15px; color: var(--muted); }
.sheet .text { width: 100%; font-size: 16px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

/* Toast: a popover, so it shows above an open dialog too. */
.toast {
  inset: auto 16px auto 16px;
  top: calc(var(--vv-top, 0px) + env(safe-area-inset-top) + 66px);
  margin: 0 auto;
  width: fit-content;
  max-width: min(420px, calc(100vw - 32px));
  padding: 11px 18px;
  border: 0;
  border-radius: 14px;
  background: var(--ink);
  color: var(--paper);
  font-size: 15px;
  text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  .dot::before { transition: none; }
}
