/* ---------- Tokens ---------- */
:root {
  --paper: #14121c;
  --paper-deep: #201c2c;
  --ink: #f4efe6;
  --ink-soft: #a79cc4;
  --coral: #ff4d6d;
  --coral-dark: #d6304f;
  --teal: #34e2b8;
  --gold: #ffce54;
  --line: #34304a;
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Nunito", sans-serif;
  line-height: 1.55;
}

h1, h2 {
  font-family: "Baloo 2", sans-serif;
  font-weight: 700;
  margin: 0 0 .3em;
  line-height: 1.2;
}

h1 { font-size: 2rem; }
h2 { font-size: 1.25rem; }

a { color: var(--teal); }

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}

.subtle { color: var(--ink-soft); font-size: .92rem; }

/* ---------- Header ---------- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 3px dashed var(--line);
  background: var(--paper);
}

.brand {
  font-family: "Baloo 2", sans-serif;
  font-weight: 700;
  font-size: 1.3rem;
  text-decoration: none;
  color: var(--ink);
}

.brand-mark { color: var(--coral); }

.site-nav { display: flex; align-items: center; gap: 1rem; font-size: .92rem; }
.whoami { color: var(--ink-soft); }
.site-nav a { text-decoration: none; }

/* ---------- Flash messages ---------- */
.flash-stack { max-width: 900px; margin: 1rem auto 0; padding: 0 1.25rem; }
.flash {
  background: var(--gold);
  color: var(--paper);
  padding: .6rem 1rem;
  border-radius: var(--radius);
  font-weight: 700;
  margin: 0 0 .5rem;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  padding: .5rem 1rem;
  border-radius: 999px;
  border: 2px solid var(--line);
  background: transparent;
  color: var(--ink);
  font-family: "Nunito", sans-serif;
  font-weight: 700;
  font-size: .92rem;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover { transform: translateY(-1px); }

.btn-primary { background: var(--coral); border-color: var(--coral-dark); color: var(--paper); }
.btn-danger { background: transparent; border-color: var(--coral-dark); color: var(--coral); }
.btn-small { padding: .3rem .7rem; font-size: .82rem; }
.btn:disabled { opacity: .35; cursor: not-allowed; transform: none; }

/* ---------- Page header row ---------- */
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin: .5rem 0 1.25rem;
}

.head-actions { display: flex; gap: .5rem; flex-shrink: 0; }
.breadcrumb { font-size: .85rem; color: var(--ink-soft); margin: 1rem 0 0; }
.breadcrumb a { text-decoration: none; }

.story-logo { max-height: 90px; display: block; margin-bottom: .4rem; }

.empty-state {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  color: var(--ink-soft);
  margin: 1.5rem 0;
}

/* ---------- Bookshelf ---------- */
.shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.book { text-decoration: none; color: var(--ink); }

.book-cover {
  aspect-ratio: 3 / 4;
  background: var(--paper-deep);
  border: 2px solid var(--story-accent, var(--line));
  border-radius: var(--radius) var(--radius) 4px 4px;
  overflow: hidden;
  box-shadow: 5px 5px 0 var(--story-accent, var(--line));
  display: flex;
  align-items: center;
  justify-content: center;
}

.book-cover img { width: 100%; height: 100%; object-fit: cover; }
.book-cover-placeholder { font-family: "Baloo 2", sans-serif; font-size: 2.5rem; color: var(--ink-soft); }

.book-label { padding: .6rem .1rem 0; }
.book-label h2 { font-size: 1rem; margin-bottom: .1rem; }
.book-label p { margin: 0; font-size: .82rem; color: var(--ink-soft); }

/* ---------- Chapter / page lists ---------- */
.chapter-list, .page-list { list-style: none; margin: 1.25rem 0 0; padding: 0; }

.chapter-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  background: var(--paper-deep);
  border-radius: var(--radius);
  padding: .9rem 1.1rem;
  margin-bottom: .7rem;
}

.chapter-info { display: flex; flex-direction: column; }
.chapter-title { font-family: "Baloo 2", sans-serif; font-weight: 600; font-size: 1.05rem; }
.chapter-actions { display: flex; gap: .4rem; flex-wrap: wrap; }

.page-row {
  display: grid;
  grid-template-columns: 70px 1fr auto;
  align-items: center;
  gap: 1rem;
  background: var(--paper-deep);
  border-radius: var(--radius);
  padding: .6rem .9rem;
  margin-bottom: .6rem;
}

.page-thumb { width: 70px; height: 70px; object-fit: cover; border-radius: 8px; border: 2px solid var(--line); }
.page-caption-preview { margin: 0; font-size: .9rem; color: var(--ink-soft); }
.page-actions { display: flex; gap: .3rem; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- Reader ---------- */
.reader-stage {
  background-image: var(--story-bg, none);
  background-size: cover;
  background-position: center;
  border-radius: var(--radius);
  padding: 2rem 1rem 1.25rem;
  margin-top: 1.5rem;
}

.reader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
}

.reader-arrow {
  flex-shrink: 0;
  width: 3rem;
  height: 3rem;
  border-radius: 50%;
  background: var(--story-accent, var(--coral));
  color: var(--paper);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  text-decoration: none;
  border: none;
}

.reader-arrow.is-disabled { background: var(--line); color: var(--ink-soft); pointer-events: none; }

.storybook-page {
  background: var(--paper-deep);
  border: 2px solid var(--story-accent, var(--line));
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 560px;
  width: 100%;
  text-align: center;
  position: relative;
  box-shadow: 6px 6px 0 var(--story-accent, var(--line));
}

.story-page-logo { max-height: 70px; margin: 0 auto .75rem; display: block; }

.story-frame {
  position: relative;
  display: inline-block;
  transform: rotate(-.6deg);
}

.story-frame::before {
  content: "";
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%) rotate(-4deg);
  width: 46px;
  height: 20px;
  background: var(--story-accent, var(--gold));
  opacity: .85;
}

.story-frame img {
  max-width: 100%;
  max-height: 55vh;
  border: 6px solid var(--ink);
  outline: 1px solid var(--line);
  box-shadow: 0 3px 14px rgba(0,0,0,.5);
}

.story-caption {
  font-size: 1.05rem;
  margin: 1.1rem 0 .3rem;
  color: var(--ink);
}

.page-counter { font-size: .8rem; color: var(--ink-soft); margin: 0; }
.reader-controls { display: flex; justify-content: center; margin-top: 1rem; }
.reader-manage { text-align: center; margin-top: 1rem; font-size: .88rem; }
.reader-manage a { cursor: pointer; }

@media (max-width: 640px) {
  .reader { flex-direction: row; gap: .5rem; }
  .reader-arrow { width: 2.4rem; height: 2.4rem; font-size: 1.1rem; }
}

/* ---------- Forms ---------- */
.login-card {
  max-width: 380px;
  margin: 2.5rem auto 0;
  background: var(--paper-deep);
  border-radius: var(--radius);
  padding: 1.75rem;
}

.stacked-form { display: flex; flex-direction: column; gap: 1rem; margin-top: 1rem; }

.stacked-form label {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  font-weight: 600;
  font-size: .92rem;
}

.stacked-form input[type="text"],
.stacked-form input[type="password"],
.stacked-form input[type="file"],
.stacked-form textarea {
  font-family: "Nunito", sans-serif;
  font-size: 1rem;
  padding: .55rem .7rem;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
}

.stacked-form input[type="color"] {
  width: 64px;
  height: 40px;
  padding: 2px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  cursor: pointer;
}

.stacked-form textarea { resize: vertical; }
.stacked-form input:focus, .stacked-form textarea:focus { outline: 2px solid var(--teal); border-color: var(--teal); }

.sharing-fieldset {
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin: 0;
}
.sharing-fieldset legend { font-weight: 700; padding: 0 .4rem; }
.radio-label { display: flex !important; flex-direction: row !important; align-items: center; gap: .5rem; font-weight: 600; font-size: .92rem; margin-bottom: .5rem; }
.radio-label input[type="radio"], .radio-label input[type="checkbox"] { width: auto; accent-color: var(--teal); }
.sharing-people { flex-direction: column; gap: .3rem; padding: .5rem 0 0 1.6rem; border-top: 1px dashed var(--line); margin-top: .3rem; }

.current-image-preview {
  max-width: 220px;
  border-radius: 8px;
  border: 2px solid var(--line);
}
