:root {
  --bg: #f6f0e7;
  --surface: #fffaf3;
  --text: #2d2620;
  --muted: #7a6d60;
  --gold: #8f6d3d;
  --line: #e4d8c6;
  --danger: #a33a2a;
  --on-gold: #fff;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1915;
    --surface: #27221d;
    --text: #f1e9de;
    --muted: #b3a491;
    --gold: #d2ae74;
    --line: #3b332b;
    --danger: #e58a78;
    --on-gold: #1d1915;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}
h1, h2 { font-family: "Playfair Display", Georgia, serif; font-weight: 600; margin: 0 0 12px; }
h1 { font-size: 34px; text-align: center; }
h2 { font-size: 28px; }

/* Login */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 360px; display: grid; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px 20px;
}
label { color: var(--muted); font-size: 15px; }
input {
  font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; width: 100%;
}
input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
button {
  font: inherit; font-weight: 600; cursor: pointer; border: 0; border-radius: 10px; padding: 12px 16px;
  background: var(--gold); color: var(--on-gold);
}
button:disabled { opacity: .6; cursor: default; }
.error { color: var(--danger); min-height: 1.5em; margin: 0; font-size: 15px; }

/* Shell: tabs at the bottom on a phone, on the left on a wide screen */
.content { padding: 20px 16px calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; }
.soon { color: var(--muted); }
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabs a {
  display: grid; justify-items: center; gap: 2px; padding: 8px 4px; min-height: var(--nav-h);
  color: var(--muted); text-decoration: none; font-size: 12px;
}
.tabs a .icon { font-size: 22px; line-height: 1.2; }
.tabs a[aria-current] { color: var(--gold); font-weight: 600; }
.logout {
  position: fixed; top: calc(10px + env(safe-area-inset-top)); right: 12px;
  background: transparent; color: var(--muted); font-weight: 400; font-size: 15px; padding: 6px 10px;
}

/* Notes */
textarea, select { font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; width: 100%; }
textarea:focus, select:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.composer { display: grid; gap: 10px; margin-bottom: 20px; }
.composer-text { resize: vertical; min-height: 88px; }
.composer-row { display: flex; gap: 8px; }
.composer-row .tags-input { flex: 1; min-width: 0; background: var(--surface); }
.mic { flex: none; min-width: 52px; padding: 0 14px; background: var(--surface); color: var(--gold); border: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.mic[data-state="rec"] { background: var(--danger); color: var(--surface); border-color: var(--danger); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { position: relative; }
.chip input { position: absolute; inset: 0; opacity: 0; pointer-events: none; }
.chip span { display: inline-block; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; font-size: 14px; color: var(--muted); cursor: pointer; background: var(--surface); }
.chip input:checked + span { border-color: var(--gold); color: var(--text); background: var(--bg); font-weight: 600; box-shadow: inset 0 0 0 1px var(--gold); }
.chip input:focus-visible + span { outline: 2px solid var(--gold); outline-offset: 1px; }
.toolbar { display: grid; grid-template-columns: 1fr auto; gap: 8px; margin-bottom: 12px; }
.toolbar .search { grid-column: 1 / -1; background: var(--surface); }
.toolbar .filter { width: auto; padding: 8px 10px; }
button.ghost { background: transparent; color: var(--gold); border: 1px solid var(--line); font-weight: 500; padding: 8px 12px; font-size: 15px; }
button.ghost:disabled { color: var(--muted); }
button.link { background: none; color: var(--gold); padding: 0; font-weight: 500; font-size: 15px; }
.notes-list { display: grid; gap: 10px; }
.note { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; display: grid; gap: 8px; }
.note-meta { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; font-size: 13px; color: var(--muted); }
.note-meta .type { font-weight: 600; color: var(--gold); text-transform: uppercase; letter-spacing: .03em; font-size: 12px; }
.note-meta .source { border: 1px solid var(--line); border-radius: 999px; padding: 0 8px; }
.note-text { overflow-wrap: anywhere; display: grid; gap: 6px; }
.note-text.clamped { max-height: 11.5em; overflow: hidden; -webkit-mask-image: linear-gradient(#000 70%, transparent); mask-image: linear-gradient(#000 70%, transparent); }
.note-text > * { margin: 0; }
.note-text p { white-space: pre-wrap; }
.note-text .md-title { font-family: "Playfair Display", Georgia, serif; font-size: 20px; font-weight: 600; line-height: 1.3; }
.note-text h3, .note-text h4 { font-size: 17px; font-weight: 600; margin-top: 6px; }
.note-text .md-li { padding-left: 1.1em; text-indent: -1.1em; }
.note-text .md-li::before { content: "•"; display: inline-block; width: 1.1em; text-indent: 0; color: var(--gold); }
.note-text blockquote { border-left: 3px solid var(--line); padding-left: 10px; color: var(--muted); font-style: italic; }
.note-text .md-meta { font-size: 13px; color: var(--muted); }
.note .ig { color: var(--gold); font-size: 15px; overflow-wrap: anywhere; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { background: var(--bg); color: var(--muted); font-weight: 400; font-size: 14px; padding: 2px 10px; border-radius: 999px; }
.note-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.more { justify-self: center; margin-top: 4px; }
.note-links { display: flex; flex-wrap: wrap; gap: 16px; }
.working { margin: 0; font-size: 14px; color: var(--muted); }
.working::before { content: ""; display: inline-block; width: 8px; height: 8px; margin-right: 8px; border-radius: 50%; background: var(--gold); animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .25; } }
@media (prefers-reduced-motion: reduce) { .working::before { animation: none; } }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 20;
  bottom: calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 15px; max-width: calc(100% - 32px);
}
/* Photos */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.button {
  display: inline-block; font-weight: 600; cursor: pointer; border-radius: 10px; padding: 12px 16px;
  background: var(--gold); color: var(--on-gold); font-size: 17px;
}
.uploader:has(input:focus-visible) .button { outline: 2px solid var(--gold); outline-offset: 2px; }
.uploader { display: grid; justify-items: start; gap: 8px; margin-bottom: 20px; }
.uploads { display: grid; gap: 6px; width: 100%; }
.uploads:empty { display: none; }
.upload-row { display: grid; grid-template-columns: minmax(0, 1fr) 90px; align-items: center; gap: 4px 10px; font-size: 14px; color: var(--muted); }
.upload-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-row progress { width: 100%; accent-color: var(--gold); }
.upload-status { grid-column: 1 / -1; }
.upload-row button { grid-column: 1 / -1; justify-self: start; }
.photos-list { display: grid; gap: 14px; }
.photo-group { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: grid; gap: 10px; }
.photo-meta { margin: 0; font-size: 13px; color: var(--muted); }
.thumb { display: block; padding: 0; border-radius: 10px; overflow: hidden; background: var(--bg); width: 100%; }
.thumb img { display: block; width: 100%; height: 100%; object-fit: cover; }
.thumb-main { aspect-ratio: 4 / 5; max-height: min(460px, 55dvh); }
.thumb-main img { object-fit: contain; }
.thumb-result { aspect-ratio: 4 / 5; }
.photo-results { display: grid; gap: 6px; }
.photo-results:empty { display: none; }
.result-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.result { margin: 0; display: grid; gap: 4px; align-content: start; }
.result figcaption, .job-prompt { font-size: 13px; color: var(--muted); margin: 0; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.job { border: 1px dashed var(--line); border-radius: 10px; padding: 10px; display: grid; gap: 4px; align-content: center; aspect-ratio: 4 / 5; }
.job-status { margin: 0; font-weight: 600; font-size: 15px; }
.job-running .job-status, .job-queued .job-status { color: var(--gold); animation: pulse 1.6s ease-in-out infinite; }
.job-failed { border-style: solid; border-color: var(--danger); aspect-ratio: auto; }
.job-failed .job-status { color: var(--danger); }
.job-error { margin: 0; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; max-height: 6em; overflow: auto; }
.job-actions { display: flex; flex-wrap: wrap; gap: 6px; }
@keyframes pulse { 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) { .job-status { animation: none !important; } }
.photo-prompt { display: grid; gap: 8px; }
.photo-prompt .composer-text { min-height: 72px; background: var(--bg); }
.photo-prompt button { justify-self: end; }
.viewer {
  border: 0; padding: 0; background: var(--surface); color: var(--text); border-radius: 14px;
  width: min(760px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto;
}
.viewer::backdrop { background: rgb(0 0 0 / .7); }
.viewer img { display: block; width: 100%; max-height: 70dvh; object-fit: contain; background: #000; }
.viewer-info { display: grid; gap: 10px; padding: 12px 14px 14px; }
/* Content plan */
.plan-month { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px; margin-bottom: 16px; }
.plan-month-head { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.plan-month-head h3 { margin: 0 auto 0 4px; font-size: 18px; font-weight: 600; order: -1; }
.plan-month-head h3::first-letter { text-transform: uppercase; }
.plan-month-head .ghost { padding: 4px 14px; font-size: 18px; line-height: 1.2; }
.plan-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.plan-wd { text-align: center; font-size: 12px; color: var(--muted); padding: 2px 0 4px; }
.plan-cell {
  display: grid; justify-items: center; align-content: start; gap: 2px; min-height: 46px; padding: 6px 0 4px;
  background: transparent; color: var(--text); border-radius: 8px; font-weight: 400;
}
.plan-cell.empty { pointer-events: none; }
.plan-cell.past { color: var(--muted); }
.plan-cell.has { background: var(--bg); }
.plan-cell.today .plan-cell-num { background: var(--gold); color: var(--on-gold); font-weight: 600; }
.plan-cell-num { font-size: 15px; min-width: 26px; line-height: 26px; border-radius: 999px; text-align: center; }
.plan-dots { display: flex; gap: 2px; align-items: center; min-height: 6px; }
.plan-dots .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--gold); }
.plan-dots .dot.status-idea { background: transparent; box-shadow: inset 0 0 0 1px var(--gold); }
.plan-dots .dot.status-published { background: var(--muted); }
.plan-dots b { font-size: 10px; line-height: 6px; color: var(--gold); }
.plan-when { display: flex; flex-wrap: wrap; align-items: end; gap: 8px 12px; }
.plan-field { display: grid; gap: 2px; font-size: 13px; }
.plan-field input { background: var(--surface); padding: 8px 10px; min-height: 42px; }
.plan-date { width: 11.5em; }
.plan-when .link { padding-bottom: 10px; }
.plan-form .link { justify-self: start; }
.plan-actions { justify-content: end; align-items: center; }
.plan-actions .filter { width: auto; margin-right: auto; padding: 8px 10px; }
.plan-from-note { margin: 0; }
.plan-toolbar { grid-template-columns: auto; justify-content: end; }
.plan-group { display: grid; gap: 8px; margin-bottom: 10px; }
.plan-group-title { margin: 8px 0 0; font-size: 15px; font-weight: 600; color: var(--muted); }
.plan-group-title::first-letter { text-transform: uppercase; }
.plan-group.late .plan-group-title { color: var(--danger); }
.plan-title { margin: 0; font-weight: 600; white-space: pre-wrap; overflow-wrap: anywhere; }
.plan-status { margin-left: auto; width: auto; padding: 2px 8px; font-size: 13px; border-radius: 999px; background: var(--bg); }
.plan-item.status-ready { border-color: var(--gold); }
.plan-item.status-published { opacity: .65; }
.plan-item.status-published .plan-title::before { content: "✓ "; color: var(--gold); }

@media (min-width: 768px) {
  .result-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .photo-prompt { grid-template-columns: minmax(0, 1fr) auto; align-items: end; }
}

@media (min-width: 768px) {
  .toolbar { grid-template-columns: 1fr auto auto; }
  .toolbar .search { grid-column: auto; }
  .toast { bottom: 24px; left: calc(50% + 100px); }
}

@media (min-width: 768px) {
  .tabs {
    top: 0; right: auto; width: 200px; border-top: 0; border-right: 1px solid var(--line);
    grid-template-columns: none; align-content: start; gap: 4px; padding: 24px 12px;
  }
  .tabs a {
    grid-auto-flow: column; justify-content: start; align-items: center; gap: 12px;
    min-height: 0; padding: 10px 12px; border-radius: 10px; font-size: 16px;
  }
  .tabs a[aria-current] { background: var(--bg); }
  .logout { position: static; text-align: left; margin-top: 16px; }
  .content { margin-left: 200px; margin-right: auto; padding: 32px 40px; }
}

/* Carousels */
.carousels { display: grid; gap: 14px; }
.carousels > * { margin: 0; }
.carousels h3 { font-size: 18px; margin: 10px 0 0; }
.back { justify-self: start; }
.carousel-start { display: flex; flex-wrap: wrap; gap: 8px; }
.carousel-start .ghost { padding: 12px 16px; font-size: 17px; }
.carousel-list { display: grid; gap: 10px; }
.carousel-card {
  display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 12px; align-items: center; text-align: left;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 10px; font-weight: 400;
}
.carousel-card-text { display: grid; gap: 4px; min-width: 0; }
.carousel-card-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.slide-thumb { display: block; width: 100%; height: auto; aspect-ratio: 1; border-radius: 6px; background: var(--bg); }
.stepper { display: flex; flex-wrap: wrap; gap: 6px 14px; list-style: none; padding: 0; font-size: 15px; color: var(--muted); }
.stepper .current { color: var(--text); font-weight: 600; }
.template-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.template-tile { display: grid; gap: 4px; justify-items: start; }
.template-pick, .template-new {
  display: grid; gap: 8px; width: 100%; text-align: left; padding: 8px; font-weight: 400;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 12px;
}
.template-tile.selected .template-pick { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }
.template-preview { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.template-new { place-content: center; justify-items: center; min-height: 120px; color: var(--gold); border-style: dashed; font-weight: 600; text-align: center; }
.template-new .plus { font-size: 32px; line-height: 1; }
.pick-list { display: grid; gap: 8px; }
.pick-note {
  display: grid; gap: 4px; text-align: left; font-weight: 400; background: var(--surface); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
}
.pick-note.selected { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); }
.pick-note-text { overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.carousels .search { background: var(--surface); }
.pick-photos { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.pick-photo { position: relative; padding: 0; aspect-ratio: 4 / 5; border-radius: 10px; overflow: hidden; background: var(--bg); border: 3px solid transparent; }
.pick-photo img { display: block; width: 100%; height: 100%; object-fit: cover; }
.pick-photo.selected { border-color: var(--gold); }
.pick-photo.selected::after { content: "✓"; position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; border-radius: 50%; background: var(--gold); color: var(--on-gold); display: grid; place-items: center; font-size: 15px; }
.pick-photo .badge { position: absolute; left: 6px; bottom: 6px; background: rgb(0 0 0 / .55); color: #fff; font-size: 12px; font-weight: 500; padding: 1px 8px; border-radius: 999px; }
.ghost-button { background: transparent; color: var(--gold); border: 1px solid var(--line); font-weight: 500; }
.build-bar {
  position: sticky; bottom: calc(var(--nav-h) + 8px + env(safe-area-inset-bottom)); z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px;
}
.slides-strip {
  display: grid; grid-auto-flow: column; grid-auto-columns: min(78%, 320px); gap: 10px;
  overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 6px; overscroll-behavior-x: contain;
}
.slide-box { margin: 0; scroll-snap-align: center; display: grid; gap: 4px; }
.slide-box .slide { display: block; width: 100%; height: auto; aspect-ratio: 1; border-radius: 8px; border: 1px solid var(--line); }
.slide-box figcaption { font-size: 13px; color: var(--muted); text-align: center; }
.slide-box.cover-drag { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.slide-box.overflow .slide { outline: 3px solid var(--danger); outline-offset: -3px; }
.carousel-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.carousel-tools .filter { width: auto; max-width: 100%; }
.carousel-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.hint { font-size: 14px; }
.slide-field { display: grid; gap: 4px; }
.slide-text { resize: vertical; }
.slide-warn { min-height: 0; }
.danger-zone { margin-top: 12px; }
.template-editor { display: grid; gap: 16px; }
.template-preview.large { gap: 8px; }
.template-preview.large .slide { display: block; width: 100%; height: auto; aspect-ratio: 1; border-radius: 8px; border: 1px solid var(--line); }
.template-form { display: grid; gap: 12px; }
.template-row { display: grid; grid-template-columns: 150px minmax(0, 1fr); align-items: center; gap: 10px; color: var(--text); font-size: 16px; }
.template-row.check { grid-template-columns: auto 1fr; }
.template-row input[type=color] { width: 64px; height: 40px; padding: 2px; }
.template-row input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--gold); }
.template-row input[type=range] { padding: 0; border: 0; background: none; accent-color: var(--gold); }
.template-colors { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px 12px; display: grid; gap: 8px; margin: 0; }
.template-colors legend { color: var(--muted); font-size: 15px; padding: 0 4px; }
@media (min-width: 900px) {
  .template-editor { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .template-preview.large { position: sticky; top: 24px; grid-template-columns: 1fr; }
  .pick-photos { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (min-width: 768px) {
  .build-bar { bottom: 16px; }
}

/* Reels */
.reel-card {
  display: grid; grid-template-columns: 72px minmax(0, 1fr); gap: 12px; align-items: center; text-align: left;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 10px; font-weight: 400;
}
.reel-badge {
  display: grid; place-items: center; aspect-ratio: 9 / 12; border-radius: 8px; background: var(--bg); color: var(--gold);
  font-weight: 600; font-size: 14px; text-align: center; padding: 4px;
}
.reel-durations { align-items: center; }
.reel-custom { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; }
.reel-seconds { width: 4.5em; padding: 6px 8px; min-height: 0; background: var(--surface); font-variant-numeric: tabular-nums; }
.reel-timing { margin: 0; }
.reel-timing.off { color: var(--danger); }
.reel-hook { min-height: 0; }
.reel-shots { display: grid; gap: 10px; }
.reel-shots > .ghost { justify-self: start; }
.reel-shot { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; display: grid; gap: 8px; }
.reel-shot-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.reel-shot-tools { display: flex; gap: 6px; margin-left: auto; }
.reel-shot-tools .ghost { padding: 4px 10px; font-size: 14px; }
.reel-shot .slide-field > span { color: var(--muted); font-size: 14px; }
.reel-rewrite { margin-bottom: 0; }
.reel-rewrite button[type=submit] { justify-self: end; }
