:root {
  --bg: #f5f0e1;
  --surface: #fffdf8;
  --ink: #1c1915;
  --muted: #4a453e;
  --accent: #b85c2e;
  --accent-dim: #8f4320;
  --border: #e3d8c8;
  --sand: #d4c4a8;
  --danger: #9b2c2c;
  --ok: #2f6a3e;
  --radius: 16px;
  --shadow: 0 8px 24px rgba(28, 25, 21, 0.06);
  --focus: 0 0 0 3px rgba(184, 92, 46, 0.35);
  --pad: max(16px, env(safe-area-inset-left, 0px));
  --pad-r: max(16px, env(safe-area-inset-right, 0px));
  --pad-t: max(12px, env(safe-area-inset-top, 0px));
  --pad-b: max(20px, env(safe-area-inset-bottom, 0px));
}

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

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  overscroll-behavior: contain;
}

h1, h2, h3 { margin: 0; line-height: 1.25; letter-spacing: -0.02em }
h1 { font-size: 1.75rem; font-weight: 700 }
h2 { font-size: 1.25rem; font-weight: 650 }
h3 { font-size: 1.05rem; font-weight: 650; margin: 1.1rem 0 0.4rem }

.page {
  max-width: 1120px;
  margin: 0 auto;
  padding: var(--pad-t) var(--pad-r) var(--pad-b) var(--pad);
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 8px;
  background: var(--accent);
  color: #fff;
  padding: 10px 14px;
  border-radius: 999px;
  z-index: 80;
}
.skip-link:focus { left: 12px }

.top {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 10;
}

.brand { margin-bottom: 12px }
.muted { color: var(--muted); font-size: 1rem }
.field-label {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
  margin: 10px 0 6px;
}
.auth .field-label { margin-top: 0 }

input, select, textarea, button { font: inherit }
input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--ink);
  border-radius: 12px;
  padding: 12px 14px;
  min-height: 44px;
}
textarea { min-height: 120px; resize: vertical }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

button {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 10px 16px;
  min-height: 44px;
  min-width: 44px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
  transition: background-color 180ms ease, border-color 180ms ease, color 180ms ease;
}
button:hover { background: #f3ebe1 }
button:disabled { opacity: 0.6; cursor: not-allowed }
#connectBtn, #saveBtn, #importUrlGo, #importPasteGo {
  background: var(--accent);
  border-color: var(--accent-dim);
  color: #fff;
}
#connectBtn:hover, #saveBtn:hover, #importUrlGo:hover, #importPasteGo:hover {
  background: var(--accent-dim);
}
.secondary { background: #fff; color: var(--ink) }
.danger { border-color: #e8b4b4; color: var(--danger); background: #fff }

.password-row { display: flex; gap: 8px; align-items: center }
.password-row input { flex: 1 }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-radius: 12px;
  color: var(--muted);
}
.remember {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
  color: var(--muted);
}
.remember input { width: auto; min-height: 22px; padding: 0; margin: 0 }
.auth #connectBtn { width: 100%; margin-top: 4px }

.actions, .filter-row, .drawer-bar, .drawer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.actions { margin-top: 4px }
.grow { flex: 1; min-width: 140px }

.status { min-height: 1.3em; margin: 10px 0 0; color: var(--ok); font-weight: 550 }
.status.err { color: var(--danger) }

.filters {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 16px;
  margin-bottom: 14px;
}
.filter-row { margin-top: 10px }
.filter-row select { flex: 1; min-width: 140px }

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.item {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0 0 12px;
  overflow: hidden;
  box-shadow: var(--shadow);
  color: inherit;
  border-radius: var(--radius);
}
.item:hover { background: var(--surface); border-color: var(--sand) }
.item h3 { padding: 0 14px; margin: 10px 0 4px; font-size: 1.12rem }
.item .muted { padding: 0 14px }
.item .pills { padding: 0 14px }

.thumb {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  background: #ede6dc;
  display: block;
  border: 0;
}
.pill {
  display: inline-block;
  margin: 6px 6px 0 0;
  padding: 4px 10px;
  border-radius: 999px;
  background: #ede6dc;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}
.empty {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
}

.hidden, [hidden] { display: none !important }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(28, 25, 21, 0.35);
  z-index: 30;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(760px, 100vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -12px 0 48px rgba(0, 0, 0, 0.12);
  z-index: 40;
}
.drawer-body {
  height: 100%;
  overflow: auto;
  padding: 14px var(--pad-r) var(--pad-b) var(--pad);
}
.drawer-bar {
  position: sticky;
  top: 0;
  background: var(--surface);
  padding-bottom: 10px;
  z-index: 2;
  gap: 8px;
}
.drawer-actions { margin-top: 14px }
#cookPane ul, #cookPane ol { padding-left: 1.2rem }
#cookPane li { margin: 0.35rem 0 }
.cook-ingredient-section {
  list-style: none;
  margin-left: -1.2rem;
  margin-top: 0.85rem;
  font-weight: 700;
}

.import-shell {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(28, 25, 21, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
}
.import-card {
  width: min(520px, 100%);
  max-height: 85vh;
  overflow: auto;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 16px;
  margin-bottom: env(safe-area-inset-bottom, 0);
  box-shadow: var(--shadow);
}
.import-copy { margin: 0 0 10px }
.import-tabs { display: flex; gap: 8px; margin: 8px 0 4px; flex-wrap: wrap }
.import-tabs button { border-radius: 12px }
.import-tabs button.active {
  background: var(--accent);
  border-color: var(--accent-dim);
  color: #fff;
}

body.noscroll { overflow: hidden }

@media (min-width: 720px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)) }
  .auth #connectBtn { width: auto }
  .password-row { max-width: 420px }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition: none !important;
    animation: none !important;
  }
}
