:root {
  --bg-primary: #f0f7ff;
  --bg-card: #ffffff;
  --text-primary: #1e293b;
  --text-secondary: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --accent: #f59e0b;
  --success: #10b981;
  --danger: #ef4444;
  --border: #e2e8f0;
  --shelf-wood: #854d0e;
  --shelf-wood-dark: #713f12;
  --font-family: 'Outfit', sans-serif;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
  --radius: 16px;
}

[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-card: #1e293b;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --border: #334155;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-family);
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Confetti Canvas */
#confetti-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 9999;
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--text-secondary);
  border-radius: 4px;
}

header {
  background-color: var(--bg-card);
  border-bottom: 2px solid var(--border);
  padding: 16px 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 2rem;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

.logo-text h1 {
  font-size: 1.5rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.btn {
  padding: 10px 18px;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.95rem;
  transition: all 0.2s ease;
}

.btn-primary {
  background-color: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background-color: var(--primary-hover);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.btn-secondary {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  border: 2px solid var(--border);
}

.btn-secondary:hover {
  border-color: var(--primary);
  background-color: rgba(79, 70, 229, 0.05);
}

.btn-accent {
  background-color: var(--accent);
  color: #fff;
}

.btn-accent:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.3);
}

.btn-danger {
  background-color: var(--danger);
  color: #fff;
}

.btn-icon {
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 50%;
}

/* Container & Layout */
.container {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 24px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

/* Section Views */
.view-section {
  display: none;
  animation: fadeIn 0.4s ease-out forwards;
}

.view-section.active {
  display: block;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Profile Card / Selector Grid */
.profiles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 24px;
  margin-top: 24px;
}

.profile-card {
  background-color: var(--bg-card);
  border: 3px solid var(--border);
  border-radius: 24px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.profile-card:hover {
  transform: translateY(-10px);
  border-color: var(--primary);
  box-shadow: var(--shadow-lg);
}

.profile-avatar-container {
  width: 110px;
  height: 110px;
  margin: 0 auto 16px;
  border-radius: 50%;
  padding: 8px;
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.1), rgba(245, 158, 11, 0.1));
  border: 3px dashed var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
}

.profile-avatar-container svg {
  width: 80px;
  height: 80px;
}

.profile-name {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.profile-badge-points {
  background-color: var(--primary);
  color: #fff;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 0.85rem;
  font-weight: 700;
  display: inline-block;
  margin-bottom: 8px;
}

.profile-stat-sub {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* Collaborative Goal Banner */
.family-banner {
  background: linear-gradient(135deg, rgba(79, 70, 229, 0.08), rgba(245, 158, 11, 0.08));
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

.family-banner-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.progress-bar-container {
  background-color: var(--border);
  border-radius: 12px;
  height: 20px;
  width: 100%;
  overflow: hidden;
  position: relative;
}

.progress-bar-fill {
  background: linear-gradient(90deg, var(--primary), var(--accent));
  height: 100%;
  width: 0%;
  transition: width 0.8s ease-out;
  border-radius: 12px;
}

.progress-bar-text {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-primary);
  text-shadow: 0 0 4px #fff;
}

/* Kid Dashboard Specifics */
.kid-dashboard {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 24px;
}

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

.card {
  background-color: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}

.dashboard-header-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-box {
  background-color: var(--bg-primary);
  border-radius: 16px;
  padding: 16px;
  text-align: center;
  border: 1px solid var(--border);
  position: relative;
}

.stat-val {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--primary);
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 4px;
}

/* Virtual Bookshelf */
.bookshelf-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.bookshelf-container {
  background: linear-gradient(180deg, #5c3b1e, #3e2511);
  border: 8px solid #2d1808;
  border-radius: 12px;
  padding: 16px 16px 4px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  box-shadow: inset 0 4px 10px rgba(0, 0, 0, 0.5), var(--shadow-md);
  margin-bottom: 24px;
}

.bookshelf-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding-bottom: 4px;
  border-bottom: 14px solid var(--shelf-wood);
  box-shadow: 0 4px 2px rgba(0, 0, 0, 0.3);
  min-height: 155px;
  overflow-x: auto;
  overflow-y: hidden;
  white-space: nowrap;
}

.bookshelf-row::-webkit-scrollbar {
  height: 4px;
}

.virtual-book {
  width: 84px;
  height: 120px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  box-shadow: 2px 4px 8px rgba(0, 0, 0, 0.4), inset 1px 1px 0 rgba(255, 255, 255, 0.15);
  transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  overflow: hidden;
  border: 1px solid rgba(0, 0, 0, 0.15);
}

.virtual-book:hover {
  transform: translateY(-8px) scale(1.06);
  box-shadow: 6px 12px 20px rgba(0, 0, 0, 0.5);
  z-index: 10;
}

.virtual-book::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.2) 0%, rgba(255, 255, 255, 0.15) 50%, rgba(0, 0, 0, 0.15) 100%);
  z-index: 2;
}

.virtual-book-fallback {
  padding: 10px 8px;
  text-align: center;
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
  box-sizing: border-box;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.virtual-book-fallback-title {
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
  white-space: normal;
}

.virtual-book-fallback-author {
  font-size: 0.58rem;
  opacity: 0.9;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Reading Timer Widget */
.timer-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  justify-content: center;
  gap: 16px;
}

.timer-ring-container {
  position: relative;
  width: 140px;
  height: 140px;
}

.timer-svg {
  transform: rotate(-90deg);
  width: 100%;
  height: 100%;
}

.timer-track {
  fill: none;
  stroke: var(--border);
  stroke-width: 8;
}

.timer-progress {
  fill: none;
  stroke: var(--primary);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 377;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 1s linear;
}

.timer-text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 1.5rem;
  font-weight: 800;
}

/* Form & Fields styling */
.form-group {
  margin-bottom: 18px;
  position: relative;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 8px;
  font-size: 0.95rem;
}

.form-control {
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 2px solid var(--border);
  background-color: var(--bg-card);
  color: var(--text-primary);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-control:focus {
  border-color: var(--primary);
}

/* Autocomplete Suggestions */
.search-suggestions-container {
  position: absolute;
  background-color: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  max-height: 200px;
  overflow-y: auto;
  width: 100%;
  z-index: 1000;
  box-shadow: var(--shadow-lg);
  display: none;
  margin-top: 4px;
}

.search-suggestion-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background-color 0.2s ease;
}

.search-suggestion-item:last-child {
  border-bottom: none;
}

.search-suggestion-item:hover {
  background-color: rgba(79, 70, 229, 0.1);
}

.search-suggestion-cover {
  width: 32px;
  height: 44px;
  object-fit: cover;
  border-radius: 4px;
  background-color: #cbd5e1;
  flex-shrink: 0;
}

.search-suggestion-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  text-align: left;
}

.search-suggestion-title {
  font-size: 0.85rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-primary);
}

.search-suggestion-author {
  font-size: 0.75rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.radio-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
}

.radio-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.radio-card:hover {
  border-color: var(--primary);
  background-color: rgba(79, 70, 229, 0.02);
}

.radio-card.selected {
  border-color: var(--primary);
  background-color: rgba(79, 70, 229, 0.08);
  color: var(--primary);
}

/* Doodle Sketchpad */
.sketchpad-container {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background-color: #fff;
}

.sketchpad-canvas {
  display: block;
  width: 100%;
  height: 200px;
  cursor: crosshair;
  touch-action: none;
}

.sketchpad-controls {
  background-color: #f1f5f9;
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border);
}

/* Modal dialog styling */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 16px;
}

.modal.active {
  display: flex;
}

.modal-content {
  background-color: var(--bg-card);
  border-radius: 24px;
  width: 100%;
  max-width: 550px;
  padding: 32px;
  position: relative;
  box-shadow: var(--shadow-lg);
  max-height: 90vh;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 20px;
  right: 20px;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-secondary);
}

/* Badges & Achievements */
.badges-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 16px;
  margin-top: 12px;
}

.badge-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 6px;
  background-color: var(--border);
  color: var(--text-secondary);
  font-size: 1.8rem;
  position: relative;
  opacity: 0.4;
  transition: all 0.3s;
}

.badge-icon.unlocked {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #fff;
  opacity: 1;
  box-shadow: 0 4px 10px rgba(245, 158, 11, 0.4);
  transform: scale(1.05);
}

.badge-card {
  text-align: center;
}

.badge-card span {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-primary);
  display: block;
}

/* Reward Store Grid */
.rewards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.reward-card {
  background-color: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  box-shadow: var(--shadow-sm);
}

.reward-cost-badge {
  position: absolute;
  top: 12px;
  right: 12px;
  background-color: var(--accent);
  color: #fff;
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 700;
}

/* Parent PIN Pad */
.pin-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 240px;
  margin: 20px auto 0;
}

.pin-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 1.5rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pin-btn:hover {
  background: var(--border);
}

.pin-display {
  font-size: 2rem;
  letter-spacing: 12px;
  text-align: center;
  margin-bottom: 12px;
  height: 48px;
}

/* Tabs for navigation inside kid dashboard */
.tab-bar {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 18px;
  gap: 8px;
}

.tab-btn {
  padding: 10px 16px;
  font-weight: 600;
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Activity & Approval lists */
.activity-list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border-bottom: 1px solid var(--border);
}

.approval-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.approval-details {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Utility */
.flex-row-center {
  display: flex;
  align-items: center;
  gap: 8px;
}

.text-center {
  text-align: center;
}

.text-success {
  color: var(--success);
}

.text-danger {
  color: var(--danger);
}

/* Toast Notification */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
}

.toast {
  background-color: var(--bg-card);
  color: var(--text-primary);
  border: 3px solid var(--primary);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 16px;
  width: 320px;
  pointer-events: auto;
  animation: slideInRight 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
  transition: opacity 0.3s ease;
}

.toast-icon {
  font-size: 2.2rem;
  animation: popScale 0.6s 0.2s ease-out infinite alternate;
}

.toast-details h4 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 2px;
}

.toast-details p {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

@keyframes slideInRight {
  from {
    transform: translateX(120%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes popScale {
  from {
    transform: scale(1);
  }
  to {
    transform: scale(1.15);
  }
}

/* Report Helper Styles */
.report-helper-toggle {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border-radius: 4px;
  margin-left: 8px;
  transition: background-color 0.2s;
}

.report-helper-toggle:hover {
  background-color: rgba(245, 158, 11, 0.1);
}

.report-helper-panel {
  display: none;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 12px;
  margin-top: 6px;
  margin-bottom: 12px;
}

.report-helper-panel.active {
  display: block;
}

.report-helper-title {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
  color: var(--text-secondary);
}

.report-helper-questions {
  list-style-type: disc;
  margin-left: 16px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.report-helper-questions li {
  margin-bottom: 4px;
}

.starters-container {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.starter-badge {
  font-size: 0.8rem;
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 4px 10px;
  border-radius: 20px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s ease;
}

.starter-badge:hover {
  border-color: var(--accent);
  background-color: rgba(245, 158, 11, 0.05);
  transform: translateY(-1px);
}

/* Speech Bubble Styles */
.speech-bubble {
  position: relative;
  background: #ffffff;
  border: 3px solid #1e293b;
  border-radius: 16px;
  padding: 10px 14px;
  font-weight: 600;
  color: #1e293b;
  font-size: 0.85rem;
  box-shadow: 4px 4px 0px #1e293b;
  max-width: 250px;
  margin-left: 12px;
  animation: bounceBubble 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  z-index: 10;
  line-height: 1.3;
}

.speech-bubble::after,
.speech-bubble::before {
  right: 100%;
  top: 50%;
  border: solid transparent;
  content: " ";
  height: 0;
  width: 0;
  position: absolute;
  pointer-events: none;
}

.speech-bubble::after {
  border-color: rgba(255, 255, 255, 0);
  border-right-color: #ffffff;
  border-width: 8px;
  margin-top: -8px;
}

.speech-bubble::before {
  border-color: rgba(30, 41, 59, 0);
  border-right-color: #1e293b;
  border-width: 12px;
  margin-top: -12px;
}

[data-theme="dark"] .speech-bubble {
  background: #1e293b;
  border-color: #f8fafc;
  color: #f8fafc;
  box-shadow: 4px 4px 0px #f8fafc;
}

[data-theme="dark"] .speech-bubble::after {
  border-right-color: #1e293b;
}

[data-theme="dark"] .speech-bubble::before {
  border-right-color: #f8fafc;
}

@keyframes bounceBubble {
  0% {
    transform: scale(0.3);
    opacity: 0;
  }
  50% {
    transform: scale(1.05);
  }
  70% {
    transform: scale(0.9);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* Currently Reading & Digital Bookmark Styles */
.currently-reading-card {
  border-left: 6px solid var(--primary);
  position: relative;
  overflow: hidden;
}

.currently-reading-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
  flex-wrap: wrap;
  gap: 12px;
}

.currently-reading-title {
  font-size: 1.25rem;
  font-weight: 800;
  margin: 0;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.currently-reading-author {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: 2px;
  font-weight: 500;
}

.currently-reading-progress-text {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--primary);
  margin-top: 8px;
  display: flex;
  justify-content: space-between;
}

.currently-reading-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.currently-reading-empty {
  text-align: center;
  padding: 16px;
}

.currently-reading-empty h4 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.currently-reading-empty p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

/* Collapsible Bookmark History */
.bookmark-history-toggle {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 16px;
  padding: 4px 0;
  transition: opacity 0.2s;
}

.bookmark-history-toggle:hover {
  opacity: 0.8;
}

.bookmark-history-panel {
  display: none;
  margin-top: 12px;
  border-top: 1px dashed var(--border);
  padding-top: 12px;
  max-height: 200px;
  overflow-y: auto;
}

.bookmark-history-panel.active {
  display: block;
}

.bookmark-timeline {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-left: 12px;
  border-left: 2px solid var(--border);
  margin-left: 6px;
}

.bookmark-node {
  position: relative;
}

.bookmark-node::before {
  content: "🔖";
  position: absolute;
  left: -23px;
  top: -2px;
  font-size: 0.85rem;
  background-color: var(--bg-card);
  padding: 2px;
}

.bookmark-node-header {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.bookmark-node-text {
  font-size: 0.85rem;
  color: var(--text-primary);
  line-height: 1.3;
}

/* Parent Bookshelf Management Styles */
.parent-bookshelf-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 400px;
  overflow-y: auto;
  margin-top: 12px;
}

.parent-book-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background-color: var(--bg-primary);
  gap: 16px;
  flex-wrap: wrap;
}

.parent-book-info {
  flex-grow: 1;
}

.parent-book-info strong {
  font-size: 0.95rem;
  display: block;
  color: var(--text-primary);
}

.parent-book-info span {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Affiliate Marketing Button Styles */
.btn-affiliate-amazon {
  background-color: #ff9900;
  color: #000000;
  border: 2px solid #000000;
  font-weight: 700;
  transition: background-color 0.2s, transform 0.1s;
}

.btn-affiliate-amazon:hover {
  background-color: #e68a00;
  transform: translateY(-1px);
}

.btn-affiliate-bookshop {
  background-color: #e56b55;
  color: #ffffff;
  border: 2px solid #000000;
  font-weight: 700;
  transition: background-color 0.2s, transform 0.1s;
}

.btn-affiliate-bookshop:hover {
  background-color: #d15640;
  transform: translateY(-1px);
}

.affiliate-disclosure {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-align: center;
  margin-top: 8px;
  font-style: italic;
}

/* Print Styles for Certificate */
#printable-certificate-container {
  display: none;
}

@media print {
  body * {
    visibility: hidden;
  }
  #printable-certificate-container,
  #printable-certificate-container * {
    visibility: visible;
  }
  #printable-certificate-container {
    display: block !important;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    background-color: #fff !important;
    color: #000 !important;
  }
}

/* =============================================
   COMPREHENSIVE MOBILE RESPONSIVENESS
   ============================================= */

/* --- Tablet / Large Mobile (≤768px) --- */
@media (max-width: 768px) {
  #tab-parent-content-analytics>div[style*="grid-template-columns"] {
    display: flex !important;
    flex-direction: column !important;
    gap: 16px !important;
  }
  .container {
    padding: 16px;
    gap: 16px;
  }
  .card {
    padding: 16px;
  }
  .modal-content {
    padding: 24px;
    max-width: 100%;
    border-radius: 20px;
  }
  .tab-bar {
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 4px;
  }
  .tab-bar::-webkit-scrollbar {
    display: none;
  }
  .tab-btn {
    flex-shrink: 0;
  }
  .approval-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }
  .approval-card>div:last-child {
    display: flex;
    gap: 8px;
    width: 100%;
  }
  .approval-card>div:last-child .btn {
    flex: 1;
    justify-content: center;
  }
  .parent-book-row {
    flex-direction: column;
    align-items: flex-start;
  }
  .parent-book-row>div:last-child {
    display: flex;
    gap: 8px;
    width: 100%;
    flex-wrap: wrap;
  }
  #tab-parent-content-settings>div[style*="display: flex"] {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }
  #tab-parent-content-settings>div[style*="display: flex"] .btn {
    flex: 1 1 calc(50% - 4px);
    min-width: 0;
    font-size: 0.8rem;
    text-align: center;
    justify-content: center;
  }
  .currently-reading-actions {
    flex-wrap: wrap;
    gap: 8px;
  }
  .currently-reading-actions .btn {
    flex: 1 1 auto;
    justify-content: center;
    min-width: 120px;
  }
}

/* --- Mobile (≤600px) --- */
@media (max-width: 600px) {
  .container {
    padding: 10px;
    gap: 12px;
  }
  header {
    padding: 10px 14px;
    gap: 8px;
  }
  .logo-text h1 {
    font-size: 1.1rem;
  }
  .logo-icon {
    font-size: 1.4rem;
  }
  .nav-actions {
    width: 100%;
    justify-content: space-between;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    margin-top: 4px;
    border-top: 1px solid var(--border);
    padding-top: 8px;
    gap: 6px;
  }
  .nav-actions::-webkit-scrollbar {
    display: none;
  }
  .nav-actions>.btn-primary {
    white-space: nowrap;
    font-size: 0.78rem;
    padding: 7px 10px;
  }
  #firebase-login-btn {
    font-size: 0.78rem !important;
    padding: 7px 10px !important;
    white-space: nowrap;
  }
  #firebase-user-pill {
    padding: 4px 8px !important;
    font-size: 0.75rem !important;
    max-width: 110px;
    overflow: hidden;
  }
  #firebase-user-name {
    max-width: 70px !important;
  }
  .btn {
    padding: 8px 12px;
    font-size: 0.82rem;
  }
  .btn-icon {
    width: 36px;
    height: 36px;
    font-size: 1rem;
  }
  .card {
    padding: 14px;
    border-radius: 14px;
  }
  .modal-content {
    padding: 18px;
    border-radius: 18px;
    max-height: 95vh;
  }
  .modal-close {
    top: 14px;
    right: 14px;
    font-size: 1.3rem;
  }
  .tab-bar {
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 2px;
    padding-bottom: 4px;
    margin-bottom: 14px;
  }
  .tab-bar::-webkit-scrollbar {
    display: none;
  }
  .tab-btn {
    padding: 7px 10px;
    font-size: 0.82rem;
    flex-shrink: 0;
  }
  .profiles-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-top: 14px;
  }
  .profile-card {
    padding: 14px 10px;
    border-radius: 16px;
    border-width: 2px;
  }
  .profile-avatar-container {
    width: 72px;
    height: 72px;
    margin-bottom: 10px;
  }
  .profile-avatar-container svg {
    width: 50px;
    height: 50px;
  }
  .profile-name {
    font-size: 1rem;
  }
  .profile-badge-points {
    font-size: 0.78rem;
    padding: 3px 10px;
  }
  #kid-dashboard-name {
    font-size: 1.4rem !important;
  }
  #kid-dashboard-slogan {
    font-size: 0.82rem !important;
  }
  .dashboard-header-stats {
    gap: 6px;
    margin-bottom: 12px;
  }
  .stat-box {
    padding: 9px 4px;
    border-radius: 10px;
  }
  .stat-val {
    font-size: 1.2rem;
  }
  .stat-label {
    font-size: 0.65rem;
    letter-spacing: 0;
  }
  .timer-card {
    gap: 10px;
    padding: 14px;
  }
  .timer-ring-container {
    width: 120px;
    height: 120px;
  }
  .family-banner {
    padding: 14px;
  }
  .family-banner-header h2 {
    font-size: 1rem;
  }
  .virtual-book {
    width: 70px;
    height: 100px;
  }
  .bookshelf-row {
    min-height: 135px;
    gap: 6px;
  }
  .rewards-grid {
    grid-template-columns: 1fr;
  }
  .badges-grid {
    grid-template-columns: repeat(auto-fill, minmax(64px, 1fr));
    gap: 10px;
  }
  .badge-icon {
    width: 58px;
    height: 58px;
    font-size: 1.5rem;
  }
  #toast-container {
    bottom: 12px;
    right: 0;
    left: 0;
    padding: 0 12px;
    align-items: center;
  }
  .toast {
    width: 100%;
    max-width: 100%;
  }
  .speech-bubble {
    max-width: 100%;
    margin-left: 0;
    margin-top: 10px;
    width: 100%;
    font-size: 0.8rem;
  }
  .speech-bubble::after,
  .speech-bubble::before {
    bottom: 100%;
    top: auto;
    left: 30px;
    right: auto;
    border-right-color: transparent !important;
  }
  .speech-bubble::after {
    border-bottom-color: #ffffff;
    border-width: 8px;
    margin-left: -8px;
    margin-top: 0;
    margin-bottom: -1px;
  }
  .speech-bubble::before {
    border-bottom-color: #1e293b;
    border-width: 12px;
    margin-left: -12px;
    margin-top: 0;
    margin-bottom: -1px;
  }
  [data-theme="dark"] .speech-bubble::after {
    border-right-color: transparent;
    border-bottom-color: #1e293b;
  }
  [data-theme="dark"] .speech-bubble::before {
    border-right-color: transparent;
    border-bottom-color: #f8fafc;
  }
  .currently-reading-title {
    font-size: 1.05rem;
  }
  .currently-reading-actions {
    flex-wrap: wrap;
    gap: 8px;
  }
  .currently-reading-actions .btn {
    flex: 1 1 auto;
    min-width: 100px;
    font-size: 0.8rem;
    justify-content: center;
  }
  .activity-list-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 10px;
  }
  .approval-card {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .approval-card>div:last-child {
    display: flex;
    gap: 8px;
    width: 100%;
  }
  .approval-card>div:last-child .btn {
    flex: 1;
    justify-content: center;
    font-size: 0.8rem;
  }
  #tab-parent-content-settings h3~div {
    flex-wrap: wrap;
    gap: 8px;
  }
  .pin-grid {
    max-width: 200px;
    gap: 8px;
    margin-top: 14px;
  }
  .pin-btn {
    width: 56px;
    height: 56px;
    font-size: 1.3rem;
  }
  .pin-display {
    font-size: 1.6rem;
    letter-spacing: 8px;
  }
  .form-control {
    padding: 10px 14px;
    font-size: 0.95rem;
  }
  .radio-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  .sketchpad-canvas {
    height: 160px;
  }
  .sketchpad-controls {
    flex-wrap: wrap;
    gap: 8px;
  }
  .parent-book-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .parent-book-row>div:last-child {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
  }
  #chart-minutes-container {
    height: 130px !important;
    padding-top: 16px !important;
  }
}

/* --- Small phones (≤400px) --- */
@media (max-width: 400px) {
  .profiles-grid {
    grid-template-columns: 1fr;
  }
  .logo-text h1 {
    font-size: 0.95rem;
  }
  .nav-actions>.btn-primary {
    font-size: 0.72rem;
    padding: 6px 8px;
  }
  .btn {
    padding: 7px 10px;
    font-size: 0.78rem;
  }
  .stat-val {
    font-size: 1.05rem;
  }
  .stat-label {
    font-size: 0.6rem;
  }
  .timer-ring-container {
    width: 100px;
    height: 100px;
  }
  .timer-text {
    font-size: 1.2rem;
  }
  .pin-btn {
    width: 48px;
    height: 48px;
    font-size: 1.1rem;
  }
  .pin-grid {
    max-width: 170px;
    gap: 6px;
  }
}

/* Currently Reading Cover Styles */
.currently-reading-cover {
  width: 90px;
  height: 130px;
  border-radius: 8px;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  box-shadow: 2px 4px 8px rgba(0, 0, 0, 0.2), inset 1px 1px 0 rgba(255, 255, 255, 0.15);
  flex-shrink: 0;
  position: relative;
  border: 1px solid rgba(0, 0, 0, 0.15);
  overflow: hidden;
}
.currently-reading-cover::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 6px;
  background: linear-gradient(90deg, rgba(0, 0, 0, 0.2) 0%, rgba(255, 255, 255, 0.15) 50%, rgba(0, 0, 0, 0.15) 100%);
  z-index: 2;
}
.currently-reading-cover.fallback {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 130px;
  box-sizing: border-box;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}
.currently-reading-cover.fallback .virtual-book-fallback {
  padding: 10px 8px;
  text-align: center;
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
  box-sizing: border-box;
}

/* Drag and Drop styles */
.virtual-book.dragging {
  opacity: 0.4;
  cursor: grabbing;
  transform: scale(0.95);
  border: 2px dashed var(--primary) !important;
  z-index: 1000;
}

/* Themed Confirmation Modal */
#modal-confirm .modal-content {
  max-width: 420px;
  text-align: center;
}
.confirm-icon {
  font-size: 3.5rem;
  margin-bottom: 12px;
  display: block;
  animation: popScale 0.5s ease-out;
}
.confirm-title {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 8px;
}
.confirm-body {
  font-size: 0.95rem;
  color: var(--text-secondary);
  margin-bottom: 24px;
  line-height: 1.5;
}
.confirm-cost-pill {
  display: inline-block;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  font-weight: 800;
  padding: 6px 18px;
  border-radius: 20px;
  font-size: 1rem;
  margin-bottom: 20px;
}
.confirm-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}
.confirm-actions .btn {
  min-width: 130px;
  padding: 12px 20px;
  font-size: 1rem;
}
/* Prompt Input Modal */
#modal-prompt .modal-content {
  max-width: 440px;
  text-align: center;
}
.prompt-icon { font-size: 2.5rem; margin-bottom: 10px; display: block; }
.prompt-title { font-size: 1.2rem; font-weight: 800; color: var(--text-primary); margin-bottom: 6px; }
.prompt-body { font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 16px; }
.prompt-input-wrap { position: relative; margin-bottom: 20px; }
.prompt-input-wrap input {
  width: 100%; padding: 12px 16px; border: 2px solid var(--border);
  border-radius: var(--radius); font-size: 1.1rem; font-family: inherit;
  background: var(--bg-primary); color: var(--text-primary);
  text-align: center; letter-spacing: 0.1em;
  transition: border-color 0.2s;
}
.prompt-input-wrap input:focus { outline: none; border-color: var(--primary); }
.prompt-actions { display: flex; gap: 12px; justify-content: center; }
.prompt-actions .btn { min-width: 120px; padding: 11px 20px; font-size: 0.95rem; }

/* Toast type colours */
.toast.toast-success { border-left: 4px solid var(--success); }
.toast.toast-warning { border-left: 4px solid var(--accent); }
.toast.toast-error   { border-left: 4px solid var(--danger); }
.toast.toast-info    { border-left: 4px solid var(--primary); }

/* Book-manage 3-button modal */
#modal-book-manage .modal-content { max-width: 420px; text-align: center; }
.book-manage-title { font-size: 1.2rem; font-weight: 800; margin-bottom: 6px; }
.book-manage-subtitle { font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 22px; }
.book-manage-actions { display: flex; flex-direction: column; gap: 10px; }
