/* =================== RESET & BASE =================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Kid-mode palette: one warm family, used consistently everywhere a child looks */
  --kid: #FF7A45;
  --kid-dark: #E8632E;
  --kid-light: #FFE9DA;
  --kid-soft: #FFF6EE;

  --sun: #FFC93C;
  --sun-dark: #E8A800;
  --sun-light: #FFF6D9;

  --leaf: #48B57E;
  --leaf-light: #E6F7EE;

  --berry: #F16B6B;
  --berry-light: #FFECEC;

  --sky: #45B8D6;
  --sky-light: #E8F8FC;

  /* Grown-up mode palette: a separate cool family so parents instantly know they're "backstage" */
  --grownup: #56697C;
  --grownup-dark: #3E4E5E;
  --grownup-light: #EAEFF2;

  --bg: #FFF9F2;
  --bg-card: #FFFFFF;
  --text: #3B2F27;
  --text-light: #9C8F82;

  --shadow: 0 6px 18px rgba(232,98,46,0.14);
  --shadow-lg: 0 12px 30px rgba(232,98,46,0.2);
  --shadow-flat: 0 2px 10px rgba(50,35,20,0.08);

  --radius: 22px;
  --radius-lg: 28px;
  --radius-sm: 14px;
  --radius-xs: 9px;
  --pill: 999px;

  --font-display: 'Baloo 2', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --font-body: -apple-system, 'PingFang SC', 'Microsoft YaHei', 'Helvetica Neue', sans-serif;

  --header-h: 56px;
  --footer-h: 96px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  touch-action: manipulation;
}

/* =================== VIEWS =================== */
.view {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(circle at 8% 0%, rgba(255,201,60,0.10) 0%, transparent 40%),
    radial-gradient(circle at 100% 15%, rgba(255,122,69,0.08) 0%, transparent 45%),
    var(--bg);
}
.view.active { display: flex; }

/* =================== HEADER =================== */
.app-header {
  height: var(--header-h);
  min-height: var(--header-h);
  padding: 0 10px;
  padding-top: var(--safe-top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-card);
  box-shadow: var(--shadow-flat);
  z-index: 10;
}
.header-left, .header-right { display: flex; align-items: center; gap: 6px; min-width: 60px; }
.header-right { justify-content: flex-end; }
.header-title {
  font-family: var(--font-display);
  font-size: 18px; font-weight: 700; text-align: center; flex: 1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.header-title .hicon { font-size: 20px; display: inline-flex; }

/* All child-facing screens share one warm family */
.child-header, .quiz-header, .wrong-header {
  background: linear-gradient(135deg, var(--kid), var(--sun) 160%);
}
.child-header .header-title, .quiz-header .header-title, .wrong-header .header-title { color: #fff; }
.child-header .icon-btn, .quiz-header .icon-btn, .wrong-header .icon-btn,
.quiz-header .page-indicator { color: #fff; background: rgba(255,255,255,0.22); }

.read-header { background: var(--bg-card); }

/* Grown-up screens share a distinct cool family */
.parent-header, .mark-header {
  background: linear-gradient(135deg, var(--grownup-dark), var(--grownup));
}
.parent-header .header-title, .mark-header .header-title { color: #fff; }
.parent-header .icon-btn, .mark-header .icon-btn { color: #fff; background: rgba(255,255,255,0.16); }

/* =================== BUTTONS =================== */
.icon-btn {
  width: 40px; height: 40px;
  border: none; border-radius: 50%;
  background: #F3ECE4;
  font-size: 18px; color: var(--text);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: transform 0.15s, background 0.15s;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:active { transform: scale(0.88) rotate(-4deg); background: #E7DED3; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  padding: 15px 32px;
  border: none; border-radius: var(--pill);
  font-family: var(--font-display);
  font-size: 18px; font-weight: 700;
  cursor: pointer; transition: transform 0.15s, box-shadow 0.15s;
  width: 100%;
  letter-spacing: 0.2px;
}
.btn svg { width: 22px; height: 22px; flex-shrink: 0; }
.btn:active { transform: scale(0.96) translateY(1px); }

.btn-child { background: linear-gradient(135deg, var(--kid), var(--kid-dark)); color: #fff; box-shadow: var(--shadow); }
.btn-parent { background: linear-gradient(135deg, var(--grownup), var(--grownup-dark)); color: #fff; box-shadow: 0 6px 18px rgba(62,78,94,0.25); }
.btn-small { padding: 10px 20px; font-size: 14px; width: auto; border-radius: var(--pill); background: var(--sky); color: #fff; }
.btn-link { background: none; color: var(--sky); text-decoration: underline; font-size: 14px; width: auto; padding: 8px; font-family: var(--font-body); font-weight: 600; }
.btn-save { background: var(--leaf) !important; }
.btn-mark { background: var(--kid) !important; color: #fff !important; }
.btn-edit { background: var(--grownup) !important; color: #fff !important; }

.page-indicator { font-size: 14px; color: var(--text-light); font-weight: 700; padding: 0 8px; font-family: var(--font-display); }

/* =================== LOGIN =================== */
.login-container {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 40px;
  gap: 14px;
  background:
    radial-gradient(circle at 15% 8%, rgba(255,201,60,0.22) 0%, transparent 38%),
    radial-gradient(circle at 88% 20%, rgba(69,184,214,0.14) 0%, transparent 40%),
    linear-gradient(180deg, var(--bg) 0%, var(--kid-soft) 100%);
}
.login-logo { margin-bottom: 4px; animation: float-bob 3.2s ease-in-out infinite; }
@keyframes float-bob {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50% { transform: translateY(-8px) rotate(2deg); }
}
.login-title { font-family: var(--font-display); font-size: 30px; font-weight: 800; color: var(--kid-dark); }
.login-subtitle { font-size: 15px; color: var(--text-light); margin-bottom: 20px; font-weight: 600; }
.login-container .btn { max-width: 280px; }

.pin-section {
  margin-top: 14px;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.pin-section p { font-size: 14px; color: var(--text-light); font-weight: 600; }
.pin-inputs { display: flex; gap: 12px; }
.pin-digit {
  width: 50px; height: 58px;
  border: 2px solid #EEE1D4; border-radius: var(--radius-sm);
  text-align: center; font-size: 24px; font-weight: 700;
  outline: none; transition: border-color 0.2s;
  background: var(--bg-card);
  font-family: var(--font-display);
}
.pin-digit:focus { border-color: var(--kid); }

/* =================== BOOKSHELF =================== */
.child-name-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: var(--bg-card);
  border-bottom: 1px solid #F4EBE1;
  font-size: 14px; color: var(--text-light);
  font-weight: 600;
}
.child-name-bar select {
  padding: 6px 10px; border: 1.5px solid var(--kid-light); border-radius: var(--pill);
  font-size: 14px; background: var(--kid-soft); color: var(--kid-dark); font-weight: 700;
}
.child-name-bar .icon-btn { width: 32px; height: 32px; background: var(--kid-light); color: var(--kid-dark); }

.bookshelf {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 14px;
  align-content: start;
}

/* Collection list */
.collection-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.collection-card {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-flat);
  cursor: pointer;
  transition: all 0.2s;
  border-left: 5px solid var(--c-color, var(--kid));
}
.collection-card:active { transform: scale(0.98); }
.collection-icon {
  width: 56px; height: 56px;
  border-radius: 16px;
  background: color-mix(in srgb, var(--c-color, var(--kid)) 15%, transparent);
  color: var(--c-color, var(--kid));
  display: flex; align-items: center; justify-content: center;
  font-size: 28px;
  flex-shrink: 0;
}
.collection-info { flex: 1; min-width: 0; }
.collection-title { font-size: 17px; font-weight: 700; color: var(--text); margin-bottom: 2px; }
.collection-subtitle { font-size: 13px; color: var(--text-light); margin-bottom: 8px; }
.collection-progress-bar {
  height: 6px;
  background: var(--grownup-light);
  border-radius: var(--pill);
  overflow: hidden;
  margin-bottom: 6px;
}
.collection-progress-fill {
  height: 100%;
  background: var(--c-color, var(--kid));
  border-radius: var(--pill);
  transition: width 0.3s;
}
.collection-stats { font-size: 12px; color: var(--text-light); }
.collection-arrow { color: var(--text-light); font-size: 18px; flex-shrink: 0; }

.book-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-flat);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  position: relative;
  border: 2px solid transparent;
}
.book-card:active { transform: scale(0.95) rotate(-1deg); box-shadow: var(--shadow); border-color: var(--kid-light); }

.book-number {
  position: absolute; top: 8px; left: 8px;
  background: var(--kid); color: #fff;
  font-size: 11px; font-weight: 800; font-family: var(--font-display);
  width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  z-index: 2; box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

.badge {
  position: absolute; top: 8px; right: 8px;
  font-size: 11px; font-weight: 700;
  padding: 3px 9px; border-radius: var(--pill); z-index: 2;
  display: flex; align-items: center; gap: 3px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.1);
}
.badge svg { width: 12px; height: 12px; }
.badge-read { background: var(--leaf-light); color: var(--leaf); }
.badge-complete { background: var(--sun); color: #8A5A00; }
.badge-progress { background: var(--sky-light); color: var(--sky); }

.book-cover {
  height: 118px;
  background: linear-gradient(135deg, var(--kid-light), #FFDCC2);
  display: flex; align-items: center; justify-content: center;
  position: relative;
  overflow: hidden;
}
.book-cover img, .book-cover canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.book-cover-placeholder { color: var(--kid-dark); opacity: 0.55; }
.book-cover-placeholder svg { width: 40px; height: 40px; }
.book-title-overlay {
  font-size: 13px; font-weight: 700; color: var(--kid-dark);
  text-align: center; padding: 4px 8px;
  text-shadow: 0 1px 2px rgba(255,255,255,0.8);
}

.book-info {
  padding: 9px 11px;
  border-top: 1px solid var(--kid-soft);
}
.book-info h3 {
  font-size: 12.5px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-bottom: 5px;
}
.quiz-status { font-size: 11px; color: var(--text-light); font-weight: 600; display: inline-flex; align-items: center; gap: 3px; }
.quiz-status svg { width: 11px; height: 11px; }
.quiz-status.done { color: var(--sun-dark); font-weight: 700; }
.quiz-status.partial { color: var(--sky); }

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-light);
  font-size: 16px;
  font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.empty-state svg { width: 56px; height: 56px; color: var(--kid-light); }

/* =================== READER =================== */
.reader-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: linear-gradient(180deg, #FBF3E8, #F3E4D2);
  position: relative;
}

.pdf-container {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

#pdf-canvas {
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  box-shadow: 0 10px 34px rgba(90,60,20,0.22);
  background: #fff;
}

/* Page nav overlay */
.page-nav-overlay {
  position: absolute; inset: 0;
  background: rgba(59,47,39,0.9);
  z-index: 20;
  overflow-y: auto;
  padding: 20px;
  -webkit-overflow-scrolling: touch;
}
.page-nav-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
}
.page-nav-item {
  background: #4A3C30;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  text-align: center;
  padding: 4px;
  transition: all 0.15s;
  color: #fff; font-weight: 700;
}
.page-nav-item.active { box-shadow: 0 0 0 3px var(--sun); }
.page-nav-item:active { background: #5C4B3C; }
.page-nav-item canvas { width: 100%; height: auto; display: block; border-radius: 6px; }

/* Book finished overlay */
.book-finished-overlay {
  position: absolute; inset: 0;
  background: rgba(59,47,39,0.85);
  z-index: 25;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.book-finished-card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  text-align: center;
  max-width: 320px;
  width: 100%;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.finished-icon { color: var(--sun-dark); font-size: 48px; margin-bottom: 12px; }
.finished-title { color: var(--text); font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.finished-subtitle { color: var(--text-light); font-size: 15px; margin-bottom: 24px; }
.finished-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.finished-actions .btn { flex: 1; min-width: 130px; white-space: nowrap; }
@keyframes popIn {
  from { opacity: 0; transform: scale(0.7); }
  to { opacity: 1; transform: scale(1); }
}

/* Reader footer */
.reader-footer {
  background: var(--bg-card);
  padding: 8px 16px;
  padding-bottom: calc(8px + var(--safe-bottom));
  box-shadow: 0 -2px 10px rgba(50,35,20,0.06);
  z-index: 10;
}

.audio-controls {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  margin-bottom: 10px;
}
.audio-btn {
  width: 42px; height: 42px;
  border: none; border-radius: 50%;
  background: var(--kid-soft);
  color: var(--kid-dark);
  font-size: 20px;
  cursor: pointer; transition: all 0.15s;
  display: flex; align-items: center; justify-content: center;
}
.audio-btn svg { width: 20px; height: 20px; }
.audio-btn:active { background: var(--kid-light); transform: scale(0.9); }
#btn-play-pause {
  width: 54px; height: 54px; font-size: 24px;
  background: linear-gradient(135deg, var(--kid), var(--kid-dark)); color: #fff;
  box-shadow: var(--shadow);
}
#btn-play-pause svg { width: 24px; height: 24px; }

.speed-control { margin-left: 6px; }
.speed-btn {
  width: 38px; height: 38px;
  border: none; border-radius: var(--pill);
  background: #F3ECE4;
  font-family: var(--font-display);
  font-size: 12px; font-weight: 700;
  color: var(--text);
  cursor: pointer;
}

.progress-bar-container {
  position: relative;
  height: 26px;
  background: #F3ECE4;
  border-radius: var(--pill);
  cursor: pointer;
  overflow: visible;
}
.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--kid), var(--sun));
  border-radius: var(--pill);
  transition: width 0.1s linear;
  width: 0%;
}
.page-markers {
  position: absolute; inset: 0;
  display: flex;
  pointer-events: none;
  border-radius: var(--pill);
  overflow: hidden;
}
.page-marker {
  height: 100%;
  background: rgba(255,255,255,0);
  border-right: 2px solid rgba(255,255,255,0.55);
  position: relative;
}
.page-marker.active::after {
  content: '';
  position: absolute; top: 50%; left: 50%;
  width: 6px; height: 6px; border-radius: 50%;
  background: #fff;
  transform: translate(-50%,-50%);
  box-shadow: 0 0 0 3px rgba(255,255,255,0.4);
}

/* =================== QUIZ =================== */
.quiz-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  -webkit-overflow-scrolling: touch;
}

.quiz-question-card { max-width: 520px; margin: 0 auto; }

.quiz-question {
  font-family: var(--font-display);
  font-size: 21px; font-weight: 700;
  text-align: center;
  margin-bottom: 22px;
  padding: 22px;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-flat);
  border-top: 5px solid var(--kid);
}

.quiz-options {
  display: flex; flex-direction: column; gap: 12px;
}

.quiz-option {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 18px;
  background: var(--bg-card);
  border: 2.5px solid #F2E9DE;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
  font-size: 17px;
  font-weight: 600;
  text-align: left;
}
.quiz-option:active { transform: scale(0.98); }
.quiz-option:disabled { cursor: default; }
.quiz-option.correct {
  border-color: var(--leaf) !important;
  background: var(--leaf-light) !important;
  animation: pop-correct 0.35s ease;
}
.quiz-option.wrong {
  border-color: var(--berry) !important;
  background: var(--berry-light) !important;
}
@keyframes pop-correct {
  0% { transform: scale(1); }
  40% { transform: scale(1.04); }
  100% { transform: scale(1); }
}

.option-key {
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--kid-light);
  color: var(--kid-dark);
  font-family: var(--font-display);
  font-size: 16px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.option-text { flex: 1; }

.quiz-feedback {
  margin-top: 20px;
  padding: 18px;
  border-radius: var(--radius);
  text-align: center;
  background: var(--bg-card);
  box-shadow: var(--shadow-flat);
}
.feedback-icon { margin-bottom: 6px; display: flex; align-items: center; justify-content: center; }
.feedback-icon svg { width: 44px; height: 44px; }
.feedback-icon.correct { color: var(--sun-dark); }
.feedback-icon.wrong { color: var(--sky); }
.feedback-text { font-family: var(--font-display); font-size: 20px; font-weight: 700; margin-bottom: 8px; }
.feedback-text.correct { color: var(--leaf); }
.feedback-text.wrong { color: var(--berry); }
.feedback-explanation { font-size: 15px; color: var(--text-light); line-height: 1.5; font-weight: 500; }

.btn-next-quiz {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  margin: 20px auto 0;
  padding: 12px 36px;
  background: linear-gradient(135deg, var(--kid), var(--kid-dark)); color: #fff;
  border: none; border-radius: var(--pill);
  font-family: var(--font-display);
  font-size: 16px; font-weight: 700;
  cursor: pointer;
}
.btn-next-quiz svg { width: 16px; height: 16px; transform: scaleX(-1); }

/* Quiz result */
.quiz-result {
  text-align: center;
  padding: 36px 20px;
}
.result-icon { margin-bottom: 12px; display: flex; align-items: center; justify-content: center; color: var(--sun-dark); }
.result-icon svg { width: 76px; height: 76px; }
#result-title { font-family: var(--font-display); font-size: 26px; margin-bottom: 8px; }
#result-score { font-size: 18px; color: var(--text-light); margin-bottom: 16px; font-weight: 600; }
.result-stars { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 26px; }
.result-stars svg { width: 34px; height: 34px; }
.result-stars .star { color: var(--sun); }
.result-stars .star-empty { color: #EEE3D4; }
.result-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.result-actions .btn { max-width: 210px; }

/* =================== PARENT MODE =================== */
.parent-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  -webkit-overflow-scrolling: touch;
}

.parent-section {
  margin-bottom: 26px;
}
.parent-section h2 {
  font-size: 16px; font-weight: 700; margin-bottom: 4px;
  display: flex; align-items: center; gap: 7px;
  color: var(--grownup-dark);
}
.parent-section h2 svg { width: 18px; height: 18px; }
.section-desc { font-size: 13px; color: var(--text-light); margin-bottom: 12px; }

.parent-book-list {
  display: flex; flex-direction: column; gap: 8px;
}
.parent-book-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-flat);
  gap: 12px;
}

.parent-collection-list { display: flex; flex-direction: column; gap: 10px; }
.parent-collection-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-flat);
  cursor: pointer;
  border-left: 4px solid var(--c-color, var(--kid));
  transition: all 0.15s;
}
.parent-collection-item:active { transform: scale(0.99); }
.parent-collection-icon {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--c-color, var(--kid)) 15%, transparent);
  color: var(--c-color, var(--kid));
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.parent-collection-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.parent-collection-title { font-size: 15px; font-weight: 600; color: var(--text); }
.parent-collection-count { font-size: 12px; color: var(--text-light); }
.parent-collection-arrow { color: var(--text-light); font-size: 16px; }

.parent-book-info { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.book-number-sm { font-size: 12px; color: var(--text-light); font-weight: 700; }
.parent-book-title { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-badge { font-size: 12px; padding: 3px 10px; border-radius: var(--pill); white-space: nowrap; display: inline-flex; align-items: center; gap: 4px; font-weight: 600; }
.status-badge svg { width: 12px; height: 12px; }
.status-badge.ready { background: var(--leaf-light); color: var(--leaf); }
.status-badge.pending { background: var(--grownup-light); color: var(--grownup); }

.parent-book-actions { display: flex; gap: 8px; flex-shrink: 0; }

.stats-panel { background: var(--bg-card); border-radius: var(--radius-sm); overflow: hidden; box-shadow: var(--shadow-flat); }
.stats-table {
  width: 100%; border-collapse: collapse;
}
.stats-table th, .stats-table td {
  padding: 10px 12px; text-align: center; font-size: 14px;
  border-bottom: 1px solid var(--grownup-light);
}
.stats-table th { background: var(--grownup-light); font-weight: 700; font-size: 13px; color: var(--grownup-dark); }
.text-wrong { color: var(--berry); font-weight: 700; }

/* =================== AUDIO MARKER =================== */
.mark-body {
  flex: 1;
  display: flex; flex-direction: column;
  overflow: hidden;
  background: var(--grownup-light);
}

.mark-current-page {
  text-align: center; font-size: 16px; font-weight: 700;
  padding: 9px; background: var(--bg-card);
  color: var(--grownup-dark);
}

.mark-canvas-area {
  height: 180px;
  display: flex; align-items: center; justify-content: center;
  background: var(--grownup-dark);
  overflow: hidden;
}
#mark-pdf-canvas { max-width: 100%; max-height: 100%; }

.mark-player {
  background: var(--bg-card);
  padding: 8px 16px;
}

.mark-time-display {
  display: flex; justify-content: space-between;
  font-size: 13px; color: var(--text-light);
  margin-bottom: 4px;
}
.mark-range-label { color: var(--grownup); font-weight: 700; font-size: 14px; }

.mark-controls {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 0;
}
.mark-controls .audio-btn { background: var(--grownup-light); color: var(--grownup-dark); }
.mark-controls .audio-btn:active { background: #DDE5EA; }
.mark-btn-start { background: var(--sky) !important; color: #fff !important; width: 46px; height: 46px; font-size: 13px !important; font-weight: 700; }
.mark-btn-end { background: var(--leaf) !important; color: #fff !important; width: 46px; height: 46px; font-size: 13px !important; font-weight: 700; }
.mark-btn-start.active { box-shadow: 0 0 0 3px rgba(69,184,214,0.4); }

.mark-hint {
  text-align: center;
  font-size: 13px;
  color: var(--grownup-dark);
  font-weight: 600;
  padding: 6px 0;
  background: var(--grownup-light);
  border-radius: var(--radius-xs);
  margin: 0 16px 8px;
}

.mark-page-nav {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 16px;
  background: var(--bg-card);
  border-top: 1px solid var(--grownup-light);
}
.mark-page-nav .icon-btn {
  width: auto; padding: 0 18px; height: 38px; border-radius: var(--pill); font-size: 14px;
  background: var(--grownup-light); color: var(--grownup-dark); font-weight: 700;
}
.mark-page-info { font-size: 14px; font-weight: 700; color: var(--grownup-dark); }

.marks-table-container {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
}
.marks-table {
  width: 100%; border-collapse: collapse;
  background: var(--bg-card); border-radius: var(--radius-sm);
  overflow: hidden;
}
.marks-table th, .marks-table td {
  padding: 7px 8px; text-align: center; font-size: 13px;
  border-bottom: 1px solid var(--grownup-light);
}
.marks-table th { background: var(--grownup-light); font-weight: 700; font-size: 12px; color: var(--grownup-dark); }
.marks-table .active-row { background: #FFF3E0; }

/* =================== WRONG ANSWERS =================== */
.wrong-body { flex: 1; overflow-y: auto; padding: 16px; -webkit-overflow-scrolling: touch; }

.wrong-child-label {
  text-align: center; font-size: 14px; color: var(--text-light); font-weight: 600;
  margin-bottom: 16px; padding: 9px; background: var(--bg-card); border-radius: var(--pill);
  box-shadow: var(--shadow-flat);
}

.wrong-book-group {
  margin-bottom: 20px;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-flat);
}
.wrong-book-group h3 {
  font-family: var(--font-display);
  font-size: 15px; font-weight: 700;
  padding: 10px 14px;
  background: linear-gradient(135deg, var(--kid), var(--kid-dark)); color: #fff;
}

.wrong-item {
  background: var(--bg-card);
  padding: 14px 16px;
}
.wrong-item + .wrong-item { border-top: 1px solid var(--kid-soft); }
.wrong-question { font-size: 15px; font-weight: 700; margin-bottom: 8px; }
.wrong-selected { font-size: 14px; color: var(--berry); margin-bottom: 4px; font-weight: 600; }
.wrong-correct { font-size: 14px; color: var(--leaf); font-weight: 700; margin-bottom: 4px; }
.wrong-explanation { font-size: 13px; color: var(--text-light); font-style: italic; }

/* =================== TOAST =================== */
.toast {
  position: fixed;
  bottom: 100px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: rgba(59,47,39,0.92); color: #fff;
  padding: 11px 26px; border-radius: var(--pill);
  font-size: 14px; font-weight: 600;
  opacity: 0; transition: all 0.3s;
  z-index: 1000; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* =================== LOADING OVERLAY =================== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(59, 47, 39, 0.75);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.loading-spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  color: #fff;
  font-size: 15px;
  font-weight: 600;
}

.loading-progress-bar {
  width: 200px;
  height: 6px;
  background: rgba(255,255,255,0.2);
  border-radius: 100px;
  overflow: hidden;
}
.loading-progress-fill {
  height: 100%;
  width: 0%;
  background: #fff;
  border-radius: 100px;
  transition: width 0.3s;
}
.loading-size {
  color: rgba(255,255,255,0.7);
  font-size: 12px;
}
.btn-cancel {
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  padding: 8px 24px;
  border-radius: var(--pill);
  font-size: 14px;
  cursor: pointer;
}
.btn-cancel:active {
  background: rgba(255,255,255,0.25);
}

/* =================== HIDDEN =================== */
.hidden { display: none !important; }

/* =================== MODAL =================== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(59,47,39,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 26px;
  width: 300px;
  box-shadow: var(--shadow-lg);
}
.modal-card h3 { font-family: var(--font-display); font-size: 17px; margin-bottom: 14px; text-align: center; }
.modal-card input {
  width: 100%; padding: 11px 14px;
  border: 2px solid var(--kid-soft); border-radius: var(--radius-sm);
  font-size: 16px; outline: none;
  transition: border-color 0.2s;
}
.modal-card input:focus { border-color: var(--kid); }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; justify-content: flex-end; }

/* =================== RESPONSIVE =================== */
@media (min-width: 768px) {
  .bookshelf { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .book-cover { height: 140px; }
}

/* Landscape-optimized for iPad */
@media (orientation: landscape) and (max-height: 500px) {
  .header-title { font-size: 16px; }
  :root { --header-h: 46px; --footer-h: 74px; }
  .audio-btn { width: 38px; height: 38px; font-size: 18px; }
  #btn-play-pause { width: 46px; height: 46px; font-size: 20px; }
  .progress-bar-container { height: 20px; }
  .reader-footer { padding: 5px 16px; }
  .mark-canvas-area { height: 140px; }
}

/* Standalone mode (PWA on iPad) */
@media (display-mode: standalone) {
  :root { --safe-top: env(safe-area-inset-top, 20px); --safe-bottom: env(safe-area-inset-bottom, 20px); }
}
