/* App UI styles (signing page, book viewer chrome, admin). */

:root {
  --paper: #fbf7f0;
  --card: #ffffff;
  --line: #e6ddcf;
  --line-strong: #d9cdb9;
  --ink: #1f2a44;
  --muted: #5a6275;
  --accent: #b9472a;
  --accent-dark: #8f3520;
  --accent-soft: #fff4ec;
  --good: #4e7a62;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Nunito', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}
a { color: var(--accent); }
a:hover { color: var(--accent-dark); }
[hidden] { display: none !important; }

.wrap { max-width: 560px; margin: 0 auto; padding: 18px 18px 48px; }
.wrap.wide { max-width: 1160px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.brand { font-family: 'Caveat', cursive; font-size: 30px; font-weight: 700; color: var(--accent); text-decoration: none; }
.eyebrow { font-size: 13px; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
.pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 12px; font-size: 14px; font-weight: 700;
}

h1, h2, h3 { line-height: 1.15; }
.hero {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 22px 20px;
  text-align: center;
  margin-bottom: 22px;
}
.hero .script { font-family: 'Caveat', cursive; font-size: 24px; color: var(--accent); }
.hero h1 { margin: 4px 0; font-family: 'Fraunces', Georgia, serif; font-weight: 600; font-size: 32px; text-wrap: balance; }
.hero p { margin: 0; color: var(--muted); font-size: 15px; }

.section { display: flex; flex-direction: column; gap: 10px; margin-bottom: 24px; }
.section > h2 { margin: 0; font-size: 18px; font-weight: 800; }
.hint { margin: 0; font-size: 14px; color: var(--muted); }

label.field { display: flex; flex-direction: column; gap: 6px; font-weight: 700; font-size: 15px; }
input[type='text'], input[type='password'], input[type='datetime-local'], textarea {
  font: inherit;
  font-weight: 400;
  font-size: 16px; /* 16px stops iOS zooming in */
  color: var(--ink);
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  padding: 12px 14px;
  min-height: 48px;
  width: 100%;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible {
  outline: 3px solid #f2c9a8;
  outline-offset: 2px;
}
.count { align-self: flex-end; font-size: 13px; color: var(--muted); font-weight: 400; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px;
  font: inherit; font-size: 16px; font-weight: 700;
  color: var(--ink); background: var(--card);
  border: 1px solid var(--line-strong); border-radius: 14px;
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--ink); color: var(--ink); }
.btn.primary { color: #fff; background: var(--accent); border-color: var(--accent); font-weight: 800; box-shadow: 0 6px 16px rgba(185, 71, 42, 0.25); }
.btn.primary:hover { background: var(--accent-dark); color: #fff; }
.btn.small { min-height: 40px; padding: 0 12px; font-size: 14px; border-radius: 12px; }
.btn.danger { color: #9b2c2c; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: 0.55; cursor: progress; }
.btn svg { flex-shrink: 0; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > .btn { flex: 1; }

/* Segmented Type / Draw control */
.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  background: #efe7da; border-radius: 14px; padding: 4px;
}
.segmented button {
  min-height: 44px; border: 0; border-radius: 11px;
  font: inherit; font-size: 15px; font-weight: 700; color: var(--ink);
  background: transparent; cursor: pointer;
}
.segmented button[aria-pressed='true'] { background: var(--card); box-shadow: 0 2px 6px rgba(31, 42, 68, 0.12); }

/* Font picker */
.fonts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.fonts button {
  min-height: 64px; display: flex; flex-direction: column; align-items: flex-start; justify-content: center;
  gap: 2px; padding: 8px 12px; border-radius: 14px; cursor: pointer; text-align: left;
  background: var(--card); border: 2px solid var(--line); color: var(--ink);
}
.fonts button[aria-pressed='true'] { background: var(--accent-soft); border-color: var(--accent); }
.fonts .demo { font-size: 24px; line-height: 1.15; }
.fonts .name { font-size: 12px; font-weight: 700; color: var(--muted); }

/* Ink swatches */
.inks { display: flex; gap: 12px; flex-wrap: wrap; }
.inks button {
  width: 44px; height: 44px; border-radius: 999px; cursor: pointer;
  border: 3px solid var(--paper); box-shadow: 0 0 0 1px var(--line-strong);
}
.inks button[aria-pressed='true'] { box-shadow: 0 0 0 3px var(--ink); }

/* Photos */
.photo-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.photo-slot {
  position: relative; aspect-ratio: 4 / 5; border-radius: 14px; overflow: hidden;
  background: var(--card); border: 2px dashed var(--line-strong);
  display: flex; align-items: center; justify-content: center;
}
.photo-slot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-slot .tools { position: absolute; inset: auto 6px 6px 6px; display: flex; gap: 6px; justify-content: center; }
.photo-slot .tools button {
  width: 40px; height: 40px; border-radius: 999px; border: 0; cursor: pointer;
  background: rgba(255, 255, 255, 0.92); color: var(--ink);
  display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}
.photo-add {
  width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-size: 14px; font-weight: 700; color: var(--muted); background: transparent; border: 0; cursor: pointer;
}
.photo-slot.busy::after {
  content: 'Uploading…'; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, 0.8); font-weight: 700; font-size: 14px;
}

/* Draw pad */
.pad-wrap { position: relative; background: #fff; border: 2px dashed var(--line-strong); border-radius: 18px; overflow: hidden; }
.pad { display: block; width: 100%; height: 280px; touch-action: none; cursor: crosshair; }
.pad-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); pointer-events: none; font-weight: 700; }
.sizes { display: flex; gap: 8px; }
.sizes button {
  width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line-strong); background: var(--card); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.sizes button[aria-pressed='true'] { border: 2px solid var(--ink); }
.sizes span { display: block; border-radius: 999px; background: var(--ink); }

/* Preview of the parent's page */
.preview-frame { max-width: 360px; width: 100%; margin: 0 auto; box-shadow: 0 10px 30px rgba(31, 42, 68, 0.15); border-radius: 4px 10px 10px 4px; overflow: hidden; }

.notice {
  background: #f3f7f4; border: 1px solid #cfe0d4; color: #234a37;
  border-radius: 14px; padding: 12px 14px; font-size: 14px;
}
.notice.warn { background: #fff7e8; border-color: #f0d9a8; color: #6b4a0e; }
.error-text { color: #9b2c2c; font-weight: 700; margin: 0; }

/* Join screen */
.join { max-width: 420px; margin: 8vh auto 0; text-align: center; }
.join form { display: flex; flex-direction: column; gap: 12px; margin-top: 18px; }
.join input { text-align: center; letter-spacing: 0.2em; text-transform: uppercase; font-weight: 800; }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 40px); opacity: 0;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-weight: 700;
  transition: all 0.25s ease; z-index: 50; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: #9b2c2c; }

/* ---------- Book viewer ---------- */
body.book-body { background: #e9dfcf; }
.book-stage { display: flex; flex-direction: column; align-items: center; gap: 20px; padding: 10px 16px 40px; }
.spread {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: min(100%, 1000px, calc((100vh - 220px) * 2 * 148 / 210));
  box-shadow: 0 24px 50px rgba(31, 42, 68, 0.25);
  border-radius: 8px;
  overflow: hidden;
  background: #fffdf8;
}
.spread.single { grid-template-columns: minmax(0, 1fr); width: min(100%, 500px, calc((100vh - 220px) * 148 / 210)); }
.spread .slot { position: relative; }
.spread .slot.left::after, .spread .slot.right::after {
  content: ''; position: absolute; top: 0; bottom: 0; width: 28px; pointer-events: none;
}
.spread .slot.left::after { right: 0; background: linear-gradient(to left, rgba(31, 42, 68, 0.18), transparent); }
.spread .slot.right::after { left: 0; background: linear-gradient(to right, rgba(31, 42, 68, 0.18), transparent); }
.spread .slot.empty { background: #e9dfcf; }
.turn-next { animation: turnNext 0.45s ease; }
.turn-prev { animation: turnPrev 0.45s ease; }
@keyframes turnNext { from { transform: perspective(1600px) rotateY(-8deg) translateX(30px); opacity: 0.3; } to { transform: none; opacity: 1; } }
@keyframes turnPrev { from { transform: perspective(1600px) rotateY(8deg) translateX(-30px); opacity: 0.3; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .turn-next, .turn-prev { animation: none; } }

.book-nav { display: flex; align-items: center; gap: 16px; }
.book-nav .label { font-weight: 700; min-width: 150px; text-align: center; }
.round {
  width: 52px; height: 52px; border-radius: 999px; display: flex; align-items: center; justify-content: center;
  background: var(--card); border: 1px solid var(--line-strong); color: var(--ink); cursor: pointer;
}
.round.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.round[disabled] { opacity: 0.4; cursor: default; }
.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; max-width: 1000px; }
.chips button {
  min-height: 40px; padding: 0 14px; font: inherit; font-size: 14px; font-weight: 700; color: var(--ink);
  background: var(--card); border: 1px solid var(--line-strong); border-radius: 999px; cursor: pointer;
}
.chips button[aria-current='true'] { background: var(--accent-soft); border-color: var(--accent); }

/* ---------- Admin ---------- */
.admin-list { display: flex; flex-direction: column; gap: 10px; }
.admin-item {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px;
}
.admin-item.is-hidden { opacity: 0.6; }
.admin-item .thumb { width: 56px; height: 70px; border-radius: 8px; object-fit: cover; background: #eee6d8; flex-shrink: 0; }
.admin-item .meta { flex: 1 1 200px; min-width: 0; }
.admin-item .meta strong { display: block; }
.admin-item .meta span { color: var(--muted); font-size: 14px; }
.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; text-align: center; }
.stat b { display: block; font-size: 24px; }
.stat span { font-size: 13px; color: var(--muted); }
.toggle { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.toggle input { width: 22px; height: 22px; }
