/* Imports
   -------------------------------------------------------------------------- */
@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,500;0,600;0,700;1,500;1,600&family=DM+Sans:opsz,wght@9..40,400;9..40,500;9..40,600;9..40,700;9..40,800&display=swap');

/* Tokens
   -------------------------------------------------------------------------- */
:root {
  color-scheme: light;

  /* Legacy palette aliases retained for compatibility. */
  --ink: oklch(22% 0.022 62);
  --ink-soft: oklch(34% 0.022 62);
  --muted: oklch(54% 0.022 62);
  --line: oklch(88% 0.016 76);
  --line-soft: oklch(92% 0.010 78);
  --paper: oklch(97.5% 0.012 80);
  --paper-warm: oklch(96% 0.018 76);
  --panel: oklch(99.5% 0.006 80);
  --accent: oklch(36% 0.10 192);
  --accent-mid: oklch(44% 0.12 192);
  --accent-2: oklch(46% 0.10 44);
  --gold: oklch(70% 0.13 78);
  --good: oklch(46% 0.12 152);

  /* Design-system aliases. */
  --color-ink: var(--ink);
  --color-ink-soft: var(--ink-soft);
  --color-muted: var(--muted);
  --color-border: var(--line);
  --color-border-soft: var(--line-soft);
  --color-paper: var(--paper);
  --color-paper-warm: var(--paper-warm);
  --color-surface: var(--panel);
  --color-primary: var(--accent);
  --color-primary-hover: var(--accent-mid);
  --color-primary-soft: oklch(94% 0.02 192);
  --color-primary-border: oklch(68% 0.08 192);
  --color-secondary: var(--paper-warm);
  --color-secondary-hover: oklch(95% 0.025 76);
  --color-secondary-border: var(--line);
  --color-accent-warm: var(--accent-2);
  --color-gold: var(--gold);
  --color-success: var(--good);
  --color-danger: oklch(45% 0.16 28);

  --font-brand: 'Lora', serif;
  --font-ui: 'DM Sans', ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-body: var(--font-ui);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-panel: 20px;
  --radius-pill: 999px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;

  --shadow-sm: 0 2px 8px oklch(22% 0.02 62 / 0.07);
  --shadow-md: 0 8px 24px oklch(22% 0.02 62 / 0.09);
  --shadow-lg: 0 16px 40px oklch(22% 0.02 62 / 0.11);
  --shadow: var(--shadow-lg);

  --transition-fast: 150ms ease;
  --transition-card: 180ms ease;
  --focus-ring: 0 0 0 3px oklch(60% 0.1 192 / 0.14);
}

/* Reset/Base
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--color-ink);
  font-family: var(--font-ui);
  background:
    radial-gradient(ellipse 72rem 48rem at top left, oklch(70% 0.13 78 / 0.13), transparent),
    linear-gradient(180deg, oklch(98.5% 0.010 82) 0%, var(--color-paper) 44%);
  position: relative;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.032;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)'/%3E%3C/svg%3E");
  background-size: 200px 200px;
}

body::after {
  content: '';
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 0;
  width: 1in;
  height: 1in;
  background-image: url('./assets/judy-makes-things-logo.svg');
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  opacity: 0.3;
  pointer-events: none;
}

button,
select,
input,
textarea {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button {
  border: 0;
}

[hidden] {
  display: none !important;
}

/* Typography
   -------------------------------------------------------------------------- */
h1,
h2,
h3,
p {
  margin-top: 0;
}

h1,
.page-title {
  margin: 0;
  color: var(--color-ink);
  font-family: var(--font-brand);
  font-size: clamp(2.4rem, 6vw, 4.2rem);
  font-weight: 700;
  line-height: 0.95;
}

h2 {
  margin: 0;
  color: var(--color-ink);
  font-family: var(--font-brand);
  font-size: 1.2rem;
  font-weight: 600;
  line-height: 1.2;
}

.section-title {
  margin: 0;
  color: var(--color-ink);
  font-family: var(--font-brand);
  font-size: clamp(1.4rem, 2.8vw, 2.1rem);
  font-weight: 600;
  line-height: 1.15;
}

.panel-title {
  margin: 0 0 var(--space-4);
  color: var(--color-ink);
  font-family: var(--font-brand);
  font-size: clamp(1.35rem, 2.2vw, 1.75rem);
  font-weight: 600;
  line-height: 1.15;
}

.book-title,
.book-card > h2 {
  margin: 0;
  color: var(--color-ink);
  font-family: var(--font-brand);
  font-size: 1.2rem;
  font-weight: 600;
  line-height: 1.2;
}

.book-author,
.author {
  margin: 0;
  color: var(--color-ink-soft);
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.5;
}

.body-copy {
  color: var(--color-ink);
  font-size: 0.95rem;
  line-height: 1.55;
}

.muted-copy,
.summary,
.why,
details {
  color: var(--color-muted);
  font-size: 0.95rem;
  line-height: 1.55;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--color-accent-warm);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.subtitle {
  margin: 9px 0 0;
  color: var(--color-muted);
  font-size: 1rem;
  font-weight: 500;
}

summary {
  color: var(--color-primary);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  list-style: none;
}

summary::-webkit-details-marker {
  display: none;
}

summary::marker {
  display: none;
}

summary:focus-visible {
  outline: none;
  border-radius: var(--radius-sm);
  box-shadow: var(--focus-ring);
}

/* Layout
   -------------------------------------------------------------------------- */
.shell {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 56px;
}

.home-header {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  align-items: center;
  gap: var(--space-5);
  padding-bottom: 28px;
}

.home-header > div {
  min-width: 0;
}

.brand-lockup {
  width: fit-content;
  max-width: 100%;
}

.brand-lockup .subtitle {
  text-align: right;
}

.home-header .page-title,
.home-header .subtitle {
  overflow-wrap: anywhere;
}

.home-nav,
.toolbar,
.importer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.home-nav,
.toolbar {
  justify-content: flex-end;
}

.home-nav {
  max-width: 100%;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding: 8px 8px 14px;
  margin: -8px -8px -14px;
  scrollbar-width: thin;
}

.home-nav .nav-button {
  flex: 0 0 auto;
}

.importer {
  justify-content: flex-start;
}

.controls {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 2fr;
  gap: var(--space-6);
  align-items: end;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--color-border);
}

.admin-hero {
  margin-bottom: var(--space-5);
}

.book-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.dashboard-row {
  display: grid;
  grid-template-columns: minmax(190px, 0.55fr) minmax(520px, 1.45fr);
  gap: 14px;
  margin: var(--space-4) 0;
}

/* Buttons
   -------------------------------------------------------------------------- */
.btn,
.primary-button,
.library-link,
.subtle-button,
.nav-button,
.book-secondary-action,
button[data-status],
.shelf-button,
.secondary-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: inherit;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.1;
  text-align: center;
  text-decoration: none;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast),
    box-shadow var(--transition-fast),
    color var(--transition-fast),
    transform 100ms ease;
}

.btn:focus-visible,
.primary-button:focus-visible,
.library-link:focus-visible,
.subtle-button:focus-visible,
.nav-button:focus-visible,
.book-secondary-action:focus-visible,
button[data-status]:focus-visible,
.shelf-button:focus-visible,
.secondary-link:focus-visible,
.selector-pill:focus-visible,
.grade-pill:focus-visible,
.profile-tile:focus-visible,
.child-profile-tile:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.btn:active,
.primary-button:active,
.library-link:active,
.subtle-button:active,
.nav-button:active,
.book-secondary-action:active,
button[data-status]:active,
.shelf-button:active,
.secondary-link:active {
  transform: translateY(1px);
}

.btn:disabled,
.primary-button:disabled,
.library-link[aria-disabled='true'],
.subtle-button:disabled,
.nav-button:disabled,
.book-secondary-action:disabled,
button[data-status]:disabled,
.shelf-button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.btn-primary,
.primary-button {
  min-height: 48px;
  padding-inline: 20px;
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
  box-shadow: 0 10px 22px oklch(36% 0.10 192 / 0.22);
}

.btn-primary:hover,
.primary-button:hover {
  background: var(--color-primary-hover);
  border-color: var(--color-primary-hover);
}

.btn-library,
.library-link {
  background: var(--color-primary-soft);
  border-color: var(--color-primary-border);
  color: var(--color-primary-hover);
  box-shadow: none;
}

.btn-library:hover,
.library-link:hover {
  background: oklch(92.5% 0.025 192);
  box-shadow: 0 6px 20px oklch(36% 0.10 192 / 0.24);
}

.btn-secondary,
.book-secondary-action,
button[data-status],
.shelf-button,
.secondary-link {
  background: var(--color-secondary);
  border-color: var(--color-secondary-border);
  color: var(--color-ink-soft);
  box-shadow: none;
}

.btn-secondary:hover,
.book-secondary-action:hover,
button[data-status]:hover,
.shelf-button:hover,
.secondary-link:hover {
  background: var(--color-secondary-hover);
  border-color: oklch(84% 0.025 76);
  box-shadow: var(--shadow-sm);
}

.btn-outline,
.subtle-button,
button[data-status='already_read'] {
  background: transparent;
  border-color: oklch(72% 0.08 192);
  color: var(--color-primary);
  box-shadow: none;
}

.btn-outline:hover,
.subtle-button:hover,
button[data-status='already_read']:hover {
  background: var(--color-primary-soft);
  border-color: oklch(60% 0.1 192);
  box-shadow: none;
}

.btn-ghost,
.nav-button {
  min-height: 38px;
  padding: 8px 16px;
  background: var(--color-surface);
  border-color: oklch(88% 0.016 76 / 0.8);
  color: var(--color-primary);
  box-shadow: var(--shadow-sm);
}

.btn-ghost:hover,
.nav-button:hover {
  background: var(--color-primary-soft);
  border-color: var(--color-primary-border);
}

.btn-ghost.is-current,
.nav-button.is-current,
.btn-primary.is-selected {
  background: var(--color-primary);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 14px oklch(36% 0.10 192 / 0.3);
}

.btn-danger,
.danger-button {
  background: transparent;
  border-color: currentColor;
  color: var(--color-danger);
  box-shadow: none;
}

.btn-danger:hover,
.danger-button:hover {
  background: oklch(96% 0.03 28);
  border-color: currentColor;
}

.btn-pill,
.selector-pill,
.grade-pill {
  min-height: 40px;
  padding: 7px 16px;
  background: var(--color-secondary);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  color: var(--color-primary-hover);
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 700;
  line-height: 1.1;
  box-shadow: none;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast),
    color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.btn-pill:hover,
.selector-pill:hover,
.grade-pill:hover {
  background: var(--color-primary-soft);
  border-color: var(--color-primary-border);
}

.btn-pill.is-selected,
.selector-pill.is-selected,
.grade-pill.is-selected {
  background: var(--color-primary);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 14px oklch(36% 0.10 192 / 0.28);
}

.btn-pill-add,
.selector-pill-add,
.add-child-tile {
  border-style: dashed;
  background: transparent;
  color: var(--color-muted);
}

/* Forms
   -------------------------------------------------------------------------- */
.form-label,
label {
  display: grid;
  gap: 6px;
  color: var(--color-muted);
  font-size: 0.875rem;
  font-weight: 600;
}

.form-control,
select,
input[type='file'],
input[type='text'],
input[type='url'],
input[type='number'],
textarea {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  color: var(--color-ink);
  transition:
    border-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

textarea {
  min-height: 72px;
  padding: 9px 12px;
  resize: vertical;
}

.form-control:focus,
select:focus,
input:focus,
textarea:focus {
  outline: none;
  border-color: oklch(60% 0.1 192);
  box-shadow: var(--focus-ring);
}

.form-check,
.check,
.settings-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.check {
  align-items: center;
  color: var(--color-ink);
}

.form-row,
.admin-action-row,
.admin-import-row,
.child-form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-3);
  align-items: center;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

.field-help,
.field-error,
.settings-check small,
.settings-field small {
  color: var(--color-muted);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-style: normal;
  font-weight: 400;
  line-height: 1.55;
}

.prompt-copy {
  display: block;
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border-soft);
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 400;
  line-height: 1.55;
}

.field-error {
  color: var(--color-danger);
}

.field-help-warn {
  color: var(--color-accent-warm);
}

/* Cards/Panels
   -------------------------------------------------------------------------- */
.card,
.admin-panel,
.read-summary-card,
.empty-state,
.tracker-card,
.mix-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
}

.card {
  padding: var(--space-5);
}

.card-elevated,
.read-summary-card,
.empty-state,
.tracker-card,
.mix-card {
  box-shadow: var(--shadow-md);
}

.panel,
.admin-panel {
  padding: var(--space-5);
  border-radius: var(--radius-lg);
}

.panel-large,
.primary-action,
.family-panel {
  display: grid;
  gap: 28px;
  align-items: start;
  margin: 0 0 18px;
  padding: 26px 28px;
  background: var(--color-surface);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-lg);
}

.card.read-summary-card,
.card.empty-state,
.admin-page .admin-panel.admin-tools {
  margin: 0 0 18px;
  padding: 26px 28px;
  min-height: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-lg);
}

.info-card {
  background: oklch(95% 0.025 192);
  border: 1px solid var(--color-primary-border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
}

.warning-card,
.warning {
  margin: 0 0 var(--space-4);
  padding: 12px 16px;
  border: 1px solid oklch(78% 0.13 78);
  border-left: 4px solid oklch(62% 0.14 68);
  border-radius: var(--radius-lg);
  background: oklch(97% 0.04 82);
  color: oklch(36% 0.10 68);
  font-size: 0.9rem;
  font-weight: 700;
}

/* Selectors/Tiles
   -------------------------------------------------------------------------- */
.selector-group,
.grade-pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.profile-tile,
.child-profile-tile {
  min-width: 92px;
}

.child-profile-tile.is-selected {
  background: var(--color-primary);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 14px oklch(36% 0.10 192 / 0.28);
}

.profile-avatar,
.child-avatar {
  width: 46px;
  height: 46px;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: oklch(91% 0.04 192);
  color: var(--color-primary);
  font-family: var(--font-brand);
  font-size: 1.05rem;
  font-weight: 800;
}

.avatar-tone-2 {
  background: oklch(92% 0.05 54);
  color: oklch(48% 0.12 50);
}

.avatar-tone-3 {
  background: oklch(92% 0.04 310);
  color: oklch(45% 0.11 305);
}

.avatar-tone-4 {
  background: oklch(93% 0.05 118);
  color: oklch(42% 0.10 132);
}

/* Tags/Pills
   -------------------------------------------------------------------------- */
.tag,
.tag-format,
.tag-level,
.tag-source,
.stat-pill,
.format-pill,
.level-pill,
.tags span {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--color-border-soft);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-muted);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.2;
  padding: 3px 9px;
  white-space: nowrap;
}

.tag-level,
.level-pill {
  border-color: oklch(88% 0.06 52);
  color: oklch(54% 0.08 48);
}

.stat-pill {
  border-color: var(--color-primary-border);
  background: var(--color-primary-soft);
  color: var(--color-primary);
  font-weight: 700;
}

/* Homepage
   -------------------------------------------------------------------------- */
.family-panel,
.primary-action {
  grid-template-columns: minmax(360px, 0.86fr) minmax(0, 1.14fr);
}

.family-panel h2,
.primary-action h2 {
  max-width: 620px;
}

.primary-action {
  margin-top: var(--space-2);
}

.family-panel .section-title,
.primary-action .section-title {
  font-size: clamp(1.35rem, 2.2vw, 1.75rem);
  white-space: nowrap;
}

.primary-action .grade-pill-group {
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.primary-action .grade-pill {
  flex: 0 0 auto;
}

.pick-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  align-items: end;
}

.tracker-card,
.mix-card {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 14px 20px;
  min-height: 92px;
}

.tracker-card {
  justify-content: flex-start;
}

.tracker-card strong,
.read-summary-card strong,
.empty-state h2 {
  display: block;
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.55;
}

.mix-card {
  justify-content: space-between;
  gap: 14px;
}

.read-summary-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  overflow: visible;
}

.read-child-profile-grid {
  flex: 1;
  justify-content: flex-end;
  align-items: center;
  padding: var(--space-2) 0;
  overflow: visible;
}

.read-summary-card #reset-read-count {
  align-self: center;
}

.read-book-grid .empty-state {
  grid-column: 1 / -1;
}

.read-book-card > .actions {
  align-items: flex-start;
}

.read-book-card {
  border-radius: var(--radius-panel);
  box-shadow: var(--shadow-lg);
}

.read-book-card.summary-hidden {
  min-height: 260px;
}

.read-book-card:hover {
  box-shadow: var(--shadow-lg);
}

.read-book-card > .book-title {
  color: var(--color-ink);
  font-family: var(--font-brand);
  font-size: clamp(1.35rem, 2.2vw, 1.75rem);
  font-weight: 600;
  line-height: 1.15;
}

.read-book-card > .author,
.read-book-card > .summary,
.read-book-card > .book-card__summary {
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: 0.95rem;
  line-height: 1.55;
}

.empty-state h2 {
  margin: 0 0 var(--space-2);
}

.empty-state p:not(.eyebrow) {
  margin: 0;
  color: var(--color-ink);
  font-size: 0.95rem;
  line-height: 1.55;
}

.composition-line {
  margin: 0;
  color: var(--color-ink);
  font-family: var(--font-body);
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.55;
  white-space: nowrap;
}

.mix-summary {
  margin: var(--space-4) 0 0;
  color: var(--color-muted);
  font-size: 0.875rem;
  line-height: 1.6;
  text-align: center;
}

/* Book Cards
   -------------------------------------------------------------------------- */
.book-card {
  min-height: 360px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
  padding: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border-soft);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  transition: box-shadow var(--transition-card);
}

.book-card.summary-hidden {
  min-height: 280px;
}

.book-card:hover {
  box-shadow: var(--shadow-lg);
}

.book-card::before {
  content: '';
  display: block;
  flex-shrink: 0;
  height: 3px;
  background: oklch(52% 0.14 175);
}

.book-topline,
.actions,
.tags,
.book-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.book-card > .book-topline {
  padding: 18px 22px 0;
}

.book-card > h2,
.book-card > .book-title {
  padding: 12px 22px 0;
}

.book-card > .author,
.book-card > .book-author {
  padding: 2px 22px 0;
}

.book-card > .summary,
.book-card > .book-card__summary {
  padding: 10px 22px 0;
}

.book-card > details {
  margin: 0;
  padding: 10px 22px 0;
}

.book-card > .tags {
  padding: 4px 22px 0;
}

.book-card > .actions,
.book-card > .book-card__actions {
  margin-top: auto;
  padding: 16px 22px 22px;
}

.summary,
.why {
  margin: 0;
}

.library-link {
  padding: 10px 18px;
}

.book-secondary-action,
.shelf-button {
  padding: 10px 18px;
}

.card-celebrated {
  animation: card-glow 900ms ease-out;
}

/* Family/Child Profiles
   -------------------------------------------------------------------------- */
.child-profile-grid {
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  justify-content: flex-end;
  gap: var(--space-3);
  overflow-x: auto;
  padding: 2px 0 8px;
  scrollbar-width: thin;
}

.child-profile-item {
  display: grid;
  justify-items: center;
  gap: 6px;
}

.child-tile-name {
  max-width: 100%;
  color: inherit;
  font-size: 0.9rem;
  font-weight: 800;
  overflow-wrap: anywhere;
  text-align: center;
}

.child-edit-link {
  min-height: auto;
  padding: 0 4px;
  border: 0;
  background: transparent;
  color: var(--color-primary-hover);
  font-size: 0.74rem;
  font-weight: 800;
  line-height: 1.25;
  cursor: pointer;
  text-decoration: none;
}

.child-edit-link:hover {
  color: var(--color-primary);
  text-decoration: underline;
}

.child-edit-link:focus-visible {
  outline: none;
  border-radius: var(--radius-sm);
  box-shadow: var(--focus-ring);
}

.child-form,
.child-edit-panel {
  grid-column: 1 / -1;
  padding: 14px;
  border: 1.5px dotted var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

.child-form {
  display: grid;
  grid-template-columns: minmax(180px, 260px) 1fr auto;
  gap: var(--space-3);
  align-items: center;
}

.child-edit-panel {
  display: grid;
  grid-template-columns: minmax(260px, 420px) 1fr;
  gap: var(--space-3);
  align-items: start;
}

.child-edit-panel > div:first-child {
  grid-column: 1 / -1;
}

.child-grade-picker {
  align-content: center;
}

.child-form-actions {
  justify-content: flex-end;
}

.child-edit-panel .child-form-actions {
  grid-column: 1 / -1;
  flex-wrap: nowrap;
}

.danger-button {
  margin-right: auto;
}

.privacy-note {
  max-width: 580px;
  margin: 6px 0 0;
  color: var(--color-ink);
  font-size: 0.95rem;
  line-height: 1.55;
}

/* Admin/Settings
   -------------------------------------------------------------------------- */
.admin-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-4);
}

.admin-tools {
  margin: 18px 0;
}

.admin-page .admin-tools .nav-button {
  background: var(--color-paper);
}

.admin-page .admin-tools .nav-button:hover {
  background: var(--color-primary-soft);
}

.admin-privacy-copy {
  max-width: 860px;
  color: var(--color-ink);
  font-size: 0.95rem;
  line-height: 1.55;
}

.admin-privacy-copy p {
  margin: 0 0 var(--space-3);
}

.admin-action-row,
.admin-import-row {
  margin-top: 18px;
  gap: var(--space-3);
  justify-content: flex-start;
}

.admin-action-row {
  align-items: center;
}

.admin-action-row .admin-import-row {
  margin-top: 0;
}

.admin-import-row input[type='file'] {
  max-width: 360px;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
}

.settings-check {
  max-width: 620px;
}

.settings-toggle {
  max-width: 620px;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--color-ink);
  font-size: 0.95rem;
  line-height: 1.55;
}

.settings-toggle + .settings-toggle {
  margin-top: var(--space-4);
}

.settings-toggle strong {
  font-weight: 400;
}

.settings-toggle input {
  appearance: none;
  width: 46px;
  height: 26px;
  margin: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: var(--color-secondary);
  position: relative;
  cursor: pointer;
  transition:
    background var(--transition-fast),
    border-color var(--transition-fast),
    box-shadow var(--transition-fast);
}

.settings-toggle input::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast);
}

.settings-toggle input:checked {
  background: var(--color-primary);
  border-color: var(--color-primary);
}

.settings-toggle input:checked::after {
  transform: translateX(20px);
}

.settings-toggle input:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.library-settings {
  display: grid;
  gap: var(--space-3);
}

.settings-subtitle {
  margin: 0;
  color: var(--color-ink);
  font-size: 0.95rem;
  font-weight: 800;
}

.library-picker {
  align-items: center;
}

.library-pill--custom {
  border-style: dashed;
  background: transparent;
  color: var(--color-muted);
}

.library-pill--custom:hover,
.library-pill--custom.is-selected {
  color: var(--color-primary);
}

.library-pill--custom:not([aria-pressed="true"]).is-selected {
  background: transparent;
  border-color: var(--color-border);
  color: var(--color-muted);
  box-shadow: none;
}

.custom-library-fields {
  display: grid;
  gap: var(--space-3);
  max-width: 760px;
  padding: var(--space-4);
  border: 1.5px dotted var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}

.custom-library-fields[hidden] {
  display: none;
}

.custom-library-title {
  margin: 0;
}

.custom-library-fields .settings-field {
  max-width: none;
  margin-top: 0;
}

.custom-library-fields .field-help,
.custom-library-fields .field-error {
  margin: 0;
}

.custom-library-fields .nav-button {
  justify-self: start;
}

.custom-library-fields > .btn-library {
  justify-self: start;
}

.custom-library-mode {
  margin: 0;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: var(--color-paper-warm);
  display: grid;
  gap: var(--space-2);
}

.custom-library-mode legend {
  padding: 0 var(--space-2);
  color: var(--color-ink);
  font-size: 0.95rem;
  font-weight: 700;
}

.custom-library-mode-option {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin: 0;
  color: var(--color-ink);
  font-size: 0.95rem;
  font-weight: 500;
}

.custom-library-mode-option input[type='radio'] {
  width: 18px;
  height: 18px;
  min-height: 18px;
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
}



.settings-check input {
  margin-top: 4px;
}

.settings-check span,
.settings-field {
  display: grid;
  gap: var(--space-1);
}

.settings-field span {
  color: var(--color-ink);
}

.settings-field {
  max-width: 420px;
  margin-top: var(--space-4);
}

.tool-message {
  margin: var(--space-3) 0 0;
  color: var(--color-ink);
  font-size: 0.95rem;
  font-weight: 400;
  line-height: 1.55;
}

.panel-heading-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.panel-heading-row h2 {
  margin-bottom: 0;
}

.preview-actions {
  justify-content: flex-end;
}

.stat-list {
  display: grid;
  gap: var(--space-2);
}

.stat-list div {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--color-border);
}

.issue-list {
  margin: 0;
  padding-left: 20px;
  color: var(--color-muted);
}

.source-review-panel {
  margin-top: var(--space-4);
}

.empty {
  margin: 0;
  color: var(--color-muted);
}

/* Admin legacy modules kept isolated while the sources tools still use them. */
.summary-band {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin: 22px 0;
}

.summary-band > div {
  padding: 14px 16px;
  border-left: 3px solid var(--color-primary);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: oklch(95% 0.025 192);
}

.summary-band span {
  font-size: 1.3rem;
  font-weight: 800;
}

.summary-band p {
  margin: 2px 0 0;
  color: var(--color-muted);
  font-size: 0.875rem;
}

/* Tables
   -------------------------------------------------------------------------- */
.table-wrap {
  overflow-x: auto;
}

.review-table {
  width: 100%;
  min-width: 900px;
  border-collapse: collapse;
}

.review-table th,
.review-table td {
  padding: var(--space-2);
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  vertical-align: top;
}

.review-table th {
  color: var(--color-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
}

.review-table input,
.review-table textarea {
  width: 100%;
  min-height: 36px;
  border-radius: var(--radius-sm);
  padding: 7px;
}

.review-table button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  margin: 0 var(--space-1) var(--space-1) 0;
  padding: 7px 11px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-secondary);
  color: var(--color-ink-soft);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 700;
}

.review-table button:hover {
  background: var(--color-secondary-hover);
}

.candidate-item {
  display: grid;
  gap: var(--space-1);
  min-width: 260px;
  margin-bottom: var(--space-2);
}

.candidate-item p {
  margin: 0;
  color: var(--color-muted);
  font-size: 0.82rem;
  line-height: 1.4;
}

/* Feedback/Animations
   -------------------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 20;
  transform: translateX(-50%);
  padding: 13px 22px;
  border: 1.5px solid rgba(255, 255, 255, 0.88);
  border-radius: var(--radius-xl);
  background: linear-gradient(135deg, var(--color-primary), var(--color-primary-hover));
  color: #fff;
  box-shadow: 0 16px 40px oklch(36% 0.10 192 / 0.36);
  font-size: 0.9rem;
  font-weight: 700;
  animation: toast-pop 240ms ease-out;
}

.sparkle-layer {
  position: fixed;
  inset: 0;
  z-index: 19;
  overflow: hidden;
  pointer-events: none;
}

.sparkle {
  position: absolute;
  width: 9px;
  height: 9px;
  border-radius: 3px;
  animation: sparkle-pop 960ms cubic-bezier(0.12, 0.7, 0.18, 1) forwards;
}

.sparkle-star {
  width: 12px;
  height: 12px;
  border-radius: var(--radius-pill);
  box-shadow: 0 0 0 4px oklch(70% 0.13 78 / 0.18);
}

.celebrate-pulse {
  animation: tracker-pop 900ms ease-out;
}

@keyframes sparkle-pop {
  to {
    opacity: 0;
    transform: translate(var(--dx), var(--dy)) rotate(var(--spin)) scale(0.35);
  }
}

@keyframes toast-pop {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(10px) scale(0.95);
  }
}

@keyframes tracker-pop {
  0% {
    box-shadow: var(--shadow-md);
    transform: scale(1);
  }
  35% {
    box-shadow: 0 16px 38px oklch(70% 0.13 78 / 0.28);
    transform: scale(1.022);
  }
  100% {
    box-shadow: var(--shadow-md);
    transform: scale(1);
  }
}

@keyframes card-glow {
  0% {
    box-shadow: var(--shadow-md);
  }
  35% {
    box-shadow:
      0 0 0 3px oklch(70% 0.13 78 / 0.28),
      0 18px 40px oklch(36% 0.10 192 / 0.18);
  }
  100% {
    box-shadow: var(--shadow-md);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
  }

  .sparkle,
  .celebrate-pulse,
  .card-celebrated,
  .toast {
    animation: none;
  }
}

/* Responsive
   -------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .dashboard-row {
    grid-template-columns: 1fr;
  }

  .composition-line {
    white-space: normal;
  }
}

@media (max-width: 760px) {
  .shell {
    width: min(100% - 24px, 1180px);
    padding-top: 28px;
  }

  .home-header {
    grid-template-columns: 1fr;
    align-items: flex-start;
  }

  body::after {
    right: 14px;
    bottom: 14px;
    width: 0.72in;
    height: 0.72in;
    opacity: 0.3;
  }

  .home-nav,
  .toolbar {
    width: 100%;
    justify-content: flex-start;
  }

  .family-panel,
  .primary-action,
  .controls,
  .summary-band,
  .book-grid,
  .admin-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .primary-action,
  .family-panel {
    gap: 18px;
    padding: 24px 20px;
  }

  .family-panel .section-title,
  .primary-action .section-title {
    white-space: normal;
  }

  .child-profile-grid {
    justify-content: flex-end;
  }

  .child-form,
  .child-edit-panel {
    grid-template-columns: 1fr;
  }

  .child-edit-panel .child-form-actions {
    flex-wrap: wrap;
  }

  .danger-button {
    margin-right: 0;
  }

  .read-summary-card,
  .mix-card,
  .admin-import-row {
    align-items: stretch;
    flex-direction: column;
  }

  .read-summary-card {
    display: flex;
  }

  .read-child-profile-grid {
    justify-content: flex-end;
  }

  .primary-action .grade-pill-group {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .btn,
  .primary-button,
  .library-link,
  .subtle-button,
  .nav-button,
  .book-secondary-action,
  button[data-status],
  .shelf-button,
  .secondary-link,
  .form-control,
  select,
  input[type='file'],
  input[type='text'],
  input[type='url'],
  input[type='number'],
  textarea {
    max-width: 100%;
  }

  .actions .library-link {
    width: 100%;
  }

  .panel-heading-row {
    align-items: stretch;
    flex-direction: column;
  }
}
