:root {
  --accent: #ff7e5f;
  --accent-2: #feb47b;
  --bg: #fdf6f1;
  --card: #ffffff;
  --text: #33261f;
  --text-light: #7a6a60;
  --border: #eee0d6;
  --danger: #d64545;
  --radius: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  padding-bottom: 2rem;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.1rem calc(1rem + env(safe-area-inset-top, 0px)) 1.1rem;
  padding-top: 1rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
}

.topbar h1 {
  font-size: 1.25rem;
  margin: 0;
}

.view {
  max-width: 640px;
  margin: 0 auto;
  padding: 1rem 1.1rem 3rem 1.1rem;
}

.toolbar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
}

#searchInput {
  flex: 1;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 1rem;
  background: var(--card);
}

.chips {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.6rem;
  margin-bottom: 0.6rem;
}

.chip {
  flex: 0 0 auto;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  white-space: nowrap;
}

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.recipe-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.8rem;
}

.recipe-card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  text-align: left;
}

.recipe-card .thumb {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: linear-gradient(135deg, #ffe3d2, #ffd0b3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.2rem;
}

.recipe-card .info {
  padding: 0.6rem 0.7rem 0.8rem 0.7rem;
}

.recipe-card h3 {
  font-size: 0.98rem;
  margin: 0 0 0.3rem 0;
  line-height: 1.25;
}

.recipe-card .badge {
  display: inline-block;
  font-size: 0.72rem;
  color: var(--accent);
  background: #fff1e8;
  border-radius: 999px;
  padding: 0.15rem 0.55rem;
}

.empty-state {
  text-align: center;
  color: var(--text-light);
  margin-top: 3rem;
  line-height: 1.5;
}

.icon-btn {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.25);
  color: #fff;
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn.primary {
  background: #fff;
  color: var(--accent);
  font-weight: 700;
}

.icon-btn.danger {
  background: rgba(255,255,255,0.25);
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 0.65rem 1rem;
  font-size: 0.95rem;
  cursor: pointer;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn.small {
  padding: 0.5rem 0.8rem;
  font-size: 0.88rem;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.btn.accent {
  background: #fff1e8;
  border-color: var(--accent-2);
  color: var(--accent);
  font-weight: 600;
}

.btn.ghost {
  background: transparent;
}

.btn.wide {
  width: 100%;
  margin-top: 1.2rem;
  padding: 0.85rem;
  font-size: 1.02rem;
}

.editor-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: -1rem -1.1rem 1rem -1.1rem;
  padding: 0.8rem 1.1rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
}

.editor-header h2 {
  flex: 1;
  font-size: 1.05rem;
  margin: 0;
}

.photo-area {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  margin-bottom: 1rem;
  text-align: center;
}

#photoPreview {
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  border-radius: 10px;
  margin-bottom: 0.7rem;
}

.photo-placeholder {
  padding: 2.2rem 1rem;
  color: var(--text-light);
  background: #fff8f3;
  border-radius: 10px;
  margin-bottom: 0.7rem;
}

.photo-buttons {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: center;
}

.ocr-progress {
  margin-top: 0.8rem;
}

.ocr-bar {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: #f1e3d7;
  overflow: hidden;
}

.ocr-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s ease;
}

#ocrStatus {
  display: block;
  margin-top: 0.35rem;
  font-size: 0.82rem;
  color: var(--text-light);
}

.field-label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-light);
  margin: 1rem 0 0.3rem 0;
  font-weight: 600;
}

#titleInput, #categorySelect, textarea {
  width: 100%;
  padding: 0.65rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  font-size: 1rem;
  color: var(--text);
  font-family: inherit;
  resize: vertical;
}

.install-banner {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  justify-content: space-between;
  background: #fff1e8;
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 1.1rem;
  font-size: 0.85rem;
  color: var(--text);
}

.install-actions {
  display: flex;
  gap: 0.4rem;
  flex: 0 0 auto;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 20;
}


.modal-card {
  background: var(--bg);
  width: 100%;
  max-width: 640px;
  border-radius: 18px 18px 0 0;
  padding: 1.2rem 1.1rem calc(1.2rem + env(safe-area-inset-bottom, 0px)) 1.1rem;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-card h3 {
  margin-top: 0;
}

.cat-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem 0;
}

.cat-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.2rem;
  border-bottom: 1px solid var(--border);
}

.cat-list .remove-cat {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.2rem 0.5rem;
}

.add-cat-row {
  display: flex;
  gap: 0.5rem;
}

.add-cat-row input {
  flex: 1;
  padding: 0.6rem 0.8rem;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.toast {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: 999px;
  font-size: 0.88rem;
  z-index: 30;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1614;
    --card: #2a211d;
    --text: #f3e9e2;
    --text-light: #baa89b;
    --border: #3c2f29;
  }
  .photo-placeholder { background: #241b17; }
  .recipe-card .badge { background: #3a2a20; }
  .install-banner { background: #2a211d; }
}
