:root {
  --green: #1e9e5a;
  --green-dark: #157a44;
  --bg: #f4f5f2;
  --card: #ffffff;
  --text: #1c2321;
  --text-soft: #6b7570;
  --line: #e3e6e1;
  --danger: #d64545;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --tabbar-h: 62px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }

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

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: var(--radius);
  padding: 12px 18px;
  min-height: 44px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:active { background: var(--green-dark); }
.btn-ghost { background: transparent; color: var(--green); }
.btn-danger { background: transparent; color: var(--danger); }
.btn-block { display: block; width: 100%; }

/* ---------- Passphrase gate ---------- */
.gate {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}
.gate-box { width: 100%; max-width: 360px; text-align: center; }
.gate-logo { font-size: 56px; }
.gate h1 { margin: 8px 0 4px; }
.gate-hint { color: var(--text-soft); margin-top: 0; }
.gate input {
  width: 100%;
  padding: 14px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  font-size: 16px;
}
.gate-error { color: var(--danger); font-weight: 600; }

/* ---------- App shell ---------- */
.app { min-height: 100dvh; }

.demo-banner {
  background: #fff3cd;
  color: #7a5d00;
  font-size: 13px;
  text-align: center;
  padding: 8px 12px;
}

#main {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 14px calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 24px);
}

.view { animation: fadein 0.18s ease; }
@keyframes fadein {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 6px 0 14px;
}
.view-header h1 { margin: 0; font-size: 26px; }

.empty {
  color: var(--text-soft);
  text-align: center;
  margin-top: 48px;
}

.logout {
  margin-top: 28px;
  color: var(--text-soft);
  font-weight: 400;
  font-size: 14px;
}

/* ---------- Recipes ---------- */
.recipe-list { display: flex; flex-direction: column; gap: 10px; }

.recipe-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.recipe-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 16px;
  min-height: 56px;
  background: none;
  border: none;
  text-align: left;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}
.recipe-chevron {
  color: var(--text-soft);
  transition: transform 0.18s ease;
  flex-shrink: 0;
  margin-left: 8px;
}
.recipe-card.open .recipe-chevron { transform: rotate(180deg); }

.recipe-body {
  display: none;
  padding: 0 16px 14px;
  border-top: 1px solid var(--line);
  animation: fadein 0.15s ease;
}
.recipe-card.open .recipe-body { display: block; }

.recipe-body h3 {
  margin: 14px 0 6px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-soft);
}
.recipe-body ul { margin: 0; padding-left: 20px; }
.recipe-body li { margin: 4px 0; }
.recipe-instructions { white-space: pre-wrap; margin: 0; }

.recipe-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.recipe-actions .btn { padding: 10px 14px; }
.recipe-actions .to-list { flex: 1; min-width: 150px; }

/* ---------- Shopping list ---------- */
.item-form {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.item-form input {
  flex: 1;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  font-size: 16px;
  min-width: 0;
}

.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.item-list:empty { box-shadow: none; }

.item-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--line);
  animation: fadein 0.15s ease;
}
.item-row:last-child { border-bottom: none; }

.item-check {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
  padding: 13px 8px 13px 16px;
  background: none;
  border: none;
  text-align: left;
  font-size: 16px;
  cursor: pointer;
  min-height: 52px;
}
.item-box {
  width: 24px;
  height: 24px;
  border: 2px solid var(--line);
  border-radius: 8px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 15px;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.item-row.checked .item-box { background: var(--green); border-color: var(--green); }
.item-name {
  overflow-wrap: anywhere;
  transition: opacity 0.12s ease;
}
.item-row.checked .item-name {
  text-decoration: line-through;
  opacity: 0.45;
}
.item-delete {
  background: none;
  border: none;
  color: var(--text-soft);
  font-size: 20px;
  padding: 13px 16px;
  min-height: 52px;
  cursor: pointer;
}

#btn-clear-checked { margin-top: 14px; }

/* ---------- Saved links ---------- */
.saved-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}
.saved-form input {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  font-size: 16px;
}
.saved-link {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
  padding: 12px 8px 12px 16px;
  min-height: 52px;
  justify-content: center;
  text-decoration: none;
  color: var(--text);
}
.saved-link:active { background: var(--bg); }
.saved-title {
  font-weight: 600;
  overflow-wrap: anywhere;
}
.saved-host {
  font-size: 13px;
  color: var(--text-soft);
  overflow-wrap: anywhere;
}

/* ---------- Bottom tab bar ---------- */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  z-index: 20;
}
.tab {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 0 10px;
  min-height: var(--tabbar-h);
  background: none;
  border: none;
  color: var(--text-soft);
  cursor: pointer;
}
.tab.active { color: var(--green); }
.tab-icon { font-size: 22px; }
.tab-label { font-size: 12px; font-weight: 600; }
.tab-badge {
  position: absolute;
  top: 4px;
  left: calc(50% + 8px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--green);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------- Modal (recipe form) ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-sheet {
  background: var(--bg);
  width: 100%;
  max-width: 640px;
  max-height: 92dvh;
  border-radius: 18px 18px 0 0;
  display: flex;
  flex-direction: column;
  animation: slideup 0.22s ease;
}
@keyframes slideup {
  from { transform: translateY(40px); opacity: 0.5; }
  to { transform: none; opacity: 1; }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.modal-header h2 { margin: 0; font-size: 17px; }
.modal-body {
  overflow-y: auto;
  padding: 14px 16px calc(24px + env(safe-area-inset-bottom, 0px));
}
.modal-body label {
  display: block;
  margin-bottom: 14px;
  font-weight: 600;
  font-size: 14px;
}
.label-hint { font-weight: 400; color: var(--text-soft); }
.modal-body input,
.modal-body textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  font-size: 16px;
  resize: vertical;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px) + 14px);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 14px;
  background: #2b332f;
  color: #fff;
  padding: 12px 18px;
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  max-width: calc(100vw - 28px);
  animation: fadein 0.18s ease;
}
.toast-undo {
  background: none;
  border: none;
  color: #6fe0a8;
  font-weight: 700;
  cursor: pointer;
  padding: 4px;
  font-size: 15px;
}

/* ---------- Desktop tweaks ---------- */
@media (min-width: 700px) {
  .modal { align-items: center; }
  .modal-sheet { border-radius: 18px; max-height: 84vh; }
}
