/* =========================================================
   APP STYLES — Redesigned for max canvas space & responsiveness
   ========================================================= */

/* ─── APP SHELL ─────────────────────────────────────────── */
html { height: 100%; }
body { height: 100%; }

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;   /* dynamic viewport height — handles mobile address bar */
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  position: relative;
  background: var(--bg);
  font-size: 13px;
}

/* ─── TOP CHROME (compact, always visible) ──────────────── */
.app-chrome {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px;
  height: 52px;
  min-height: 52px;
  flex-shrink: 0;
  background: var(--card);
  border-bottom: 2px solid var(--border);
  box-shadow: 0 2px 8px rgba(0,0,0,.07);
  z-index: 100;
  position: relative;
  transition: height .3s, opacity .3s;
}
.chrome-left {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}
.chrome-scene-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--text);
  font-family: 'Fredoka One', sans-serif;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chrome-center {
  flex: 1;
  max-width: 180px;
  padding: 0 6px;
}
.chrome-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.chrome-stars {
  font-size: 13px;
  letter-spacing: 1px;
  white-space: nowrap;
}

/* ─── CHROME ICON BUTTONS ───────────────────────────────── */
.chrome-icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--soft);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: all .15s;
  position: relative;
  flex-shrink: 0;
  color: var(--text);
}
.chrome-icon-btn:hover,
.chrome-icon-btn:active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
/* Math-ready badge dot */
.chrome-icon-btn.has-badge::after {
  content: '';
  position: absolute;
  top: -3px;
  right: -3px;
  width: 11px;
  height: 11px;
  background: #FF6B9D;
  border-radius: 50%;
  border: 2px solid white;
  animation: pulse-dot 1.5s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%,100% { transform: scale(1); }
  50%      { transform: scale(1.3); }
}

/* ─── PROFILE BUTTON (in chrome) ────────────────────────── */
.app-profile-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 9px;
  border-radius: 20px;
  border: 2px solid var(--border);
  background: var(--soft);
  cursor: pointer;
  transition: all .15s;
  flex-shrink: 0;
}
.app-profile-btn:hover { background: #F0E8FF; border-color: #C084FC; }
.app-profile-avatar { font-size: 18px; line-height: 1; }
.app-profile-name {
  font-size: 11px;
  font-weight: 800;
  color: var(--text);
  max-width: 70px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── PROGRESS BAR (in chrome) ──────────────────────────── */
.prog-wrap {
  height: 8px;
  background: rgba(0,0,0,.08);
  border-radius: 8px;
  overflow: hidden;
  width: 100%;
}
.prog-fill {
  height: 100%;
  border-radius: 8px;
  background: linear-gradient(90deg, #FF9ED2, #FF6BAE, #FFB347);
  transition: width .4s;
  position: relative;
}
.prog-fill::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.4), transparent);
  animation: shimmer 1.5s infinite;
}

/* ─── CANVAS AREA (fills all remaining space) ───────────── */
.canvas-area {
  flex: 1;
  min-height: 0;               /* critical for flex children to shrink */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  overflow: hidden;
  position: relative;
  /* Space for fixed floating toolbar */
  padding-bottom: 150px;
}
.canvas-box {
  position: relative;
  width: 100%;
  max-width: 960px;
  flex-shrink: 0;
}
svg.scene {
  display: block;
  width: 100%;
  cursor: crosshair;
}
.zone { cursor: pointer; transition: filter .1s; }
.zone:hover path { filter: brightness(1.08); }
.zone.done { cursor: default; }
.num-label {
  pointer-events: none;
  font-weight: 800;
  font-size: 13px;
  fill: #444;
  text-anchor: middle;
  dominant-baseline: central;
  font-family: 'Fredoka One', sans-serif;
}

/* Canvas border & shadow */
.canvas-box {
  border-radius: var(--radius);
  overflow: hidden;
  border: 3px solid var(--border);
  background: white;
  box-shadow: 0 8px 32px rgba(100,50,150,.15);
}

/* ─── QUIZ OVERLAY (on canvas) ──────────────────────────── */
.overlay {
  display: none;
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255,245,255,.97), rgba(235,245,255,.97));
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 10;
  text-align: center;
}
.overlay.show { display: flex; }
.ov-emoji { font-size: 52px; margin-bottom: 10px; animation: bounce .6s ease infinite alternate; }
.ov-title {
  font-size: 19px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 6px;
  font-family: 'Fredoka One', sans-serif;
}
.ov-q { font-size: 15px; color: #6B5A82; margin-bottom: 14px; line-height: 1.5; }
.ov-opts { display: flex; flex-direction: column; gap: 8px; width: 100%; max-width: 300px; }
.ov-btn {
  padding: 10px 18px;
  min-height: 44px;
  border-radius: 12px;
  border: 2px solid #DDD;
  background: white;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  text-align: left;
  transition: all .15s;
  color: #4A3860;
  font-family: 'Nunito', sans-serif;
}
.ov-btn:hover { background: #F4EEF9; transform: translateX(3px); }
.ov-btn.ok { background: #E8F8E8; border-color: #4CAF50; color: #2E7D32; }
.ov-btn.no { background: #FEE8E8; border-color: #E53935; color: #C62828; }
.ov-hint { font-size: 13px; color: #9E8FB8; margin-top: 10px; font-weight: 600; }
.ov-math {
  font-size: 13px;
  color: #6B9BD2;
  background: #EEF5FF;
  border-radius: 8px;
  padding: 6px 12px;
  margin-bottom: 10px;
  font-weight: 700;
  border: 1.5px solid #C5DCF5;
}

/* ─── FLOATING TOOLBAR ──────────────────────────────────── */
.float-toolbar {
  position: fixed;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  width: min(calc(100% - 24px), 820px);
  background: rgba(255,255,255,0.97);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: 22px;
  padding: 10px 14px 8px;
  box-shadow: 0 -2px 0 rgba(0,0,0,.04), 0 10px 40px rgba(0,0,0,.16);
  border: 2px solid var(--border);
  z-index: 200;
  /* Auto-hide transition */
  transition: opacity .35s ease, transform .35s ease;
}
.float-toolbar.toolbar-hidden {
  opacity: 0;
  transform: translateX(-50%) translateY(18px);
  pointer-events: none;
}

/* Color pills row */
.ft-colors { margin-bottom: 8px; }
.color-strip {
  display: flex;
  gap: 5px;
  flex-wrap: nowrap;
  overflow-x: auto;
  padding: 2px 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.color-strip::-webkit-scrollbar { display: none; }
.strip-label {
  font-weight: 800;
  font-size: 10px;
  color: #AAA;
  text-transform: uppercase;
  letter-spacing: 1px;
  flex-shrink: 0;
  align-self: center;
  margin-right: 4px;
  display: none;
}

/* Color pill — circle on mobile, pill on desktop */
.cpill {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  min-width: 36px;
  border-radius: 50%;
  border: 2.5px solid transparent;
  cursor: pointer;
  transition: all .15s;
  padding: 0;
  flex-shrink: 0;
  position: relative;
}
.cpill .cswatch {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1.5px solid rgba(0,0,0,.18);
  flex-shrink: 0;
}
.cpill span { display: none; }  /* hide label on small screens */
.cpill.sel {
  border-color: #222;
  transform: scale(1.18);
  box-shadow: 0 0 0 3px rgba(0,0,0,.12);
}

/* Tools + controls row */
.ft-bottom {
  display: flex;
  align-items: center;
  gap: 8px;
}
.tools-row {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  flex: 1;
  padding: 2px 0;
}
.tools-row::-webkit-scrollbar { display: none; }

.tbtn {
  min-width: 44px;
  height: 40px;
  border-radius: 20px;
  border: 2px solid #E0D5F5;
  background: white;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  color: #7A6890;
  transition: all .15s;
  font-family: 'Nunito', sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 0 10px;
  flex-shrink: 0;
  white-space: nowrap;
}
.tbtn.active {
  background: var(--secondary);
  color: white;
  border-color: var(--secondary);
  box-shadow: 0 3px 10px rgba(78,205,196,.4);
}
.tbtn:disabled { opacity: .32; cursor: default; }
.tbtn:not(:disabled):active { transform: scale(.95); }

#fill-all-btn {
  background: linear-gradient(135deg, #FFB347, #FF8C00);
  color: white;
  border-color: #FF8C00;
  box-shadow: 0 2px 8px rgba(255,140,0,.3);
}

/* Size + Undo controls */
.ft-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.size-row {
  display: flex;
  align-items: center;
  gap: 5px;
}
.size-row label {
  font-size: 10px;
  font-weight: 700;
  color: #AAA;
  white-space: nowrap;
  display: none;
}
input[type=range] {
  width: 65px;
  accent-color: var(--secondary);
}
.size-val {
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  min-width: 18px;
  text-align: center;
}
#undo-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid #DDD;
  background: white;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  color: #888;
  transition: all .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
}
#undo-btn:hover { background: #F4F0FF; }
#undo-btn:active { transform: scale(.92); }

/* Stamp picker */
.stamp-picker {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  margin-top: 7px;
  padding: 4px 0;
  border-top: 1.5px solid var(--border);
}
.stamp-opt {
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
  border-radius: 10px;
  border: 2px solid transparent;
  transition: all .12s;
  line-height: 1;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.stamp-opt.sel { border-color: var(--primary); background: #FFF0F8; transform: scale(1.2); }
.stamp-opt:hover { background: #F8F0FF; }

/* Hint */
.hint-bar {
  font-size: 11px;
  color: #9E8FB8;
  text-align: center;
  padding: 4px 0 0;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 4px;
  border-top: 1.5px solid var(--border);
}

/* ─── SPEAK BUTTON ──────────────────────────────────────── */
.speak-btn {
  background: none;
  border: 2px solid currentColor;
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-size: 13px;
  cursor: pointer;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin-left: 7px;
  opacity: .65;
  transition: opacity .15s, transform .15s;
  vertical-align: middle;
  flex-shrink: 0;
}
.speak-btn:hover { opacity: 1; transform: scale(1.18); }

/* ─── CONFETTI CANVAS ────────────────────────────────────── */
#confetti-canvas { position: fixed; inset: 0; pointer-events: none; z-index: 999; }

/* ─── SIDE PANELS ───────────────────────────────────────── */
.side-panel {
  position: fixed;
  top: 0;
  bottom: 0;
  width: 300px;
  background: var(--card);
  z-index: 400;
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
}
.panel-left {
  left: 0;
  transform: translateX(-100%);
  box-shadow: 4px 0 24px rgba(0,0,0,.15);
}
.panel-right {
  right: 0;
  transform: translateX(100%);
  box-shadow: -4px 0 24px rgba(0,0,0,.15);
}
.side-panel.open { transform: translateX(0); }

/* Panel backdrop */
.panel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 350;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
}
.panel-backdrop.show { opacity: 1; pointer-events: all; }

/* Panel header */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
  background: var(--soft);
}
.panel-title {
  font-family: 'Fredoka One', sans-serif;
  font-size: 18px;
  color: var(--text);
}
.panel-close {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: white;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
}
.panel-close:hover { background: #FEE; border-color: #F44336; }

.panel-body {
  padding: 14px;
  flex: 1;
  overflow-y: auto;
}

/* Branding inside panel */
.panel-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 4px 14px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 14px;
}
.app-topbar-logo { width: 36px; height: 36px; object-fit: contain; flex-shrink: 0; }
.app-topbar-brand {
  font-family: 'Fredoka One', sans-serif;
  font-size: 15px;
  color: #3D2B56;
  flex: 1;
  line-height: 1.1;
}
.app-topbar-brand small {
  display: block;
  font-size: 9px;
  color: #9E8FB8;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
}

/* ─── LEVEL TABS (inside panel) ─────────────────────────── */
.level-tabs {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}
.ltab {
  padding: 10px 14px;
  border-radius: 14px;
  border: 2px solid #ddd;
  background: white;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  color: #888;
  transition: all .15s;
  font-family: 'Nunito', sans-serif;
  min-height: 44px;
  text-align: left;
}
.ltab.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 3px 12px rgba(255,107,157,.35);
}
.ltab.locked { opacity: .4; cursor: default; }

/* ─── COLLAPSIBLES ──────────────────────────────────────── */
.collapsible-item {
  border-radius: 14px;
  border: 2px solid var(--border);
  margin-bottom: 10px;
  overflow: hidden;
}
.collapsible-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px;
  cursor: pointer;
  background: var(--soft);
  border: none;
  width: 100%;
  font-weight: 800;
  font-size: 14px;
  color: var(--text);
  font-family: 'Nunito', sans-serif;
  min-height: 44px;
}
.coll-arrow {
  font-size: 11px;
  transition: transform .3s ease;
  display: inline-block;
  opacity: .6;
}
.collapsible-body {
  max-height: 0;
  overflow: hidden;
  transition: max-height .35s ease;
}
.collapsible-body.open { max-height: 600px; }

/* ─── FACT BOX (inside collapsible) ────────────────────── */
.fact-box {
  font-size: 12px;
  color: #5B4A7A;
  background: linear-gradient(135deg, #EEF7FF, #E8F0FF);
  border-radius: 10px;
  padding: 10px 12px;
  margin: 8px;
  line-height: 1.6;
  border: 1.5px solid #C5D9F8;
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.fact-icon { font-size: 18px; flex-shrink: 0; margin-top: -1px; }

/* ─── MATH BOX (inside collapsible in right panel) ───────── */
.math-box {
  margin: 8px;
  background: linear-gradient(135deg, #FFFBEE, #FFF5CC);
  border-radius: 12px;
  padding: 12px 14px;
  border: 2px solid #FFD700;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.math-q {
  font-size: 16px;
  font-weight: 800;
  color: #6B4C00;
  font-family: 'Fredoka One', sans-serif;
  flex: 1 0 100%;
}
.math-opts { display: flex; gap: 6px; flex-wrap: wrap; }
.math-btn {
  padding: 8px 16px;
  min-height: 44px;
  border-radius: 22px;
  border: 2px solid #FFBC00;
  background: white;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  color: #6B4C00;
  transition: all .15s;
  font-family: 'Nunito', sans-serif;
}
.math-btn:hover { background: #FFFACC; }
.math-btn.math-ok { background: #C8F0C8; border-color: #4CAF50; color: #1B5E20; }
.math-btn.math-no { background: #FFCCCC; border-color: #F44336; color: #B71C1C; }
.math-streak {
  font-size: 11px;
  font-weight: 700;
  color: #B78600;
  margin-left: auto;
  white-space: nowrap;
}

/* ─── FOCUS MODE ─────────────────────────────────────────── */
body.focus-mode .app-chrome {
  height: 0;
  min-height: 0;
  overflow: hidden;
  padding: 0;
  border: none;
  box-shadow: none;
}
body.focus-mode .canvas-area {
  padding-bottom: 0;
}
body.focus-mode .float-toolbar {
  opacity: 0 !important;
  transform: translateX(-50%) translateY(24px) !important;
  pointer-events: none !important;
}
body.focus-mode .side-panel,
body.focus-mode .panel-backdrop {
  display: none !important;
}
/* Tiny exit button — only visible in focus mode */
.focus-exit-btn {
  display: none;
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 600;
  background: rgba(0,0,0,.52);
  color: white;
  border: none;
  border-radius: 20px;
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  backdrop-filter: blur(6px);
  font-family: 'Nunito', sans-serif;
  letter-spacing: .3px;
  transition: background .15s;
}
.focus-exit-btn:hover { background: rgba(0,0,0,.72); }
body.focus-mode .focus-exit-btn { display: flex; align-items: center; gap: 5px; }

/* ─── RESPONSIVE: DESKTOP (≥1025px) ─────────────────────── */
@media (min-width: 1025px) {
  .canvas-area {
    align-items: center;
    padding-bottom: 130px;
  }
  .canvas-box { max-width: 960px; }
  /* Expand color pills to full pills on desktop */
  .cpill {
    width: auto;
    height: auto;
    min-width: unset;
    border-radius: 25px;
    padding: 5px 11px;
    gap: 5px;
  }
  .cpill .cswatch { width: 14px; height: 14px; }
  .cpill span { display: inline; font-size: 11px; font-weight: 700; }
  .strip-label { display: block; }
  .size-row label { display: block; }
  input[type=range] { width: 100px; }
  .chrome-stars { font-size: 16px; }
  .app-profile-name { display: block; }
  .tbtn { height: 38px; }
}

/* ─── RESPONSIVE: TABLET (769px – 1024px) ───────────────── */
@media (min-width: 769px) and (max-width: 1024px) {
  .canvas-area { padding-bottom: 145px; }
  .cpill { width: 40px; height: 40px; min-width: 40px; }
  .cpill .cswatch { width: 32px; height: 32px; }
  .tbtn { height: 44px; font-size: 13px; }
  input[type=range] { width: 80px; }
}

/* ─── RESPONSIVE: MOBILE (≤480px) ───────────────────────── */
@media (max-width: 480px) {
  .app-chrome { padding: 0 8px; height: 48px; min-height: 48px; }
  .chrome-scene-title { font-size: 12px; }
  .chrome-stars { display: none; }        /* shown in panel instead */
  .app-profile-name { display: none; }    /* save space */
  .chrome-icon-btn { width: 34px; height: 34px; font-size: 14px; }
  .canvas-area { padding-bottom: 155px; }
  .float-toolbar {
    bottom: 8px;
    padding: 8px 10px 6px;
    border-radius: 18px;
  }
  .cpill { width: 34px; height: 34px; min-width: 34px; }
  .cpill .cswatch { width: 26px; height: 26px; }
  .tbtn { min-width: 38px; height: 42px; padding: 0 7px; font-size: 11px; }
  .hint-bar { font-size: 10px; }
  input[type=range] { width: 55px; }
  #undo-btn { width: 38px; height: 38px; }
}

/* ─── RESPONSIVE: LANDSCAPE MOBILE ─────────────────────── */
@media (max-width: 900px) and (orientation: landscape) {
  .app-chrome { height: 42px; min-height: 42px; }
  .canvas-area { padding-bottom: 100px; }
  .float-toolbar { padding: 6px 14px 5px; }
  .ft-colors { margin-bottom: 5px; }
  .hint-bar { display: none; }  /* maximise canvas in landscape */
}
