:root {
  --background: #101418;
  --surface: #1a2026;
  --surface-hover: #232b33;
  --foreground: #e6edf3;
  --muted: #8b98a5;
  --accent: #7ee0a3;
  --accent-strong: #58c981;
  --danger: #e06c6c;
  --border: #2b343d;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--background);
  color: var(--foreground);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  line-height: 1.5;
}

.app {
  max-width: 760px;
  margin: 0 auto;
  padding: 3rem 1.25rem 5rem;
}

header { margin-bottom: 2rem; }

.lang-toggle-row {
  display: flex;
  justify-content: flex-end;
  margin-bottom: .75rem;
}

.lang-toggle-row .lang-toggle {
  padding: .3rem .7rem;
  font-size: .82rem;
}

.header-actions {
  display: flex;
  justify-content: space-between;
  gap: .6rem;
  margin-top: .7rem;
}

.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.8rem 1.6rem;
}

.auth-card h1 { font-size: 1.6rem; }

.auth-form { display: flex; flex-direction: column; gap: 1rem; margin-top: 1.2rem; }

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  font-size: .9rem;
  color: var(--muted);
  font-weight: 600;
}

.auth-form button { align-self: flex-start; }

.eyebrow {
  margin: 0 0 .35rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: .78rem;
  color: var(--accent);
  font-weight: 600;
}

h1 {
  margin: 0 0 .35rem;
  font-size: 2.2rem;
  letter-spacing: -.02em;
}

.subtitle { margin: 0; color: var(--muted); }

h2 { font-size: 1.15rem; margin: 0 0 1rem; }

section.controls, section.recipes {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem;
  margin-bottom: 1.5rem;
}

.config-banner {
  background: #3a2a1a;
  border: 1px solid #6b4a22;
  color: #f0c98a;
  border-radius: var(--radius);
  padding: .8rem 1rem;
  margin-bottom: 1.5rem;
  font-size: .92rem;
}
.config-banner code { background: #00000033; padding: .1em .4em; border-radius: 4px; }

.recipe-form { display: flex; flex-direction: column; gap: 1rem; }

.recipe-form label {
  display: flex;
  flex-direction: column;
  gap: .4rem;
  font-size: .9rem;
  color: var(--muted);
  font-weight: 600;
}

input, textarea {
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--foreground);
  padding: .6rem .7rem;
  font: inherit;
  resize: vertical;
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-strong);
}

.actions { display: flex; gap: .6rem; }

button {
  background: var(--accent-strong);
  color: #0c1410;
  border: none;
  border-radius: 8px;
  padding: .55rem 1.1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

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

button.secondary {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

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

button.danger { background: transparent; color: var(--danger); border: 1px solid var(--border); }
button.danger:hover { border-color: var(--danger); }

.form-group { display: flex; flex-direction: column; gap: .6rem; }
.form-group h3 { margin: .4rem 0 0; font-size: .95rem; }

.row {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .6rem;
}

.row > input { flex: 1 1 150px; }
.row .row-section { flex: 1 1 110px; }
.row .row-duration { flex: 0 1 130px; }
.row textarea { flex-basis: 100%; }
.row .row-media { flex: 1 1 100%; display: flex; flex-wrap: wrap; gap: .4rem; }

.row .row-actions { display: flex; gap: .3rem; margin-left: auto; }
.row .row-actions button { padding: .3rem .6rem; font-size: .85rem; }

.file-label {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-size: .8rem;
  color: var(--muted);
  cursor: pointer;
  font-weight: 600;
}
.file-label input[type=file] { max-width: 200px; }

.media-previews { display: flex; flex-wrap: wrap; gap: .5rem; }

.media-preview { position: relative; margin: 0; }
.media-preview img, .media-preview video {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: 6px;
  display: block;
  background: #000;
}
.media-preview video { object-fit: contain; }
.media-preview button.remove-media {
  position: absolute;
  top: 2px;
  right: 2px;
  padding: 0 6px;
  font-size: .8rem;
  background: #000000b3;
  color: #fff;
  border: 1px solid #ffffff55;
}
.media-preview button.remove-media:hover { background: var(--danger); color: #fff; }

.recipes-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.recipes-header h2 { margin: 0; }

.recipes-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: .5rem 0 1rem;
}

.recipes-toolbar .count { margin: 0; }

.sort,
.page-size {
  display: flex;
  align-items: center;
  gap: .4rem;
  color: var(--muted);
  font-size: .85rem;
  font-weight: 600;
}

.sort select,
.page-size select {
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--foreground);
  padding: .35rem .5rem;
  font: inherit;
}

.search-wrap { position: relative; }

#search { width: 180px; padding-right: 26px; }
#search::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }

.search-clear {
  position: absolute;
  top: 50%;
  right: 5px;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.search-clear:hover { color: var(--foreground); background: var(--surface-hover); }

.count { color: var(--muted); font-size: .85rem; margin: .5rem 0 1rem; }

.recipe-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .9rem; }

.recipe {
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}

.recipe:hover { border-color: var(--surface-hover); }

.recipe h3 { margin: 0 0 .35rem; font-size: 1.1rem; }

.recipe .meta { color: var(--muted); font-size: .8rem; margin-bottom: .6rem; }

.recipe section { margin-bottom: .6rem; }

.recipe h4 {
  margin: 0 0 .25rem;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent);
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: .6rem;
  margin: .4rem 0 .8rem;
}

.media-item { margin: 0; }
.media-item img, .media-item video { cursor: zoom-in; }

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: #000000cc;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  cursor: zoom-out;
}

.lightbox img, .lightbox video {
  max-width: 100%;
  max-height: 92vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 8px 40px #0008;
  background: #000;
  cursor: default;
}

.lightbox-close {
  position: fixed;
  top: .75rem;
  right: .9rem;
  z-index: 201;
  font-size: 2rem;
  line-height: 1;
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  opacity: .85;
  padding: .25rem .5rem;
}
.lightbox-close:hover { opacity: 1; }
.media-item img, .media-item video {
  width: 100%;
  max-height: 240px;
  object-fit: cover;
  display: block;
  background: #000;
  border-radius: 8px;
}
.media-item video { object-fit: contain; }

.media-inline { display: inline-flex; gap: .3rem; margin-right: .3rem; vertical-align: middle; }
.media-inline img, .media-inline video { width: 40px; height: 40px; object-fit: cover; border-radius: 4px; display: block; background: #000; }

.ingredient-list, .cookware-list { margin: .3rem 0 0; padding-left: 1.1rem; }
.ingredient-list li, .cookware-list li { margin-bottom: .15rem; }

.section-heading {
  list-style: none;
  margin-top: .5rem;
  margin-left: -1.1rem;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--accent);
  font-weight: 600;
}

.ingredient-list .amount { font-weight: 600; }

.muted-note { color: var(--muted); }

.step-list { list-style: none; margin: .3rem 0 0; padding: 0; counter-reset: step; }

.step-list li { display: flex; gap: .6rem; margin-bottom: .6rem; }

.step-num {
  flex: 0 0 1.6rem;
  height: 1.6rem;
  border-radius: 50%;
  background: var(--accent-strong);
  color: #0c1410;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: .85rem;
  font-weight: 600;
}

.step-body { flex: 1; }
.step-body p { margin: 0 0 .2rem; }
.step-text { white-space: pre-wrap; }
.step-duration { color: var(--muted); font-size: .8rem; }
.step-note { color: var(--muted); font-style: italic; font-size: .9rem; }

.recipe .notes {
  margin: .4rem 0 0;
  color: var(--muted);
  font-style: italic;
  white-space: pre-wrap;
}

.recipe .actions { margin-top: .8rem; }

.recipe .actions button.delete {
  background: transparent;
  color: var(--danger);
  border: 1px solid transparent;
}

.recipe .actions button.delete:hover { border-color: var(--danger); }

.status { color: var(--accent); font-size: .9rem; margin-top: 1rem; }
.status.error { color: var(--danger); }

.empty { color: var(--muted); }

.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  justify-content: center;
  margin-top: 1.2rem;
}

.pagination .page-btn {
  min-width: 2rem;
  padding: .35rem .6rem;
  font-size: .85rem;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.pagination .page-btn:hover:not(:disabled):not(.active) {
  color: var(--foreground);
  border-color: var(--muted);
}

.pagination .page-btn.active {
  background: var(--accent-strong);
  color: #0c1410;
  border-color: var(--accent-strong);
}

.pagination .page-btn:disabled { opacity: .45; cursor: default; }

.pagination .page-ellipsis { align-self: center; color: var(--muted); padding: 0 .1rem; }

/* Tags */

.tag-chips { display: flex; flex-wrap: wrap; gap: .4rem; }

.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: .1rem .55rem;
  font-size: .8rem;
  color: var(--foreground);
}

.tag-chip button.tag-remove {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  padding: 0 .15rem;
  cursor: pointer;
}

.tag-chip button.tag-remove:hover { color: var(--danger); }

.tag-chip.static { cursor: default; }

#tag-picker-selected { margin-top: -.2rem; }

.tag-list { margin: 0 0 .6rem; display: flex; flex-wrap: wrap; gap: .3rem; }

.recipes-header-actions { display: flex; align-items: center; gap: .5rem; }

.tag-filter {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem;
  margin: .6rem 0;
}

.tag-filter-label { color: var(--muted); font-size: .85rem; }

/* Tag picker modal */

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #00000099;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

.modal-panel {
  width: 100%;
  max-width: 420px;
  max-height: 82vh;
  display: flex;
  flex-direction: column;
  gap: .8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem;
}

.modal-header { display: flex; align-items: center; justify-content: space-between; }
.modal-header h2 { margin: 0; }
.modal-actions { display: flex; justify-content: flex-end; }

#add-recipe-section.controls {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: #00000099;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  margin: 0;
  border: none;
  border-radius: 0;
  overflow-y: auto;
}

.add-recipe-panel {
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  gap: .8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.4rem;
  overflow-y: auto;
}

.tag-picker-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  min-height: 140px;
  max-height: 50vh;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.tag-picker-list li { border-bottom: 1px solid var(--border); }
.tag-picker-list li:last-child { border-bottom: none; }

.tag-picker-item {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .45rem .6rem;
  font-size: .9rem;
  cursor: pointer;
}

.tag-picker-item:hover { background: var(--surface-hover); }
.tag-picker-item .tag-name { flex: 1; }
.tag-picker-item .tag-count { color: var(--muted); font-size: .78rem; }

.tag-picker-item .tag-actions {
  display: inline-flex;
  align-items: center;
  gap: .15rem;
}

.tag-picker-item button.tag-edit,
.tag-picker-item button.tag-delete {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 4px;
  padding: .1rem .3rem;
  font-size: .8rem;
  font-weight: 400;
  line-height: 1.2;
}

.tag-picker-item button.tag-edit:hover { color: var(--foreground); border-color: var(--border); }
.tag-picker-item button.tag-delete { color: var(--danger); }
.tag-picker-item button.tag-delete:hover { border-color: var(--danger); }

/* Recycle bin */

.recycle-bin-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: .4rem .55rem;
}

.recycle-bin-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  min-height: 120px;
  max-height: 50vh;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.recycle-bin-item {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .5rem;
  padding: .6rem;
  border-bottom: 1px solid var(--border);
}

.recycle-bin-item:last-child { border-bottom: none; }

.recycle-bin-item .bin-title { flex: 1; font-weight: 600; }
.recycle-bin-item .bin-meta { color: var(--muted); font-size: .78rem; }
.recycle-bin-item .bin-actions { display: inline-flex; gap: .4rem; }
.recycle-bin-item .bin-actions button { padding: .35rem .7rem; font-size: .85rem; }

.recycle-bin-panel button:disabled { opacity: .45; cursor: default; }
.recycle-bin-panel button:disabled:hover { background: var(--accent-strong); }
.recycle-bin-panel button.secondary:disabled:hover { background: transparent; border-color: var(--border); color: var(--muted); }
.recycle-bin-panel button.danger:disabled:hover { border-color: var(--border); }

.hidden { display: none !important; }

.back-to-top {
  position: fixed;
  bottom: 1.2rem;
  right: 1.2rem;
  z-index: 50;
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 50%;
  padding: 0;
  font-size: 1.15rem;
  line-height: 1;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .4);
}

/* Responsive & mobile */

html { -webkit-text-size-adjust: 100%; }
* { -webkit-tap-highlight-color: transparent; }

.auth-screen { min-height: 100vh; min-height: 100dvh; }
.row > input, .row .row-section, .row .row-duration { min-width: 0; }

@media (pointer: coarse) {
  button, .sort select, .page-size select, .tag-picker-item { min-height: 44px; }
  .row .row-actions button { min-height: 40px; padding: .4rem .75rem; }
  .tag-chip button.tag-remove { min-width: 40px; min-height: 40px; }
  input, textarea, select { font-size: 16px; }
}

@media (max-width: 640px) {
  .app { padding: 1.5rem 1rem calc(4rem + env(safe-area-inset-bottom)); }
  h1 { font-size: 1.8rem; }
  section.controls, section.recipes { padding: 1.1rem; }

  .recipes-header { flex-wrap: wrap; gap: .6rem; }
  .recipes-header-actions { width: 100%; }
  .search-wrap { width: 100%; }
  #search { width: 100%; }

  .recipes-toolbar { flex-wrap: wrap; gap: .5rem; }
  .recipes-toolbar .sort { margin-left: auto; }

  .modal { padding: 0; align-items: stretch; }
  .modal-panel {
    width: 100%;
    max-width: none;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    padding: 1.1rem;
  }
  .tag-picker-list { flex: 1; max-height: none; }
  .recycle-bin-list { flex: 1; max-height: none; }

  .back-to-top {
    bottom: calc(.8rem + env(safe-area-inset-bottom));
    right: calc(.8rem + env(safe-area-inset-right));
  }
}

@media (orientation: landscape) and (max-height: 480px) {
  .modal { padding: 0; align-items: stretch; }
  .modal-panel {
    width: 100%;
    height: 100dvh;
    max-height: 100dvh;
    border-radius: 0;
    padding: 1rem;
  }
  .tag-picker-list { flex: 1; max-height: none; }
  .recycle-bin-list { flex: 1; max-height: none; }
}

@media (orientation: portrait) and (max-width: 640px) {
  .recipe .actions { flex-direction: column; }
  .recipes-header-actions { flex-direction: column; align-items: stretch; }
}
