/* ==========================================================================
   Academia PMM — hoja de estilos única
   Móvil primero: la mayoría del estudio se hace en el teléfono.
   ========================================================================== */

:root {
  --bg:        #0b1018;
  --bg-soft:   #111827;
  --surface:   #161f2e;
  --surface-2: #1d2839;
  --border:    #2a3648;
  --text:      #e9eef7;
  --muted:     #93a3ba;
  --accent:    #3b82f6;
  --accent-dk: #1d4ed8;
  --gold:      #f0b429;
  --ok:        #22c55e;
  --ok-dim:    #14532d;
  --bad:       #ef4444;
  --bad-dim:   #601b1b;
  --radius:    16px;
  --radius-sm: 10px;
  --shadow:    0 6px 24px rgba(0,0,0,.35);
  --tap:       48px;
}

html[data-theme="light"] {
  --bg:        #f4f6fb;
  --bg-soft:   #ffffff;
  --surface:   #ffffff;
  --surface-2: #eef2f9;
  --border:    #d8e0ee;
  --text:      #16202f;
  --muted:     #5d6e88;
  --accent:    #2563eb;
  --accent-dk: #1e40af;
  --gold:      #b7791f;
  --ok:        #15803d;
  --ok-dim:    #d7f5de;
  --bad:       #dc2626;
  --bad-dim:   #fde2e2;
  --shadow:    0 4px 18px rgba(20,40,80,.10);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  overflow-x: hidden;              /* red de seguridad: nada debe desbordar a lo ancho */
  overflow-wrap: break-word;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--accent); }

/* ------------------------------------------------------------------ layout */
.wrap { max-width: 620px; margin: 0 auto; padding: 16px 16px 24px; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 17px; margin: 0; flex: 1; font-weight: 650; letter-spacing: -.2px; }
.topbar .back { font-size: 22px; width: 34px; height: 34px; display: grid; place-items: center;
                border-radius: 50%; color: var(--muted); }
.topbar .back:hover { background: var(--surface-2); color: var(--text); }

.iconbtn {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  font-size: 16px; color: var(--muted); background: var(--surface);
  border: 1px solid var(--border);
}
.iconbtn:hover { color: var(--text); border-color: var(--accent); }

/* -------------------------------------------------------------- navegación */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
  display: flex; justify-content: space-around;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg-soft) 94%, transparent);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border);
}
.tabbar a {
  flex: 1; text-decoration: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 6px 2px; border-radius: 12px; font-size: 10.5px; font-weight: 600;
  min-height: var(--tap); justify-content: center;
}
.tabbar a .ic { font-size: 19px; line-height: 1; }
.tabbar a.on { color: var(--accent); }
.tabbar a.on .ic { transform: translateY(-1px); }

/* ------------------------------------------------------------------ tarjetas */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; margin-bottom: 12px;
}
.card.flat { background: var(--bg-soft); }
.card h2 { font-size: 15px; margin: 0 0 12px; letter-spacing: -.1px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; }

/* --------------------------------------------------------------- cabecera */
.hero {
  background: linear-gradient(150deg, var(--accent-dk), #0f2a56 55%, var(--surface));
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; margin-bottom: 12px; position: relative; overflow: hidden;
}
html[data-theme="light"] .hero {
  background: linear-gradient(150deg, #2563eb, #3b82f6 60%, #60a5fa);
  color: #fff;
}
html[data-theme="light"] .hero .muted { color: rgba(255,255,255,.85); }
.hero .greet { font-size: 20px; font-weight: 700; margin: 0 0 2px; }
.hero .sub { font-size: 13px; opacity: .85; margin: 0; }

.herorow { display: flex; align-items: center; gap: 14px; margin-top: 14px; }

/* aro de objetivo diario */
.ring { position: relative; width: 78px; height: 78px; flex: 0 0 78px; }
.ring svg { transform: rotate(-90deg); display: block; }
.ring .val {
  position: absolute; inset: 0; display: grid; place-items: center;
  font-size: 17px; font-weight: 750; letter-spacing: -.5px;
}
.ring .val small { display: block; font-size: 9.5px; font-weight: 600; opacity: .7;
                   letter-spacing: .3px; max-width: 60px; overflow: hidden;
                   text-overflow: ellipsis; white-space: nowrap; }

.streakbox { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.streak { display: flex; align-items: baseline; gap: 6px; font-weight: 700; font-size: 15px; }
.streak .n { font-size: 26px; letter-spacing: -1px; }
.streak .flame { font-size: 20px; filter: drop-shadow(0 0 6px rgba(240,180,41,.5)); }

/* barra de rango */
.rankbar { margin-top: 4px; }
.rankbar .lbl { display: flex; justify-content: space-between; font-size: 11.5px; margin-bottom: 4px; }
.rankbar .lbl b { font-weight: 700; }
.bar { height: 8px; border-radius: 99px; background: rgba(255,255,255,.16); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 99px;
           background: linear-gradient(90deg, var(--gold), #ffd873); transition: width .5s ease; }
.bar.thin { height: 6px; }
.bar.blue > i { background: linear-gradient(90deg, var(--accent), #7dd3fc); }
.bar.green > i { background: linear-gradient(90deg, var(--ok), #86efac); }

/* --------------------------------------------------------- acciones sugeridas */
/* minmax(0,1fr) y min-width:0 son necesarios: por defecto un item de grid no baja
   de su ancho min-content, y el texto con nowrap ensanchaba la página en el móvil. */
.actions { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); }
.action {
  display: flex; align-items: center; gap: 13px; width: 100%; min-width: 0; text-align: left;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; min-height: var(--tap);
  transition: transform .12s ease, border-color .12s ease;
}
.action:active { transform: scale(.985); }
.action.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dk));
  border-color: transparent; color: #fff;
  box-shadow: 0 6px 18px rgba(59,130,246,.28);
}
.action.primary .a-desc { color: rgba(255,255,255,.85); }
.action .a-ic { font-size: 24px; flex: 0 0 auto; }
.action .a-txt { flex: 1; min-width: 0; }
/* display:block es imprescindible: el recorte con puntos suspensivos no se
   aplica a elementos en línea y el texto desbordaba el ancho del móvil. */
.action .a-tit { display: block; font-weight: 680; font-size: 15px; }
.action .a-desc { display: block; font-size: 12.5px; color: var(--muted);
                  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.action .a-eta { font-size: 11px; font-weight: 700; opacity: .75; flex: 0 0 auto; }

/* ------------------------------------------------------------- lista temas */
.temalist { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); }
.tema {
  display: flex; align-items: center; gap: 12px; width: 100%; min-width: 0; text-align: left;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 14px; min-height: var(--tap);
}
.tema:active { transform: scale(.99); }
.tema.locked { opacity: .45; }
.tema .num {
  flex: 0 0 38px; height: 38px; border-radius: 11px; display: grid; place-items: center;
  background: var(--surface-2); font-weight: 750; font-size: 15px; color: var(--muted);
}
.tema.done .num { background: var(--ok-dim); color: var(--ok); }
.tema.started .num { background: rgba(59,130,246,.16); color: var(--accent); }
.tema .body { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.tema .t { font-size: 14px; font-weight: 620; display: -webkit-box; -webkit-line-clamp: 2;
           -webkit-box-orient: vertical; overflow: hidden; line-height: 1.3; }
.tema .meta { font-size: 11.5px; color: var(--muted); margin-top: 3px;
              display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.tema .pct { font-size: 13px; font-weight: 750; flex: 0 0 auto; color: var(--muted); }
.tema.done .pct { color: var(--ok); }

.pill { display: inline-block; padding: 1px 7px; border-radius: 99px; font-size: 10.5px;
        font-weight: 700; background: var(--surface-2); color: var(--muted); }
.pill.ok  { background: var(--ok-dim);  color: var(--ok); }
.pill.due { background: rgba(240,180,41,.16); color: var(--gold); }
.pill.new { background: rgba(59,130,246,.16); color: var(--accent); }

/* ------------------------------------------------------------------- quiz */
.qhead { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.qhead .cnt { font-size: 12.5px; font-weight: 700; color: var(--muted); }
.qhead .combo { font-size: 12.5px; font-weight: 750; color: var(--gold); margin-left: auto; }
.qhead .timer { font-size: 12.5px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
.qprog { height: 5px; border-radius: 99px; background: var(--surface-2); overflow: hidden; margin: 8px 0 16px; }
.qprog > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), #60a5fa);
             transition: width .3s ease; }

.qtext { font-size: 17px; font-weight: 620; line-height: 1.4; margin: 0 0 16px;
         letter-spacing: -.2px; overflow-wrap: anywhere; }
.qtag { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase;
        letter-spacing: .6px; margin-bottom: 6px; }

.opts { display: grid; gap: 9px; grid-template-columns: minmax(0, 1fr); }
.opt {
  display: flex; align-items: flex-start; gap: 11px; width: 100%; text-align: left;
  overflow-wrap: anywhere;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: 14px; padding: 13px 14px; font-size: 14.5px; line-height: 1.4;
  transition: border-color .15s, background .15s, transform .1s;
}
.opt:active { transform: scale(.99); }
.opt .k {
  flex: 0 0 26px; height: 26px; border-radius: 8px; display: grid; place-items: center;
  background: var(--surface-2); font-weight: 750; font-size: 13px; color: var(--muted);
}
.opt.sel        { border-color: var(--accent); }
.opt.good       { border-color: var(--ok);  background: color-mix(in srgb, var(--ok) 12%, var(--surface)); }
.opt.good .k    { background: var(--ok); color: #fff; }
.opt.bad        { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 12%, var(--surface)); }
.opt.bad .k     { background: var(--bad); color: #fff; }
.opt[disabled]  { cursor: default; }
.opt.dim        { opacity: .5; }

.verdict { margin-top: 14px; padding: 12px 14px; border-radius: 14px; font-size: 13.5px; font-weight: 620; }
.verdict.good { background: var(--ok-dim);  color: var(--ok); }
.verdict.bad  { background: var(--bad-dim); color: var(--bad); }
.verdict .ans { display: block; font-weight: 500; margin-top: 4px; color: var(--text); opacity: .9; }

/* ----------------------------------------------------------------- fichas */
.flip {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
  padding: 22px 18px; min-height: 190px; display: flex; flex-direction: column;
  justify-content: center; gap: 14px; text-align: center;
}
.flip .fq { font-size: 17px; font-weight: 620; line-height: 1.4; }
.flip .fa { font-size: 15px; color: var(--text); border-top: 1px dashed var(--border); padding-top: 14px; }
.flip .tap { font-size: 12.5px; color: var(--muted); }

/* --------------------------------------------------------------- botonera */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 13px 18px; border-radius: 14px; font-weight: 700; font-size: 15px;
  background: var(--surface-2); border: 1px solid var(--border); min-height: var(--tap);
}
.btn.block { width: 100%; }
.btn.pri  { background: linear-gradient(135deg, var(--accent), var(--accent-dk)); color: #fff; border-color: transparent; }
.btn.ok   { background: var(--ok); color: #fff; border-color: transparent; }
.btn.bad  { background: var(--bad); color: #fff; border-color: transparent; }
.btn.ghost{ background: transparent; }
.btn:active { transform: scale(.98); }
.btnrow { display: flex; gap: 10px; margin-top: 14px; }
.btnrow .btn { flex: 1; }

/* -------------------------------------------------------------- resultados */
.score { text-align: center; padding: 8px 0 4px; }
.score .big { font-size: 54px; font-weight: 800; letter-spacing: -2px; line-height: 1; }
.score .of  { font-size: 14px; color: var(--muted); margin-top: 4px; }
.score .msg { font-size: 15px; font-weight: 650; margin-top: 10px; }
.xpgain { display: inline-flex; align-items: center; gap: 6px; margin-top: 10px;
          background: rgba(240,180,41,.14); color: var(--gold);
          padding: 6px 14px; border-radius: 99px; font-weight: 750; font-size: 14px; }

.statgrid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 14px; }
.stat { background: var(--surface-2); border-radius: 12px; padding: 11px 8px; text-align: center; }
.stat .v { font-size: 19px; font-weight: 780; letter-spacing: -.5px; }
.stat .l { font-size: 10.5px; color: var(--muted); font-weight: 600; margin-top: 1px; }

/* ------------------------------------------------------------------ logros */
.achgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 9px; }
.ach { background: var(--surface-2); border: 1px solid var(--border); border-radius: 13px;
       padding: 11px 7px; text-align: center; }
.ach.off { opacity: .34; filter: grayscale(1); }
.ach .i { font-size: 24px; }
.ach .n { font-size: 11px; font-weight: 700; margin-top: 4px; line-height: 1.25; }
.ach .d { font-size: 9.5px; color: var(--muted); margin-top: 2px; line-height: 1.3; }

/* --------------------------------------------------------------- calendario */
.heat { display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr);
        gap: 3px; overflow-x: auto; padding-bottom: 4px; }
.heat i { width: 11px; height: 11px; border-radius: 3px; background: var(--surface-2); display: block; }
.heat i.l1 { background: color-mix(in srgb, var(--accent) 30%, var(--surface-2)); }
.heat i.l2 { background: color-mix(in srgb, var(--accent) 55%, var(--surface-2)); }
.heat i.l3 { background: color-mix(in srgb, var(--accent) 78%, var(--surface-2)); }
.heat i.l4 { background: var(--accent); }

/* ------------------------------------------------------------------- avisos */
.toasts { position: fixed; left: 12px; right: 12px; bottom: calc(84px + env(safe-area-inset-bottom));
          z-index: 60; display: grid; gap: 8px; pointer-events: none; }
.toast {
  background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--gold);
  border-radius: 12px; padding: 11px 14px; box-shadow: var(--shadow);
  font-size: 13.5px; font-weight: 620; display: flex; align-items: center; gap: 10px;
  animation: rise .28s ease both;
}
.toast .i { font-size: 20px; }
.toast .d { font-size: 11.5px; color: var(--muted); font-weight: 500; }
.toast.up { border-left-color: var(--accent); }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }

/* ------------------------------------------------------------------ varios */
.empty { text-align: center; padding: 42px 20px; color: var(--muted); }
.empty .i { font-size: 42px; margin-bottom: 10px; }
.empty .t { font-size: 15px; font-weight: 650; color: var(--text); margin-bottom: 4px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 650; color: var(--muted); margin-bottom: 6px; }
.field input, .field select {
  width: 100%; padding: 12px 13px; border-radius: 12px; min-height: var(--tap);
  background: var(--bg-soft); border: 1px solid var(--border); color: var(--text);
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { padding: 9px 14px; border-radius: 99px; background: var(--surface-2);
        border: 1px solid var(--border); font-size: 13px; font-weight: 650; min-height: 40px; }
.chip.on { background: var(--accent); border-color: transparent; color: #fff; }

.readerframe { width: 100%; height: 74vh; border: 1px solid var(--border);
               border-radius: var(--radius); background: #fff; }

.spin { width: 26px; height: 26px; border-radius: 50%; margin: 40px auto;
        border: 3px solid var(--border); border-top-color: var(--accent);
        animation: sp .7s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }

.sectitle { font-size: 12px; font-weight: 750; color: var(--muted); text-transform: uppercase;
            letter-spacing: .7px; margin: 20px 2px 9px; }

@media (min-width: 640px) {
  body { padding-bottom: 24px; }
  .tabbar { position: sticky; top: 0; bottom: auto; border-top: none; border-bottom: 1px solid var(--border); }
  .tabbar a { flex-direction: row; gap: 7px; font-size: 13px; }
  .toasts { left: auto; right: 20px; bottom: 20px; width: 320px; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
