/* Nordic minimal — light by default, dark follows the system setting. */
:root {
  color-scheme: light dark;
  --bg: #f7f7f4;
  --surface: #ffffff;
  --ink: #1d1f1e;
  --muted: #6c706d;
  --border: #e3e3de;
  --accent: #2f5d50;
  --accent-ink: #ffffff;
  --accent-soft: #e6eeea;
  --danger: #a33a2f;
  --placeholder: #e9e9e4;
  --backdrop: rgba(20, 22, 21, 0.45);
  --radius: 10px;
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141615;
    --surface: #1c1f1e;
    --ink: #e9ebe8;
    --muted: #9ba19d;
    --border: #2d3230;
    --accent: #8fc0ab;
    --accent-ink: #10201a;
    --accent-soft: #22302b;
    --danger: #e0857a;
    --placeholder: #252927;
    --backdrop: rgba(0, 0, 0, 0.6);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

.hidden { display: none !important; }

/* Header */

header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 20px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}

header h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.header-actions {
  display: flex;
  gap: 8px;
}

/* Buttons */

button {
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 16px;
  min-height: 40px;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

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

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
.recipe-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

button.primary:hover { filter: brightness(1.08); }

button.danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
}

button:disabled { opacity: 0.6; cursor: default; }

/* Recipe list */

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 20px 72px;
}

.recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 32px 24px;
}

.recipe-card {
  cursor: pointer;
  border-radius: var(--radius);
}

.recipe-card .card-img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: var(--radius);
  background: var(--placeholder);
  transition: opacity 0.15s ease;
}

.recipe-card .card-img.placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  font-weight: 300;
  color: var(--muted);
  text-transform: uppercase;
}

.recipe-card:hover .card-img { opacity: 0.9; }

.recipe-card .card-body {
  padding: 12px 2px 0;
}

.recipe-card h3 {
  margin: 0 0 4px;
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.3;
}

.recipe-card p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.muted { color: var(--muted); }
.hint { font-weight: 400; color: var(--muted); font-size: 0.8rem; }

#emptyState {
  grid-column: 1 / -1;
  text-align: center;
  padding: 48px 0;
}

/* Modals — centered dialog on desktop, full-screen sheet on phones */

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--backdrop);
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface);
  border-radius: 14px;
  padding: 32px;
}

.close {
  position: sticky;
  top: 0;
  float: right;
  z-index: 1;
  width: 40px;
  height: 40px;
  min-height: 0;
  padding: 0;
  margin: -12px -12px 0 8px;
  border: none;
  border-radius: 50%;
  background: var(--surface);
  font-size: 1.6rem;
  font-weight: 300;
  line-height: 1;
  color: var(--muted);
}

.close:hover { color: var(--ink); background: var(--accent-soft); }

@media (max-width: 640px) {
  .modal { padding: 0; align-items: stretch; }
  .modal-content {
    max-width: none;
    max-height: none;
    height: 100%;
    border-radius: 0;
    padding: 20px;
    padding-top: calc(20px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(32px + env(safe-area-inset-bottom, 0px));
  }
}

/* Recipe view — optimized for reading while cooking */

#viewBody img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border-radius: var(--radius);
  margin: 0 0 24px;
  background: var(--placeholder);
}

#viewBody h2 {
  margin: 0 0 8px;
  font-size: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

#viewBody > p {
  margin: 0;
  color: var(--muted);
}

#viewBody h3 {
  margin: 32px 0 12px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

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

#viewBody ul li {
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

#viewBody ul li:last-child { border-bottom: none; }

#viewBody ol {
  list-style: none;
  counter-reset: step;
  margin: 0;
  padding: 0;
}

#viewBody ol li {
  counter-increment: step;
  position: relative;
  padding: 0 0 20px 44px;
}

#viewBody ol li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
}

.view-actions {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
}

/* Form */

#formTitle {
  margin: 0 0 24px;
  font-size: 1.4rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

form label {
  display: block;
  margin-bottom: 18px;
  font-size: 0.85rem;
  font-weight: 600;
}

form input[type="text"],
form textarea,
form input[type="file"] {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 11px 12px;
  font: inherit;
  font-size: 1rem; /* ≥16px stops iOS from zooming on focus */
  font-weight: 400;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

form textarea { resize: vertical; }

form input[type="file"] { padding: 9px; font-size: 0.9rem; }

.preview {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 8px;
  margin-bottom: 18px;
}

.form-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 8px;
}

.form-actions .primary { margin-left: auto; }
