/* ---------- Palette & base ---------- */
:root {
  --paper: #FBF9F4;
  --ink: #1F1D1A;
  --accent: #3A4A3F;
  --rose: #B5726A;
  --hairline: #E4DFD3;
  --measure: 65ch;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
}

body {
  font-family: "Literata", Georgia, serif;
  font-size: 1.125rem;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, .display {
  font-family: "Fraunces", Georgia, serif;
  font-weight: 600;
  line-height: 1.25;
  margin: 0 0 0.5em;
}

a {
  color: var(--accent);
  text-decoration-color: var(--hairline);
  text-underline-offset: 3px;
}
a:hover { text-decoration-color: var(--accent); }

.label {
  font-family: "Literata", Georgia, serif;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-size: 0.72rem;
  color: #6b6558;
}
.label.rose { color: var(--rose); }

/* ---------- Layout ---------- */
.wrap {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 2.5rem 1.25rem 5rem;
}

.site-header {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 2.5rem 1.25rem 1.5rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  border-bottom: 1px solid var(--hairline);
}

.wordmark {
  font-family: "Fraunces", Georgia, serif;
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
}

.site-nav {
  display: flex;
  gap: 1.25rem;
  flex-wrap: wrap;
}
.site-nav a {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: #6b6558;
  text-decoration: none;
}
.site-nav a:hover { color: var(--accent); }

.site-footer {
  max-width: var(--measure);
  margin: 3rem auto 0;
  padding: 1.5rem 1.25rem 3rem;
  border-top: 1px solid var(--hairline);
  font-size: 0.8rem;
  color: #8a8474;
}

/* ---------- Post list (home / category) ---------- */
.post-list { list-style: none; margin: 2rem 0 0; padding: 0; }
.post-entry {
  display: flex;
  gap: 1.25rem;
  padding: 1.75rem 0;
  border-bottom: 1px solid var(--hairline);
  align-items: flex-start;
}
.post-entry:first-child { padding-top: 0; }

.post-entry-thumb {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: 3px;
  flex-shrink: 0;
  background: var(--hairline);
}

.post-entry-title {
  font-size: 1.3rem;
  margin: 0.15em 0 0.35em;
}
.post-entry-title a { color: var(--ink); text-decoration: none; }
.post-entry-title a:hover { color: var(--accent); }

.post-entry-excerpt {
  color: #4a463d;
  font-size: 0.98rem;
  margin: 0;
}

.post-meta {
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
}

.empty-note { color: #8a8474; margin-top: 2rem; }

/* ---------- Individual post ---------- */
.post-header {
  margin-bottom: 2rem;
  display: flex;
  gap: 1.5rem;
  align-items: flex-start;
  justify-content: space-between;
}
.post-header-text { flex: 1; min-width: 0; }
.post-header .label { margin-bottom: 0.6rem; display: block; }
.post-title { font-size: 2.1rem; margin-bottom: 0.3em; }
.post-byline {
  display: block;
  font-style: italic;
  font-size: 0.9rem;
  color: #6b6558;
  margin-bottom: 0.35rem;
}
.post-date { font-size: 0.8rem; color: #8a8474; }

.cover-image {
  width: 160px;
  height: 160px;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
}

.inline-image {
  max-width: 100%;
  border-radius: 4px;
  display: block;
  margin: 1.5rem auto;
}

/* Poems: centered, preserved line breaks, italic */
.post-body.form-poem {
  text-align: center;
  font-style: italic;
  font-size: 1.15rem;
  line-height: 1.9;
}

/* Stories: flowing prose */
.post-body.form-story p {
  margin: 0 0 1.3em;
  text-align: left;
}

/* Lyrics: left-aligned, lead-sheet style */
.post-body.form-lyrics {
  text-align: left;
  line-height: 1.85;
}
.lyrics-label {
  display: block;
  margin-top: 1.3em;
  font-family: "Literata", Georgia, serif;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
  color: var(--rose);
}

/* ---------- Audio player ---------- */
.audio-player {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin: 1.75rem 0 2.25rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--hairline);
  border-radius: 999px;
  max-width: 380px;
}
.audio-play-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
}
.audio-play-btn svg { width: 16px; height: 16px; }
.audio-progress {
  flex: 1;
  height: 4px;
  background: var(--hairline);
  border-radius: 2px;
  position: relative;
  cursor: pointer;
}
.audio-progress-fill {
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 0%;
  background: var(--accent);
  border-radius: 2px;
}
.audio-time {
  font-size: 0.72rem;
  color: #8a8474;
  min-width: 3.4em;
  text-align: right;
}

/* ---------- Screenplay ---------- */
.screenplay {
  font-family: "Courier Prime", "Courier New", monospace;
  font-size: 0.98rem;
  line-height: 1.6;
  max-width: 58ch;
  margin: 0 auto;
}

/* Each screenplay page renders as its own sheet. */
.sp-page {
  background: #fff;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 2.5rem 2.25rem;
  margin: 0 0 1.75rem;
  position: relative;
}
.sp-page-number {
  position: absolute;
  top: 1rem;
  right: 1.5rem;
  font-size: 0.82rem;
  color: #8a8474;
}
.sp-title-page {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 22rem;
}
.sp-title {
  text-transform: uppercase;
  font-weight: bold;
  font-size: 1.05rem;
  letter-spacing: 0.05em;
  margin-bottom: 2.5rem;
}
.sp-byline { margin-bottom: 0.75rem; }
.sp-author { text-transform: uppercase; }
.sp-block { margin: 0 0 1em; white-space: pre-wrap; }
.sp-scene_heading { text-transform: uppercase; font-weight: bold; text-align: left; }
.sp-action { text-align: left; }
.sp-character {
  text-transform: uppercase;
  text-align: center;
  max-width: 3.6in;
  margin: 0 auto 0.2em;
}
.sp-dialogue {
  max-width: 3.2in;
  margin: 0 auto 1em;
  text-align: left;
}
.sp-parenthetical {
  font-style: italic;
  text-align: center;
  max-width: 2.6in;
  margin: 0 auto 0.2em;
}
.sp-transition { text-transform: uppercase; font-weight: bold; text-align: right; }
.sp-image { text-align: center; margin: 1.5em auto; }
.sp-image img { max-width: 100%; border-radius: 4px; }

/* ---------- 404 ---------- */
.not-found { text-align: center; padding: 5rem 1rem; }

/* ============================================================
   Admin area — same palette/fonts, plainer & more utilitarian
   ============================================================ */
.admin-wrap {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.25rem 5rem;
}

.admin-header {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--hairline);
}
.admin-header nav { display: flex; gap: 1.25rem; align-items: center; }
.admin-header a { font-size: 0.85rem; text-decoration: none; color: #6b6558; }
.admin-header a:hover { color: var(--accent); }

.flash-list { list-style: none; padding: 0; margin: 1.25rem 0 0; }
.flash-list li {
  background: #EEF2ED;
  border: 1px solid var(--hairline);
  color: var(--accent);
  padding: 0.6rem 0.9rem;
  border-radius: 4px;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.login-box {
  max-width: 320px;
  margin: 6rem auto;
  text-align: center;
}
.login-box input[type="password"] {
  width: 100%;
  padding: 0.7rem 0.9rem;
  font-size: 1rem;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  margin: 1.25rem 0;
  background: #fff;
  font-family: inherit;
}
.btn {
  display: inline-block;
  font-family: "Literata", Georgia, serif;
  font-size: 0.92rem;
  padding: 0.6rem 1.15rem;
  border-radius: 4px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--paper);
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { opacity: 0.88; }
.btn.btn-secondary {
  background: transparent;
  color: var(--accent);
}
.btn.btn-danger {
  background: transparent;
  border-color: var(--rose);
  color: var(--rose);
}
.btn.btn-small { font-size: 0.78rem; padding: 0.35rem 0.7rem; }
.error-text { color: var(--rose); font-size: 0.9rem; }
.error-box {
  background: #F7ECEA;
  border: 1px solid var(--rose);
  color: #8a3d35;
  padding: 0.7rem 0.9rem;
  border-radius: 4px;
  font-size: 0.9rem;
  margin: 1.25rem 0 0;
  text-align: left;
}

table.admin-table { width: 100%; border-collapse: collapse; margin-top: 1.5rem; }
table.admin-table th, table.admin-table td {
  text-align: left;
  padding: 0.7rem 0.6rem;
  border-bottom: 1px solid var(--hairline);
  font-size: 0.92rem;
  vertical-align: middle;
}
table.admin-table th { font-family: "Literata"; text-transform: uppercase; font-size: 0.7rem; letter-spacing: 0.06em; color: #8a8474; }
.status-pill {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--hairline);
}
.status-pill.draft { color: #8a8474; }
.status-pill.published { color: var(--accent); border-color: var(--accent); }
.status-pill.archived { color: var(--rose); border-color: var(--rose); }

.status-filters { display: flex; gap: 1rem; margin-top: 1rem; font-size: 0.85rem; }
.status-filters a { text-decoration: none; color: #6b6558; }
.status-filters a.active { color: var(--accent); font-weight: 600; }

.row-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.row-actions form { display: inline; }

/* Editor */
.editor-field { margin-bottom: 1.25rem; }
.editor-field label { display: block; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em; color: #6b6558; margin-bottom: 0.4rem; }
.editor-field input[type="text"],
.editor-field select,
.editor-field textarea,
.editor-field input[type="file"] {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  font-family: inherit;
  font-size: 1rem;
  background: #fff;
}
.editor-field textarea {
  min-height: 340px;
  line-height: 1.6;
  resize: vertical;
}
.editor-row { display: flex; gap: 1rem; }
.editor-row > div { flex: 1; }

.editor-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}
.editor-toolbar button {
  font-family: "Courier Prime", monospace;
  font-size: 0.78rem;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--hairline);
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
}
.editor-toolbar button:hover { border-color: var(--accent); color: var(--accent); }
.editor-toolbar button.insert-image-btn { border-color: var(--rose); color: var(--rose); }
.editor-toolbar .kbd {
  display: inline-block;
  margin-left: 0.45em;
  padding: 0 0.3em;
  border: 1px solid var(--hairline);
  border-radius: 3px;
  font-size: 0.66rem;
  color: #8a8474;
  background: var(--paper);
}

/* Write/Preview tabs + preview panel */
.editor-tabs {
  display: flex;
  border-bottom: 1px solid var(--hairline);
  margin-bottom: 1.25rem;
}
.editor-tabs button {
  background: none;
  border: none;
  padding: 0.5rem 0.95rem;
  font-family: inherit;
  font-size: 0.92rem;
  color: #6b6558;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.editor-tabs button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  font-weight: 600;
}
#preview-panel {
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 1.75rem 1.5rem;
  background: var(--paper);
  margin-bottom: 1.25rem;
}

/* Sticky screenplay toolbar with live page indicator */
#screenplay-toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--paper);
  padding: 0.5rem 0;
  margin-bottom: 0.25rem;
}
.sp-page-indicator {
  margin-left: auto;
  align-self: center;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: #8a8474;
  white-space: nowrap;
}

/* Uploaded-images panel in the editor */
.image-list { list-style: none; margin: 0; padding: 0; }
.image-list li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--hairline);
}
.image-list img {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 3px;
  flex-shrink: 0;
}
.image-list .image-name {
  flex: 1;
  font-size: 0.88rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.screenplay-editor {
  border: 1px solid var(--hairline);
  border-radius: 4px;
  padding: 1.5rem;
  background: #fff;
  min-height: 340px;
}
.screenplay-editor .sp-block {
  outline: none;
  padding: 0.15rem 0.3rem;
  border-radius: 2px;
}
.screenplay-editor .sp-block:focus { background: #F4F1E8; }
.screenplay-editor .sp-block[data-empty="true"]:before {
  content: attr(data-placeholder);
  color: #b8b2a2;
}

.save-actions { display: flex; gap: 0.75rem; align-items: center; margin-top: 1.5rem; }
.autosave-indicator { font-size: 0.78rem; color: #8a8474; }

.category-list { list-style: none; padding: 0; margin: 1.5rem 0; }
.category-list li {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--hairline);
  flex-wrap: wrap;
}
.category-list li > .label { margin-left: auto; }
.category-move { display: flex; gap: 0.25rem; }
.category-move button[disabled] { opacity: 0.35; cursor: default; }
.category-list form { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.category-list input[type="text"] {
  padding: 0.3rem 0.5rem;
  border: 1px solid var(--hairline);
  border-radius: 4px;
  font-family: inherit;
}

@media (max-width: 640px) {
  .editor-row { flex-direction: column; }
  .post-entry { flex-wrap: wrap; }
  .cover-image { width: 96px; height: 96px; }
  .post-title { font-size: 1.6rem; }
  .sp-page { padding: 1.75rem 1.1rem; }
}
