/* ===================================================
   VERSOS — CSS
   Mobile-first, theme-aware poetry reader
   =================================================== */

/* ---------- Reset & base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-tap-highlight-color: transparent; }
body {
  font-family: 'Inter', sans-serif;
  min-height: 100dvh;
  transition: background-color .3s, color .3s;
}

button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, textarea { font-family: inherit; }
a { color: inherit; }

/* ---------- Themes (background) ---------- */
[data-bg="white"]     { --bg: #ffffff; --bg2: #f5f5f5; --text: #1a1a1a; --muted: #666; --border: #e0e0e0; --card: #ffffff; --card-shadow: 0 2px 8px rgba(0,0,0,.08); }
[data-bg="cream"]     { --bg: #fdf6e3; --bg2: #f5ead0; --text: #2c2108; --muted: #7a6a40; --border: #e8d8b0; --card: #fffdf5; --card-shadow: 0 2px 8px rgba(90,60,0,.1); }
[data-bg="parchment"] { --bg: #f2ead8; --bg2: #e8dcca; --text: #2e200e; --muted: #7a6a50; --border: #d8c8a8; --card: #faf5e8; --card-shadow: 0 2px 8px rgba(80,50,0,.1); }
[data-bg="gray"]      { --bg: #f0f0f0; --bg2: #e4e4e4; --text: #1a1a1a; --muted: #666; --border: #d0d0d0; --card: #fafafa; --card-shadow: 0 2px 8px rgba(0,0,0,.08); }
[data-bg="dark"]      { --bg: #2c2c2c; --bg2: #1e1e1e; --text: #e8e0d0; --muted: #aaa; --border: #444; --card: #363636; --card-shadow: 0 2px 8px rgba(0,0,0,.3); }
[data-bg="night"]     { --bg: #0d0d0d; --bg2: #161616; --text: #d8d0c0; --muted: #888; --border: #2a2a2a; --card: #181818; --card-shadow: 0 2px 8px rgba(0,0,0,.5); }

body { background-color: var(--bg); color: var(--text); }

/* ---------- Font sizes ---------- */
[data-font-size="sm"] { --poem-size: 15px; --poem-lh: 1.4; }
[data-font-size="md"] { --poem-size: 18px; --poem-lh: 1.48; }
[data-font-size="lg"] { --poem-size: 22px; --poem-lh: 1.58; }
[data-font-size="xl"] { --poem-size: 26px; --poem-lh: 1.68; }

/* ---------- Accent color ---------- */
:root {
  --accent: #8B5E3C;
  --accent-light: #c9956a;
  --accent-dark: #6b3e24;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: .2s ease;
}

/* ---------- Utility ---------- */
.hidden { display: none !important; }
.view { min-height: 100dvh; }
.view.active { display: block; }

/* ---------- BRAND ---------- */
.brand {
  font-family: 'Playfair Display', serif;
  font-size: clamp(1rem, 4.3vw, 2rem);
  font-weight: 700;
  color: var(--accent);
  margin-bottom: .15rem;
  letter-spacing: .01em;
  line-height: 1.1;
  white-space: nowrap;
}
.brand-sub {
  font-size: .88rem;
  color: var(--muted);
  font-style: italic;
  margin-bottom: 1rem;
}
.auth-hero-wrap {
  display: flex;
  justify-content: center;
  margin: 0 0 1.1rem;
}
.auth-hero-image {
  display: block;
  width: min(180px, 52%);
  height: auto;
  object-fit: contain;
}
.brand-sm { 
  font-family: 'Playfair Display', serif;
  font-size: clamp(.62rem, 2vw, .95rem);
  font-weight: 700;
  color: var(--accent);
  cursor: pointer;
  padding: 0;
  background: none;
  border: none;
  letter-spacing: .01em;
  line-height: 1.1;
  max-width: 320px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* =============================================
   AUTH VIEW
   ============================================= */
#view-auth {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem 1rem;
  min-height: 100dvh;
}
.auth-shell {
  width: 100%;
  min-height: calc(100dvh - 2.5rem);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
}
.auth-container {
  width: 100%;
  max-width: 380px;
  text-align: center;
  margin: auto 0;
}
.auth-copyright {
  font-size: .82rem;
  color: var(--muted);
  text-align: center;
  padding-top: 1rem;
}
.auth-random-poem {
  text-align: left;
  margin: 0 0 1.35rem;
  padding: 1rem 1rem 1.1rem;
  background: linear-gradient(135deg, rgba(139,94,60,.08), rgba(139,94,60,.02));
  border: 1px solid rgba(139,94,60,.16);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
}
.auth-random-kicker {
  font-size: .72rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
  margin-bottom: .4rem;
}
.auth-random-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.15rem;
  line-height: 1.25;
  color: var(--text);
  margin-bottom: .55rem;
}
.auth-random-text {
  white-space: pre-line;
  color: var(--muted);
  font-size: .9rem;
  line-height: 1.65;
}
.tabs { display: flex; gap: .5rem; margin-bottom: .95rem; }
.tab {
  flex: 1;
  padding: .52rem;
  border-radius: var(--radius-sm);
  font-size: .92rem;
  font-weight: 500;
  color: var(--muted);
  background: var(--bg2);
  transition: var(--transition);
}
.tab.active {
  background: var(--accent);
  color: #fff;
}
.auth-form { text-align: left; }
.field { margin-bottom: .75rem; }
.field label {
  display: block;
  font-size: .82rem;
  font-weight: 500;
  margin-bottom: .22rem;
  color: var(--muted);
}
.hint { font-weight: 300; font-size: .74rem; }
.field input {
  width: 100%;
  padding: .58rem .9rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  font-size: .96rem;
  transition: var(--transition);
  -webkit-appearance: none;
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139,94,60,.15);
}
.auth-error {
  color: #c0392b;
  font-size: .82rem;
  min-height: 1em;
  margin-bottom: .35rem;
}
.btn-primary {
  width: 100%;
  padding: .66rem;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: .96rem;
  font-weight: 500;
  transition: var(--transition);
  -webkit-appearance: none;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:active { transform: scale(.98); }

/* =============================================
   APP HEADER
   ============================================= */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1rem;
  max-width: 800px;
  margin: 0 auto;
}
.header-actions { display: flex; gap: .5rem; }
.header-brand {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  min-width: 0;
  cursor: pointer;
}
.header-brand-image {
  width: 30px;
  height: 30px;
  object-fit: contain;
  flex-shrink: 0;
}
.reader-header-inner {
  gap: .75rem;
}
.reader-book-title {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-family: 'Playfair Display', serif;
  font-size: clamp(.75rem, 2.5vw, 1rem);
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.btn-icon {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--bg2);
  color: var(--text);
  transition: var(--transition);
}
.btn-icon svg { width: 20px; height: 20px; fill: var(--text); }
.btn-icon:hover { background: var(--border); }
.btn-back {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .9rem;
  color: var(--muted);
  padding: .4rem .6rem;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.btn-back svg { width: 18px; height: 18px; fill: var(--muted); }
.btn-back:hover { background: var(--bg2); color: var(--text); }

/* =============================================
   SETTINGS PANEL
   ============================================= */
.settings-panel {
  position: fixed;
  top: 57px;
  left: 0;
  right: 0;
  z-index: 220;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--card-shadow);
}
.settings-inner {
  max-width: 800px;
  margin: 0 auto;
  padding: 1rem;
}
.settings-inner h3 { font-size: .9rem; color: var(--muted); margin-bottom: .75rem; }
.setting-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: .75rem;
}
.setting-row > span { font-size: .85rem; color: var(--muted); min-width: 80px; }
.color-swatches { display: flex; gap: .5rem; flex-wrap: wrap; }
.swatch {
  width: 28px; height: 28px;
  border-radius: 50%;
  border: 2px solid transparent;
  box-shadow: 0 0 0 1px var(--border);
  transition: var(--transition);
}
.swatch.active, .swatch:hover { box-shadow: 0 0 0 2px var(--accent); }
.mode-toggles {
  display: flex;
  gap: .45rem;
  flex-wrap: wrap;
}
.mode-btn {
  padding: .45rem .8rem;
  border-radius: var(--radius-sm);
  background: var(--bg2);
  color: var(--text);
  border: 1.5px solid transparent;
  font-size: .85rem;
  transition: var(--transition);
}
.mode-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.mode-btn:hover {
  background: var(--border);
}
.font-sizes { display: flex; gap: .4rem; }
.fs-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: .35rem .6rem;
  border-radius: var(--radius-sm);
  background: var(--bg2);
  color: var(--text);
  font-size: 1rem;
  line-height: 1.2;
  transition: var(--transition);
  border: 1.5px solid transparent;
}
.fs-btn small { font-size: .6rem; color: var(--muted); }
.fs-btn.active { border-color: var(--accent); color: var(--accent); }
.fs-btn:hover { background: var(--border); }

/* =============================================
   POEMS LIST
   ============================================= */
.poems-main {
  max-width: 800px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

/* Search */
.search-wrap { margin-bottom: 1.5rem; }
.search-box {
  display: flex;
  align-items: center;
  gap: .6rem;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 2rem;
  padding: .6rem 1rem;
  box-shadow: var(--card-shadow);
}
.search-icon { width: 18px; height: 18px; fill: var(--muted); flex-shrink: 0; }
#search-input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: .95rem;
  outline: none;
}
#search-input::placeholder { color: var(--muted); }

/* Grid of poem cards */
.poems-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}
@media (min-width: 520px) {
  .poems-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 700px) {
  .poems-grid { grid-template-columns: repeat(3, 1fr); }
}

.poem-card {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: .5rem;
}
.poem-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,.12);
  border-color: var(--accent-light);
}
.poem-card:active { transform: translateY(0); }
.poem-card-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
}
.poem-card-desc {
  font-size: .82rem;
  color: var(--muted);
  line-height: 1.5;
}
.poem-card-meta {
  font-size: .78rem;
  color: var(--muted);
}
.poem-card-rating {
  display: flex;
  align-items: center;
  gap: .35rem;
  font-size: .85rem;
  color: var(--accent);
  font-weight: 500;
  margin-top: auto;
}
.poem-card-rating svg { width: 14px; height: 14px; fill: var(--accent); }
.poem-read-check {
  position: absolute;
  top: .7rem;
  right: .7rem;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(150, 150, 150, .14);
  border: 1px solid rgba(160, 160, 160, .22);
  color: #b6b6b6;
  font-size: .82rem;
  font-weight: 700;
}
.poem-card-keywords {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
}
.kw-tag {
  background: var(--bg2);
  color: var(--muted);
  font-size: .7rem;
  padding: .15rem .5rem;
  border-radius: 1rem;
}

/* Loading / empty */
.loading { text-align: center; color: var(--muted); padding: 3rem 0; font-style: italic; }
.empty { text-align: center; color: var(--muted); padding: 3rem 0; font-style: italic; }

/* Pagination */
.pagination {
  display: flex;
  gap: .5rem;
  justify-content: center;
  margin-top: 2rem;
  flex-wrap: wrap;
}
.page-btn {
  padding: .45rem .8rem;
  border-radius: var(--radius-sm);
  background: var(--bg2);
  color: var(--text);
  font-size: .9rem;
  border: 1.5px solid transparent;
  transition: var(--transition);
}
.page-btn.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.page-btn:hover:not(.active) { background: var(--border); }

/* =============================================
   POEM DETAIL
   ============================================= */
.poem-main {
  max-width: 620px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 5rem;
}

.poem-article {
  margin: 0 auto .75rem;
  width: 100%;
}

.book-page {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 10px 24px rgba(60,40,10,.08);
  padding: 3rem 2.8rem 3.2rem;
  min-height: 52vh;
}

.book-page::after {
  content: '';
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(139,94,60,.06);
  border-radius: 12px;
  pointer-events: none;
}

.poem-reader-status {
  text-align: center;
  color: var(--muted);
  font-size: .82rem;
  font-style: italic;
  margin-bottom: 1.5rem;
}

.poem-page-center {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: .15rem;
}

.reader-more-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: rgba(139,94,60,.12);
  color: var(--accent-dark);
  font-size: 1.1rem;
  font-weight: 800;
  line-height: 1;
  box-shadow: 0 1px 4px rgba(60,40,10,.12);
  animation: readerArrowBounce 1.2s ease-in-out infinite;
}

@keyframes readerArrowBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(3px); }
}

.poem-title {
  font-family: 'Playfair Display', serif;
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  font-weight: 700;
  line-height: 1.25;
  margin-bottom: 1.35rem;
  color: var(--text);
}
.poem-meta {
  font-size: .82rem;
  color: var(--muted);
  display: flex;
  gap: .55rem;
  flex-wrap: wrap;
}

.poem-meta-below {
  margin: .35rem 0 1rem;
  justify-content: center;
}
.poem-content {
  font-family: 'Playfair Display', serif;
  font-size: var(--poem-size, 18px);
  line-height: var(--poem-lh, 1.9);
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  padding-bottom: 1.8rem;
}

/* ---- Rating section ---- */
.rating-section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 0 auto 2rem;
  box-shadow: var(--card-shadow);
  max-width: 100%;
}
.rating-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: .5rem;
}
.rating-header h3 { font-size: 1rem; font-weight: 600; }
.avg-display {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--accent);
  font-family: 'Playfair Display', serif;
}
.avg-display span { font-size: .8rem; color: var(--muted); font-family: 'Inter', sans-serif; font-weight: 400; }

.my-rating-area { margin-bottom: 1rem; }
.rating-label { font-size: .85rem; color: var(--muted); margin-bottom: .6rem; }

.rating-stars {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: .45rem;
  width: 100%;
}
.star-btn {
  width: 100%;
  height: 56px;
  border-radius: var(--radius-sm);
  background: rgba(139,94,60,.05);
  color: #c7b9a2;
  font-size: 2rem;
  line-height: 1;
  font-weight: 700;
  border: 1px solid rgba(139,94,60,.08);
  transition: transform .15s ease, color .15s ease, background .15s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.star-btn:hover { color: var(--accent-light); background: rgba(139,94,60,.12); }
.star-btn.selected { color: #d9a441; background: rgba(217,164,65,.12); }

@media (min-width: 420px) {
  .star-btn { height: 64px; font-size: 2.25rem; }
}

.rating-feedback {
  font-size: .82rem;
  color: var(--accent);
  margin-top: .5rem;
  min-height: 1.2em;
  font-style: italic;
}

/* Distribution bars */
.rating-distribution { margin-top: .75rem; }
.dist-label { font-size: .75rem; color: var(--muted); margin-bottom: .4rem; }
.dist-bar-wrap { display: flex; align-items: center; gap: .5rem; margin-bottom: .2rem; }
.dist-num { font-size: .75rem; color: var(--muted); width: 14px; text-align: right; }
.dist-bar-bg { flex: 1; height: 6px; background: var(--bg2); border-radius: 3px; overflow: hidden; }
.dist-bar-fill { height: 100%; background: var(--accent-light); border-radius: 3px; transition: width .4s ease; }
.dist-count { font-size: .72rem; color: var(--muted); width: 26px; }

/* ---- Comments section ---- */
.comments-section {
  margin: 0 auto 2rem;
  max-width: 100%;
}
.comments-section h3 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.badge {
  background: var(--bg2);
  color: var(--muted);
  font-size: .75rem;
  padding: .1rem .45rem;
  border-radius: 1rem;
  font-weight: 400;
}

.comment-form { margin-bottom: 1.5rem; }
.comment-form textarea {
  width: 100%;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  padding: .75rem 1rem;
  font-size: .95rem;
  resize: vertical;
  transition: var(--transition);
  margin-bottom: .6rem;
}
.comment-form textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139,94,60,.12);
}
.comment-form .btn-primary { width: auto; padding: .65rem 1.5rem; }

.comments-list { display: flex; flex-direction: column; gap: .9rem; }
.comment-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: .9rem 1rem;
  position: relative;
}
.comment-author {
  font-size: .82rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: .3rem;
}
.comment-date { font-size: .75rem; color: var(--muted); }
.comment-text { font-size: .92rem; line-height: 1.6; margin-top: .4rem; color: var(--text); word-break: break-word; }
.comment-delete {
  position: absolute;
  top: .6rem; right: .6rem;
  font-size: .75rem;
  color: var(--muted);
  padding: .2rem .45rem;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.comment-delete:hover { background: #fee; color: #c0392b; }

/* =============================================
   ADMIN PANEL (admin.html uses this too)
   ============================================= */
.admin-wrap {
  width: min(1440px, calc(100vw - 1rem));
  max-width: 1440px;
  margin: 0 auto;
  padding: 1.5rem .75rem 4rem;
}
.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.admin-header h1 {
  font-family: 'Playfair Display', serif;
  font-size: 1.6rem;
  color: var(--accent);
}
.admin-nav { display: flex; gap: .5rem; flex-wrap: wrap; }
.admin-nav-btn {
  padding: .5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  background: var(--bg2);
  color: var(--text);
  border: 1.5px solid transparent;
  transition: var(--transition);
}
.admin-nav-btn.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.admin-nav-btn:hover:not(.active) { background: var(--border); }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.2rem;
  text-align: center;
  box-shadow: var(--card-shadow);
}
.stat-card .stat-num {
  font-family: 'Playfair Display', serif;
  font-size: 2rem;
  font-weight: 700;
  color: var(--accent);
}
.stat-card .stat-label { font-size: .78rem; color: var(--muted); margin-top: .2rem; }

.admin-setting-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin: 0 0 1.25rem;
  box-shadow: var(--card-shadow);
}
.admin-setting-card h3 {
  font-size: .92rem;
  color: var(--accent);
  margin-bottom: .75rem;
}
.admin-setting-row {
  display: flex;
  gap: .75rem;
  align-items: end;
  flex-wrap: wrap;
}
.admin-setting-field {
  flex: 1;
  min-width: 220px;
}
.admin-setting-field select {
  width: 100%;
  padding: .65rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: .95rem;
}
.admin-setting-row .btn-primary {
  width: auto;
  min-width: 180px;
}

.admin-section { margin-bottom: 2rem; }
.admin-section h2 { font-size: 1.1rem; margin-bottom: 1rem; color: var(--text); }
.poem-tools {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin: -.35rem 0 .9rem;
}
.poem-order-hint {
  font-size: .84rem;
  color: var(--muted);
  margin: 0;
}
.poem-filter-wrap {
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
.poem-filter-wrap label {
  font-size: .78rem;
  color: var(--muted);
}
.poem-filter-wrap select {
  min-width: 220px;
  padding: .5rem .75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
}
.admin-section h2 button {
  float: right;
  padding: .4rem .9rem;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  font-weight: 500;
  transition: var(--transition);
}
.admin-section h2 button:hover { background: var(--accent-dark); }

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--card-shadow);
}
.admin-table th {
  text-align: left;
  padding: .75rem 1rem;
  background: var(--bg2);
  color: var(--muted);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
}
.admin-table td {
  padding: .7rem 1rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
.drag-cell {
  width: 28px;
  text-align: center;
  cursor: grab;
  color: var(--muted);
  -webkit-user-select: none;
  user-select: none;
}
.drag-handle {
  display: inline-block;
  letter-spacing: -0.08em;
  font-size: 1rem;
  line-height: 1;
}
#poems-table tbody tr[draggable="true"] {
  cursor: grab;
}
#poems-table tbody tr.poem-row-dragging {
  opacity: .55;
  background: var(--bg2);
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: var(--bg2); }
.table-wrap { overflow-x: auto; border-radius: var(--radius); width: 100%; }

#poems-table {
  table-layout: fixed;
}
#poems-table th,
#poems-table td {
  padding: .58rem .45rem;
  font-size: .78rem;
}
#poems-table th:nth-child(1),
#poems-table td:nth-child(1) {
  width: 30px;
}
#poems-table th:nth-child(2),
#poems-table td:nth-child(2) {
  width: 17%;
}
#poems-table th:nth-child(3),
#poems-table td:nth-child(3) {
  width: 10%;
}
#poems-table th:nth-child(4),
#poems-table td:nth-child(4) {
  width: 9%;
}
#poems-table th:nth-child(5),
#poems-table td:nth-child(5) {
  width: 13%;
}
#poems-table th:nth-child(6),
#poems-table td:nth-child(6) {
  width: 15%;
}
#poems-table th:nth-child(7),
#poems-table td:nth-child(7),
#poems-table th:nth-child(8),
#poems-table td:nth-child(8),
#poems-table th:nth-child(9),
#poems-table td:nth-child(9) {
  width: 6%;
}
#poems-table th:nth-child(10),
#poems-table td:nth-child(10) {
  width: 10%;
}
#poems-table th:nth-child(11),
#poems-table td:nth-child(11) {
  width: 92px;
}
#poems-table td:nth-child(2),
#poems-table td:nth-child(3),
#poems-table td:nth-child(5),
#poems-table td:nth-child(6),
#poems-table td:nth-child(10) {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.poem-actions {
  display: flex;
  flex-direction: column;
  gap: .28rem;
}
.poem-actions .btn-edit,
.poem-actions .btn-del {
  width: 100%;
  margin-right: 0;
  text-align: center;
}

.btn-edit {
  padding: .3rem .7rem;
  background: var(--bg2);
  border-radius: var(--radius-sm);
  font-size: .8rem;
  color: var(--text);
  margin-right: .3rem;
  transition: var(--transition);
  border: 1px solid var(--border);
}
.btn-edit:hover { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-del {
  padding: .3rem .7rem;
  background: #fee;
  color: #c0392b;
  border-radius: var(--radius-sm);
  font-size: .8rem;
  transition: var(--transition);
  border: 1px solid #fcc;
}
.btn-del:hover { background: #c0392b; color: #fff; border-color: #c0392b; }

/* Admin form modal */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 200;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
}
.modal {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 640px;
  margin: auto;
}
.modal-poem-editor {
  width: min(1380px, calc(100vw - .75rem));
  max-width: min(1380px, calc(100vw - .75rem));
}
.modal h3 { font-size: 1.1rem; margin-bottom: 1.25rem; color: var(--text); }
.modal .field input, .modal .field textarea {
  width: 100%;
  padding: .7rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: .95rem;
}
.modal .field textarea { resize: vertical; min-height: 180px; font-family: 'Playfair Display', serif; line-height: 1.8; }
.modal .field input:focus, .modal .field textarea:focus { outline: none; border-color: var(--accent); }
.modal-actions { display: flex; gap: .75rem; justify-content: flex-end; margin-top: 1rem; }
.btn-secondary {
  padding: .7rem 1.2rem;
  border-radius: var(--radius-sm);
  background: var(--bg2);
  color: var(--text);
  font-size: .9rem;
  transition: var(--transition);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }
.modal-actions .btn-primary { width: auto; padding: .7rem 1.4rem; }

/* Admin auth screen */
.admin-auth {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 2rem 1rem;
}
.admin-auth .auth-container { max-width: 340px; }
.admin-auth-error { color: #c0392b; font-size: .85rem; min-height: 1.2em; margin-bottom: .5rem; }

/* Toast notifications */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #2c2c2c;
  color: #fff;
  padding: .7rem 1.4rem;
  border-radius: 2rem;
  font-size: .88rem;
  z-index: 999;
  transition: transform .3s ease;
  white-space: nowrap;
  pointer-events: none;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { background: #c0392b; }

/* =============================================
   SCROLLBAR (subtle)
   ============================================= */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* =============================================
   MOBILE extra care
   ============================================= */
@media (max-width: 400px) {
  .rating-stars { gap: .25rem; }
  .star-btn { width: 32px; height: 32px; font-size: .82rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* =============================================
   BOOKS VIEW
   ============================================= */
.books-heading {
  font-family: 'Playfair Display', serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 1.5rem;
}

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: .85rem;
}

.book-card {
  display: flex;
  align-items: flex-start;
  gap: .7rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--card-shadow);
  overflow: hidden;
  min-height: 160px;
}
.book-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0,0,0,.14);
  border-color: var(--accent-light);
}
.book-card-spine {
  width: 10px;
  background: var(--accent);
  flex-shrink: 0;
}
.book-card-cover-wrap {
  width: 82px;
  min-width: 82px;
  align-self: center;
}
.book-card-cover {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg2);
  box-shadow: 0 6px 18px rgba(0,0,0,.12);
}
.book-card-body {
  padding: .75rem .75rem .75rem 0;
  display: flex;
  flex-direction: column;
  gap: .3rem;
  flex: 1;
  min-width: 0;
}
.book-card-title {
  font-family: 'Playfair Display', serif;
  font-size: .92rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
  text-transform: uppercase;
  white-space: normal;
  overflow-wrap: normal;
  word-break: normal;
  -webkit-hyphens: none;
  hyphens: none;
}
.book-card-desc {
  font-size: .8rem;
  color: var(--muted);
  font-style: italic;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-card-count {
  font-size: .78rem;
  color: var(--accent);
  font-weight: 500;
  margin-top: auto;
}
.book-physical-link,
.btn-link-mini {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  margin-top: .45rem;
  padding: .38rem .7rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--accent);
  font-size: .78rem;
  font-weight: 600;
  text-decoration: none;
  transition: var(--transition);
}
.book-physical-link:hover,
.btn-link-mini:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.book-table-cover {
  width: 42px;
  height: 56px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}

/* Book breadcrumb (appears when filtering poems by book) */
.book-breadcrumb {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
}
.book-breadcrumb > * {
  max-width: 800px;
  margin: 0 auto;
  padding: .5rem 1rem;
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  flex-wrap: wrap;
}
.breadcrumb-back {
  display: flex;
  align-items: center;
  gap: .3rem;
  font-size: .82rem;
  color: var(--muted);
  padding: .25rem .5rem;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.breadcrumb-back:hover { background: var(--border); color: var(--text); }
.breadcrumb-copy {
  display: flex;
  flex-direction: column;
  gap: .2rem;
  min-width: 0;
  flex: 1;
}

.breadcrumb-title {
  font-family: 'Playfair Display', serif;
  font-weight: 700;
  font-size: .95rem;
  color: var(--accent);
  text-transform: uppercase;
}

.breadcrumb-desc {
  font-size: .86rem;
  color: var(--muted);
  line-height: 1.5;
}

/* Small text nav button in header */
.btn-text-sm {
  padding: .3rem .65rem;
  border-radius: var(--radius-sm);
  font-size: .82rem;
  background: var(--bg2);
  color: var(--muted);
  border: 1px solid var(--border);
  transition: var(--transition);
}
.btn-text-sm:hover { background: var(--border); color: var(--text); }

/* =============================================
   IMPORT SECTION (admin)
   ============================================= */
.import-form {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 600px;
  box-shadow: var(--card-shadow);
}
.import-form .field input,
.import-form .field select {
  width: 100%;
  padding: .65rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: .95rem;
}
.import-form .field select { cursor: pointer; }
.import-form .field input[type="file"] { padding: .5rem; }
.import-form .btn-primary { width: auto; margin-top: .5rem; }

.import-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .75rem;
  margin-bottom: 1rem;
  padding-bottom: .75rem;
  border-bottom: 1px solid var(--border);
}
.import-preview-header strong { font-size: 1rem; }

.import-preview-list {
  max-height: 400px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--card-shadow);
}
.import-preview-item {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
}
.import-preview-item:last-child { border-bottom: none; }
.import-cb-label {
  display: flex;
  align-items: center;
  gap: .6rem;
  cursor: pointer;
}
.import-cb-label input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); flex-shrink: 0; }
.import-poem-title {
  font-family: 'Playfair Display', serif;
  font-weight: 700;
  font-size: .95rem;
}
.import-poem-preview {
  font-size: .8rem;
  color: var(--muted);
  margin-top: .25rem;
  padding-left: 1.6rem;
  font-style: italic;
  line-height: 1.5;
}

.import-success {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 2rem;
  text-align: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  max-width: 400px;
}
.import-success strong { font-size: 1.1rem; }

/* Select inside modal */
.modal .field select {
  width: 100%;
  padding: .65rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: .95rem;
  cursor: pointer;
}
.modal .field select:focus { outline: none; border-color: var(--accent); }

/* Book modal description textarea */
#book-modal .modal .field textarea { min-height: 100px; font-family: 'Inter', sans-serif; line-height: 1.6; }

/* =============================================
   STATUS BADGES (admin poems table)
   ============================================= */
.status-badge {
  display: inline-block;
  padding: .2rem .5rem;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
}
.status-badge.published {
  background: rgba(var(--accent-rgb, 120,90,60), .12);
  color: var(--accent);
}
.status-badge.draft {
  background: var(--bg2);
  color: var(--muted);
  border: 1px solid var(--border);
}

/* Status toggle in poem modal */
.status-toggle-wrap {
  display: flex;
  gap: .5rem;
}
.status-btn {
  padding: .35rem .9rem;
  border-radius: 20px;
  font-size: .82rem;
  font-weight: 500;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: var(--transition);
}
.status-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* EPUB export button */
.btn-epub {
  padding: .3rem .65rem;
  border-radius: var(--radius-sm);
  font-size: .78rem;
  font-weight: 500;
  background: var(--bg2);
  color: var(--muted);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.btn-epub:hover { background: var(--accent); color: #fff; border-color: var(--accent); }

/* =============================================
   QUILL EDITOR in poem modal
   ============================================= */
.ql-toolbar.ql-snow {
  border-color: var(--border) !important;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0 !important;
  background: var(--bg2);
  font-family: 'Inter', sans-serif;
}
.ql-container.ql-snow {
  border-color: var(--border) !important;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm) !important;
  font-family: 'Playfair Display', serif;
  font-size: 1rem;
  line-height: 1.8;
  background: var(--card);
  color: var(--text);
}
.ql-editor {
  min-height: 220px;
  max-height: 420px;
  overflow-y: auto;
}
.ql-editor.ql-blank::before {
  color: var(--muted) !important;
  font-style: italic;
}
/* Dark/light toolbar icon colors */
.ql-snow .ql-stroke { stroke: var(--muted) !important; }
.ql-snow .ql-fill  { fill: var(--muted) !important; }
.ql-snow .ql-picker { color: var(--muted) !important; }
.ql-snow .ql-picker-options { background: var(--card) !important; border-color: var(--border) !important; }

/* =============================================
   HTML POEM CONTENT (public view)
   ============================================= */
.poem-content-html {
  font-family: 'Playfair Display', serif;
  font-size: inherit;
  line-height: inherit;
}
.poem-content-html p {
  margin: 0 0 .12em;
}
.poem-content-html p:empty, .poem-content-html .ql-align-center { text-align: center; }
.poem-content-html .ql-align-right  { text-align: right; }
.poem-content-html strong { font-weight: 700; }
.poem-content-html em    { font-style: italic; }

/* =============================================
   PAGE-TURN ANIMATION (poem detail entry)
   ============================================= */
@keyframes pageTurnIn {
  from {
    transform: perspective(1200px) rotateY(-14deg) translateX(18px) translateY(0);
    opacity: 0.12;
  }
  to {
    transform: perspective(1200px) rotateY(0deg) translateX(0) translateY(0);
    opacity: 1;
  }
}

@keyframes fadeSoftIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.page-turn-in {
  animation: pageTurnIn 0.5s cubic-bezier(0.22, 0.61, 0.36, 1) forwards;
  transform-origin: left center;
  will-change: transform, opacity;
}

.fade-soft-in {
  animation: fadeSoftIn 0.42s ease-out forwards;
}

.rating-section,
.comments-section {
  opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
  .page-turn-in,
  .fade-soft-in { animation: none; }
}

@media (max-width: 720px) {
  .swipe-reader {
    touch-action: pan-y;
    position: relative;
    z-index: 2;
  }

  .book-page {
    padding: 2rem 1.45rem 2.2rem;
    min-height: calc(100dvh - 120px);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
  }

  .book-page .poem-content {
    flex: 1;
  }

  .rating-section,
  .comments-section {
    position: relative;
    z-index: 1;
  }

  .poem-reader-status {
    padding: 0 .25rem;
  }

  .poem-page-center {
    gap: .1rem;
  }

  .poem-nav-row {
    flex-wrap: nowrap;
    justify-content: space-between;
  }

  .poem-pg-btn {
    min-width: 46px;
    padding: .55rem .7rem;
  }

  .pg-label {
    display: none;
  }

  .pg-arrow {
    font-size: 1.2rem;
  }

  .rating-stars {
    gap: .25rem;
  }

  .star-btn {
    height: 66px;
    font-size: 2.15rem;
  }

  .reader-more-indicator {
    width: 32px;
    height: 32px;
    font-size: 1.3rem;
  }

  [data-font-size="sm"] { --poem-size: 17px; --poem-lh: 1.45; }
  [data-font-size="md"] { --poem-size: 20px; --poem-lh: 1.52; }
  [data-font-size="lg"] { --poem-size: 24px; --poem-lh: 1.62; }
  [data-font-size="xl"] { --poem-size: 28px; --poem-lh: 1.72; }
}

/* =============================================
   POEM PAGE NAVIGATION (long poem pagination)
   ============================================= */
.poem-page-nav {
  display: flex;
  flex-direction: column;
  gap: .65rem;
  margin-top: 1.5rem;
  padding: .9rem 0 .15rem;
  border-top: 1px solid var(--border);
}
.poem-nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}
.poem-nav-pages {
  justify-content: center;
}
.poem-pg-btn {
  padding: .5rem .9rem;
  border-radius: var(--radius-sm);
  background: var(--bg2);
  color: var(--text);
  font-size: .84rem;
  border: 1.5px solid var(--border);
  cursor: pointer;
  transition: var(--transition);
  font-family: 'Playfair Display', serif;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
}
.pg-arrow {
  font-size: 1rem;
  line-height: 1;
}
.pg-label {
  white-space: nowrap;
}
.poem-pg-btn:hover:not([disabled]) { background: var(--accent); color: #fff; border-color: var(--accent); }
.poem-pg-btn[disabled] { opacity: .4; cursor: default; }
.poem-pg-info {
  font-size: .8rem;
  color: var(--muted);
  font-style: italic;
  min-width: 80px;
  text-align: center;
}

/* =============================================
   SYLLABLE COUNTER PANEL (admin editor)
   ============================================= */
.editor-syllable-wrap {
  display: flex;
  gap: .75rem;
  align-items: stretch;
}
.editor-main {
  flex: 1 1 auto;
  min-width: 0;
}
.modal-poem-editor #quill-editor {
  min-width: 0;
}
.editor-main .ql-toolbar.ql-snow,
.editor-main .ql-container.ql-snow {
  width: 100%;
}
.syllable-panel {
  min-width: 76px;
  max-width: 86px;
  flex-shrink: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0;
  font-size: .7rem;
  font-family: 'Inter', monospace, sans-serif;
  color: var(--muted);
  max-height: 474px; /* matches quill max-height + toolbar */
  overflow-y: auto;
}
.syl-header {
  text-align: center;
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  padding: .35rem .3rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  position: sticky;
  top: 0;
}
.syl-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .18rem .4rem;
  border-bottom: 1px solid var(--border);
  line-height: 1.4;
}
.syl-line:last-child { border-bottom: none; }
.syl-n { color: var(--muted); opacity: .55; font-size: .65rem; }
.syl-c { color: var(--accent); font-weight: 700; font-size: .72rem; }

@media (max-width: 900px) {
  .modal-poem-editor {
    max-width: 100%;
  }

  .editor-syllable-wrap {
    flex-direction: column;
  }

  .syllable-panel {
    max-width: none;
    max-height: 160px;
  }
}
