:root {
  --cream: #f7f1e4;
  --cream-soft: #fbf7ee;
  --gold: #b8923f;
  --gold-soft: #e4cd9a;
  --navy: #2a2a35;
  --navy-soft: #46465a;
  --pink: #f0c9c9;
  --pink-soft: #f8e2e2;
  --white: #ffffff;
  --danger: #c94b3f;
  --warning: #c98a2c;
  --shadow: 0 6px 18px rgba(42, 42, 53, 0.08);
  --radius: 18px;
  --radius-sm: 12px;
  --font: "Georgia", "Iowan Old Style", "Palatino Linotype", serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --max-width: 480px;
}

* { box-sizing: border-box; }

[role="button"]:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--cream);
  color: var(--navy);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

#app {
  width: 100%;
  max-width: var(--max-width);
  min-height: 100vh;
  background: var(--cream);
  display: flex;
  flex-direction: column;
  position: relative;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

/* ---- Top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: var(--cream);
  border-bottom: 1px solid rgba(184, 146, 63, 0.25);
}

.topbar .brand {
  font-family: var(--font);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--navy);
  display: flex;
  align-items: center;
  gap: 6px;
}

.lang-switch {
  display: flex;
  gap: 4px;
  background: var(--white);
  border-radius: 999px;
  padding: 3px;
  box-shadow: var(--shadow);
}

.lang-switch button {
  border: none;
  background: transparent;
  color: var(--navy-soft);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 5px 9px;
  border-radius: 999px;
  cursor: pointer;
}

.lang-switch button.active {
  background: var(--gold);
  color: var(--white);
}

.auto-badge {
  display: inline-block;
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  background: var(--pink-soft);
  color: var(--navy);
  border: 1px solid var(--pink);
  border-radius: 999px;
  padding: 2px 7px;
  margin-left: 6px;
  vertical-align: middle;
}

/* ---- Main content ---- */
main {
  flex: 1;
  padding: 18px 18px 90px;
  overflow-y: auto;
}

.screen-title {
  font-family: var(--font);
  font-size: 1.5rem;
  margin: 4px 0 2px;
  color: var(--navy);
}

.screen-subtitle {
  font-size: 0.92rem;
  color: var(--navy-soft);
  margin: 0 0 18px;
  line-height: 1.4;
}

/* ---- Bottom nav ---- */
.bottom-nav {
  position: sticky;
  bottom: 0;
  z-index: 20;
  display: flex;
  background: var(--white);
  border-top: 1px solid rgba(184, 146, 63, 0.25);
  padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
}

.bottom-nav button {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: var(--navy-soft);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 6px 2px;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.bottom-nav button .icon { font-size: 1.25rem; }
.bottom-nav button.active { color: var(--gold); background: var(--cream-soft); }

/* ---- Cards ---- */
.card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.card-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.card-title { font-weight: 700; font-size: 1rem; margin: 0 0 2px; }
.card-desc { font-size: 0.85rem; color: var(--navy-soft); margin: 0; line-height: 1.4; }

/* ---- Home ---- */
.hero-card {
  background: linear-gradient(135deg, var(--navy) 0%, #363646 100%);
  color: var(--cream-soft);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}

.hero-card .greeting { font-family: var(--font); font-size: 1.3rem; margin: 0 0 4px; }
.hero-card .greeting-sub { font-size: 0.85rem; opacity: 0.85; margin: 0 0 16px; }

.level-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.08);
  border: 1px solid var(--gold-soft);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 0.8rem;
  margin-bottom: 12px;
}

.level-pill .badge-num {
  background: var(--gold);
  color: var(--navy);
  font-weight: 800;
  border-radius: 50%;
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.72rem;
}

.progress-track {
  height: 8px;
  background: rgba(255,255,255,0.15);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--gold);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.progress-track.light { background: var(--pink-soft); }
.progress-track.light .progress-fill { background: var(--pink); }

.quick-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.quick-tile {
  background: var(--white);
  border-radius: var(--radius-sm);
  padding: 14px;
  box-shadow: var(--shadow);
  text-align: left;
  cursor: pointer;
  border: none;
  font-family: inherit;
  color: var(--navy);
}

.quick-tile .emoji { font-size: 1.4rem; }
.quick-tile .label { display: block; font-weight: 700; font-size: 0.85rem; margin-top: 6px; }

/* ---- Chapter list ---- */
.chapter-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--white);
  border-radius: var(--radius-sm);
  padding: 13px 15px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.chapter-item .num {
  min-width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--cream-soft);
  border: 1.5px solid var(--gold-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.78rem; font-weight: 700; color: var(--gold);
}

.chapter-item.done .num { background: var(--gold); color: var(--white); border-color: var(--gold); }
.chapter-item .title { font-weight: 600; font-size: 0.92rem; flex: 1; }
.chapter-item .chev { color: var(--gold-soft); }
.chapter-item.done .chev::after { content: "✓"; color: var(--gold); font-weight: 800; }

/* ---- Section tabs ---- */
.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
}

.tabs button {
  border: 1px solid var(--gold-soft);
  background: var(--white);
  color: var(--navy-soft);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.tabs button.active { background: var(--navy); color: var(--cream); border-color: var(--navy); }

/* ---- Chapter reading view ---- */
.chapter-header { margin-bottom: 16px; }
.chapter-kicker { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--gold); font-weight: 700; }
.chapter-header h1 { font-family: var(--font); font-size: 1.4rem; margin: 4px 0 0; line-height: 1.3; }

.block-p { font-size: 0.97rem; line-height: 1.65; margin: 0 0 14px; color: var(--navy); }
.block-h3 { font-family: var(--font); font-size: 1.08rem; margin: 20px 0 10px; color: var(--navy); }
.block-list { margin: 0 0 14px; padding-left: 20px; }
.block-list li { font-size: 0.95rem; line-height: 1.55; margin-bottom: 7px; }
.block-quote {
  font-family: var(--font);
  font-style: italic;
  font-size: 1.05rem;
  border-left: 3px solid var(--gold);
  padding: 6px 0 6px 16px;
  margin: 16px 0;
  color: var(--navy-soft);
}

.callout { border-radius: var(--radius-sm); padding: 14px 16px; margin: 0 0 16px; }
.callout-title { font-weight: 700; font-size: 0.85rem; margin-bottom: 5px; display: flex; align-items: center; gap: 6px; }
.callout-text { font-size: 0.9rem; line-height: 1.55; margin: 0; }

.callout-tip { background: var(--pink-soft); border: 1px solid var(--pink); }
.callout-tip .callout-title { color: #a5525b; }

.callout-warning { background: #fbeed9; border: 1px solid var(--warning); }
.callout-warning .callout-title { color: var(--warning); }

.callout-danger { background: #fbe1dd; border: 1px solid var(--danger); }
.callout-danger .callout-title { color: var(--danger); }

.callout-exercise { background: var(--cream-soft); border: 1.5px dashed var(--gold); }
.callout-exercise .callout-title { color: var(--gold); }

.reframed-note {
  font-size: 0.75rem;
  color: var(--navy-soft);
  background: var(--cream-soft);
  border-radius: 999px;
  padding: 5px 12px;
  display: inline-block;
  margin-bottom: 14px;
}

.chapter-nav { display: flex; gap: 10px; margin-top: 22px; }
.btn {
  border: none;
  border-radius: 999px;
  padding: 12px 20px;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  font-family: inherit;
}
.btn-primary { background: var(--gold); color: var(--white); flex: 1; }
.btn-primary:disabled { background: var(--gold-soft); cursor: default; }
.btn-secondary { background: var(--white); color: var(--navy); border: 1px solid var(--gold-soft); }
.btn-block { width: 100%; }

/* ---- Checklists ---- */
.checklist-group h4 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--gold); margin: 20px 0 8px; }
.check-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--white);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.check-item .box {
  min-width: 22px; height: 22px;
  border-radius: 6px;
  border: 2px solid var(--gold-soft);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; color: var(--white);
  margin-top: 1px;
}
.check-item.checked .box { background: var(--gold); border-color: var(--gold); }
.check-item.checked .box::after { content: "✓"; }
.check-item .text { font-size: 0.9rem; line-height: 1.45; }
.check-item.checked .text { text-decoration: line-through; color: var(--navy-soft); }

/* ---- FAQ ---- */
.faq-item { background: var(--white); border-radius: var(--radius-sm); box-shadow: var(--shadow); margin-bottom: 8px; overflow: hidden; }
.faq-q { padding: 14px 16px; font-weight: 700; font-size: 0.9rem; cursor: pointer; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.faq-a { padding: 0 16px 14px; font-size: 0.88rem; line-height: 1.55; color: var(--navy-soft); display: none; }
.faq-item.open .faq-a { display: block; }
.faq-item .chev { transition: transform 0.2s; color: var(--gold); }
.faq-item.open .chev { transform: rotate(180deg); }

/* ---- Resources ---- */
.resource-card { position: relative; }
.resource-card.star { border: 2px solid var(--gold); background: linear-gradient(135deg, var(--cream-soft), var(--white)); }
.star-badge {
  position: absolute; top: -9px; right: 14px;
  background: var(--gold); color: var(--white);
  font-size: 0.65rem; font-weight: 800;
  padding: 4px 10px; border-radius: 999px;
  box-shadow: var(--shadow);
}

/* ---- Achievements ---- */
.medal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.medal {
  background: var(--white);
  border-radius: var(--radius-sm);
  padding: 16px 12px;
  text-align: center;
  box-shadow: var(--shadow);
  opacity: 0.4;
  filter: grayscale(1);
}
.medal.unlocked { opacity: 1; filter: none; }
.medal .icon { font-size: 2rem; display: block; margin-bottom: 8px; }
.medal .title { font-weight: 700; font-size: 0.8rem; margin-bottom: 3px; }
.medal .desc { font-size: 0.72rem; color: var(--navy-soft); line-height: 1.35; }

/* ---- Toast ---- */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--navy);
  color: var(--cream);
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 50;
  max-width: 90%;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* =====================================================================
   Paleta de excepción — Primeros Auxilios: fondo claro, rojo/naranja
   para alertas, "modo manual de emergencia". Se aplica solo dentro de
   [data-theme="auxilios"], misma tipografía, otra paleta.
   ===================================================================== */
[data-theme="auxilios"] {
  --cream: #ffffff;
  --cream-soft: #fdf5f2;
  --gold: #d9633b;
  --gold-soft: #f3c3ab;
  --pink: #f4b8ac;
  --pink-soft: #fbe6df;
  --navy: #2a2320;
  --navy-soft: #6b5c54;
}

[data-theme="auxilios"] .hero-card,
[data-theme="auxilios"] .chapter-kicker { color: inherit; }

[data-theme="auxilios"] .hero-card { background: linear-gradient(135deg, #c94b3f 0%, #d9633b 100%); }

.install-banner {
  background: var(--gold-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}
.install-banner button { background: var(--navy); color: var(--cream); border: none; border-radius: 999px; padding: 8px 14px; font-size: 0.78rem; font-weight: 700; cursor: pointer; }

.offline-banner {
  background: var(--navy);
  color: var(--cream);
  font-size: 0.78rem;
  text-align: center;
  padding: 8px;
}

@media (min-width: 481px) {
  body { align-items: center; padding: 24px 0; }
  #app { min-height: 90vh; border-radius: 28px; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,0.15); }
}
