:root {
  /* Default "Garden" theme for the first paint. app.js applies the chosen theme from public/theme.js. */
  color-scheme: light;
  --bg: #f6f9f7;
  --surface: #ffffff;
  --text: #17211c;
  --muted: #5a6861;
  --line: #dae2de;
  --accent: #1d7348;
  --accent-hover: #185f3b;
  --on-accent: #ffffff;
  --accent-soft: #e4eee9;
  --check: #1d7348;
  --on-check: #ffffff;
  --danger: #b3261e;
  --warn-bg: #fdf0c8;
  --warn-text: #4d3b00;
  --shadow: 0 1px 2px rgb(20 30 25 / 6%), 0 4px 16px rgb(20 30 25 / 6%);
  --radius: 14px;
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 100%;
  line-height: 1.4;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121714;
    --surface: #1c211f;
    --text: #e8edeb;
    --muted: #a2afa8;
    --line: #323936;
    --accent: #279c62;
    --accent-hover: #2eb974;
    --on-accent: #111111;
    --accent-soft: #1e3a2c;
    --check: #1f7b4d;
    --on-check: #ffffff;
    --danger: #f28b82;
    --warn-bg: #3a3214;
    --warn-text: #f4e3a3;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%);
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
}

[hidden] {
  display: none !important;
}

h1,
h2,
p {
  margin: 0;
}

ul {
  margin: 0;
  padding: 0;
  list-style: none;
}

button,
input {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.icon {
  width: 22px;
  height: 22px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---- Header ---- */

.bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top);
}

.bar-inner,
.page {
  max-width: 640px;
  margin: 0 auto;
  padding-inline: max(16px, env(safe-area-inset-left)) max(16px, env(safe-area-inset-right));
}

.bar-inner {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 60px;
}

h1 {
  margin-right: auto;
  font-size: 1.2rem;
  font-weight: 700;
  min-width: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
  white-space: nowrap;
}

.brand span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.status {
  max-width: 640px;
  margin: 12px auto 0;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--warn-bg);
  color: var(--warn-text);
  font-size: 0.9rem;
  width: calc(100% - 32px);
}

/* ---- Buttons and fields ---- */

.button,
.icon-button,
.link,
.chip-button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

.button:hover {
  border-color: var(--muted);
}

.button:disabled {
  opacity: 0.5;
  cursor: default;
}

.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}

.button.primary:hover {
  background: var(--accent-hover);
}

.button.wide {
  width: 100%;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
}

.icon-button:hover {
  background: var(--accent-soft);
  color: var(--text);
}

.icon-button.small {
  width: 36px;
  height: 36px;
}

.icon-button.small .icon {
  width: 18px;
  height: 18px;
}

.link {
  min-height: 44px;
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 600;
}

.link.danger {
  color: var(--danger);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
}

.optional {
  font-weight: 400;
}

input {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 1rem; /* 16px avoids zoom on focus in iOS */
}

input:focus-visible {
  outline-offset: 0;
  border-color: var(--accent);
}

input[type='number'] {
  appearance: textfield;
}

/* Suggestions come from the datalist; hide Chrome's dropdown arrow. */
input::-webkit-calendar-picker-indicator {
  display: none !important;
}

/* ---- Page ---- */

.page {
  padding-top: 16px;
  padding-bottom: 120px;
}

#app {
  display: grid;
  gap: 24px;
}

.message {
  padding: 48px 0;
  color: var(--muted);
  text-align: center;
}

.message-box {
  display: grid;
  gap: 12px;
  margin-top: 32px;
  padding: 24px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.message-box p {
  color: var(--muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.add-form,
.edit-form {
  display: grid;
  grid-template-columns: 1fr 5.5rem;
  gap: 10px;
}

.add-form {
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.add-form .note,
.edit-form .note {
  grid-column: 1 / -1;
}

.add-button {
  grid-column: 1 / -1;
}

@media (min-width: 560px) {
  .add-form {
    grid-template-columns: 1fr 5rem 1fr auto;
    align-items: end;
  }

  .add-form .note,
  .add-button {
    grid-column: auto;
  }
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
}

h2 {
  font-size: 1rem;
  font-weight: 700;
}

.count {
  color: var(--muted);
  font-weight: 500;
}

.hint {
  color: var(--muted);
  font-size: 0.875rem;
}

.empty {
  padding: 20px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

/* ---- Frequently bought ---- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip-button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  max-width: 100%;
  min-height: 40px;
  padding: 0 14px 0 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--text);
  font-weight: 500;
}

.chip-button span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip-button .icon {
  width: 18px;
  height: 18px;
  color: var(--accent);
}

.chip-button:hover {
  border-color: var(--accent);
}

.chip.managing {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  min-height: 40px;
  padding: 0 2px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pin[aria-pressed='true'] {
  color: #c98a00;
}

.pin[aria-pressed='true'] .icon {
  fill: currentColor;
}

/* ---- Items ---- */

.items {
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.items:empty {
  display: none;
}

.item {
  display: flex;
  align-items: center;
  gap: 2px;
  padding-right: 6px;
  border-top: 1px solid var(--line);
}

.item:first-child {
  border-top: 0;
}

.item-main {
  display: flex;
  flex: 1;
  align-items: center;
  gap: 14px;
  min-width: 0;
  min-height: 60px;
  padding: 10px 6px 10px 16px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.check {
  appearance: none;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  min-height: 0;
  flex: none;
  margin: 0;
  padding: 0;
  border: 2px solid var(--muted);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
}

.check::after {
  content: '';
  width: 7px;
  height: 13px;
  margin-top: -3px;
  border: solid var(--on-check);
  border-width: 0 3px 3px 0;
  transform: rotate(45deg);
  opacity: 0;
}

.check:checked,
.check.checked {
  border-color: var(--check);
  background: var(--check);
}

.check:checked::after,
.check.checked::after {
  opacity: 1;
}

.check:focus-visible {
  outline-offset: 2px;
}

.item-text {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.item-title {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 8px;
}

.item-name {
  font-size: 1.05rem;
  font-weight: 500;
  overflow-wrap: anywhere;
}

.qty {
  font-weight: 700;
  color: var(--accent);
  white-space: nowrap;
}

.item-note {
  color: var(--muted);
  font-size: 0.875rem;
  overflow-wrap: anywhere;
}

.done .item-name,
.done .qty {
  color: var(--muted);
  text-decoration: line-through;
}

.item.editing {
  padding: 14px 16px;
}

.edit-form {
  flex: 1;
  min-width: 0;
}

.edit-actions {
  display: flex;
  grid-column: 1 / -1;
  gap: 8px;
}

.edit-actions .button {
  flex: 1;
}

/* ---- Toast ---- */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 6px 8px 6px 18px;
  border-radius: 14px;
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 8px 24px rgb(0 0 0 / 25%);
  transform: translateX(-50%);
}

.toast .link {
  color: var(--accent-soft);
  text-decoration: underline;
}

#toast-text {
  padding: 8px 0;
}

/* ---- Dialogs ---- */

dialog {
  width: min(480px, calc(100% - 32px));
  max-height: calc(100% - 32px);
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 16px 48px rgb(0 0 0 / 30%);
}

dialog::backdrop {
  background: rgb(10 15 12 / 50%);
}

.dialog-body {
  display: grid;
  gap: 16px;
  padding: 8px 20px 20px;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-right: -12px;
}

.dialog-head h2 {
  font-size: 1.15rem;
}

.copy-row {
  display: flex;
  gap: 8px;
}

.copy-row input {
  flex: 1;
  color: var(--muted);
}

.qr {
  display: grid;
  justify-items: center;
  gap: 8px;
  margin: 0;
}

.qr svg {
  width: 180px;
  height: 180px;
  border-radius: 8px;
}

.qr figcaption {
  color: var(--muted);
  font-size: 0.875rem;
}

.device-lists {
  display: grid;
  gap: 8px;
}

.device-lists:empty {
  display: none;
}

.device-list {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 6px 10px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.device-list.current {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.device-list-info {
  display: grid;
  flex: 1;
  min-width: 0;
}

.device-list-name {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Language ---- */

.lang-button {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  cursor: pointer;
}

.lang-button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* ---- About ---- */

.dialog-body h3 {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.about-steps {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 1.4em;
}

.about-steps li::marker {
  color: var(--accent);
  font-weight: 700;
}

.about-tips {
  display: grid;
  gap: 10px;
}

.about-tips li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.about-tips .icon {
  color: var(--accent);
}

.tip-badge {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  flex: none;
  border: 1.5px solid var(--accent);
  border-radius: 50%;
  color: var(--accent);
  font-size: 0.6rem;
  font-weight: 700;
}

/* ---- Appearance ---- */

.setting {
  display: grid;
  gap: 8px;
}

.setting h3 {
  margin: 0;
}

.segmented {
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
}

.segmented button {
  min-height: 40px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  cursor: pointer;
}

.segmented button:hover {
  color: var(--text);
}

.segmented button[aria-pressed='true'] {
  background: var(--accent);
  color: var(--on-accent);
}

.themes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.theme-option {
  display: grid;
  justify-items: center;
  gap: 6px;
  min-height: 72px;
  padding: 10px 4px 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.theme-option:hover {
  border-color: var(--muted);
}

.theme-option[aria-pressed='true'] {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
  background: var(--accent-soft);
}

.swatch {
  width: 28px;
  height: 28px;
  border: 1px solid rgb(0 0 0 / 15%);
  border-radius: 50%;
  background: linear-gradient(135deg, var(--swatch-accent) 50%, var(--swatch-check) 50%);
}

.custom-colors {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.color-field {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  cursor: pointer;
}

.color-field input {
  width: 52px;
  min-height: 40px;
  padding: 3px;
  cursor: pointer;
}

.theme-preview {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--bg);
}

.preview-row {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.preview-row .check {
  cursor: default;
}

.preview-row.done .item-name {
  color: var(--muted);
  text-decoration: line-through;
}

.preview-button {
  margin-left: auto;
  min-height: 36px;
  pointer-events: none;
}

/* Five header buttons leave little room on phones: icon-only Share, no logo, smaller buttons. */
@media (max-width: 420px) {
  #share-open span {
    display: none;
  }

  .bar-inner {
    gap: 2px;
  }

  .bar-inner .icon-button,
  .bar-inner .lang-button,
  #share-open {
    width: 40px;
    height: 40px;
    min-height: 40px;
    padding: 0;
  }

  h1 {
    font-size: 1.05rem;
    line-height: 1.15;
  }

  /* The logo is decoration; the title needs the room. On the narrowest phones it wraps. */
  .brand img {
    display: none;
  }

  .brand,
  .brand span {
    white-space: normal;
  }
}

@media (max-width: 360px) {
  .bar-inner .icon-button,
  .bar-inner .lang-button,
  #share-open {
    width: 38px;
    height: 38px;
    min-height: 38px;
  }

  h1 {
    font-size: 0.95rem;
  }
}
