/* Paprika Recipe Generator — styled after Paprika Recipe Manager itself.
 *
 * Light is the base palette; the dark block below is the look in the reference
 * screenshot (near-black chrome, red accent, gold stars) and is what most phones
 * will show. Only the tokens change between them — no component rule is
 * duplicated per scheme. */

:root {
  --accent: #e02a20;          /* Paprika red */
  --accent-dim: #b3211a;
  --gold: #d8a01c;            /* rating stars */
  --bg: #f2f2f4;
  --bg-elevated: #ffffff;     /* top bar, sheets */
  --card: #ffffff;
  --card-empty: #e6e6ea;      /* image placeholder */
  --text: #16181d;
  --muted: #6b6f76;
  --border: #dcdce2;
  --error: #c0392b;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  --radius: 10px;
  --topbar-h: 52px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --accent: #f0332a;
    --accent-dim: #c2251d;
    --gold: #e0aa22;
    --bg: #0e0e0f;
    --bg-elevated: #1d1d1f;
    --card: #161617;
    --card-empty: #2a2a2d;
    --text: #f3f3f5;
    --muted: #8b8b93;
    --border: #2e2e33;
    --error: #ff6b5e;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  /* The FAB and radial arc live in the bottom-right; never let the page bounce
     horizontally because of them. */
  overflow-x: hidden;
}

button, input, select, textarea {
  font-family: inherit;
  /* 16px floor: iOS Safari auto-zooms the page on focus below it. */
  font-size: 16px;
  color: inherit;
}

button { cursor: pointer; }

.hidden { display: none !important; }

/* Keeps a file input laid out (iOS WebKit refuses to open a file dialog for a
   display:none / visibility:hidden input) while making it invisible. */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ------------------------- top bar ------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 6px;
  padding-top: env(safe-area-inset-top);
  height: calc(var(--topbar-h) + env(safe-area-inset-top));
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  flex: 1;
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  text-align: center;
  /* A long recipe title must clip, not push the buttons off the bar. */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.icon-btn {
  flex: none;
  width: 40px; height: 40px;
  display: grid;
  place-items: center;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--accent);
  padding: 0;
}
.icon-btn:disabled { color: var(--muted); opacity: 0.5; }
@media (hover: hover) {
  .icon-btn:hover { background: color-mix(in srgb, var(--accent) 12%, transparent); }
}
.icon-btn svg { width: 24px; height: 24px; display: block; }

.home-link {
  flex: none;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  padding: 0 8px;
  white-space: nowrap;
}

main { padding-bottom: 120px; }

/* ------------------------- library grid ------------------------- */

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  padding: 14px;
}
@media (min-width: 620px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) {
  .grid { grid-template-columns: repeat(4, 1fr); max-width: 1100px; margin: 0 auto; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  text-align: left;
  padding: 0;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}
@media (hover: hover) { .card:hover { border-color: var(--accent); } }

.card-img {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: var(--card-empty);
}
.card-img-empty {
  display: grid;
  place-items: center;
  color: var(--muted);
}
.card-img-empty svg { width: 46px; height: 46px; opacity: 0.65; }

.card-body { padding: 8px 10px 10px; }
.card-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.3;
  /* Two lines, then ellipsis — keeps every tile the same height. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.stars { margin-top: 3px; font-size: 13px; letter-spacing: 1px; color: var(--muted); }
.stars .on { color: var(--gold); }

.empty-state {
  padding: 64px 28px;
  text-align: center;
  color: var(--muted);
}
.empty-state strong { display: block; color: var(--text); font-size: 17px; margin-bottom: 6px; }

/* ------------------------- radial add menu ------------------------- */
/* Geometry mirrors Stash's RadialAddMenu: options 30 degrees apart on a 130px
   arc sweeping from straight up to straight left. The JS positions them; these
   rules only style them. */

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  width: 56px; height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  z-index: 40;
  transition: transform 0.15s ease;
  /* The long-press-and-drag gesture needs the browser to stop trying to scroll
     or text-select while a finger is down on the button. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.fab svg { width: 28px; height: 28px; }
.fab.open { transform: rotate(45deg); }

.radial-backdrop { position: fixed; inset: 0; z-index: 39; }

.radial-opt {
  position: fixed;
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--accent);
  display: grid;
  place-items: center;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  z-index: 41;
  transition: transform 0.12s ease, background 0.12s ease;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
.radial-opt svg { width: 22px; height: 22px; }
.radial-opt.active { background: var(--accent); border-color: var(--accent); color: #fff; transform: scale(1.12); }

.radial-label {
  position: fixed;
  z-index: 41;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 6px 12px;
  border-radius: 20px;
  white-space: nowrap;
  pointer-events: none;
}

/* ------------------------- full-screen flows ------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
}

.overlay-head {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}
.overlay-head span {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.overlay-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.overlay-foot {
  flex: none;
  display: flex;
  gap: 10px;
  padding: 12px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
}

.center-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 32px;
  text-align: center;
}

.preview-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
  margin: auto;
}

/* ------------------------- buttons ------------------------- */

.btn {
  flex: 1;
  padding: 13px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn svg { width: 19px; height: 19px; flex: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:disabled { background: var(--muted); border-color: var(--muted); opacity: 0.6; }
.btn-danger { color: var(--error); }
.btn-wide { width: 100%; flex: none; }
@media (hover: hover) {
  .btn:hover { border-color: var(--accent); }
  .btn-primary:hover { background: var(--accent-dim); }
}

.btn-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
}

/* ------------------------- source list (capture) ------------------------- */

.section-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 16px 14px 6px;
}

.source-list { padding: 0 14px; display: flex; flex-direction: column; gap: 8px; }

.source-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.source-thumb {
  flex: none;
  width: 46px; height: 46px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--card-empty);
  display: grid;
  place-items: center;
  color: var(--muted);
  border: none;
  padding: 0;
}
.source-thumb svg { width: 20px; height: 20px; }
.source-thumb.is-primary { outline: 2px solid var(--accent); outline-offset: 1px; }

.source-meta { flex: 1; min-width: 0; }
.source-name {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.source-sub { font-size: 12px; color: var(--muted); }

.field { padding: 6px 14px 14px; }
/* Direct child only. A <label class="btn"> that opens a file input lives inside
   .field > .row, and this rule would otherwise turn it into a 12px uppercase
   block — nothing like the sibling <button class="btn"> next to it. */
.field > label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.field input[type="text"],
.field input[type="password"],
.field select,
.field textarea {
  width: 100%;
  padding: 11px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
}
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field .hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; }

/* ------------------------- recorder ------------------------- */

.record-btn {
  width: 76px; height: 76px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
}
.record-btn.recording { background: var(--error); }
.record-btn svg { width: 32px; height: 32px; }

.timer {
  font-size: 30px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.level-meter {
  width: 180px; height: 4px;
  border-radius: 2px;
  background: var(--border);
  overflow: hidden;
}
.level-meter i { display: block; height: 100%; background: var(--accent); width: 0; }

/* ------------------------- recipe view ------------------------- */

.hero {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-height: 46vh;
  object-fit: cover;
  display: block;
  background: var(--card-empty);
}

.recipe-body { padding: 16px; max-width: 720px; margin: 0 auto; }

.rating-row { display: flex; align-items: center; gap: 4px; margin-bottom: 10px; }
.rating-row button {
  background: none;
  border: none;
  padding: 2px;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
}
.rating-row button.on { color: var(--gold); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip {
  font-size: 12.5px;
  padding: 4px 10px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
  border: none;
}

.warnings {
  border: 1px solid var(--border);
  border-left: 3px solid var(--gold);
  border-radius: var(--radius);
  background: var(--card);
  padding: 10px 12px;
  margin: 12px 0;
  font-size: 13.5px;
}
.warnings strong { display: block; margin-bottom: 4px; }
.warnings ul { margin: 0; padding-left: 18px; }

/* Rendered markdown — the same string the .md export produces. */
.md h1 { font-size: 24px; margin: 0 0 4px; line-height: 1.25; }
.md h2 {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 26px 0 8px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--border);
}
.md p { margin: 8px 0; }
.md ul, .md ol { margin: 8px 0; padding-left: 22px; }
.md li { margin: 5px 0; }
.md ol li { padding-left: 4px; }
.md em { color: var(--muted); font-style: normal; font-size: 13.5px; }
.md a { color: var(--accent); }
.md strong { font-weight: 700; }

/* ------------------------- share sheet ------------------------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet {
  width: 100%;
  max-width: 520px;
  background: var(--bg-elevated);
  border-radius: 16px 16px 0 0;
  padding: 8px 12px calc(12px + env(safe-area-inset-bottom));
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.3);
}
.sheet h2 {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
  margin: 8px 0 12px;
}
.sheet-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 12px;
  background: none;
  border: none;
  border-radius: var(--radius);
  text-align: left;
  font-size: 15.5px;
}
.sheet-item svg { width: 22px; height: 22px; color: var(--accent); flex: none; }
.sheet-item small { display: block; color: var(--muted); font-size: 12.5px; font-weight: 400; }
.sheet-item b { font-weight: 600; }
@media (hover: hover) { .sheet-item:hover { background: var(--bg); } }

/* ------------------------- status / toast ------------------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 80;
  max-width: min(92vw, 460px);
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: 14px;
  box-shadow: var(--shadow);
}
.toast.error { border-left-color: var(--error); }
.toast .req { display: block; margin-top: 4px; font-size: 11px; color: var(--muted); }

.busy {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 40px;
  color: var(--muted);
  text-align: center;
}

.spin {
  width: 26px; height: 26px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ------------------------- settings ------------------------- */

.cat-list { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 14px 8px; }
.cat-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  padding: 6px 8px 6px 12px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
}
.cat-tag button {
  background: none;
  border: none;
  padding: 0 2px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
}
.row { display: flex; gap: 8px; align-items: stretch; }
.row input { flex: 1; min-width: 0; }
.row .btn { flex: none; padding: 11px 16px; }

.key-status { font-size: 13px; color: var(--muted); padding: 0 14px 10px; }
.key-status.ok { color: var(--accent); }
