/* ===== Reading Rocket — kid-first PWA styles ===== */
:root {
  --bg: #fff7ec;
  --bg-card: #ffffff;
  --bg-soft: #fdeeda;
  --text: #2c2218;
  --text-soft: #8a7a66;
  --line: #f0e3d0;
  --radius: 22px;
  --radius-sm: 14px;
  --tap: 56px;
  --shadow: 0 8px 24px rgba(120, 90, 50, 0.12);
  --shadow-lg: 0 16px 40px rgba(120, 90, 50, 0.20);
  --accent: #c0492f; /* warning/attention (page-count hints, missing markers) */
  /* Active reader theme — overwritten per kid by JS */
  --kid: #3f6fd1;
  --kid-accent: #ffd23f;
  --kid-soft: #e8f0ff;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* the [hidden] attribute must win over the display rules below (.celebrate/.recent-wrap use flex) */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  font-feature-settings: "cv11", "ss01";
  -webkit-text-size-adjust: 100%;
}

body {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100dvh;
  padding:
    calc(env(safe-area-inset-top) + 8px)
    calc(env(safe-area-inset-right) + 16px)
    calc(env(safe-area-inset-bottom) + 120px)
    calc(env(safe-area-inset-left) + 16px);
  position: relative;
  overflow-x: hidden;
}

h1, h2 { margin: 0; line-height: 1.1; }

/* ===== Top bar ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 2px 14px;
}
.readers { display: flex; gap: 10px; flex: 1; }
.reader-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 3px solid var(--line);
  background: var(--bg-card);
  border-radius: 999px;
  padding: 8px 16px 8px 10px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text-soft);
  cursor: pointer;
  transition: transform 0.12s ease, border-color 0.15s ease, color 0.15s ease;
  min-height: var(--tap);
}
.reader-chip .av { font-size: 24px; line-height: 1; }
.reader-chip[aria-selected="true"] {
  border-color: var(--chip-color, var(--kid));
  color: var(--chip-color, var(--kid));
  background: var(--chip-soft, var(--kid-soft));
  transform: translateY(-1px) scale(1.02);
}
.reader-chip:active { transform: scale(0.96); }

.grown-btn {
  width: var(--tap);
  height: var(--tap);
  border-radius: 50%;
  border: none;
  background: var(--bg-card);
  box-shadow: var(--shadow);
  font-size: 22px;
  cursor: pointer;
  flex: none;
}
.grown-btn:active { transform: scale(0.92); }

/* ===== Hello card ===== */
.hello-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: linear-gradient(135deg, var(--kid-soft), var(--bg-card));
  border: 3px solid var(--kid);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 22px;
}
.mascot { width: 76px; height: 76px; flex: none; position: relative; border: none; background: none; padding: 0; cursor: pointer; }
.mascot::after {
  content: "✏️"; position: absolute; right: -5px; bottom: -5px;
  font-size: 12px; width: 23px; height: 23px; border-radius: 50%;
  background: var(--bg-card); box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center;
}
.mascot:active { transform: scale(0.94); }
.mascot svg, .celebrate-mascot svg { width: 100%; height: 100%; display: block; }
.hello-text h1 { font-size: 26px; color: var(--kid); }
.count-line { margin: 6px 0 0; font-size: 17px; font-weight: 600; color: var(--text-soft); }
.count-line strong { color: var(--text); }
.last-read { margin: 5px 0 0; font-size: 12.5px; font-weight: 600; color: var(--text-soft); }
.last-read strong { color: var(--kid); }

/* ===== Shelf ===== */
.shelf-head { display: flex; align-items: baseline; justify-content: space-between; margin: 0 4px 12px; }
.shelf-head h2 { font-size: 20px; }
.shelf {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
@media (min-width: 440px) { .shelf { grid-template-columns: repeat(4, 1fr); } }

.book {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 10px;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0,0,0,0.35);
  animation: pop 0.45s cubic-bezier(0.18, 1.4, 0.5, 1) both;
}
.book::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 7px;
  background: rgba(0,0,0,0.18);
}
.book .b-emoji { position: absolute; top: 10px; right: 10px; font-size: 22px; text-shadow: none; }
.book .b-title { font-size: 13px; font-weight: 800; line-height: 1.15; }
.book .b-author { font-size: 10.5px; font-weight: 600; opacity: 0.9; margin-top: 3px; }
.book .b-readcount {
  position: absolute; top: 8px; left: 12px;
  font-size: 11px; font-weight: 800;
  background: rgba(255,255,255,0.9); color: var(--text);
  padding: 1px 7px; border-radius: 999px; text-shadow: none;
}
.book img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; animation: fadeIn 0.35s ease both; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.book.flying { animation: flyIn 0.7s cubic-bezier(0.16, 1, 0.3, 1) both; }

@keyframes pop { from { transform: scale(0.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes flyIn {
  0% { transform: translateY(60vh) scale(1.4) rotate(-8deg); opacity: 0; }
  60% { opacity: 1; }
  100% { transform: translateY(0) scale(1) rotate(0); opacity: 1; }
}

.empty-note { text-align: center; color: var(--text-soft); font-size: 16px; font-weight: 600; margin-top: 30px; }
.spacer { height: 8px; }

/* ===== Big button ===== */
.big-btn {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  width: min(488px, calc(100% - 32px));
  min-height: 68px;
  border: none;
  border-radius: 999px;
  background: var(--kid);
  color: #fff;
  font-size: 21px;
  font-weight: 800;
  box-shadow: var(--shadow-lg);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  z-index: 30;
  transition: transform 0.1s ease;
}
.big-btn-emoji { font-size: 26px; }
.big-btn:active { transform: translateX(-50%) scale(0.96); }

/* ===== Celebrate overlay ===== */
.celebrate {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(40, 30, 18, 0.55);
  backdrop-filter: blur(3px);
}
#confetti { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.celebrate-inner {
  position: relative;
  text-align: center;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 28px 26px 24px;
  box-shadow: var(--shadow-lg);
  width: min(360px, calc(100% - 48px));
  animation: pop 0.4s cubic-bezier(0.18, 1.4, 0.5, 1) both;
}
.celebrate-mascot { width: 110px; height: 110px; margin: 0 auto 8px; }
#celebrate-title { font-size: 28px; color: var(--kid); }
#celebrate-sub { margin: 8px 0 18px; font-size: 17px; font-weight: 600; color: var(--text-soft); }
.celebrate-done {
  min-height: var(--tap);
  width: 100%;
  border: none;
  border-radius: 999px;
  background: var(--kid-accent);
  color: var(--text);
  font-size: 19px;
  font-weight: 800;
  cursor: pointer;
}
.celebrate-done:active { transform: scale(0.96); }

/* ===== Dialogs ===== */
dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  width: min(460px, calc(100% - 28px));
  box-shadow: var(--shadow-lg);
  background: var(--bg-card);
  color: var(--text);
}
dialog::backdrop { background: rgba(40, 30, 18, 0.5); backdrop-filter: blur(2px); }
.dlg-form { padding: 24px 22px; display: flex; flex-direction: column; gap: 14px; }
.dlg-form h2 { font-size: 22px; }

.fld { display: flex; flex-direction: column; gap: 6px; font-size: 14px; font-weight: 700; color: var(--text-soft); }
.fld em { font-weight: 500; }
.fld input {
  min-height: var(--tap);
  border: 2px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  font-size: 18px;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
}
.fld input:focus { outline: none; border-color: var(--kid); }

.recent-wrap { display: flex; flex-direction: column; gap: 8px; }
.recent-label { margin: 0; font-size: 14px; font-weight: 700; color: var(--text-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 2px solid var(--line);
  background: var(--bg);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip:active { transform: scale(0.95); border-color: var(--kid); }
.or-line { text-align: center; color: var(--text-soft); font-size: 13px; font-weight: 600; margin: 4px 0 0; }

.dlg-actions { display: flex; gap: 8px; margin-top: 4px; flex-wrap: wrap; }
.dlg-actions button { flex: 1 1 0; min-width: 92px; min-height: var(--tap); border-radius: var(--radius-sm); font-size: 15px; font-weight: 800; cursor: pointer; border: none; white-space: nowrap; padding: 0 6px; }
.btn-go { background: var(--kid); color: #fff; }
.btn-ghost { background: var(--bg); color: var(--text-soft); border: 2px solid var(--line) !important; }
.btn-ghost.danger { color: #c0492f; }
.btn-go:active, .btn-ghost:active { transform: scale(0.97); }

/* Scan */
.btn-scan {
  width: 100%; min-height: 56px; border: none; border-radius: var(--radius-sm);
  background: var(--kid); color: #fff; font-size: 18px; font-weight: 800; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-scan:active { transform: scale(0.97); }
.add-or { text-align: center; color: var(--text-soft); font-size: 13px; font-weight: 600; margin: -4px 0 -2px; }
#scan-video {
  width: 100%; border-radius: var(--radius-sm); background: #000;
  aspect-ratio: 4 / 3; object-fit: cover; display: block;
}
.scan-status { text-align: center; font-weight: 600; color: var(--text-soft); margin: 6px 0 0; min-height: 20px; }
.scan-dbg { text-align: center; font-size: 10.5px; color: var(--text-soft); opacity: 0.6; margin: 2px 0 0; font-variant-numeric: tabular-nums; }
.scan-isbn { display: flex; gap: 8px; margin-top: 8px; }
.scan-isbn input { flex: 1; min-width: 0; min-height: var(--tap); border: 2px solid var(--line); border-radius: var(--radius-sm); padding: 0 12px; font-size: 16px; font-family: inherit; color: var(--text); background: var(--bg); }
.scan-isbn input:focus { outline: none; border-color: var(--kid); }
.scan-isbn button { flex: none; min-height: var(--tap); padding: 0 16px; border: none; border-radius: var(--radius-sm); font-size: 15px; font-weight: 800; cursor: pointer; }
.scan-typeit { width: 100%; margin-top: 8px; min-height: 44px; border: 2px solid var(--line) !important; border-radius: var(--radius-sm); background: var(--bg); color: var(--text-soft); font-size: 14px; font-weight: 700; cursor: pointer; }
.confirm-book { display: flex; gap: 14px; align-items: center; padding: 4px 0 12px; }
.confirm-cover { width: 84px; flex: none; }
.confirm-cover img, .confirm-ph {
  width: 84px; height: 118px; border-radius: 8px; object-fit: cover; box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center; font-size: 32px; color: #fff;
}
.confirm-meta { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.confirm-meta strong { font-size: 18px; line-height: 1.2; }
.cm-author { color: var(--text-soft); font-size: 14px; }
.cm-pages {
  align-self: flex-start; margin-top: 4px; font-family: inherit;
  border: 1.5px dashed var(--kid); background: var(--kid-soft); color: var(--kid);
  font-weight: 800; font-size: 13px; border-radius: 999px; padding: 5px 12px; cursor: pointer;
}
.cm-pages:active { transform: scale(0.96); }

/* ===== Icon picker ===== */
.icon-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.icon-opt {
  font-size: 27px; min-height: 50px; border: 2px solid var(--line);
  border-radius: var(--radius-sm); background: var(--bg); cursor: pointer; line-height: 1;
}
.icon-opt.current { border-color: var(--kid); background: var(--kid-soft); }
.icon-opt:active { transform: scale(0.9); }

.muted { color: var(--text-soft); }
.small { font-size: 13.5px; line-height: 1.5; }
.dlg-form a { color: var(--kid); font-weight: 700; }
.dlg-form hr { border: none; border-top: 1px solid var(--line); margin: 4px 0; }

/* Grown-ups manage list */
.manage { display: flex; flex-direction: column; gap: 8px; max-height: 34vh; overflow-y: auto; }
.manage-row {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 8px 10px; font-size: 15px; font-weight: 600;
}
.manage-row .m-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.manage-row .m-count { font-size: 12px; color: var(--text-soft); font-weight: 700; }
.manage-row button {
  border: none; background: var(--bg-soft); border-radius: 8px;
  width: 36px; height: 36px; font-size: 16px; cursor: pointer; flex: none;
}

@media (prefers-reduced-motion: reduce) {
  .book, .book.flying, .celebrate-inner, .big-medal { animation: none; }
}

/* ===== Currently reading ===== */
.reading-now { margin-bottom: 18px; }
.rn-title { font-size: 16px; margin: 0 4px 10px; }
.rn-row { display: flex; gap: 12px; overflow-x: auto; padding: 2px 4px 8px; -webkit-overflow-scrolling: touch; }
.rn-card {
  flex: none; width: 124px;
  background: var(--bg-card); border: 2px solid var(--kid); border-radius: var(--radius-sm);
  padding: 10px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px;
}
.rn-cover { width: 100%; aspect-ratio: 2/3; border-radius: 8px; overflow: hidden; position: relative; }
.rn-cover img, .rn-ph {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  display: flex; align-items: center; justify-content: center; font-size: 30px; color: #fff;
}
.rn-bt { font-size: 12px; font-weight: 700; line-height: 1.2; max-height: 2.4em; overflow: hidden; }
.rn-finish {
  border: none; border-radius: 999px; background: var(--good, #7FA88F); color: #fff;
  font-size: 13px; font-weight: 800; padding: 8px 6px; cursor: pointer; min-height: 38px;
}
.rn-finish:active { transform: scale(0.96); }

.btn-soft { background: var(--kid-soft); color: var(--kid); border: 2px solid var(--kid) !important; }
.btn-wide { width: 100%; min-height: 50px; border-radius: var(--radius-sm); font-size: 16px; font-weight: 800; cursor: pointer; }
.btn-wide:active { transform: scale(0.98); }
.build-line { text-align: center; font-size: 11px; color: var(--text-soft); opacity: 0.65; margin: 6px 0 0; }

/* ===== Crane reading challenge ===== */
.challenge {
  background: var(--bg-card);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.ch-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.ch-title { font-size: 16px; }
.ch-pages { font-size: 16px; font-weight: 800; color: var(--kid); white-space: nowrap; }
.ch-bar {
  height: 14px; border-radius: 999px; background: var(--bg-soft);
  overflow: hidden; margin: 10px 0 6px;
}
.ch-fill {
  height: 100%; width: 0; border-radius: 999px;
  background: linear-gradient(90deg, var(--kid), var(--kid-accent));
  transition: width 0.5s cubic-bezier(0.16, 1, 0.3, 1);
}
.ch-next { font-size: 12.5px; font-weight: 600; color: var(--text-soft); }
.ch-tiers { display: flex; justify-content: space-between; gap: 6px; margin-top: 10px; }
.ch-tier { display: flex; flex-direction: column; align-items: center; gap: 2px; flex: 1; opacity: 0.5; }
.ch-tier.done { opacity: 1; }
.ct-emoji { font-size: 20px; }
.ct-label { font-size: 11px; font-weight: 700; color: var(--text-soft); }
.ch-tier.done .ct-label { color: var(--kid); }
.ch-hint { font-size: 12px; font-weight: 600; color: var(--accent); margin: 8px 0 0; }

.grown-btns { display: flex; gap: 10px; margin-top: 8px; }
.grown-btns button { flex: 1; min-height: 48px; border-radius: var(--radius-sm); font-size: 15px; font-weight: 800; border: none; cursor: pointer; }
.manage-row .m-count.missing { color: var(--accent); font-weight: 800; }

/* ===== Medals (trophy shelf) ===== */
.medals { margin: 0 0 20px; }
.medals-title { font-size: 18px; margin: 0 4px 10px; }
.medal-row {
  display: flex; gap: 12px; overflow-x: auto;
  padding: 2px 4px 8px; -webkit-overflow-scrolling: touch;
}
.medal-badge { flex: none; width: 80px; text-align: center; }
.mb-emoji {
  display: flex; align-items: center; justify-content: center;
  width: 62px; height: 62px; margin: 0 auto 5px; border-radius: 50%;
  background: radial-gradient(circle at 50% 32%, #fff, var(--kid-soft));
  border: 3px solid var(--kid-accent); font-size: 29px; box-shadow: var(--shadow);
}
.mb-name { font-size: 11px; font-weight: 700; color: var(--text-soft); line-height: 1.2; display: block; }
.big-medal { font-size: 92px; line-height: 110px; text-align: center; animation: pop 0.5s cubic-bezier(0.18, 1.4, 0.5, 1) both; }

/* ===== Printable certificate ===== */
#certificate { display: none; }
@media print {
  body > *:not(#certificate) { display: none !important; }
  body { max-width: none; margin: 0; padding: 0; }
  #certificate { display: block; }
  .cert-inner {
    border: 10px double var(--kid, #3f6fd1); border-radius: 16px;
    margin: 22px; padding: 48px 36px; text-align: center;
    font-family: Georgia, "Times New Roman", serif; color: #1d1d1d;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .cert-emoji { font-size: 66px; }
  .cert-kicker { letter-spacing: 3px; text-transform: uppercase; font-size: 13px; color: #666; margin-top: 8px; }
  .cert-name { font-size: 46px; font-weight: 800; margin: 14px 0 6px; color: var(--kid, #3f6fd1); }
  .cert-line { font-size: 22px; margin-bottom: 18px; }
  .cert-medals { font-size: 15px; margin: 0 auto 8px; max-width: 86%; line-height: 1.9; }
  .cert-foot { display: flex; justify-content: space-between; font-size: 13px; color: #666; margin-top: 44px; padding: 0 8px; }
}
