@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url("/static/fonts/Inter-variable.woff2") format('woff2');
}
@font-face {
  font-family: 'Lora';
  font-style: normal;
  font-weight: 500 700;
  font-display: swap;
  src: url("/static/fonts/Lora-variable.woff2") format('woff2');
}

:root {
  /* neutros cálidos (identidad "lectura en familia") */
  --bg: #fcf6ee;
  --surface: #fffcf8;
  --surface-2: #f7ede2;
  --text: #241b14;
  --text-2: #645850;
  --text-3: #978d87;
  --border: #241b141a;
  --dark: #241b14;
  --on-dark: #fefbf8;

  /* acento cálido / celebración */
  --accent: #db633c;
  --accent-ink: #551400;
  --accent-bg: #ffe2d5;
  --streak: #dd7b2b;
  --streak-bg: #ffe7ce;
  --success: #3b8d5d;
  --success-bg: #d7f4dc;
  --danger: #bd413f;
  --danger-bg: #ffdfda;
  --shadow-soft: 0 2px 10px #633c2e1a;

  /* tipografía: Lora para títulos/momentos destacados, Inter para UI */
  --font-display: 'Lora', Georgia, serif;
  --font-ui: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* espaciado y esquinas */
  --space-1: 4px; --space-2: 8px; --space-3: 12px; --space-4: 16px;
  --space-5: 20px; --space-6: 24px; --space-7: 32px; --space-8: 40px;
  --radius-sm: 8px; --radius-md: 14px; --radius-lg: 20px; --radius-pill: 999px;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1410;
    --surface: #28201a;
    --surface-2: #332923;
    --text: #f0eae4;
    --text-2: #aba39b;
    --text-3: #766d66;
    --border: #ffffff1a;
    --dark: #f0eae4;
    --on-dark: #17100c;

    --accent: #f3906d;
    --accent-ink: #fbeae5;
    --accent-bg: #4c271a;
    --streak: #f5a15e;
    --streak-bg: #4d2c15;
    --success: #68b986;
    --success-bg: #173523;
    --danger: #ed756e;
    --danger-bg: #512320;
  }
}

/* Panel de profesor/colegio: paleta fría y sobria, sin sombras ni celebración
   — se aplica a las pantallas de gestión (grupo, quizzes, reportes). */
.pro-scope {
  --bg: #f9fafc;
  --surface: #ffffff;
  --surface-2: #eff2f6;
  --text: #14161a;
  --text-2: #5a5e63;
  --text-3: #898c91;
  --border: #14161a17;
  --accent: #3c5590;
  --accent-bg: #e5ebf9;
  --danger: #af3c3a;
  --danger-bg: #ffdfda;
  --radius-sm: 6px; --radius-md: 10px; --radius-lg: 14px; --radius: 10px;
  --shadow-soft: none;
}
@media (prefers-color-scheme: dark) {
  .pro-scope {
    --bg: #101214;
    --surface: #1b1d21;
    --surface-2: #24272b;
    --text: #e5e8ec;
    --text-2: #9b9fa3;
    --border: #ffffff17;
    --accent: #89a4de;
    --accent-bg: #212d47;
  }
}

@keyframes streakPulse { 0% { transform: scale(1); } 35% { transform: scale(1.22); } 60% { transform: scale(0.96); } 100% { transform: scale(1); } }
@keyframes bounceIn { 0% { transform: scale(0.75); opacity: 0; } 60% { transform: scale(1.05); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
@keyframes confettiBurst { 0% { transform: translate(0, 0) scale(1); opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)) scale(0.3); opacity: 0; } }

* { box-sizing: border-box; margin: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 0 16px calc(76px + env(safe-area-inset-bottom));
}
.hidden { display: none !important; }

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 0 16px;
}
h1 { font-family: var(--font-display); font-size: 24px; font-weight: 700; }
.chip {
  font-size: 13px; color: var(--streak); font-weight: 600;
  background: var(--streak-bg); border-radius: 999px; padding: 4px 12px;
  display: inline-block;
}
.chip.pulse { animation: streakPulse 0.5s ease; }

.view { display: none; }
.view.active { display: block; }

/* ---- tarjetas ---- */
.card {
  background: var(--surface);
  border: 0.5px solid var(--border);
  border-radius: 16px;
  padding: 20px 16px;
  margin-bottom: 16px;
}
.card-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; }

/* ---- portada como hero (pestaña Leer) ---- */
.hero-cover {
  position: relative; height: 190px; background-size: cover; background-position: center;
  flex-shrink: 0; margin-top: 4px;
}
.hero-cover.no-cover {
  background: repeating-linear-gradient(135deg, var(--accent), var(--accent) 14px, var(--streak) 14px, var(--streak) 28px);
}
.hero-cover-fade {
  position: absolute; inset: 0;
  background: linear-gradient(to bottom, transparent 35%, var(--bg) 96%);
}
.hero-cover-info {
  position: absolute; bottom: 16px; left: 18px; right: 56px;
}
.hero-cover-info .book-title { color: #fff; font-size: 19px; }
.hero-cover-info .book-sub { color: rgba(255, 255, 255, 0.8); }
.hero-sheet { padding: 22px 16px 0; margin-top: -14px; position: relative; }

/* ---- cronómetro ---- */
.book-row { display: flex; align-items: center; gap: 12px; }
.cover {
  width: 42px; height: 60px; border-radius: 4px; flex-shrink: 0;
  background: var(--accent-bg) center/cover no-repeat;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.book-info { flex: 1; min-width: 0; }
.book-title {
  font-family: var(--font-display);
  font-size: 16px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.book-sub { font-size: 13px; color: var(--text-2); }
.timer-display { text-align: center; margin: 24px 0 8px; }
.clock-ring {
  position: relative; width: 176px; height: 176px; margin: 0 auto;
  border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--ring-percent, 0) * 1%), var(--surface-2) 0);
  transition: background 0.3s ease;
}
.clock-ring::before {
  content: ""; position: absolute; inset: 8px; border-radius: 50%; background: var(--surface);
}
.clock-ring-inner {
  position: absolute; inset: 8px; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.clock {
  font-size: 34px; font-weight: 700; font-variant-numeric: tabular-nums;
  letter-spacing: 0.5px; position: relative; z-index: 1;
}
.clock-sub { font-size: 12px; color: var(--text-2); position: relative; z-index: 1; }
.play-btn {
  width: 72px; height: 72px; border-radius: 50%;
  background: var(--dark); color: var(--on-dark);
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  margin: 16px auto;
  transition: transform 0.1s;
}
.play-btn:active { transform: scale(0.94); }
.play-btn.running { background: var(--danger); color: #fff; }
.mode-switch { display: flex; gap: 6px; margin-bottom: 4px; }
.mode-btn {
  flex: 1; padding: 8px 0; font-size: 13px; border-radius: 10px;
  border: 0.5px solid var(--border); background: var(--surface-2);
  color: var(--text-2); cursor: pointer;
}
.mode-btn.active { background: var(--dark); color: var(--on-dark); border-color: transparent; font-weight: 600; }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-btn {
  padding: 6px 14px; font-size: 13px; border-radius: 999px;
  border: 0.5px solid var(--border); background: var(--surface-2);
  color: var(--text); cursor: pointer;
}
.chip-btn.active { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); font-weight: 600; }
.clock.overtime { color: var(--accent); }
.clock.paused { opacity: 0.5; }
#paused-badge {
  font-size: 12px; color: var(--text-2); font-weight: 600; margin-top: 2px;
}
#alarm-banner {
  background: var(--accent-bg); color: var(--accent); font-weight: 600;
  border-radius: 10px; padding: 8px 12px; margin: 8px 0 0; font-size: 13px;
}
.mini-stats {
  display: flex; justify-content: center; gap: 20px;
  border-top: 0.5px solid var(--border);
  padding-top: 14px; margin-top: 8px;
  font-size: 13px; color: var(--text-2);
}
.mini-stats b { color: var(--text); font-weight: 600; }

/* ---- lista de libros ---- */
.book-item {
  display: flex; gap: 12px; align-items: center;
  background: var(--surface); border: 0.5px solid var(--border);
  border-radius: var(--radius); padding: 12px; margin-bottom: 10px;
}
.progress {
  height: 5px; background: var(--surface-2); border-radius: 3px;
  overflow: hidden; margin-top: 6px;
}
.progress > div { height: 100%; background: var(--accent); border-radius: 3px; }
.badge {
  font-size: 11px; padding: 2px 8px; border-radius: 999px;
  background: var(--success-bg); color: var(--success); font-weight: 600;
  flex-shrink: 0;
}
.book-actions { display: flex; flex-direction: column; gap: 6px; flex-shrink: 0; }

/* ---- estadísticas ---- */
.metric-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px;
}
.metric { background: var(--surface-2); border-radius: var(--radius); padding: 12px 14px; }
.bento-grid {
  display: grid; grid-template-columns: 1.3fr 1fr; grid-template-rows: auto auto;
  gap: 10px; margin-bottom: 10px;
}
.bento-streak {
  grid-column: 1; grid-row: 1 / 3; min-height: 148px;
  background: linear-gradient(135deg, var(--streak), var(--accent));
  border-radius: var(--radius-lg, 20px); padding: 16px; color: #fff;
  display: flex; flex-direction: column; justify-content: space-between;
}
.bento-label { font-size: 12px; opacity: 0.85; margin: 0; }
.bento-value { font-family: var(--font-display); font-weight: 700; font-size: 30px; margin: 0; }
.bento-value small { font-weight: 400; opacity: 0.85; }
.m-label { font-size: 12px; color: var(--text-2); }
.m-value { font-size: 22px; font-weight: 600; margin-top: 2px; }
.m-value small { font-size: 13px; font-weight: 400; color: var(--text-2); }
.week-chart {
  display: flex; align-items: flex-end; gap: 8px; height: 120px;
}
.week-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.week-bar { width: 100%; max-width: 34px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.week-bar.empty-bar { background: var(--surface-2); }
.week-label { font-size: 11px; color: var(--text-3); }
.week-min { font-size: 11px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.footnote { font-size: 12px; color: var(--text-3); text-align: center; margin-top: 4px; }

/* ---- navegación ---- */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 0.5px solid var(--border);
  display: flex; justify-content: space-around;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom));
  max-width: 480px; margin: 0 auto;
}
.nav-btn {
  background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--text-3); font-size: 11px; padding: 4px 18px;
}
.nav-btn.active { color: var(--text); }

/* ---- botones ---- */
.btn {
  border-radius: 10px; border: 0.5px solid var(--border);
  padding: 10px 18px; font-size: 14px; cursor: pointer;
  background: var(--surface); color: var(--text);
}
.btn.primary { background: var(--dark); color: var(--on-dark); border: none; font-weight: 600; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn:active { transform: scale(0.98); }
.link {
  background: none; border: none; color: var(--accent);
  font-size: 13px; cursor: pointer; display: block; margin: 10px auto 0;
}

/* ---- modales ---- */
.backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50;
}
.modal {
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  width: 100%; max-width: 480px; max-height: 85dvh; overflow-y: auto;
}
.modal-title { font-family: var(--font-display); font-size: 19px; font-weight: 700; margin-bottom: 6px; }
.celebration-card {
  position: relative; overflow: hidden; text-align: center;
  background: var(--surface); border-radius: var(--radius-lg, 20px);
  padding: 32px 24px; animation: bounceIn 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.confetti-dot { position: absolute; width: 8px; height: 8px; animation: confettiBurst 0.9s ease-out forwards; }
.modal-sub { font-size: 13px; color: var(--text-2); margin-bottom: 12px; }
.modal label { display: block; font-size: 13px; color: var(--text-2); margin: 12px 0; }
.modal input {
  width: 100%; margin-top: 4px;
  padding: 10px 12px; font-size: 16px;
  border: 0.5px solid var(--border); border-radius: 10px;
  background: var(--bg); color: var(--text);
}
.modal input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }
.search-results { margin: 12px 0; max-height: 45dvh; overflow-y: auto; }
.search-item {
  display: flex; gap: 10px; align-items: center; width: 100%; text-align: left;
  background: none; border: none; border-bottom: 0.5px solid var(--border);
  padding: 10px 2px; cursor: pointer; color: var(--text);
}
.search-item .cover { width: 34px; height: 48px; font-size: 16px; }
.search-hint { font-size: 13px; color: var(--text-3); text-align: center; padding: 12px 0; }
.picker-item {
  display: flex; gap: 10px; align-items: center; width: 100%; text-align: left;
  background: none; border: none; border-bottom: 0.5px solid var(--border);
  padding: 10px 2px; cursor: pointer; color: var(--text);
}

/* ---- amigos ---- */
.avatar-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; }
.avatar-grid button {
  font-size: 22px; padding: 6px 0; background: var(--surface-2);
  border: 2px solid transparent; border-radius: 10px; cursor: pointer;
}
.avatar-grid button.selected { border-color: var(--accent); background: var(--accent-bg); }
.avatar-circle {
  width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0;
  background: var(--surface-2); display: flex; align-items: center;
  justify-content: center; font-size: 22px;
}
.reaction-btn {
  flex: 1; font-size: 24px; padding: 10px 0; background: var(--surface-2);
  border: 0.5px solid var(--border); border-radius: 12px; cursor: pointer;
}
.reaction-btn:active { transform: scale(0.92); }
.plan-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 10px 0 6px; }
.plan-card {
  border: 2px solid var(--border); border-radius: 12px; padding: 10px 8px;
  background: var(--surface-2); cursor: pointer; text-align: center;
}
.plan-card.selected { border-color: var(--accent); background: var(--accent-bg); }
.plan-card .plan-name { font-size: 13px; font-weight: 600; }
.plan-card .plan-cap { font-size: 11px; color: var(--text-2); margin-top: 2px; }
.plan-card .plan-price { font-size: 12px; margin-top: 4px; font-weight: 600; }

/* ---- quizzes ---- */
.quiz-qrow {
  background: var(--surface-2); border-radius: 10px; padding: 10px; margin-bottom: 10px;
}
.quiz-qrow input[type="text"] {
  width: 100%; margin-bottom: 6px; padding: 8px 10px; font-size: 14px;
  border: 0.5px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text);
}
.quiz-opt-row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.quiz-opt-row input[type="text"] { flex: 1; margin-bottom: 0; }
.quiz-take-opt {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  border: 0.5px solid var(--border); border-radius: 8px; margin-bottom: 6px; cursor: pointer;
}
.quiz-take-opt.selected { border-color: var(--accent); background: var(--accent-bg); }
.btn.small.link-btn { text-decoration: none; display: inline-flex; align-items: center; }
.code-big {
  font-size: 34px; font-weight: 700; letter-spacing: 6px;
  font-variant-numeric: tabular-nums; margin: 8px 0 12px;
}
.friend-meta { display: flex; gap: 14px; font-size: 12px; color: var(--text-2); margin-top: 2px; }
.friend-meta b { color: var(--text); }

/* ---- vacío y toast ---- */
.empty { text-align: center; padding: 48px 20px; color: var(--text-2); }
.empty p { margin-bottom: 16px; }
.toast {
  position: fixed; bottom: calc(86px + env(safe-area-inset-bottom));
  left: 50%; transform: translateX(-50%);
  background: var(--dark); color: var(--on-dark);
  font-size: 13px; padding: 10px 18px; border-radius: 999px;
  z-index: 60; white-space: nowrap;
}
