/* The Content Pantry — styles follow Jade Mc Neil's DESIGN.md:
   forest green, warm cream and brown; editorial serif headings; pill buttons; flat, no shadows. */

@font-face { font-family: "Silver Editorial"; src: url(fonts/silver-editorial-regular.woff2) format("woff2"), url(fonts/silver-editorial-regular.woff) format("woff"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Silver Editorial"; src: url(fonts/silver-editorial-italic.woff2) format("woff2"), url(fonts/silver-editorial-italic.woff) format("woff"); font-weight: 400; font-style: italic; font-display: swap; }
@font-face { font-family: "Avenir Pro"; src: url(fonts/avenir-pro-light.woff2) format("woff2"), url(fonts/avenir-pro-light.woff) format("woff"); font-weight: 300; font-style: normal; font-display: swap; }
@font-face { font-family: "Avenir Pro"; src: url(fonts/avenir-pro-medium.woff2) format("woff2"), url(fonts/avenir-pro-medium.woff) format("woff"); font-weight: 500; font-style: normal; font-display: swap; }

:root {
  --bg: #f7f2ef;
  --surface: #ffffff;
  --surface-2: #efe7e1;
  --sage: #d1d3c7;
  --text: #2c1b0d;
  --muted: #76685b;
  --primary: #092f05;
  --on-primary: #ffffff;
  --accent: #717d4e;
  --chip: #ebe3dc;
  --chip-on: #092f05;
  --chip-on-text: #ffffff;
  --danger: #8a2c1b;
  --rec: #b3261e;
  --serif: "Silver Editorial", "Cormorant Garamond", Georgia, serif;
  --sans: "Avenir Pro", "DM Sans", -apple-system, system-ui, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d160b; --surface: #152012; --surface-2: #1f2c1b; --sage: #26331f;
    --text: #f3ede8; --muted: #aaa497; --primary: #f7f2ef; --on-primary: #092f05;
    --accent: #aab684; --chip: #22301e; --chip-on: #d1d3c7; --chip-on-text: #092f05;
    --danger: #e8a08b; --rec: #ff7b6e; color-scheme: dark;
  }
  :root:not([data-theme="light"]) .logo-light { display: none; }
  :root:not([data-theme="light"]) .logo-dark { display: block; }
}
:root[data-theme="dark"] {
  --bg: #0d160b; --surface: #152012; --surface-2: #1f2c1b; --sage: #26331f;
  --text: #f3ede8; --muted: #aaa497; --primary: #f7f2ef; --on-primary: #092f05;
  --accent: #aab684; --chip: #22301e; --chip-on: #d1d3c7; --chip-on-text: #092f05;
  --danger: #e8a08b; --rec: #ff7b6e; color-scheme: dark;
}
:root[data-theme="dark"] .logo-light { display: none; }
:root[data-theme="dark"] .logo-dark { display: block; }

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: var(--sans); font-weight: 300; font-size: 16px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
body.locked { overflow: hidden; }
p { margin: 0; }
strong, b { font-weight: 500; }
.ic { width: 20px; height: 20px; flex: none; }
.muted { color: var(--muted); }
.sm { font-size: 13px; }

/* ---------- Layout ---------- */
#app { display: flex; min-height: 100vh; min-height: 100dvh; }
main {
  flex: 1; min-width: 0; width: 100%; max-width: 880px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 22px) 16px calc(110px + env(safe-area-inset-bottom));
}
.sidebar { display: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around; align-items: center;
  background: var(--surface); padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
}
.nav-btn {
  appearance: none; border: 0; background: none; color: var(--muted); cursor: pointer;
  font: 500 11px/1.2 var(--sans); display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 8px; border-radius: 14px; min-width: 56px;
}
.nav-btn .ic { width: 22px; height: 22px; }
.nav-btn.active { color: var(--primary); }
.tabbar .nav-add {
  background: var(--primary); color: var(--on-primary); width: 54px; height: 54px; border-radius: 50%;
  padding: 0; justify-content: center; margin-top: -22px;
}
.tabbar .nav-add span { display: none; }
.tabbar .nav-add .ic { width: 26px; height: 26px; }

@media (min-width: 900px) {
  .tabbar { display: none; }
  .sidebar {
    display: flex; flex-direction: column; gap: 4px; width: 250px; flex: none;
    position: sticky; top: 0; height: 100vh; padding: 28px 18px; background: var(--surface);
  }
  .sidebar .nav-btn { flex-direction: row; font-size: 15px; gap: 12px; padding: 12px 16px; width: 100%; justify-content: flex-start; }
  .sidebar .nav-btn.active { background: var(--surface-2); }
  .sidebar .nav-add { background: var(--primary); color: var(--on-primary); border-radius: 80px; justify-content: center; margin: 6px 0 14px; }
  main { padding: 48px 44px 64px; }
}
.side-brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 20px; }
.side-brand img { width: 40px; height: 40px; }
.side-brand div { font-family: var(--serif); font-size: 21px; line-height: 1.1; }
.side-foot { margin-top: auto; padding: 0 16px; font-size: 12px; color: var(--muted); }

/* ---------- Type ---------- */
h1 { font-family: var(--serif); font-weight: 400; font-size: 36px; line-height: 1.08; letter-spacing: -0.01em; margin: 0 0 6px; }
h2 { font-family: var(--serif); font-weight: 400; font-size: 26px; line-height: 1.15; margin: 0; }
h3 { font-size: 16px; font-weight: 500; line-height: 1.35; margin: 0; }
h1 em, h2 em { font-style: italic; }
@media (min-width: 900px) { h1 { font-size: 48px; } }
.page-head .sub { color: var(--muted); }

/* ---------- Controls ---------- */
.pill {
  appearance: none; border: 0; cursor: pointer; text-decoration: none;
  background: var(--primary); color: var(--on-primary); font: 500 15px var(--sans);
  padding: 12px 26px; border-radius: 80px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.pill.sm { font-size: 13px; padding: 8px 14px; gap: 6px; }
.pill.ghost { background: var(--surface-2); color: var(--text); }
.pill.danger { color: var(--danger); }
.pill .ic { width: 16px; height: 16px; }
.icon-btn {
  appearance: none; border: 0; cursor: pointer; flex: none;
  background: var(--surface-2); color: var(--text); width: 38px; height: 38px; border-radius: 50%;
  display: grid; place-items: center;
}
.icon-btn .ic { width: 18px; height: 18px; }
.link-btn { appearance: none; border: 0; background: none; color: var(--text); font: 500 14px var(--sans); display: inline-flex; gap: 6px; align-items: center; cursor: pointer; padding: 6px 0; }
.link-btn .ic { width: 16px; height: 16px; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

select {
  font: 500 14px var(--sans); color: var(--text); background: var(--surface);
  border: 0; border-radius: 80px; padding: 8px 14px;
}

.search {
  display: flex; align-items: center; gap: 10px; background: var(--surface);
  border-radius: 80px; padding: 0 18px; margin: 20px 0 14px; color: var(--muted);
}
.search input { flex: 1; min-width: 0; border: 0; background: transparent; color: var(--text); font: 300 16px var(--sans); padding: 14px 0; outline: none; }
.search:focus-within { outline: 2px solid var(--accent); }

.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 0 16px 2px; }
.chips::-webkit-scrollbar { display: none; }
.chips.wrap { flex-wrap: wrap; overflow: visible; margin: 0; padding: 0; }
@media (min-width: 900px) { .chips { margin: 0; padding: 0 0 2px; } }
.chip {
  appearance: none; border: 0; cursor: pointer; white-space: nowrap;
  background: var(--chip); color: var(--text); font: 500 14px var(--sans); padding: 8px 15px; border-radius: 80px;
}
.chip.on { background: var(--chip-on); color: var(--chip-on-text); }
.chip .n { opacity: 0.6; margin-left: 3px; }
.chip.sm { font-size: 13px; padding: 6px 12px; }
.chip-input {
  border: 0; background: transparent; color: var(--text); font: 500 13px var(--sans);
  padding: 6px 12px; width: 104px; border-radius: 80px; outline: 1px dashed var(--muted); outline-offset: -1px;
}
.chip-input:focus { outline: 2px solid var(--accent); }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 12px; }
.sort { font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.panel { background: var(--surface); border-radius: 20px; padding: 16px; margin-top: 10px; display: grid; gap: 14px; }
.tg-name { font: 500 12px var(--sans); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 8px; }

/* ---------- Install banner ---------- */
.install { background: var(--primary); color: var(--on-primary); border-radius: 20px; padding: 16px 18px; display: flex; gap: 12px; align-items: flex-start; margin-top: 18px; }
.install > div { flex: 1; display: grid; gap: 6px; justify-items: start; }
.install p { font-size: 14px; }
.install .pill { background: var(--on-primary); color: var(--primary); }
.install .icon-btn { background: transparent; color: inherit; }

/* ---------- Cards ---------- */
.list { display: grid; gap: 12px; margin-top: 16px; }
@media (min-width: 640px) { .list { grid-template-columns: 1fr 1fr; } }
.card { background: var(--surface); border-radius: 20px; padding: 16px 18px; cursor: pointer; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.card-top { display: flex; align-items: center; gap: 8px; color: var(--accent); }
.card-top .ic { width: 15px; height: 15px; }
.badge { font: 500 11px var(--sans); letter-spacing: 0.09em; text-transform: uppercase; color: var(--accent); }
.when { margin-left: auto; font-size: 12px; color: var(--muted); }
.clamp { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; overflow-wrap: anywhere; }
.card.t-hook .clamp { font-family: var(--serif); font-size: 20px; line-height: 1.25; }
.card-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: auto; }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 12px; background: var(--surface-2); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 12px; background: var(--surface-2); padding: 3px 10px; border-radius: 80px; color: var(--muted); font-weight: 500; }

.empty-state { text-align: center; padding: 48px 16px; color: var(--muted); display: grid; gap: 10px; justify-items: center; }
.empty-state h3 { font-family: var(--serif); font-weight: 400; font-size: 26px; color: var(--text); }

/* ---------- Sheet (add, edit, details) ---------- */
.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(20, 14, 8, 0.45); }
.sheet-panel {
  position: absolute; left: 0; right: 0; bottom: 0; max-height: 94dvh; overflow-y: auto; overscroll-behavior: contain;
  background: var(--bg); border-radius: 24px 24px 0 0; padding: 20px 16px calc(16px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 14px; animation: sheet-up 0.22s ease-out;
}
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } }
@media (min-width: 700px) {
  .sheet-panel { left: 50%; top: 50%; bottom: auto; transform: translate(-50%, -50%); width: min(660px, 92vw); max-height: 88vh; border-radius: 24px; padding: 28px; animation: none; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.seg { display: flex; background: var(--surface-2); border-radius: 80px; padding: 4px; gap: 2px; }
.seg button { flex: 1; appearance: none; border: 0; background: none; cursor: pointer; font: 500 14px var(--sans); color: var(--text); padding: 9px 8px; border-radius: 80px; }
.seg button.on { background: var(--primary); color: var(--on-primary); }

.lbl { display: flex; flex-direction: column; gap: 6px; font: 500 13px var(--sans); color: var(--muted); }
.lbl .opt { font-weight: 300; }
.lbl input, .lbl textarea, .lbl select {
  font: 300 16px/1.5 var(--sans); color: var(--text); background: var(--surface);
  border: 0; border-radius: 14px; padding: 12px 14px; width: 100%; outline: none;
}
.lbl select { border-radius: 14px; }
.lbl textarea { resize: vertical; }
.lbl input:focus, .lbl textarea:focus, .lbl select:focus { outline: 2px solid var(--accent); }

.tools { display: flex; flex-wrap: wrap; gap: 8px; }
.rec { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--rec); font-weight: 500; }
.rec .note { color: var(--muted); font-weight: 300; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--rec); animation: pulse 1s ease-in-out infinite; flex: none; }
@keyframes pulse { 50% { opacity: 0.3; } }
.audio-row { display: flex; align-items: center; gap: 8px; }
audio { width: 100%; height: 40px; }
.thumbs.edit .th { position: relative; }
.thumbs.edit img { width: 84px; height: 84px; }
.th .rm { position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 50%; border: 0; cursor: pointer; background: var(--text); color: var(--bg); display: grid; place-items: center; padding: 0; }
.th .rm .ic { width: 13px; height: 13px; }
.tag-edit { display: grid; gap: 14px; background: var(--surface); border-radius: 18px; padding: 16px; }

.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.actions.sticky { position: sticky; bottom: calc(-16px - env(safe-area-inset-bottom)); background: var(--bg); padding: 12px 0 calc(4px + env(safe-area-inset-bottom)); margin-bottom: calc(-16px - env(safe-area-inset-bottom)); }

.field { background: var(--surface); border-radius: 18px; padding: 14px 16px; }
.field-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; font: 500 12px var(--sans); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-bottom: 8px; }
.field-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.field.hook .field-body { font-family: var(--serif); font-size: 24px; line-height: 1.25; }
.gallery { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
.gallery img { width: 100%; border-radius: 14px; cursor: zoom-in; background: var(--surface-2); display: block; }
.meta { font-size: 13px; color: var(--muted); }

#lightbox { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, 0.92); display: grid; place-items: center; padding: 16px; cursor: zoom-out; }
#lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* ---------- Create mode ---------- */
.create-pick { display: grid; gap: 10px; margin: 20px 0 18px; }
.lbl-sm { font: 500 12px var(--sans); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); margin-top: 6px; }
#c-tag { width: 100%; padding: 13px 16px; font-size: 16px; }
.slots { display: grid; gap: 14px; }
@media (min-width: 760px) { .slots { grid-template-columns: 1fr 1fr; } }
.slot { background: var(--surface); border-radius: 22px; padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.slot-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.slot-label { font: 500 12px var(--sans); text-transform: uppercase; letter-spacing: 0.1em; color: var(--accent); }
.slot-text { white-space: pre-line; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 8; -webkit-box-orient: vertical; overflow: hidden; }
.slot-cap { font-size: 14px; white-space: pre-line; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.slot-cap b { display: block; font: 500 11px var(--sans); text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.slot-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: auto; padding-top: 4px; }
.slot.t-hook { background: var(--primary); color: var(--on-primary); }
.slot.t-hook .slot-label, .slot.t-hook .muted { color: inherit; opacity: 0.75; }
.slot.t-hook .slot-text { font-family: var(--serif); font-size: 26px; line-height: 1.22; }
.slot.t-hook .pill { background: var(--on-primary); color: var(--primary); }
.slot.t-hook .pill.ghost { background: color-mix(in srgb, currentColor 14%, transparent); color: inherit; }
.slot.t-proof { background: var(--sage); }
.slot.t-proof .pill.ghost { background: var(--bg); }
.slot.empty { justify-content: center; }
.center { display: flex; justify-content: center; margin: 24px 0 8px; }

/* ---------- Settings ---------- */
.card-sec { background: var(--surface); border-radius: 22px; padding: 20px; margin-top: 16px; display: grid; gap: 12px; }
.card-sec .lbl input { background: var(--surface-2); }
.group-edit { display: grid; gap: 10px; padding-top: 14px; }
.group-edit + .group-edit { border-top: 1px solid var(--surface-2); }
.ge-head { display: flex; gap: 8px; align-items: center; }
.ge-name { flex: 1; min-width: 0; font: 500 15px var(--sans); background: var(--surface-2); color: var(--text); border: 0; border-radius: 12px; padding: 10px 12px; }
.chip.removable { display: inline-flex; align-items: center; gap: 4px; padding: 4px 5px 4px 12px; cursor: default; }
.chip.removable .tname { appearance: none; border: 0; background: none; font: inherit; color: inherit; padding: 2px 0; cursor: pointer; }
.chip.removable .x { appearance: none; border: 0; cursor: pointer; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; padding: 0; background: color-mix(in srgb, currentColor 12%, transparent); color: inherit; }
.chip.removable .x .ic { width: 12px; height: 12px; }
.about { text-align: center; padding: 40px 0 12px; display: grid; justify-items: center; gap: 6px; }
.about img { width: 128px; height: 128px; margin-bottom: 10px; }
.logo-dark { display: none; }
.about .brand { font-family: var(--serif); font-size: 28px; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 80;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none; transition: 0.2s ease;
  background: var(--text); color: var(--bg); padding: 10px 20px; border-radius: 80px; font: 500 14px var(--sans);
  max-width: calc(100vw - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (min-width: 900px) { #toast { bottom: 32px; } }
