/* Read Buddy styles are scoped to #readBuddyView and inherit global theme tokens */

#readBuddyView * { box-sizing: border-box; }
/* Do not override global page body; scope background/colors to the Read Buddy container */
#readBuddyView{
  background:var(--bg);
  color:var(--text);
  /* Inherit app font (supports dyslexic font on main page) */
  font-family: inherit;
}

#readBuddyView .app-header{
  display:flex; align-items:center; justify-content:space-between;
  padding:16px 20px; position:sticky; top:0; background:var(--bg); z-index:5;
  backdrop-filter: blur(6px);
}

/* Hide manual controls per requirements */
#readBuddyView #btnStart,
#readBuddyView #btnStop,
#readBuddyView #btnCalibrate { display: none !important; }

#readBuddyView .brand { display:flex; align-items:center; gap:12px; }
#readBuddyView .brand-emoji{ font-size:30px; }
#readBuddyView .brand h1{ margin:0; font-size:24px; }
#readBuddyView .subtitle{ color:var(--muted); font-size:14px; }

#readBuddyView .controls{ display:flex; gap:10px; align-items:center; flex-wrap:wrap; }

/* Modern Glass Carousel Design */
#readBuddyView .avatar-carousel-wrapper{
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}

#readBuddyView .carousel-label{
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-left: 4px;
}

#readBuddyView .avatar-carousel{
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08),
              inset 0 1px 0 rgba(255, 255, 255, 0.4);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#readBuddyView .avatar-carousel:hover{
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.35);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12),
              inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.theme-dark #readBuddyView .avatar-carousel{
  background: rgba(30, 30, 50, 0.4);
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3),
              inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.theme-dark #readBuddyView .avatar-carousel:hover{
  background: rgba(40, 40, 60, 0.5);
  border-color: rgba(255, 255, 255, 0.25);
}

#readBuddyView .carousel-track-container{
  flex: 1;
  position: relative;
  min-width: 280px;
  height: 140px;
  perspective: 1200px;
}

#readBuddyView .carousel-track{
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transform-style: preserve-3d;
}

#readBuddyView .carousel-item{
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  min-width: 100px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

/* Position items in 3D space */
#readBuddyView .carousel-item[data-position="-2"]{
  transform: translateX(-180px) translateZ(-150px) scale(0.65);
  opacity: 0.3;
  z-index: 1;
  filter: blur(1px);
}

#readBuddyView .carousel-item[data-position="-1"]{
  transform: translateX(-110px) translateZ(-80px) scale(0.8) rotateY(15deg);
  opacity: 0.5;
  z-index: 2;
}

#readBuddyView .carousel-item[data-position="-1"]:hover{
  transform: translateX(-110px) translateZ(-40px) scale(0.88) rotateY(12deg);
  opacity: 0.75;
  background: rgba(255, 255, 255, 0.22);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
}

#readBuddyView .carousel-item[data-position="0"],
#readBuddyView .carousel-item.active{
  transform: translateX(0) translateZ(0) scale(1);
  opacity: 1;
  z-index: 10;
  background: rgba(255, 255, 255, 0.3);
  border-color: rgba(255, 255, 255, 0.5);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.25),
              inset 0 2px 0 rgba(255, 255, 255, 0.4);
}

#readBuddyView .carousel-item[data-position="1"]{
  transform: translateX(110px) translateZ(-80px) scale(0.8) rotateY(-15deg);
  opacity: 0.5;
  z-index: 2;
}

#readBuddyView .carousel-item[data-position="1"]:hover{
  transform: translateX(110px) translateZ(-40px) scale(0.88) rotateY(-12deg);
  opacity: 0.75;
  background: rgba(255, 255, 255, 0.22);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.22);
}

#readBuddyView .carousel-item[data-position="2"]{
  transform: translateX(180px) translateZ(-150px) scale(0.65);
  opacity: 0.3;
  z-index: 1;
  filter: blur(1px);
}

.theme-dark #readBuddyView .carousel-item{
  background: rgba(40, 40, 70, 0.35);
  border-color: rgba(255, 255, 255, 0.15);
}

.theme-dark #readBuddyView .carousel-item[data-position="0"],
.theme-dark #readBuddyView .carousel-item.active{
  background: rgba(70, 70, 120, 0.55);
  border-color: rgba(255, 255, 255, 0.35);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5),
              inset 0 2px 0 rgba(255, 255, 255, 0.2);
}

#readBuddyView .carousel-emoji{
  font-size: 28px;
  line-height: 1;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.15));
  transition: all 0.4s ease;
}

#readBuddyView .carousel-item[data-position="0"] .carousel-emoji,
#readBuddyView .carousel-item.active .carousel-emoji{
  font-size: 42px;
  transform: scale(1);
  filter: drop-shadow(0 6px 12px rgba(0, 0, 0, 0.25));
}

#readBuddyView .carousel-name{
  font-size: 10px;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  opacity: 0.8;
  transition: all 0.4s ease;
}

#readBuddyView .carousel-item[data-position="0"] .carousel-name,
#readBuddyView .carousel-item.active .carousel-name{
  font-size: 13px;
  font-weight: 700;
  opacity: 1;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

#readBuddyView .carousel-nav{
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(8px);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  flex-shrink: 0;
}

#readBuddyView .carousel-nav:hover{
  background: rgba(255, 255, 255, 0.4);
  transform: scale(1.08);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

#readBuddyView .carousel-nav:active{
  transform: scale(0.95);
}

.theme-dark #readBuddyView .carousel-nav{
  background: rgba(80, 80, 120, 0.4);
}

.theme-dark #readBuddyView .carousel-nav:hover{
  background: rgba(100, 100, 140, 0.6);
}

#readBuddyView .carousel-indicators{
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-top: 4px;
}

#readBuddyView .carousel-indicator{
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(150, 150, 170, 0.3);
  transition: all 0.3s ease;
  cursor: pointer;
}

#readBuddyView .carousel-indicator.active{
  background: rgba(100, 120, 255, 0.8);
  transform: scale(1.3);
  box-shadow: 0 0 8px rgba(100, 120, 255, 0.4);
}

.theme-dark #readBuddyView .carousel-indicator{
  background: rgba(200, 200, 220, 0.2);
}

.theme-dark #readBuddyView .carousel-indicator.active{
  background: rgba(150, 180, 255, 0.9);
  box-shadow: 0 0 8px rgba(150, 180, 255, 0.5);
}

#readBuddyView .toggle{ display:flex; gap:8px; align-items:center; font-size:14px; }
#readBuddyView .toggle input{ width:18px; height:18px; }

#readBuddyView .btn{
  border:1px solid color-mix(in srgb, var(--text) 14%, transparent); background:var(--card); color:var(--text);
  padding:10px 14px; border-radius:999px; cursor:pointer; box-shadow:var(--shadow);
  transition: transform .05s ease, background .2s ease;
}
#readBuddyView .btn:hover{ transform: translateY(-1px); }
#readBuddyView .btn:disabled{ opacity:.5; cursor:not-allowed; }
#readBuddyView .btn.primary{ background:linear-gradient(135deg, var(--primary), var(--accent)); color:#fff; border:0; }
#readBuddyView .btn.ghost{ background:transparent; border-color:transparent; box-shadow:none; }
#readBuddyView .btn.small{ padding:8px 12px; font-size:14px; }

#readBuddyView .layout{
  display:grid; gap:20px; grid-template-columns: 1fr 1.2fr;
  padding: 0 20px 40px;
}
#readBuddyView .panel{
  background:var(--card); border-radius:var(--radius); box-shadow:var(--shadow);
  padding:18px; position:relative; overflow:hidden;
}

#readBuddyView .card{
  background:var(--card);
  border-radius:var(--radius); padding:18px; box-shadow:var(--shadow);
  color: var(--text);
}
#readBuddyView .card p,
#readBuddyView .card li,
#readBuddyView .card span { color: var(--text); }
#readBuddyView .card h2{ margin-top:0; color: var(--text); letter-spacing: -.2px; }
#readBuddyView .hint{ color:var(--muted); margin-top:-6px; }

/* Dark theme: slightly lift card surface and increase text contrast */
.theme-dark #readBuddyView .card{
  background: color-mix(in srgb, var(--card) 92%, var(--text) 8%);
}
.theme-dark #readBuddyView .card h2{
  color: color-mix(in srgb, var(--text) 96%, transparent);
}
.theme-dark #readBuddyView .hint{
  color: color-mix(in srgb, var(--text) 70%, transparent);
}

/* Ensure reading panel text is comfortably legible in dark theme */
.theme-dark #readBuddyView .read-panel .card{
  background: color-mix(in srgb, var(--card) 92%, var(--text) 8%);
}
.theme-dark #readBuddyView .read-panel .card p{
  color: color-mix(in srgb, var(--text) 92%, transparent);
}
.theme-dark #readBuddyView .read-panel .card strong{
  color: color-mix(in srgb, var(--text) 100%, transparent);
}

#readBuddyView .exercise{
  display:flex; align-items:center; justify-content:space-between; gap:10px; margin:12px 0 16px;
}
#readBuddyView .exercise-prompt{
  flex:1; padding:20px 22px; border-radius:18px; border:1px solid color-mix(in srgb, var(--text) 14%, transparent); min-height:104px;
  /* High-contrast but gentle reading background */
  background: color-mix(in srgb, var(--card) 95%, var(--text) 5%);
  color: var(--text);
  font-size: 22px; line-height: 1.72; letter-spacing: .2px; word-spacing: .6px;
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--text) 6%, transparent), var(--shadow);
  font-variant-ligatures: none;
}
/* Dark theme fine-tune: raise prompt background for legibility */
.theme-dark #readBuddyView .exercise-prompt{
  background: color-mix(in srgb, var(--card) 85%, var(--text) 15%);
  box-shadow: inset 0 1px 0 color-mix(in srgb, var(--text) 12%, transparent), var(--shadow);
}
/* Ensure direct id also benefits */
#readBuddyView #promptText{ color: var(--text); }
#readBuddyView .exercise-actions{ display:flex; gap:8px; }

/* Live transcript (heard speech) — small and below the exercise prompt */
#readBuddyView #heardLive{
  margin-top:10px;
  font-size: 14px;
  line-height: 1.4;
  color: var(--muted);
  opacity: .85;
  text-wrap: balance;
}

#readBuddyView .progress{ margin:14px 0 8px; }
#readBuddyView .progress-head{ display:flex; justify-content:space-between; margin-bottom:6px; color:var(--muted); }
#readBuddyView .progress-bar{ width:100%; height:14px; background:var(--bg-soft); border-radius:999px; overflow:hidden; }
#readBuddyView .progress-fill{ height:100%; background:linear-gradient(90deg, var(--success), #9af7cc); width:0%; transition:width .4s ease; }
#readBuddyView .progress-label{ font-weight:700; }

#readBuddyView .star-row{ display:flex; gap:6px; padding:8px 0; min-height:36px; }
#readBuddyView .star-row .star{ width:28px; height:28px; border-radius:8px; display:grid; place-items:center; background:var(--card); box-shadow:var(--shadow); }

#readBuddyView .metrics{ display:grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap:10px; margin-top:10px; align-items:center; }
#readBuddyView .emotion-indicator{ width:32px; height:32px; border-radius:50%; background:var(--bg-soft); display:grid; place-items:center; font-size:18px; border:2px solid color-mix(in srgb, var(--text) 12%, transparent); transition:all 0.3s ease; }
#readBuddyView .emotion-indicator.emotion-excited{ background:#ffeb3b; border-color:#ffc107; animation:bounce 0.6s ease; }
#readBuddyView .emotion-indicator.emotion-calm{ background:#e3f2fd; border-color:#2196f3; }
#readBuddyView .emotion-indicator.emotion-struggling{ background:#ffebee; border-color:#f44336; }
#readBuddyView .emotion-indicator.emotion-neutral{ background:#f1f8e9; border-color:#8bc34a; }
#readBuddyView .meter span{ display:block; font-size:12px; color:var(--muted); margin-bottom:4px; }
#readBuddyView .meter .bar{ width:100%; height:10px; background:#eef5ff; border-radius:999px; overflow:hidden; }
#readBuddyView .meter .fill{ height:100%; width:0%; background:linear-gradient(90deg, #9ab7ff, #a1f0ff); transition:width .15s linear; }

#readBuddyView .state-pill{ padding:6px 10px; border-radius:999px; background:#f1f5ff; color:#2a4365; font-size:12px; border:1px solid #dce7ff; min-width:72px; text-align:center; }

#readBuddyView .stickers{ margin-top:18px; }
#readBuddyView .sticker-board{
  display:flex; flex-wrap:wrap; gap:8px; min-height:48px; background:var(--card); border-radius:12px;
  border:1px dashed color-mix(in srgb, var(--accent) 45%, transparent); padding:8px;
}

#readBuddyView .app-footer{ text-align:center; padding:12px 20px; color:var(--muted); }

#readBuddyView .avatar-panel{ min-height:420px; display:flex; flex-direction:column; align-items:center; justify-content:center; }
#readBuddyView .avatar-buttons{ display:flex; gap:8px; margin-top:12px; }

/* Toast */
#readBuddyView #toast{
  position:absolute; bottom:12px; left:50%; translate:-50% 0;
  background:#000; color:#fff; padding:10px 14px; border-radius:999px;
  opacity:0; pointer-events:none; transition:opacity .25s ease, transform .25s ease;
  transform: translateY(10px);
}
#readBuddyView #toast.show{ opacity:0.9; transform: translateY(0); }

/* Confetti canvas on top */
#readBuddyView .confetti-canvas{
  position:fixed; inset:0; pointer-events:none; z-index:50;
}

/* Modal Panels */
#readBuddyView .modal-panel{
  position:fixed; inset:0; background:rgba(0,0,0,0.5); z-index:100;
  display:flex; align-items:center; justify-content:center;
  opacity:0; pointer-events:none; transition:opacity 0.3s ease;
}
#readBuddyView .modal-panel.show{ opacity:1; pointer-events:all; }
#readBuddyView .modal-content{
  background:var(--card); border-radius:var(--radius); box-shadow:0 20px 60px rgba(0,0,0,0.3);
  max-width:90vw; max-height:90vh; overflow:hidden;
  transform:scale(0.9); transition:transform 0.3s ease;
}
#readBuddyView .modal-panel.show .modal-content{ transform:scale(1); }
#readBuddyView .modal-header{ display:flex; justify-content:space-between; align-items:center; padding:20px; border-bottom:1px solid #e2e8f0; }
#readBuddyView .modal-body{ padding:20px; max-height:70vh; overflow-y:auto; }
#readBuddyView .modal-footer{ padding:20px; border-top:1px solid #e2e8f0; text-align:right; }

/* Customization Panel */
#readBuddyView .customization-header{ display:flex; justify-content:space-between; align-items:center; margin-bottom:20px; }
#readBuddyView .customization-section{ margin-bottom:30px; }
#readBuddyView .customization-section h4{ margin:0 0 15px 0; color:var(--muted); }
#readBuddyView .items-grid{ display:grid; grid-template-columns:repeat(auto-fill, minmax(140px, 1fr)); gap:15px; }
#readBuddyView .item-card{ background:#fff; border:2px solid #e2e8f0; border-radius:12px; padding:15px; text-align:center; transition:all 0.3s ease; }
#readBuddyView .item-card:hover{ transform:translateY(-2px); box-shadow:var(--shadow); }
#readBuddyView .item-card.unlocked{ border-color:var(--ok); background:#f0fff4; }
#readBuddyView .item-emoji{ font-size:32px; margin-bottom:8px; }
#readBuddyView .item-name{ font-weight:bold; margin-bottom:4px; }
#readBuddyView .item-cost{ color:var(--muted); font-size:14px; margin-bottom:10px; }

/* Read-along token highlighting inside the prompt */
#promptText .word{ padding:2px 3px; margin:0 1px; border-radius:6px; transition: background-color .12s linear, color .12s linear, box-shadow .12s linear; }
#promptText .word.read{ background:#173823; color:#d6ffe8; }
#promptText .word.current{ background:#1b2550; box-shadow:0 0 0 2px rgba(109,168,255,.3) inset; color:#e8f0ff; }
#promptText .punct{ opacity:.6; }

/* Dashboard */
#readBuddyView .dashboard-header{ text-align:center; margin-bottom:30px; }
#readBuddyView .stats-grid{ display:grid; grid-template-columns:repeat(auto-fit, minmax(150px, 1fr)); gap:20px; margin-bottom:30px; }
#readBuddyView .stat-card{ background:linear-gradient(135deg, #667eea, #764ba2); color:white; padding:20px; border-radius:12px; text-align:center; }
#readBuddyView .stat-value{ font-size:24px; font-weight:bold; margin-bottom:5px; }
#readBuddyView .stat-label{ font-size:14px; opacity:0.9; }
#readBuddyView .recent-sessions h4{ margin-bottom:15px; }
#readBuddyView .sessions-list{ max-height:300px; overflow-y:auto; }
#readBuddyView .session-item{ background:#f8f9fa; padding:12px; border-radius:8px; margin-bottom:8px; }
#readBuddyView .session-date{ font-weight:bold; margin-bottom:5px; }
#readBuddyView .session-details{ display:flex; gap:15px; font-size:14px; color:var(--muted); }
#readBuddyView .session-details span{ padding:2px 8px; background:#fff; border-radius:4px; }

/* Background Themes */
#readBuddyView.bg-forest{ background:linear-gradient(180deg, #2d5016, #4a7c59); }
#readBuddyView.bg-beach{ background:linear-gradient(180deg, #87ceeb, #f4a460); }
#readBuddyView.bg-castle{ background:linear-gradient(180deg, #483d8b, #9370db); }
#readBuddyView.bg-garden{ background:linear-gradient(180deg, #98fb98, #90ee90); }

/* Animations */
@keyframes treatPop{
  0%{ transform:translate(-50%, -50%) scale(0.5); opacity:0; }
  50%{ transform:translate(-50%, -50%) scale(1.2); opacity:1; }
  100%{ transform:translate(-50%, -60%) scale(1); opacity:0; }
}
@keyframes slideIn{
  0%{ transform:translateX(100%); opacity:0; }
  20%{ transform:translateX(0); opacity:1; }
  80%{ transform:translateX(0); opacity:1; }
  100%{ transform:translateX(100%); opacity:0; }
}
@keyframes bounce{
  0%, 20%, 50%, 80%, 100%{ transform:translateY(0); }
  40%{ transform:translateY(-10px); }
  60%{ transform:translateY(-5px); }
}

/* Responsive */
@media (max-width: 1000px){
  #readBuddyView .layout{ grid-template-columns:1fr; }
  #readBuddyView .controls{ justify-content:flex-start; }
  #readBuddyView .modal-content{ max-width:95vw; }
  #readBuddyView .items-grid{ grid-template-columns:repeat(auto-fill, minmax(120px, 1fr)); }
  #readBuddyView .stats-grid{ grid-template-columns:repeat(auto-fit, minmax(120px, 1fr)); }
  
  /* Adjust carousel for smaller screens */
  #readBuddyView .carousel-track-container{
    min-width: 220px;
    height: 120px;
  }
  
  #readBuddyView .carousel-item[data-position="-2"],
  #readBuddyView .carousel-item[data-position="2"]{
    display: none !important;
  }
  
  #readBuddyView .carousel-item[data-position="-1"]{
    transform: translateX(-80px) translateZ(-60px) scale(0.75) rotateY(15deg);
  }
  
  #readBuddyView .carousel-item[data-position="1"]{
    transform: translateX(80px) translateZ(-60px) scale(0.75) rotateY(-15deg);
  }
}

