/* ── Variables ──────────────────────────────────────────────────────────── */
:root {
  --bg:            #FAF9F7;
  --surface:       #FFFFFF;
  --border:        #E8E4DC;
  --primary:       #5B4FCF;
  --primary-light: #EBE9FB;
  --accent:        #F5A623;
  --accent-dark:   #D4891A;
  --text:          #1A1A2E;
  --text-muted:    #6B7280;
  --danger:        #DC2626;
  --success:       #16A34A;
}

/* ── Reset & base ───────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  padding-top: env(safe-area-inset-top);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  position: relative;
}

/* Prevent font-size zoom on iOS for inputs/selects */
input, select, textarea, button {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
}

/* ── App header ─────────────────────────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px;
  z-index: 100;
}

.app-logo-img {
  height: 36px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
}

.app-wordmark {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 22px;
  font-weight: 600;
  color: var(--primary);
  letter-spacing: -0.01em;
}

/* ── Bottom tab bar ─────────────────────────────────────────────────────── */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(60px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -1px 0 var(--border);
  display: flex;
  align-items: flex-start;
  padding-top: 0;
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 100;
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 60px;
  gap: 3px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s;
  padding: 0;
}

.tab-btn svg {
  width: 24px;
  height: 24px;
  stroke: currentColor;
}

.tab-btn span {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.tab-btn.active {
  color: var(--primary);
}

/* ── Screens ────────────────────────────────────────────────────────────── */
.screens {
  padding-bottom: calc(60px + env(safe-area-inset-bottom));
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

.screen-scroll {
  padding: 0 0 24px;
}

/* ── Themed packs (quick-start chips) ────────────────────────────────────── */
.themed-packs {
  display: flex;
  gap: 8px;
  padding: 16px 16px 4px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.themed-packs::-webkit-scrollbar { display: none; }

.pack-btn {
  flex-shrink: 0;
  padding: 8px 14px;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: white;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
  line-height: 1;
}

.pack-btn:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}
/* Selected confirms which pack the user tapped — fills + bold border so it
   reads as "this is your current choice" not just a hover artifact. */
.pack-btn.selected {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  font-weight: 600;
}

/* ── Form sections ──────────────────────────────────────────────────────── */
.form-section {
  padding: 20px 16px 0;
}

.section-title {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 12px;
}

.optional-tag {
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 6px;
}

/* ── Genre groups & pills ───────────────────────────────────────────────── */
.genre-groups {
  display: flex;
  flex-direction: column;
}

.genre-group {
  margin-bottom: 16px;
}

.genre-group-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.genre-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.genre-pill {
  padding: 8px 14px;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1;
}

.genre-pill:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.genre-pill.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* ── Length picker ──────────────────────────────────────────────────────── */
.length-picker {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.length-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 4px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
  transition: all 0.15s;
  gap: 2px;
}

.length-option:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.length-option.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.length-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  transition: color 0.15s;
}

.length-desc {
  font-size: 0.65rem;
  color: var(--text-muted);
  margin-top: 2px;
  text-align: center;
  line-height: 1.2;
}

.length-option.selected .length-name {
  color: var(--primary);
}

.length-option:hover .length-name {
  color: var(--primary);
}

/* ── Generate button ────────────────────────────────────────────────────── */
.generate-wrap {
  padding: 24px 16px 8px;
}

.generate-row-utility {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
  min-height: 36px;
}

.clear-form-btn {
  font-size: 0.85rem;
}

.generate-row-utility .surprise-btn {
  margin-left: auto;
  width: auto;
  flex-shrink: 0;
}

.generate-btn {
  width: 100%;
  padding: 16px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 14px;
  font-family: 'Inter', sans-serif;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 54px;
}

.generate-btn:hover:not(:disabled) {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

.generate-btn:active:not(:disabled) {
  transform: translateY(0);
}

.generate-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-loading {
  display: none;
}

.generate-btn.loading .btn-text {
  display: none;
}

.generate-btn.loading .btn-loading {
  display: inline;
}

/* ── Inputs & selects ───────────────────────────────────────────────────── */
input, select {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-family: 'Inter', sans-serif;
  font-size: 1rem;
  background: white;
  color: var(--text);
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236B7280' stroke-width='1.5' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
}

input::placeholder {
  color: var(--text-muted);
}

/* ── Roster chips ───────────────────────────────────────────────────────── */
.roster {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
  min-height: 0;
}

.roster:empty {
  margin-bottom: 0;
}

.roster-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  transition: all 0.15s;
  line-height: 1.2;
}

.roster-chip:hover {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

.roster-chip.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.roster-chip.selected:hover {
  background: #4a3fb5;
  border-color: #4a3fb5;
}

.chip-remove {
  font-size: 0.95rem;
  line-height: 1;
  opacity: 0.65;
}

.chip-edit {
  font-size: 0.85rem;
  line-height: 1;
  opacity: 0.65;
}

.chip-edit:hover {
  opacity: 1;
}

.roster-chip.selected .chip-remove {
  opacity: 0.8;
}

.chip-remove:hover {
  opacity: 1;
}

.roster-add-btn {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  background: transparent;
  border: 1.5px dashed var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
  transition: all 0.15s;
}

.roster-add-btn:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

/* ── Roster new form ────────────────────────────────────────────────────── */
.roster-new-form {
  background: white;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.roster-new-form input,
.roster-new-form select {
  padding: 10px 12px;
  font-size: 0.9rem;
  flex: 1;
  min-width: 100px;
}

.roster-new-form .secondary-btn {
  flex-shrink: 0;
  padding: 10px 16px;
  font-size: 0.9rem;
}

.roster-new-form .link-btn {
  flex-shrink: 0;
}

.roster-traits-input {
  flex: 1 1 100% !important;
  min-width: 100% !important;
}

.trait-select {
  flex: 1 1 calc(50% - 4px) !important;
  min-width: calc(50% - 4px) !important;
}

/* ── Child / family entries ─────────────────────────────────────────────── */
#children-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.child-entry {
  display: grid;
  grid-template-columns: 1.6fr 1.1fr 0.9fr 1.2fr auto;
  gap: 6px;
  align-items: center;
}

.child-entry input,
.child-entry select {
  padding: 10px 10px;
  font-size: 0.9rem;
}

.child-entry:first-child .child-relation {
  visibility: hidden;
}

#family-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.family-entry {
  display: grid;
  grid-template-columns: 2fr 1.5fr auto;
  gap: 6px;
  align-items: center;
}

.family-entry input,
.family-entry select {
  padding: 10px 10px;
  font-size: 0.9rem;
}

.family-role-custom {
  grid-column: 1 / -2;
}

/* ── Remove buttons ─────────────────────────────────────────────────────── */
.remove-child, .remove-family {
  width: 40px;
  height: 40px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: white;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.15s;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.remove-child:hover, .remove-family:hover {
  background: #FEF2F2;
  border-color: #FCA5A5;
  color: var(--danger);
}

/* ── Ghost button ───────────────────────────────────────────────────────── */
.ghost-btn {
  width: 100%;
  padding: 10px;
  border: 1.5px dashed var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--primary);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 8px;
  transition: all 0.15s;
}

.ghost-btn:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

/* ── Secondary button ───────────────────────────────────────────────────── */
.secondary-btn {
  padding: 12px 20px;
  border: 1.5px solid var(--primary);
  border-radius: 10px;
  background: white;
  color: var(--primary);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

@media (hover: hover) and (pointer: fine) {
  .secondary-btn:hover {
    background: var(--primary);
    color: white;
  }
}

/* On touch devices the button can retain :focus styling after tap. Force it
   back to default unless the user is actually keyboard-navigating. */
.secondary-btn:focus:not(:focus-visible) {
  background: white;
  color: var(--primary);
  outline: none;
}

/* ── Link button ────────────────────────────────────────────────────────── */
.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.15s;
}

.link-btn:hover {
  background: var(--primary-light);
}

.link-btn.danger {
  color: var(--danger);
}

.link-btn.danger:hover {
  background: #FEF2F2;
}

/* ── Optional details ───────────────────────────────────────────────────── */
.optional-details {
  background: white;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.optional-details > summary {
  padding: 14px 16px;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
  list-style: none;
  font-size: 0.95rem;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.optional-details > summary::-webkit-details-marker {
  display: none;
}

.optional-details > summary::before {
  content: '▸';
  display: inline-block;
  transition: transform 0.15s;
  font-size: 0.85rem;
}

.optional-details[open] > summary::before {
  transform: rotate(90deg);
}

.optional-content {
  padding: 0 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}

.field-hint {
  margin-top: 4px;
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ── Teacher Mode ────────────────────────────────────────────────────────── */
.field-label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
  margin: 14px 0 6px;
}

.text-input,
.select-input {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font-size: 1rem;
  background: white;
  color: var(--text);
}

.form-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 16px;
  flex-wrap: wrap;
}

.classroom-card {
  text-align: left;
}

.roster-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  background: white;
  margin-bottom: 8px;
}

.roster-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.roster-meta {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.roster-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.roster-actions .secondary-btn {
  padding: 6px 12px;
  font-size: 0.85rem;
  min-width: auto;
}

.roster-actions .secondary-btn.disabled,
.roster-actions .secondary-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: var(--surface-muted, #efefef);
  color: var(--text-muted, #888);
  border-color: transparent;
}

.library-student-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 12px;
  padding: 10px 14px;
  background: rgba(91, 79, 207, 0.08);
  border: 1px solid rgba(91, 79, 207, 0.25);
  border-radius: 10px;
  font-size: 0.9rem;
}

.library-student-chip.hidden {
  display: none;
}

.library-student-chip .student-chip-label {
  color: var(--text-primary, #222);
}

.roster-add-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.roster-paste-form {
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--border-subtle, #e5e5e5);
  border-radius: 10px;
  background: var(--surface-muted, #fafafa);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.roster-paste-form.hidden {
  display: none;
}

.paste-roster-help {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-muted, #666);
  line-height: 1.4;
}

.paste-roster-help code {
  background: rgba(91, 79, 207, 0.08);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.82rem;
}

#paste-roster-text {
  width: 100%;
  min-height: 110px;
  padding: 10px 12px;
  font-family: ui-monospace, 'SF Mono', Consolas, monospace;
  font-size: 0.9rem;
  border: 1px solid var(--border-subtle, #ddd);
  border-radius: 8px;
  resize: vertical;
}

.paste-roster-defaults {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.85rem;
}

.paste-roster-defaults label {
  color: var(--text-muted, #666);
}

.paste-roster-preview {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 220px;
  overflow-y: auto;
}

.paste-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: white;
  border-radius: 6px;
  font-size: 0.85rem;
  border: 1px solid var(--border-subtle, #eee);
}

.paste-row span {
  color: var(--text-muted, #666);
}

.paste-row.invalid {
  background: rgba(220, 53, 69, 0.05);
  border-color: rgba(220, 53, 69, 0.3);
}

.paste-row-err {
  margin-left: auto;
  color: #c62828 !important;
  font-size: 0.78rem;
  font-style: italic;
}

.differentiated-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: rgba(91, 79, 207, 0.06);
  border: 1px solid rgba(91, 79, 207, 0.2);
  border-radius: 8px;
  font-size: 0.92rem;
  cursor: pointer;
}

.differentiated-toggle input[type="checkbox"] {
  margin: 0;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  padding: 0;
  /* The global `input, select` rule sets `appearance: none`, which strips
     the native checkbox tick. Restore it here so the toggle actually shows
     the check when ticked instead of looking inert. */
  -webkit-appearance: checkbox;
  appearance: checkbox;
  accent-color: var(--primary);
}

.chapter-heading {
  font-family: var(--font-display, 'Fraunces', serif);
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 18px;
  color: var(--primary);
  letter-spacing: 0.01em;
  text-align: center;
  border-bottom: 1px solid rgba(91, 79, 207, 0.2);
  padding-bottom: 12px;
}

/* Chapter picker modal */
.chapter-panel {
  max-width: 480px;
  text-align: left;
}

.chapter-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
  max-height: 60vh;
  overflow-y: auto;
}

.chapter-option {
  width: 100%;
  text-align: left;
  padding: 14px 16px;
  background: white;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: border-color 0.15s, background 0.15s;
}

@media (hover: hover) and (pointer: fine) {
  .chapter-option:hover:not(.disabled) {
    border-color: var(--primary);
    background: rgba(91, 79, 207, 0.04);
  }
}

.chapter-option.disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: var(--bg, #fafafa);
}

.chapter-option-title {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text, #1A1A2E);
}

.chapter-option-meta {
  font-size: 0.85rem;
  color: var(--text-muted, #666);
}

.chapter-option-cta {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  margin-top: 4px;
}

.leveled-set-banner {
  margin: 0 0 12px;
  padding: 10px 14px;
  background: rgba(34, 139, 34, 0.08);
  border: 1px solid rgba(34, 139, 34, 0.3);
  border-radius: 8px;
  font-size: 0.9rem;
  color: #1d6f1d;
}

.reading-log-panel {
  margin: 12px 0;
  background: rgba(91, 79, 207, 0.05);
  border: 1px solid rgba(91, 79, 207, 0.2);
  border-radius: 8px;
  overflow: hidden;
}

.reading-log-panel > summary {
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 10px;
  list-style: none;
}

.reading-log-panel > summary::-webkit-details-marker { display: none; }

.reading-log-panel > summary::after {
  content: '▾';
  margin-left: auto;
  color: var(--text-muted, #666);
  font-size: 0.85rem;
  transition: transform 0.15s;
}

.reading-log-panel[open] > summary::after {
  transform: rotate(180deg);
}

.reading-log-summary-meta {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted, #666);
}

.reading-log-summary-meta.overdue {
  color: #b51d2a;
  font-weight: 600;
}

.reading-log-summary-meta.done {
  color: #1d6f1d;
  font-weight: 600;
}

.reading-log-content {
  padding: 4px 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.reading-log-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  flex-wrap: wrap;
}

.reading-log-row label {
  font-weight: 600;
}

#story-due-date {
  padding: 6px 10px;
  border: 1px solid var(--border-subtle, #ddd);
  border-radius: 6px;
  font-size: 0.9rem;
}

.reading-log-complete-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 500 !important;
}

.reading-log-complete-label input[type="checkbox"] {
  width: 18px;
  height: 18px;
  padding: 0;
  -webkit-appearance: checkbox;
  appearance: checkbox;
  accent-color: var(--primary);
}

.reading-log-meta {
  color: var(--text-muted, #666);
  font-size: 0.85rem;
}

.reading-log-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.log-section-title {
  margin: 8px 0 4px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted, #666);
  font-weight: 700;
}

.log-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: white;
  border: 1px solid var(--border-subtle, #eee);
  border-radius: 8px;
  flex-wrap: wrap;
}

.log-row-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.log-topic {
  font-size: 0.92rem;
}

.log-row-meta {
  font-size: 0.78rem;
  color: var(--text-muted, #666);
}

.log-row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.log-pill {
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.log-pill.log-overdue {
  background: rgba(220, 53, 69, 0.12);
  color: #b51d2a;
}

.log-pill.log-upcoming {
  background: rgba(91, 79, 207, 0.12);
  color: #4338ca;
}

.log-pill.log-completed {
  background: rgba(34, 139, 34, 0.12);
  color: #1d6f1d;
}

@media (max-width: 480px) {
  .roster-item {
    flex-wrap: wrap;
  }
  .roster-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

.phonics-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.phonics-chip {
  padding: 6px 12px;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: white;
  color: var(--text);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.phonics-chip.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* ── Tap-to-define popover ──────────────────────────────────────────────── */
.word-popover {
  position: absolute;
  z-index: 1100;
  background: white;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px 12px;
  box-shadow: 0 10px 28px rgba(15, 23, 42, 0.18);
  max-width: 280px;
  font-family: 'Inter', sans-serif;
  font-size: 0.92rem;
  color: var(--text);
}

.word-popover.hidden { display: none; }

.word-popover-close {
  position: absolute;
  top: 4px;
  right: 6px;
  background: none;
  border: none;
  font-size: 1rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 2px 6px;
  line-height: 1;
}

.word-popover-word {
  font-family: 'Fraunces', Georgia, serif;
  font-weight: 600;
  font-size: 1.15rem;
  color: var(--primary);
  margin-bottom: 4px;
  padding-right: 18px;
}

.word-popover-definition {
  margin-bottom: 6px;
  line-height: 1.45;
}

.word-popover-example {
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.85rem;
  line-height: 1.4;
}

.word-popover-example:empty { display: none; }

.word-popover-arrow {
  position: absolute;
  bottom: -7px;
  width: 12px;
  height: 12px;
  background: white;
  border-right: 1.5px solid var(--border);
  border-bottom: 1.5px solid var(--border);
  transform: rotate(45deg);
}

.word-popover.placed-below .word-popover-arrow {
  bottom: auto;
  top: -7px;
  border-right: none;
  border-bottom: none;
  border-left: 1.5px solid var(--border);
  border-top: 1.5px solid var(--border);
}

/* ── Length warning ─────────────────────────────────────────────────────── */
.length-warning {
  margin-top: 8px;
  padding: 10px 12px;
  background: #FFFBEB;
  color: #92400E;
  border-left: 3px solid #F59E0B;
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1.4;
}

/* ── Progress ───────────────────────────────────────────────────────────── */
.progress {
  margin: 16px;
  padding: 16px;
  background: white;
  border-radius: 14px;
  border-left: 4px solid var(--primary);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.06);
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  font-size: 0.92rem;
}

#progress-status {
  font-weight: 600;
  color: var(--text);
}

#progress-elapsed {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.85rem;
}

.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary) 0%, #7B6FE0 100%);
  border-radius: 999px;
  transition: width 0.4s ease-out;
  animation: progress-shimmer 2s linear infinite;
  background-size: 200% 100%;
}

@keyframes progress-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Error ──────────────────────────────────────────────────────────────── */
.error {
  margin: 16px;
  padding: 14px 16px;
  background: #FEF2F2;
  color: #991B1B;
  border-radius: 10px;
  border-left: 4px solid var(--danger);
  font-size: 0.95rem;
  line-height: 1.5;
}

/* ── Library screen ─────────────────────────────────────────────────────── */
.library-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px 16px 8px;
}

.library-title {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
}

.icon-btn {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: background 0.15s;
}

.icon-btn:hover {
  background: var(--bg);
  color: var(--text);
}

/* ── Story grid / cards ─────────────────────────────────────────────────── */
.story-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
}

.story-card {
  background: white;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 12px rgba(0,0,0,0.06);
  position: relative;
}

.library-stats {
  display: flex;
  gap: 16px;
  padding: 0 16px 12px;
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.library-stats:empty {
  display: none;
}

.library-stats strong {
  color: var(--text);
  font-weight: 700;
}

.library-filters {
  display: flex;
  gap: 8px;
  padding: 0 16px 4px;
  flex-wrap: wrap;
}

.library-filter {
  padding: 6px 14px;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  background: white;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}

.library-filter:hover {
  border-color: var(--primary);
}

.library-filter.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.library-search {
  flex: 1;
  min-width: 140px;
  max-width: 280px;
  padding: 6px 14px !important;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  font-size: 0.85rem;
  background: white;
}

.favorite-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 8px;
  transition: color 0.15s, transform 0.15s;
}

.favorite-btn:hover {
  color: var(--accent);
}

.favorite-btn.favorited {
  color: var(--accent);
}

.favorite-btn.favorited:hover {
  transform: scale(1.1);
}

.story-card-genre {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 8px;
  text-transform: capitalize;
}

.story-card-title {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
  line-height: 1.3;
}

.story-card-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.story-card-readtime {
  font-size: 0.72rem;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  margin-bottom: 12px;
  font-family: 'Inter', sans-serif;
}

.story-card-actions {
  display: flex;
  gap: 8px;
}

.card-action-btn {
  flex: 1;
  padding: 8px 4px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  font-family: 'Inter', sans-serif;
}

.card-action-btn:hover {
  background: var(--bg);
  border-color: #ccc;
}

.card-action-btn.danger {
  color: var(--danger);
  border-color: #FCA5A5;
}

.card-action-btn.danger:hover {
  background: #FEF2F2;
}

/* ── Welcome banner (new users) ──────────────────────────────────────────── */
.welcome-banner {
  margin: 16px 16px 0;
  padding: 16px 18px;
  background: var(--primary-light);
  border: 1.5px solid var(--primary);
  border-radius: 14px;
  color: var(--text);
}

.welcome-banner h3 {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0 0 4px;
  color: var(--primary);
}

.welcome-banner p {
  margin: 0;
  font-size: 0.9rem;
  color: var(--text);
  line-height: 1.5;
}

/* ── Library empty state ─────────────────────────────────────────────────── */
.library-empty {
  text-align: center;
  padding: 40px 24px;
}

.library-empty-art {
  height: 110px;
  width: auto;
  margin-bottom: 14px;
  opacity: 0.9;
}

.library-empty h3 {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 6px;
}

.library-empty p {
  font-size: 0.95rem;
  color: var(--text-muted);
  margin: 0 0 20px;
  line-height: 1.5;
}

.library-empty-cta {
  max-width: 260px;
  margin: 0 auto;
}

/* ── Loading spinner on secondary buttons ────────────────────────────────── */
.secondary-btn.loading {
  pointer-events: none;
  opacity: 0.85;
}

.secondary-btn.loading::before {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: btn-spin 0.7s linear infinite;
  margin-right: 8px;
  vertical-align: -3px;
}

/* ── Empty state ────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
  font-size: 0.95rem;
  line-height: 1.6;
}

/* ── Story sheet (bottom sheet) ─────────────────────────────────────────── */
.story-sheet {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  max-width: 100vw;
  z-index: 200;
  overflow: hidden;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.45);
}

.sheet-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  max-width: 100vw;
  height: 92vh;
  height: 92dvh;
  border-radius: 20px 20px 0 0;
  background: white;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.12);
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  margin: 12px auto 0;
  flex-shrink: 0;
}

.sheet-header {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-shrink: 0;
}

.sheet-close-btn {
  background: var(--bg);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 1rem;
  color: var(--text-muted);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.sheet-close-btn:hover {
  background: var(--border);
  color: var(--text);
}

.sheet-title {
  flex: 1;
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sheet-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.icon-action-btn {
  background: var(--bg);
  border: none;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--text-muted);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.icon-action-btn:hover {
  background: var(--border);
  color: var(--text);
}

.icon-action-btn.loading {
  pointer-events: none;
  font-size: 0;
}

.icon-action-btn.loading::after {
  content: '';
  display: block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: btn-spin 0.7s linear infinite;
}

@keyframes btn-spin {
  to { transform: rotate(360deg); }
}

.audio-progress-bar.generating {
  overflow: hidden;
}

.audio-progress-bar.generating .audio-progress-fill {
  width: 35%;
  transition: none;
  animation: audio-loading-stripe 1.4s ease-in-out infinite;
}

@keyframes audio-loading-stripe {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(285%); }
}

.sheet-body {
  flex: 1;
  overflow: hidden;
  padding: 0;
  position: relative;
  -webkit-overflow-scrolling: touch;
}

.audio-progress-bar {
  height: 4px;
  background: var(--bg);
  cursor: pointer;
  flex-shrink: 0;
  position: relative;
}

.audio-progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.15s linear;
}

.audio-controls {
  display: flex;
  gap: 10px;
  padding: 6px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  font-family: 'Inter', sans-serif;
  flex-shrink: 0;
}

.audio-controls select {
  flex: 1;
  padding: 6px 28px 6px 12px !important;
  font-size: 0.8rem !important;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background-color: white;
}

.audio-download-btn,
.audio-music-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: white;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}

@media (hover: hover) {
  .audio-download-btn:hover:not(:disabled),
  .audio-music-btn:hover:not(:disabled) {
    color: var(--primary);
    border-color: var(--primary);
  }
}

.audio-music-btn.active {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
}

.story-body {
  position: relative;
  width: 100%;
  height: 100%;
}

/* ── Book reader (paged) ─────────────────────────────────────────────────── */
.story-book {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.book-pages {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.book-page {
  position: absolute !important;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  padding: 32px 28px;
  background: white;
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  transition: opacity 0.32s ease, visibility 0s 0.32s;
}

.book-page.current {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  z-index: 2;
  transition: opacity 0.32s ease, visibility 0s 0s;
}

/* Cover page */
.book-page-cover {
  align-items: center;
  justify-content: center;
  text-align: center;
  background: linear-gradient(180deg, #FAF9F7 0%, #FFFFFF 100%);
  gap: 18px;
}

.book-cover-eyebrow {
  font-family: 'Inter', sans-serif;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--primary);
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.book-cover-wordmark {
  height: 34px;
  width: auto;
  object-fit: contain;
  margin-bottom: 6px;
}

.book-cover-credit {
  font-family: 'Fraunces', Georgia, serif;
  font-style: italic;
  font-size: 0.95rem;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: center;
}

.book-cover-start-btn {
  margin-top: 18px;
  padding: 12px 28px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 999px;
  font-family: 'Inter', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(91, 79, 207, 0.28);
  transition: transform 0.12s, box-shadow 0.12s;
}

.book-cover-start-btn:active {
  transform: translateY(1px);
  box-shadow: 0 2px 8px rgba(91, 79, 207, 0.28);
}

@media (hover: hover) and (pointer: fine) {
  .book-cover-start-btn:hover {
    background: #4d44b8;
  }
}

.book-cover-footer {
  margin-top: 12px;
  padding-top: 6px;
  font-family: 'Inter', sans-serif;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--primary);
  opacity: 0.7;
}

.book-cover-art {
  max-width: 78%;
  max-height: 55%;
  width: auto;
  height: auto;
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  object-fit: contain;
}

.book-cover-title {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
  margin: 0;
  max-width: 90%;
}

/* Image-only page */
.book-page-image {
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 16px;
  overflow: hidden;
}

.book-page-img {
  max-width: 100%;
  /* Hard viewport cap so the scene image can't push #story-text taller than
     the modal, which would send the book-nav arrows off-screen. */
  max-height: min(100%, 65vh);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  display: block;
  margin: auto;
}

@media (max-width: 600px) {
  .book-page-image {
    padding: 10px;
  }
}

/* Text page */
.book-page-text {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.05rem;
  line-height: 1.85;
  color: var(--text);
  padding: 36px 22px 44px;
}

.book-page-text p {
  margin: 0 0 1em;
  word-wrap: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}

/* Read-along: each word is a span; the one currently being spoken gets .active.
   The transition is short so the highlight glides instead of strobing. */
.audio-word {
  border-radius: 4px;
  padding: 0 1px;
  transition: background-color 0.18s ease, color 0.18s ease;
}

.audio-word.active {
  background-color: rgba(255, 213, 79, 0.55);  /* warm yellow */
  color: var(--text);
}

/* ── Kid mode — bigger text, simplified controls ────────────────────────── */
.story-sheet.kid-mode .book-page-text {
  font-size: 1.6rem;
  line-height: 2.05;
  padding: 28px 26px 36px;
}

.story-sheet.kid-mode .book-page-text p {
  margin: 0 0 1.1em;
}

.story-sheet.kid-mode .book-cover-title {
  font-size: 2.2rem;
  line-height: 1.2;
}

.story-sheet.kid-mode .audio-word {
  padding: 2px 3px;
}

.story-sheet.kid-mode .audio-word.active {
  background-color: rgba(255, 213, 79, 0.7);
  outline: 2px solid rgba(255, 167, 38, 0.5);
}

/* Hide every parent/teacher action while reading. Only audio + nav stay. */
.story-sheet.kid-mode .sheet-footer,
.story-sheet.kid-mode .sheet-actions {
  display: none;
}

/* Hide auxiliary audio bits — speed selector, voice picker, music, download.
   Keep only play/pause + the syllable + kid-mode toggles + progress bar. */
.story-sheet.kid-mode #audio-voice,
.story-sheet.kid-mode #audio-speed,
.story-sheet.kid-mode #audio-music-btn,
.story-sheet.kid-mode #audio-download-btn {
  display: none;
}

/* Bigger, friendlier nav arrows */
.story-sheet.kid-mode .book-nav {
  width: 58px;
  height: 58px;
  font-size: 2rem;
}

/* Bigger page indicator for tiny eyes */
.story-sheet.kid-mode .book-page-indicator {
  font-size: 1.1rem;
  font-weight: 700;
}

/* Hide the affiliate book card + generic ad slot when a kid is reading */
.story-sheet.kid-mode .book-rec-card,
.story-sheet.kid-mode .ad-slot {
  display: none !important;
}

/* ── Book recommendation card (teacher affiliate) ──────────────────────── */
.book-rec-card {
  margin: 20px 18px 0;
  padding: 16px 18px;
  border: 1.5px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: 12px;
  background: #FAF9F7;
}

.book-rec-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 4px;
}

.book-rec-title {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.book-rec-author {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.book-rec-description {
  font-size: 0.95rem;
  line-height: 1.45;
  color: var(--text);
  margin-bottom: 10px;
}

.book-rec-link {
  display: inline-block;
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
  padding: 6px 0;
}

.book-rec-disclosure {
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-style: italic;
}

/* ── Generic ad slot placeholder ───────────────────────────────────────── */
.ad-slot {
  margin: 16px 18px 0;
  min-height: 90px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* Hide empty ad-slots entirely so the dashed "wire to your network"
   placeholder doesn't pollute the layout (especially in the story sheet,
   where it was pushing book-nav arrows off-screen). Once an ad network
   populates the slot, it becomes non-empty and renders. */
.ad-slot:empty {
  display: none;
}

.ad-slot:not(:empty) {
  border: none;
}

/* ── Teacher signup form extras ─────────────────────────────────────────── */
.teacher-grade-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 4px 0;
}

.teacher-grade-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  width: 100%;
  margin-bottom: 2px;
}

.teacher-location-row {
  display: flex;
  gap: 10px;
}

.teacher-location-row input {
  flex: 1;
}

.teacher-disclaimer {
  margin-top: 10px;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.4;
}

/* ── Teacher application banners (pending / approved / denied) ─────────── */
.teacher-pending-banner,
.teacher-approved-banner,
.teacher-denied-banner {
  padding: 10px 16px;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 500;
  border-bottom: 1px solid transparent;
}

.teacher-pending-banner {
  background: #FEF3C7;
  border-bottom-color: #FDE68A;
  color: #78350F;
}

.teacher-approved-banner {
  background: #D1FAE5;
  border-bottom-color: #6EE7B7;
  color: #065F46;
}

.teacher-denied-banner {
  background: #FEE2E2;
  border-bottom-color: #FCA5A5;
  color: #991B1B;
}

/* ── Mobile 3-step flow ──────────────────────────────────────────────────
   Activated when <body> has the .flow-active class. Hides the classic
   form and turns the create screen into a full-bleed, one-decision-per-
   screen flow.

   Design principles:
   - Each step fills the viewport — no scroll wells of fields.
   - One decision per screen — tap one card, advance.
   - Slide transitions left/right so direction reinforces back/forward.
   - Touch targets are generous (min 56pt height per Apple HIG / Material).
*/

.flow-container {
  display: none;
  position: absolute;
  inset: 0;
  background: var(--bg, #fafaf9);
  overflow: hidden;
}
body.flow-active .flow-container {
  display: flex;
  flex-direction: column;
}
body.flow-active .classic-form-wrapper {
  display: none;
}

/* Progress dots — anchored at the top so the user knows where they are. */
.flow-progress {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 14px 0 0;
  flex-shrink: 0;
}
.flow-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: rgba(91, 79, 207, 0.2);
  transition: background 0.2s, transform 0.2s;
}
.flow-dot.active {
  background: var(--primary);
  transform: scale(1.3);
}
.flow-dot.done {
  background: var(--primary);
}

/* Each step is a fixed-positioned full-screen panel. Slide via translateX. */
.flow-step {
  position: absolute;
  inset: 38px 0 0 0;   /* leaves room for the progress dots above */
  display: none;
  flex-direction: column;
  padding: 20px 22px 28px;
  transform: translateX(0);
  transition: transform 0.32s ease, opacity 0.32s ease;
  opacity: 1;
  background: var(--bg, #fafaf9);
}
.flow-step.active { display: flex; }
.flow-step.exit-left   { transform: translateX(-100%); opacity: 0; }
.flow-step.exit-right  { transform: translateX(100%);  opacity: 0; }
.flow-step.enter-from-right { transform: translateX(100%); opacity: 0; }
.flow-step.enter-from-left  { transform: translateX(-100%); opacity: 0; }

.flow-header {
  flex-shrink: 0;
  margin-bottom: 24px;
}
.flow-title {
  font-family: var(--font-display, 'Fraunces', serif);
  font-size: 1.85rem;
  line-height: 1.15;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}
.flow-subtitle {
  margin: 8px 0 0;
  color: var(--text-muted);
  font-size: 1rem;
}
.flow-back-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.95rem;
  font-weight: 500;
  padding: 6px 0;
  margin-bottom: 12px;
  cursor: pointer;
  min-height: 36px;
}
.flow-back-btn:hover { text-decoration: underline; }

.flow-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 12px;
}

/* Step 1 — Kid grid */
.flow-kid-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.flow-kid-card {
  background: white;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s, box-shadow 0.15s;
  min-height: 130px;
  font-family: inherit;
  font-size: inherit;
  color: var(--text);
}
.flow-kid-card:active { transform: scale(0.97); }
.flow-kid-card:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(91, 79, 207, 0.12);
}
.flow-kid-avatar {
  width: 56px; height: 56px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: var(--font-display, 'Fraunces', serif);
  font-size: 1.5rem;
  font-weight: 700;
  color: white;
}
.flow-kid-avatar.girl    { background: linear-gradient(135deg, #ec4899, #f472b6); }
.flow-kid-avatar.boy     { background: linear-gradient(135deg, #3b82f6, #60a5fa); }
.flow-kid-avatar.neutral { background: linear-gradient(135deg, #8b5cf6, #a78bfa); }
.flow-kid-name {
  font-weight: 600;
  font-size: 1rem;
}
.flow-kid-age {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Step 2 — Vibe tiles */
.flow-vibe-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.flow-vibe-tile {
  background: white;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s, box-shadow 0.15s;
  min-height: 130px;
  font-family: inherit;
  color: var(--text);
}
.flow-vibe-tile:active { transform: scale(0.97); }
.flow-vibe-tile:hover {
  border-color: var(--primary);
  box-shadow: 0 4px 12px rgba(91, 79, 207, 0.12);
}
.flow-vibe-emoji { font-size: 2.2rem; line-height: 1; }
.flow-vibe-name {
  font-weight: 600;
  font-size: 1rem;
  margin-top: 4px;
}
.flow-vibe-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-align: center;
}

/* Step 3 — Topic list */
.flow-topic-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.flow-topic-chip {
  background: white;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  text-align: left;
  font-family: inherit;
  font-size: 0.95rem;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s;
  min-height: 50px;
}
.flow-topic-chip:active { transform: scale(0.98); }
.flow-topic-chip:hover  { border-color: var(--primary); }
.flow-topic-input {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  font-size: 1rem;
  background: white;
  -webkit-appearance: none;
  appearance: none;
}
.flow-topic-input:focus {
  outline: none;
  border-color: var(--primary);
}

.flow-primary-btn {
  margin-top: auto;
  padding: 16px 20px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 12px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 54px;
  position: sticky;
  bottom: 0;
}
.flow-primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.flow-secondary-btn {
  padding: 14px 20px;
  background: white;
  color: var(--primary);
  border: 1.5px dashed var(--primary);
  border-radius: 12px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  min-height: 50px;
}
.flow-secondary-btn:hover { background: var(--primary-light); }


/* "More options" expander — wraps Genre, Length, Family, Language, Mood
   on the create form. The expander is collapsed by default so first-time
   users see a short flow (Hero → Topic → Generate) instead of a wall of
   form fields. Themed packs at the top + Surprise me at the bottom pre-
   fill enough of these knobs that most users never open this drawer. */
.customize-section {
  margin-top: 8px;
}
.customize-details > summary {
  font-size: 1rem;
  font-weight: 600;
}
.customize-content {
  padding: 4px 16px 12px;
}
/* When a form-section is inside the expander, drop its outer spacing so
   the drawer doesn't feel as visually heavy as the always-visible sections. */
.form-section.nested {
  margin-top: 14px;
  padding: 0;
  border: none;
  box-shadow: none;
  background: transparent;
}
.form-section.nested .section-title {
  font-size: 0.95rem;
  margin-bottom: 8px;
}

/* Recurring characters editor inside the new/edit-kid form */
.kid-characters-section {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.kid-characters-label {
  font-weight: 600;
  font-size: 0.95rem;
  display: block;
  margin-bottom: 8px;
}
.kid-characters-hint {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.kid-characters-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}
.kid-character-row {
  display: grid;
  grid-template-columns: 1fr 1.5fr auto;
  gap: 8px;
  align-items: center;
}
.kid-character-row .kid-character-name,
.kid-character-row .kid-character-desc {
  padding: 8px 10px;
  font-size: 0.9rem;
  border-radius: 6px;
}
.kid-character-remove {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: white;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}
.kid-character-remove:hover {
  background: #fee2e2;
  color: #991b1b;
  border-color: #fca5a5;
}
.kid-character-add-btn {
  align-self: flex-start;
  font-size: 0.85rem;
  padding: 6px 12px;
}

/* Quick Create tile — one-tap repeat creation. Visible above the library
   stats for users with at least one prior story + a saved kid. Tap fires
   a new generation with the last-used vibe + a random topic, skipping
   the entire flow. The 90th-percentile path for daily-active users. */
.quick-create-btn {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 18px;
  margin: 8px 0 14px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: white;
  border: none;
  border-radius: 14px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(91, 79, 207, 0.25);
  font-family: inherit;
  text-align: left;
  transition: transform 0.1s, box-shadow 0.15s;
}
.quick-create-btn:hover  { box-shadow: 0 6px 20px rgba(91, 79, 207, 0.35); }
.quick-create-btn:active { transform: scale(0.98); }
.quick-create-icon {
  font-size: 1.8rem;
  line-height: 1;
}
.quick-create-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.quick-create-title {
  font-weight: 600;
  font-size: 1rem;
}
.quick-create-sub {
  font-size: 0.8rem;
  opacity: 0.9;
}

/* Monthly story quota meter — shown in the library header. Reads
   from /me .quotas + .story_counts so the bar reflects current state
   without a separate fetch. Hidden entirely for founders (unlimited)
   and when the user has no quota at all yet (no stories generated). */
.quota-meter {
  margin: 8px 0 14px;
  padding: 8px 12px;
  background: rgba(91, 79, 207, 0.04);
  border: 1px solid rgba(91, 79, 207, 0.12);
  border-radius: 10px;
}
.quota-meter-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.quota-meter-upgrade {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.82rem;
}
.quota-meter-upgrade:hover { text-decoration: underline; }
.quota-meter-track {
  height: 6px;
  background: rgba(91, 79, 207, 0.12);
  border-radius: 3px;
  overflow: hidden;
}
.quota-meter-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #8b5cf6);
  border-radius: 3px;
  transition: width 0.3s ease;
}
/* Color-shift the fill bar as the user nears the cap — green safe band
   feels wrong here (this isn't health/risk); we keep purple→amber→red. */
.quota-meter.warning .quota-meter-fill {
  background: linear-gradient(90deg, #f59e0b, #f97316);
}
.quota-meter.full .quota-meter-fill {
  background: linear-gradient(90deg, #dc2626, #b91c1c);
}

/* Upgrade modal — shown when a free user hits a paid feature */
.upgrade-tier-card {
  margin: 18px 0 12px;
  padding: 18px 20px;
  background: linear-gradient(140deg, rgba(91, 79, 207, 0.08), rgba(245, 158, 11, 0.06));
  border: 1.5px solid rgba(91, 79, 207, 0.25);
  border-radius: 14px;
}
.upgrade-tier-name {
  font-family: var(--font-display, 'Fraunces', serif);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 6px;
}
.upgrade-tier-price {
  font-size: 1.05rem;
  margin-bottom: 14px;
  color: var(--text);
}
.upgrade-tier-price strong {
  font-size: 1.25rem;
  color: var(--primary);
}
.upgrade-tier-features {
  list-style: none;
  padding: 0;
  margin: 0 0 18px;
}
.upgrade-tier-features li {
  padding: 4px 0;
  font-size: 0.95rem;
  color: var(--text);
}
.upgrade-cta {
  width: 100%;
}
.upgrade-teacher-note {
  margin-top: 14px;
  font-size: 0.85rem;
  text-align: center;
  color: var(--text-muted);
}
.upgrade-teacher-note a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

/* Paid-feature accent — premium, not broken.
   We deliberately *don't* grey these out. Greyed buttons read as "disabled
   for some reason I should figure out"; that's friction without intent.
   Instead we add a soft gold sparkle accent + a small "✨" badge so the
   feature reads as "this is a premium thing you can unlock" — the
   psychological lift between "broken" and "aspirational" is huge.

   Tapping still opens the upgrade modal (intercepted by the capture-phase
   click handler in the JS). Visible-to-everyone, accessible to paid users
   only — same pattern that Spotify, Notion, Linear, etc. all converged on. */
.feature-locked {
  position: relative;
  cursor: pointer;
  box-shadow:
    inset 0 0 0 1.5px rgba(245, 158, 11, 0.55),
    0 0 0 0 rgba(245, 158, 11, 0);
  transition: box-shadow 0.2s ease, transform 0.1s ease;
}
.feature-locked:hover {
  box-shadow:
    inset 0 0 0 1.5px rgba(245, 158, 11, 0.85),
    0 0 0 4px rgba(245, 158, 11, 0.18);
  transform: translateY(-1px);
}
.feature-locked::after {
  content: "✨";
  position: absolute;
  top: -6px;
  right: -6px;
  width: 16px;
  height: 16px;
  font-size: 0.65rem;
  line-height: 16px;
  text-align: center;
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(245, 158, 11, 0.4);
  pointer-events: none;
}

/* Attention-grab on the first paint when a free user lands and sees the
   locked features for the first time. A short, single-shot pulse — not a
   forever-loop animation (that would be annoying). Triggered by adding the
   .first-look class via JS once per session. */
@keyframes premium-pulse {
  0%   { box-shadow: inset 0 0 0 1.5px rgba(245, 158, 11, 0.55), 0 0 0 0 rgba(245, 158, 11, 0); }
  50%  { box-shadow: inset 0 0 0 1.5px rgba(245, 158, 11, 0.9),  0 0 0 8px rgba(245, 158, 11, 0.25); }
  100% { box-shadow: inset 0 0 0 1.5px rgba(245, 158, 11, 0.55), 0 0 0 0 rgba(245, 158, 11, 0); }
}
.feature-locked.first-look {
  animation: premium-pulse 1.8s ease-out 1;
}

/* Share modal — expiry note + permanent toggle */
.share-expires-note {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 6px;
}
.share-permanent-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 14px;
  font-size: 0.9rem;
  cursor: pointer;
}
.share-permanent-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  padding: 0;
  -webkit-appearance: checkbox;
  appearance: checkbox;
  accent-color: var(--primary);
}

/* In-library NPS micro-survey banner */
.nps-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  margin: 12px 0;
  background: linear-gradient(90deg, rgba(91, 79, 207, 0.07), rgba(245, 158, 11, 0.07));
  border: 1px solid rgba(91, 79, 207, 0.2);
  border-radius: 10px;
}
.nps-banner-text {
  font-size: 0.92rem;
  font-weight: 500;
}
.nps-banner-actions {
  display: flex;
  gap: 6px;
}
.nps-thumb {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid transparent;
  background: white;
  font-size: 1.1rem;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s;
}
.nps-thumb:hover {
  border-color: var(--primary);
  transform: scale(1.08);
}

/* Monthly usage banner — 80% warning + 100% hard-cap variant */
.usage-banner {
  padding: 10px 16px;
  text-align: center;
  font-size: 0.9rem;
  font-weight: 500;
  background: #FEF3C7;
  border-bottom: 1px solid #FDE68A;
  color: #78350F;
}
.usage-banner-hard {
  background: #FEE2E2;
  border-bottom-color: #FCA5A5;
  color: #991B1B;
}

/* Small red badge on the admin shield icon — count of pending teacher apps */
.admin-pending-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--danger);
  color: white;
  font-size: 0.7rem;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  font-family: 'Inter', sans-serif;
  box-shadow: 0 0 0 2px var(--bg);
}

/* ── Admin: teacher application queue ───────────────────────────────────── */
.teacher-app-card {
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 10px;
  background: white;
}

.teacher-app-school {
  font-weight: 700;
  font-size: 1rem;
  margin-bottom: 4px;
}

.teacher-app-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.teacher-app-applied {
  font-style: italic;
}

.teacher-app-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
}

/* ── Cloudflare Turnstile widget spacing in auth modals ─────────────────── */
.turnstile-widget {
  margin: 6px 0;
  display: flex;
  justify-content: center;
}

/* Navigation buttons */
.book-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.92);
  border: 1.5px solid var(--border);
  border-radius: 50%;
  width: 44px;
  height: 44px;
  font-size: 1.6rem;
  line-height: 1;
  color: var(--primary);
  cursor: pointer;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  padding: 0 0 4px 0;
  transition: opacity 0.2s, background 0.2s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.book-nav:hover:not(:disabled) {
  background: white;
}

.book-nav:disabled {
  opacity: 0;
  pointer-events: none;
}

.book-nav-prev { left: 10px; }
.book-nav-next { right: 10px; }

.book-page-indicator {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.55);
  color: white;
  padding: 4px 12px;
  border-radius: 999px;
  font-family: 'Inter', sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  z-index: 10;
  pointer-events: none;
}

.chapter-jump {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 20px;
  border-top: 1px solid var(--border);
  background: white;
  font-size: 0.88rem;
}

.chapter-jump.hidden {
  display: none;
}

.chapter-jump label {
  font-weight: 600;
  color: var(--text-muted, #666);
  flex-shrink: 0;
}

#chapter-jump-select {
  flex: 1 1 auto;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: white;
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text, #1A1A2E);
  cursor: pointer;
  /* leave room for the native dropdown arrow */
}

.page-nav {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 20px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: white;
}

.page-nav.hidden {
  display: none;
}

.page-nav-btn {
  flex: 0 0 auto;
  padding: 10px 18px;
  background: white;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  color: var(--primary);
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  min-width: 96px;
  transition: background 0.15s, color 0.15s;
}

.page-nav-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

@media (hover: hover) and (pointer: fine) {
  .page-nav-btn:hover:not(:disabled) {
    background: var(--primary);
    color: white;
  }
}

.page-nav-indicator {
  flex: 1 1 auto;
  text-align: center;
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted, #666);
}

.sheet-actions {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  background: white;
}

.sheet-actions-summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text-muted, #666);
  user-select: none;
}

.sheet-actions-summary::-webkit-details-marker { display: none; }

.sheet-actions-caret {
  font-size: 0.9rem;
  transition: transform 0.15s;
}

.sheet-actions[open] .sheet-actions-caret {
  transform: rotate(180deg);
}

.sheet-footer {
  padding: 4px 20px 12px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  border-top: none;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  flex-shrink: 0;
  box-sizing: border-box;
  max-width: 100%;
}

.sheet-footer .secondary-btn {
  flex: 1 1 calc(50% - 5px);
  min-width: 0;
  text-align: center;
  box-sizing: border-box;
}

@media (max-width: 480px) {
  .sheet-footer .secondary-btn {
    font-size: 0.85rem;
    padding: 10px 8px;
  }
  .icon-action-btn {
    width: 34px;
    height: 34px;
    font-size: 1rem;
  }
  .sheet-header-actions {
    gap: 5px;
  }
  .sheet-header {
    padding: 12px 14px;
    gap: 8px;
  }
}

/* ── Fullscreen image viewer ─────────────────────────────────────────────── */
.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  touch-action: pinch-zoom;
}

.image-viewer img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  touch-action: pinch-zoom;
  border-radius: 12px;
  cursor: zoom-out;
}

.image-viewer-close {
  position: absolute;
  top: max(20px, env(safe-area-inset-top));
  right: 20px;
  background: rgba(255, 255, 255, 0.18);
  border: none;
  color: white;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}

.image-viewer-close:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* Make book images look tappable */
.book-cover-art,
.book-page-img {
  cursor: zoom-in;
}

/* ── Fullscreen reader mode ──────────────────────────────────────────────── */
.fullscreen-exit-btn {
  display: none;
  position: fixed;
  top: max(14px, env(safe-area-inset-top));
  right: 14px;
  background: rgba(255, 255, 255, 0.92);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  width: 40px;
  height: 40px;
  font-size: 0.95rem;
  color: var(--text-muted);
  z-index: 250;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

.story-sheet.fullscreen-reading .fullscreen-exit-btn {
  display: flex;
}

.story-sheet.fullscreen-reading .sheet-panel {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  max-width: none;
  max-height: none;
  border-radius: 0;
  transform: none;
  box-shadow: none;
}

.story-sheet.fullscreen-reading .sheet-handle,
.story-sheet.fullscreen-reading .sheet-header,
.story-sheet.fullscreen-reading .sheet-footer,
.story-sheet.fullscreen-reading .sheet-actions,
.story-sheet.fullscreen-reading .audio-progress-bar,
.story-sheet.fullscreen-reading .audio-controls {
  display: none !important;
}

.story-sheet.fullscreen-reading .book-nav {
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}

/* ── Hidden utility ─────────────────────────────────────────────────────── */
.hidden {
  display: none !important;
}

/* Desktop right-pane tabs — hidden on mobile by default, shown on desktop
   via the @media block below. */
.desktop-pane-tabs {
  display: none;
}

/* ── Desktop layout (≥ 900px) ───────────────────────────────────────────── */
@media (min-width: 900px) {
  /* Full-viewport shell */
  #app-wrapper {
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .app-header {
    padding: 0 32px;
    height: 60px;
    gap: 16px;
    flex-shrink: 0;
  }

  .app-logo-img {
    height: 40px;
  }

  /* Hide mobile bottom tabs */
  .tab-bar {
    display: none;
  }

  /* Three-area grid: left column always shows Create. Right column has a
     tab strip at the top and the active right-pane (Library or Classroom)
     filling the rest. Left column spans both rows. */
  .screens {
    flex: 1;
    display: grid;
    grid-template-columns: 440px 1fr;
    grid-template-rows: auto 1fr;
    overflow: hidden;
    padding-bottom: 0;
    min-height: 0;
  }

  /* Create — pinned to left column, both rows */
  #screen-create {
    display: block !important;
    grid-column: 1;
    grid-row: 1 / span 2;
    overflow-y: auto;
    height: 100%;
    border-right: 1px solid var(--border);
    background: var(--bg);
  }

  /* Desktop tab strip — right column, top row */
  .desktop-pane-tabs {
    grid-column: 2;
    grid-row: 1;
    display: flex;
    gap: 8px;
    padding: 12px 24px 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }

  .desktop-pane-tab {
    background: none;
    border: none;
    padding: 10px 16px;
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-muted, #666);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -1px;
    transition: color 0.15s, border-color 0.15s;
  }

  .desktop-pane-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
  }

  @media (hover: hover) and (pointer: fine) {
    .desktop-pane-tab:hover:not(.active) {
      color: var(--text, #1A1A2E);
    }
  }

  /* Library + Classroom share the right pane — only the one with .active
     is visible. JS keeps exactly one active at a time on desktop. */
  #screen-library,
  #screen-classroom {
    grid-column: 2;
    grid-row: 2;
    overflow-y: auto;
    height: 100%;
    background: var(--surface);
    display: none;
  }

  #screen-library.active,
  #screen-classroom.active {
    display: block;
  }

  .screen-scroll {
    padding-bottom: 32px;
  }

  /* Form padding in left column */
  .form-section {
    padding: 20px 24px 0;
  }

  .generate-wrap {
    padding: 24px 24px 24px;
  }

  .progress,
  .error {
    margin: 16px 24px;
  }

  /* Library: 2-col card grid */
  .library-header {
    padding: 24px 24px 8px;
  }

  .story-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    padding: 16px 24px;
  }

  /* Child / family entries: wrap inside the 440px column */
  .child-entry {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .child-entry .child-name {
    flex: 1 1 calc(100% - 48px);
  }

  .child-entry .remove-child {
    flex: 0 0 40px;
  }

  .child-entry .child-gender,
  .child-entry .child-age {
    flex: 1 1 calc(50% - 4px);
  }

  .child-entry .child-relation {
    flex: 1 1 100%;
  }

  .child-entry:first-child .child-relation {
    display: none;
  }

  .family-entry {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }

  .family-entry .family-name {
    flex: 1 1 calc(100% - 48px);
  }

  .family-entry .remove-family {
    flex: 0 0 40px;
  }

  .family-entry .family-role,
  .family-entry .family-role-custom {
    flex: 1 1 100%;
  }

  /* Story sheet: centered dialog instead of bottom sheet */
  .sheet-panel {
    position: absolute;
    bottom: auto;
    top: 50%;
    left: 50%;
    right: auto;
    transform: translate(-50%, -50%);
    width: min(1100px, 95vw);
    height: min(92vh, 1100px);
    border-radius: 20px;
    box-shadow: 0 16px 60px rgba(0, 0, 0, 0.22);
  }

  /* Force the body to be a flex column so the paginated reader gets real
     height, and the affiliate card / nav buttons don't have to fight for
     space against intrinsic content sizing. */
  .sheet-body {
    display: flex;
    flex-direction: column;
  }
  .sheet-body > .story-body,
  .sheet-body > #story-text {
    flex: 1 1 auto;
    min-height: 0;
  }

  /* Larger book-page typography on desktop */
  .book-page-text {
    font-size: 1.2rem;
    line-height: 1.9;
    padding: 56px 64px 64px;
    max-width: 720px;
    margin: 0 auto;
  }
  .book-cover-title {
    font-size: 2.4rem;
  }
  .book-cover-art {
    max-width: 360px;
  }

  /* Nav buttons bigger and pushed further in from the edge so they don't
     collide with the scrollbar or panel border. */
  .book-nav {
    width: 56px;
    height: 56px;
    font-size: 2rem;
  }
  .book-nav-prev { left: 20px; }
  .book-nav-next { right: 20px; }
}

/* ── Mobile: child/family entry responsive ──────────────────────────────── */
@media (max-width: 480px) {
  .child-entry {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  .child-entry .child-name {
    flex: 1 1 calc(100% - 48px);
  }
  .child-entry .remove-child {
    flex: 0 0 40px;
  }
  .child-entry .child-gender,
  .child-entry .child-age,
  .child-entry .child-relation {
    flex: 1 1 calc(50% - 4px);
  }
  .child-entry:first-child .child-relation {
    display: none;
  }

  .family-entry {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  .family-entry .family-name {
    flex: 1 1 calc(100% - 48px);
  }
  .family-entry .remove-family {
    flex: 0 0 40px;
  }
  .family-entry .family-role,
  .family-entry .family-role-custom {
    flex: 1 1 100%;
  }

  .length-picker {
    grid-template-columns: repeat(3, 1fr);
  }
  .length-picker .length-option:nth-child(4) {
    grid-column: 1;
  }
  .length-picker .length-option:nth-child(5) {
    grid-column: 2;
  }
}

/* ── PWA standalone mode ────────────────────────────────────────────────── */
@media (display-mode: standalone) {
  body {
    background: white;
  }
}

/* ── Landing page ───────────────────────────────────────────────────────── */
.landing-page {
  min-height: 100vh;
  background: var(--bg);
  overflow-x: hidden;
}

.lp-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
  gap: 16px;
}

.lp-nav-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.lp-nav-logo {
  height: 40px;
  width: auto;
  object-fit: contain;
}

.lp-nav-wordmark-img {
  height: 32px;
  width: auto;
  object-fit: contain;
  display: block;
}

.lp-nav-links {
  display: none;
  gap: 28px;
}

.lp-nav-item {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.15s;
}

.lp-nav-item:hover {
  color: var(--primary);
}

.lp-nav-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.lp-nav-signin {
  font-size: 0.875rem;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  color: var(--primary);
  text-decoration: none;
  padding: 8px 16px;
  border: 1.5px solid var(--primary);
  border-radius: 8px;
  background: transparent;
  cursor: pointer;
  transition: all 0.15s;
}

@media (hover: hover) {
  .lp-nav-signin:hover {
    background: var(--primary);
    color: white;
  }
}

.lp-nav-cta-btn {
  display: none;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: 'Inter', sans-serif;
  color: white;
  padding: 8px 18px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  cursor: pointer;
  transition: all 0.15s;
}

.lp-nav-cta-btn:hover {
  background: var(--accent-dark);
}

@media (min-width: 720px) {
  .lp-nav {
    padding: 16px 48px;
  }

  .lp-nav-links {
    display: flex;
  }

  .lp-nav-cta-btn {
    display: inline-block;
  }
}

.lp-hero {
  padding: 56px 24px 48px;
  text-align: center;
  max-width: 680px;
  margin: 0 auto;
}

.lp-hero-logo {
  height: 160px;
  width: auto;
  object-fit: contain;
  margin: 0 auto 24px;
  display: block;
}

.lp-headline {
  font-family: 'Fraunces', Georgia, serif;
  font-size: clamp(2rem, 6vw, 3rem);
  font-weight: 700;
  color: var(--text);
  line-height: 1.15;
  letter-spacing: -0.02em;
  margin-bottom: 16px;
}

.lp-headline em {
  font-style: italic;
  color: var(--primary);
}

.lp-sub {
  font-size: 1.05rem;
  color: var(--text-muted);
  line-height: 1.6;
  max-width: 580px;
  margin: 0 auto 32px;
}

.lp-hero-eyebrow {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--primary);
  margin: 8px 0 16px;
}

.lp-hero-meta {
  margin-top: 14px;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-style: italic;
}

/* ── Teacher cross-sell callout ─────────────────────────────────────────── */
.lp-teacher-cta {
  background: linear-gradient(135deg, #EEF2FF 0%, #F0EAFE 100%);
  padding: 48px 24px;
  margin: 24px 0;
}

.lp-teacher-cta-inner {
  max-width: 880px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  align-items: flex-start;
}

.lp-teacher-cta-title {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.6rem;
  font-weight: 700;
  margin: 0 0 8px;
  color: var(--text);
  line-height: 1.25;
}

.lp-teacher-cta-sub {
  margin: 0;
  font-size: 1rem;
  color: var(--text-muted);
  line-height: 1.55;
  max-width: 640px;
}

.lp-teacher-cta-btn {
  align-self: flex-start;
}

@media (min-width: 720px) {
  .lp-teacher-cta-inner {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 32px;
  }
  .lp-teacher-cta-btn {
    flex-shrink: 0;
  }
}

.lp-cta-btn {
  display: inline-block;
  background: var(--accent);
  color: white;
  font-family: 'Inter', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  padding: 16px 32px;
  border-radius: 14px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s;
}

.lp-cta-btn:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

.lp-features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  padding: 0 24px 56px;
  max-width: 960px;
  margin: 0 auto;
}

.lp-feature {
  background: white;
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 24px 20px;
  text-align: center;
}

.lp-feature-icon {
  font-size: 2rem;
  margin-bottom: 12px;
}

.lp-feature-title {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 8px;
}

.lp-feature-desc {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.lp-how {
  background: white;
  border-top: 1.5px solid var(--border);
  border-bottom: 1.5px solid var(--border);
  padding: 48px 24px;
  margin-bottom: 56px;
}

.lp-section-title {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  margin-bottom: 32px;
}

.lp-steps {
  display: flex;
  flex-direction: column;
  gap: 24px;
  max-width: 480px;
  margin: 0 auto;
}

.lp-step {
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

.lp-step-num {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: var(--primary);
  color: white;
  font-size: 0.9rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lp-step-title {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.lp-step-desc {
  font-size: 0.875rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.lp-auth-section {
  padding: 0 24px 56px;
  max-width: 420px;
  margin: 0 auto;
  text-align: center;
}

.lp-auth-sub {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 24px;
}

.lp-footer {
  border-top: 1.5px solid var(--border);
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.lp-footer p {
  margin: 0 0 4px;
}

.lp-footer-links a {
  color: var(--primary);
  text-decoration: none;
  margin: 0 4px;
}

.lp-footer-links a:hover {
  text-decoration: underline;
}

@media (max-width: 600px) {
  .lp-features {
    grid-template-columns: 1fr;
  }
  .lp-hero {
    padding: 40px 20px 36px;
  }
}

/* ── Shared story (public view) ──────────────────────────────────────────── */
body.shared-page {
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.shared-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.shared-wordmark {
  height: 28px;
  width: auto;
}

.shared-cta {
  display: inline-block;
}

.shared-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px;
}

.shared-book-shell {
  position: relative;
  width: min(700px, 100%);
  height: min(80vh, 800px);
  background: white;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
}

.shared-book-shell .story-body {
  width: 100%;
  height: 100%;
}

.shared-audio-player {
  width: min(700px, 100%);
  margin-top: 16px;
}

.shared-footer {
  padding: 20px 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
}

.shared-footer a {
  color: var(--primary);
  text-decoration: none;
}

.shared-footer-cta {
  display: inline-block;
  margin-top: 12px;
}

.shared-footer a:hover {
  text-decoration: underline;
}

.shared-notfound {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
  text-align: center;
  gap: 16px;
}

.shared-notfound-art {
  height: 120px;
  width: auto;
  opacity: 0.7;
}

.shared-notfound h1 {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

.shared-notfound p {
  color: var(--text-muted);
  margin: 0 0 8px;
}

/* ── Legal pages (Terms / Privacy) ──────────────────────────────────────── */
body.legal-page {
  background: var(--bg);
  min-height: 100vh;
}

.legal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.legal-back-link {
  display: inline-flex;
  align-items: center;
}

.legal-wordmark {
  height: 28px;
  width: auto;
}

.legal-back-text {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--primary);
  text-decoration: none;
}

.legal-back-text:hover {
  text-decoration: underline;
}

.legal-content {
  max-width: 720px;
  margin: 0 auto;
  padding: 40px 24px 60px;
  font-family: 'Inter', -apple-system, sans-serif;
  color: var(--text);
  line-height: 1.7;
}

.legal-content h1 {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 8px;
  color: var(--text);
}

.legal-content h2 {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.25rem;
  font-weight: 600;
  margin: 28px 0 10px;
  color: var(--text);
}

.legal-content p,
.legal-content ul {
  margin: 0 0 14px;
  font-size: 0.95rem;
}

.legal-content ul {
  padding-left: 20px;
}

.legal-content li {
  margin-bottom: 6px;
}

.legal-effective {
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 24px !important;
}

.legal-content a {
  color: var(--primary);
  text-decoration: underline;
}

/* ── Pricing page ───────────────────────────────────────────────────────── */
.pricing-notice {
  background: #FEF3C7;
  border: 1px solid #FDE68A;
  color: #78350F;
  padding: 14px 16px;
  border-radius: 12px;
  margin: 16px 0 32px;
  font-size: 0.95rem;
}

.pricing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
  margin: 32px 0;
}

.pricing-card {
  background: white;
  border: 1.5px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  position: relative;
}

.pricing-card-featured {
  border-color: var(--primary);
  box-shadow: 0 8px 24px rgba(91, 79, 207, 0.08);
}

.pricing-badge {
  position: absolute;
  top: -10px;
  right: 18px;
  background: var(--primary);
  color: white;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
}

.pricing-card h2 {
  margin: 0 0 4px;
  font-family: 'Inter', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.pricing-price {
  margin: 6px 0 18px;
  font-family: 'Fraunces', Georgia, serif;
  font-size: 2.6rem;
  font-weight: 600;
  line-height: 1;
  color: var(--text);
}

.pricing-currency {
  font-size: 1.4rem;
  vertical-align: super;
  font-weight: 500;
  margin-right: 2px;
}

.pricing-period {
  font-size: 1rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 4px;
}

.pricing-features {
  list-style: none;
  padding: 0;
  margin: 0 0 24px;
}

.pricing-features li {
  position: relative;
  padding: 6px 0 6px 24px;
  font-size: 0.95rem;
}

.pricing-features li::before {
  content: "✓";
  position: absolute;
  left: 0;
  color: var(--primary);
  font-weight: 700;
}

.pricing-cta {
  width: 100%;
}

.legal-footer {
  border-top: 1px solid var(--border);
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.legal-footer a {
  color: var(--primary);
  text-decoration: none;
  margin: 0 4px;
}

.legal-footer a:hover {
  text-decoration: underline;
}

/* ── Auth modal ─────────────────────────────────────────────────────────── */
.auth-modal {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
}

.auth-modal-panel {
  position: relative;
  background: white;
  border-radius: 20px;
  padding: 32px 28px 28px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.18);
  z-index: 1;
}

.auth-modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: var(--bg);
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.auth-modal-close:hover {
  background: var(--border);
  color: var(--text);
}

.auth-modal-logo {
  height: 64px;
  width: auto;
  object-fit: contain;
  margin-bottom: 8px;
}

.auth-modal-tagline {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 24px;
}

/* ── Discussion questions modal ──────────────────────────────────────────── */
.questions-list {
  padding-left: 24px;
  margin: 8px 0 0;
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.02rem;
  line-height: 1.6;
  color: var(--text);
}

.questions-list li {
  margin-bottom: 14px;
}

.questions-list .loading-q {
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  color: var(--text-muted);
  list-style: none;
  margin-left: -24px;
}

.sheet-footer {
  flex-wrap: wrap;
}

/* ── Style picker modal ──────────────────────────────────────────────────── */
.style-panel {
  max-width: 460px;
  text-align: left;
}

.style-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 16px 0 20px;
}

.style-option {
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: white;
  padding: 12px 14px;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
  text-align: left;
  transition: all 0.15s;
}

.style-option:hover {
  border-color: var(--primary);
  background: var(--primary-light);
}

.style-option.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.style-name {
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text);
  margin-bottom: 2px;
}

.style-option.selected .style-name {
  color: var(--primary);
}

.style-desc {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.3;
}

/* ── Regenerate image button ─────────────────────────────────────────────── */
.image-regen-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(255, 255, 255, 0.94);
  border: 1.5px solid var(--border);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  font-size: 1.1rem;
  color: var(--text-muted);
  cursor: pointer;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s, border-color 0.15s, transform 0.15s;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.image-regen-btn:hover:not(:disabled) {
  color: var(--primary);
  border-color: var(--primary);
  transform: rotate(60deg);
}

.image-regen-btn:disabled {
  cursor: wait;
  opacity: 0.6;
}

img.regenerating {
  opacity: 0.35;
  filter: blur(2px);
  transition: opacity 0.2s ease, filter 0.2s ease;
}

.book-page-cover,
.book-page-image {
  position: relative;
}

/* ── Share modal ─────────────────────────────────────────────────────────── */
.share-panel {
  max-width: 440px;
  text-align: left;
}

.share-desc {
  font-size: 0.88rem;
  color: var(--text-muted);
  margin: 0 0 16px;
  line-height: 1.5;
}

.share-url-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.share-url-row input {
  flex: 1;
  font-size: 0.85rem;
  font-family: 'Consolas', monospace;
  background: var(--bg);
}

.share-url-row .secondary-btn {
  flex-shrink: 0;
  padding: 10px 16px;
  font-size: 0.9rem;
}

#share-stop-btn {
  font-size: 0.85rem;
}

/* ── Settings modal ──────────────────────────────────────────────────────── */
.settings-panel {
  max-width: 440px;
  text-align: left;
  max-height: 90vh;
  overflow-y: auto;
}

.settings-title {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 20px;
  text-align: center;
}

.settings-section {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 16px;
}

.settings-section:first-of-type {
  border-top: none;
  padding-top: 0;
  margin-top: 0;
}

.settings-section h3 {
  font-family: 'Fraunces', Georgia, serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 10px;
}

.settings-section input {
  margin-bottom: 8px;
}

.settings-section .secondary-btn {
  margin-top: 4px;
}

.settings-current {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0 0 10px;
}

.settings-danger p {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0 0 12px;
  line-height: 1.4;
}

.danger-btn {
  padding: 10px 18px;
  border: 1.5px solid var(--danger);
  border-radius: 10px;
  background: white;
  color: var(--danger);
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.danger-btn:hover {
  background: var(--danger);
  color: white;
}

/* ── Auth card ───────────────────────────────────────────────────────────── */
.auth-card {
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
  text-align: center;
}

.auth-tabs {
  display: flex;
  background: var(--primary-light);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 20px;
  gap: 4px;
}

.auth-tab {
  flex: 1;
  padding: 9px;
  border: none;
  background: transparent;
  border-radius: 7px;
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s;
}

.auth-tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-msg {
  font-size: 0.85rem;
  margin: 0;
  padding: 0;
  text-align: left;
}

.auth-agreement {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.45;
  text-align: left;
  cursor: pointer;
  padding: 0 2px;
}

/* Custom checkbox — native styling on Android is unreliable (especially with
   accent-color), so we render our own. Larger touch target + obvious ✓. */
.auth-agreement input[type="checkbox"] {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  margin: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  border: 2px solid var(--text-muted);
  border-radius: 5px;
  background: white;
  position: relative;
  transition: background 0.15s, border-color 0.15s;
}

.auth-agreement input[type="checkbox"]:checked {
  background: var(--primary);
  border-color: var(--primary);
}

.auth-agreement input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 7px;
  top: 2px;
  width: 6px;
  height: 12px;
  border: solid white;
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
}

.auth-agreement input[type="checkbox"]:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 40%, transparent);
  outline-offset: 2px;
}

.auth-agreement a {
  color: var(--primary);
  text-decoration: underline;
}

.password-requirements {
  list-style: none;
  padding: 12px 14px;
  margin: 6px 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.82rem;
  text-align: left;
  line-height: 1.3;
}

.password-requirements li {
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 10px;
  transition: color 0.2s;
}

.password-requirements li.met {
  color: var(--text);
}

.req-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: white;
  font-size: 0.72rem;
  font-weight: 700;
  flex-shrink: 0;
  transition: background 0.2s, border-color 0.2s;
}

.req-icon::before {
  content: '✓';
  color: transparent;
  transition: color 0.2s;
  line-height: 1;
}

.password-requirements li.met .req-icon {
  background: var(--success);
  border-color: var(--success);
  animation: req-pop 0.35s ease-out;
}

.password-requirements li.met .req-icon::before {
  color: white;
}

@keyframes req-pop {
  0%   { transform: scale(1); }
  45%  { transform: scale(1.18); }
  100% { transform: scale(1); }
}

/* ── Credit badge ───────────────────────────────────────────────────────── */
.credit-badge {
  margin-left: auto;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
}

.credit-badge.low {
  color: var(--danger);
  border-color: #FCA5A5;
  background: #FEF2F2;
}

.credit-badge.founder {
  color: var(--primary);
  border-color: var(--primary-light);
  background: var(--primary-light);
}

/* ── Sign-out button (in header) ────────────────────────────────────────── */
.signout-btn {
  margin-left: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
  flex-shrink: 0;
}

.signout-btn:hover {
  background: var(--primary-light);
  color: var(--primary);
}
