:root {
  --bg: #f6f5f1;
  --surface: #ffffff;
  --text: #1d1f1b;
  --muted: #6c7068;
  --line: #e6e4dd;
  --accent: #2f7d4f;
  --accent-ink: #ffffff;
  --accent-soft: #e2efe6;
  --warn: #b3412e;
  --toast-bg: #1d1f1b;
  --toast-text: #f6f5f1;
  --toast-action: #9fd8b4;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.05), 0 4px 14px rgb(0 0 0 / 0.05);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141614;
    --surface: #1d201d;
    --text: #ecede8;
    --muted: #9a9f96;
    --line: #2b2f2b;
    --accent: #5fb583;
    --accent-ink: #0d1a12;
    --accent-soft: #1d3224;
    --warn: #e58a73;
    --toast-bg: #ecede8;
    --toast-text: #141614;
    --toast-action: #2f7d4f;
    --shadow: none;
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.app {
  max-width: 560px;
  margin: 0 auto;
  padding:
    calc(env(safe-area-inset-top) + 20px)
    calc(env(safe-area-inset-right) + 16px)
    calc(env(safe-area-inset-bottom) + 96px)
    calc(env(safe-area-inset-left) + 16px);
}

/* Header */
.title-row { display: flex; align-items: baseline; gap: 10px; }
.top h1 { margin: 0; font-size: 32px; font-weight: 700; letter-spacing: -0.02em; }
.count { color: var(--muted); font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums; }
.fridge-status {
  display: flex; align-items: center; gap: 7px;
  min-height: 20px; margin: 4px 0 0;
  color: var(--muted); font-size: 14px;
}
.dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--accent); }
.dot.warn { background: var(--warn); }

/* Add bar */
.add-form {
  position: sticky; top: 0; z-index: 2;
  display: flex; gap: 8px;
  margin: 12px -16px 8px; padding: 8px 16px;
  background: var(--bg);
}
.add-form input {
  flex: 1; min-width: 0; height: 50px; padding: 0 16px;
  font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); outline: none;
}
.add-form input::placeholder { color: var(--muted); }
.add-form input:focus { border-color: var(--accent); }
.add-button {
  flex: none; width: 50px; height: 50px; display: grid; place-items: center;
  border: 0; border-radius: 14px; background: var(--accent); color: var(--accent-ink);
}
.add-button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; }

.sync-banner {
  margin: 0 0 8px; padding: 9px 12px; border-radius: 10px;
  background: var(--accent-soft); font-size: 14px;
}

/* Lists */
.list {
  list-style: none; margin: 0; padding: 0;
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden;
}
.list:empty { display: none; }
.row { display: flex; align-items: center; min-height: 54px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row.pending { opacity: 0.55; }

.check {
  flex: none; width: 54px; height: 54px; display: grid; place-items: center;
  padding: 0; border: 0; background: none; color: var(--muted);
}
.check svg { width: 26px; height: 26px; }
.check .ring { fill: none; stroke: currentColor; stroke-width: 1.8; }
.check:active .ring { fill: var(--accent-soft); stroke: var(--accent); }

.label {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 8px;
  padding: 15px 16px 15px 0; border: 0; background: none; text-align: left; overflow-wrap: anywhere;
}
.voice-mark { flex: none; width: 15px; height: 15px; color: var(--muted); fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.edit {
  flex: 1; min-width: 0; height: 40px; margin: 7px 12px 7px 0; padding: 0 10px;
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--accent); border-radius: 9px; outline: none;
}

/* Recently bought */
.done-section { margin-top: 28px; }
.done-header { display: flex; align-items: center; justify-content: space-between; padding: 0 2px 6px; }
.done-toggle {
  display: flex; align-items: center; gap: 6px; padding: 8px 0;
  border: 0; background: none; color: var(--muted); font-size: 15px; font-weight: 600;
}
.chev { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: transform 0.15s ease; }
.done-toggle[aria-expanded="true"] .chev { transform: rotate(90deg); }
.text-button { padding: 8px; border: 0; background: none; color: var(--accent); font-size: 15px; font-weight: 600; }
.done-list .check { color: var(--accent); }
.done-list .label { color: var(--muted); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--muted) 60%, transparent); }

/* Empty state */
.empty { padding: 56px 24px; text-align: center; color: var(--muted); }
.empty-title { margin: 0 0 4px; color: var(--text); font-weight: 600; }
.empty-body { margin: 0; font-size: 15px; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 20px); z-index: 10;
  width: min(calc(100% - 32px), 528px); transform: translateX(-50%);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 13px 16px; border-radius: 14px;
  background: var(--toast-bg); color: var(--toast-text); font-size: 15px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.22);
}
.toast-undo { flex: none; padding: 4px 6px; border: 0; background: none; color: var(--toast-action); font-weight: 700; }

/* Login */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login-card h1 { margin: 4px 0 0; font-size: 28px; letter-spacing: -0.02em; }
.login-hint { margin: 0 0 8px; color: var(--muted); }
.login-icon { margin: 0 auto; border-radius: 16px; }
.login-card input {
  height: 50px; padding: 0 16px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; outline: none;
}
.login-card input:focus { border-color: var(--accent); }
.primary { height: 50px; border: 0; border-radius: 14px; background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.primary:disabled { opacity: 0.6; }
.login-error { margin: 0; color: var(--warn); font-size: 15px; }
