:root {
  --bg: #14161f;
  --surface: #1e2130;
  --surface-2: #272b3d;
  --text: #eef0f7;
  --muted: #9aa0b8;
  --accent: #7b93ff;
  --good: #4fc38a;
  --bad: #e0707a;
  --radius: 22px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5fa;
    --surface: #ffffff;
    --surface-2: #e9ebf4;
    --text: #1b1e2b;
    --muted: #61677f;
    --accent: #4a5fd6;
    color-scheme: light;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  overscroll-behavior: none;
}
#app {
  min-height: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 24px);
  display: flex;
  flex-direction: column;
}

/* ---------- Barra superior ---------- */
.topbar {
  display: flex; align-items: center; gap: 8px; min-height: 48px; margin-bottom: 8px;
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  margin-top: calc(-1 * (var(--safe-top) + 12px)); padding-top: calc(var(--safe-top) + 12px); padding-bottom: 6px;
}
.topbar h1 { font-size: 20px; margin: 0; flex: 1; font-weight: 650; }
.icon-btn {
  border: 0; background: var(--surface); color: var(--text);
  width: 44px; height: 44px; border-radius: 14px; font-size: 20px;
  display: grid; place-items: center; cursor: pointer; flex: none;
}
.icon-btn:active { transform: scale(.95); }

/* ---------- Inicio: rejilla de emociones ---------- */
.prompt { color: var(--muted); margin: 0 0 14px; font-size: 16px; }
.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  flex: 1;
  align-content: start;
}
.emotion {
  border: 0; cursor: pointer; color: #1b1e2b;
  border-radius: var(--radius);
  aspect-ratio: 1 / .92;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: 17px;
  transition: transform .12s ease;
  box-shadow: 0 2px 0 rgba(0,0,0,.08);
}
.emotion:active { transform: scale(.94); }
.emotion .emo { font-size: 64px; line-height: 1; }
.emotion img.emo { width: 72px; height: 72px; object-fit: contain; border-radius: 12px; }
.grid.compact { grid-template-columns: repeat(3, 1fr); gap: 10px; }
.grid.compact .emotion { aspect-ratio: 1 / 1.3; font-size: 14px; padding: 6px; text-align: center; line-height: 1.2; }
.grid.compact .emotion .emo { font-size: 50px; }
.grid.compact .emotion img.emo { width: 52px; height: 52px; }
.help-line {
  margin-top: 18px; text-align: center; color: var(--muted); font-size: 14px;
}
.help-line a { color: var(--accent); font-weight: 600; text-decoration: none; }

/* ---------- Recurso ---------- */
.resource-head { display: flex; align-items: center; gap: 12px; margin: 4px 0 14px; }
.resource-head .badge {
  width: 56px; height: 56px; border-radius: 18px; display: grid; place-items: center; font-size: 34px; flex: none;
}
.resource-head .badge img { width: 40px; height: 40px; object-fit: contain; }
.resource-head .label { color: var(--muted); font-size: 14px; }
.resource-head .name { font-size: 20px; font-weight: 650; }
.card {
  background: var(--surface); border-radius: var(--radius); padding: 22px;
  animation: fadeIn .35s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.card .kind { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 10px; }
.card h2 { margin: 0 0 10px; font-size: 21px; }
.card .quote { font-size: 24px; line-height: 1.35; font-weight: 500; margin: 0; white-space: pre-line; }
.card .quote::before { content: "“"; color: var(--accent); }
.card .quote::after { content: "”"; color: var(--accent); }
.card .author { color: var(--muted); margin-top: 12px; }
.card .body { white-space: pre-wrap; font-size: 19px; }
.card .video { position: relative; aspect-ratio: 16/9; border-radius: 14px; overflow: hidden; background: #000; margin-top: 8px; }
.card .video iframe, .card .video video { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.card img.doc { max-width: 100%; border-radius: 12px; margin-top: 8px; }
.card iframe.doc { width: 100%; height: 60vh; border: 0; border-radius: 12px; margin-top: 8px; background: #fff; }

.feedback { margin-top: 18px; }
.feedback p { margin: 0 0 10px; color: var(--muted); text-align: center; }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; }

.btn {
  border: 0; cursor: pointer; font: inherit; font-weight: 600;
  background: var(--surface-2); color: var(--text);
  padding: 15px 16px; border-radius: 16px; min-height: 52px;
  text-decoration: none; text-align: center; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.good { background: var(--good); color: #0f2a1d; }
.btn.bad { background: var(--surface-2); }
.btn.danger { background: transparent; color: var(--bad); border: 1px solid var(--bad); }
.btn.small { padding: 8px 12px; min-height: 38px; font-size: 15px; border-radius: 12px; }
.btn.block { width: 100%; margin-top: 10px; }
.thanks { text-align: center; padding: 10px; color: var(--good); font-weight: 600; }

/* ---------- Respiración ---------- */
.breath { display: grid; place-items: center; padding: 16px 0 6px; }
.breath .circle {
  width: 200px; height: 200px; border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #a9b8ff, var(--accent));
  display: grid; place-items: center; color: #fff; font-weight: 650; font-size: 20px;
  transform: scale(.55);
  transition-property: transform; transition-timing-function: ease-in-out;
  box-shadow: 0 0 60px rgba(123,147,255,.35);
}
.breath .count { margin-top: 18px; color: var(--muted); }

/* ---------- Ajustes / formularios ---------- */
.tabs { display: flex; gap: 6px; background: var(--surface); padding: 5px; border-radius: 16px; margin-bottom: 14px; }
.tabs button {
  flex: 1; border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600;
  padding: 10px 6px; border-radius: 12px; cursor: pointer; font-size: 15px;
}
.tabs button.on { background: var(--surface-2); color: var(--text); }
.list { display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 12px; background: var(--surface); border-radius: 16px; padding: 12px 14px;
  border: 0; color: var(--text); font: inherit; text-align: left; cursor: pointer; width: 100%;
}
.item .ico { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; font-size: 24px; flex: none; }
.item .ico img { width: 30px; height: 30px; object-fit: contain; }
.item .txt { flex: 1; min-width: 0; }
.item .t1 { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .t2 { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.section-title { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .08em; margin: 18px 4px 8px; }
.filter { margin-bottom: 10px; }

form { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 15px; color: var(--muted); font-weight: 600; }
input[type=text], input[type=url], input[type=tel], textarea, select {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--surface-2);
  border-radius: 14px; padding: 12px 14px; width: 100%;
}
textarea { min-height: 120px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 999px;
  background: var(--surface); color: var(--text); font-weight: 500; cursor: pointer; border: 1px solid var(--surface-2);
}
.chip input { display: none; }
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.colors { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { width: 38px; height: 38px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.swatch.on { border-color: var(--text); }
.emoji-preview { font-size: 54px; width: 84px; height: 84px; border-radius: 22px; display: grid; place-items: center; }
.emoji-preview img { width: 60px; height: 60px; object-fit: contain; }
.hint { color: var(--muted); font-size: 14px; margin: 0; font-weight: 400; }
.muted { color: var(--muted); }

/* ---------- Historial ---------- */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 6px; }
.stat { background: var(--surface); border-radius: 16px; padding: 12px; text-align: center; }
.stat b { display: block; font-size: 24px; }
.stat span { color: var(--muted); font-size: 13px; }
.bar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--good); }

/* ---------- Siento / pienso ---------- */
.seg { display: flex; gap: 4px; background: var(--surface); padding: 4px; border-radius: 16px; margin-bottom: 14px; }
.seg button {
  flex: 1; border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 650; font-size: 16px;
  padding: 11px 6px; border-radius: 12px; cursor: pointer;
}
.seg button.on { background: var(--surface-2); color: var(--text); }
.thoughts { display: flex; flex-direction: column; gap: 10px; }
.thought {
  display: flex; align-items: center; gap: 12px; text-align: left; width: 100%; cursor: pointer;
  background: var(--surface); color: var(--text); border: 0; border-radius: 18px; padding: 16px; font: inherit;
  border-left: 5px solid var(--accent);
}
.thought:active { transform: scale(.98); }
.thought .ti { font-size: 28px; }
.thought .tt { flex: 1; font-size: 18px; font-weight: 600; line-height: 1.3; }
.thought .go { font-size: 26px; color: var(--muted); }
.t-head .t-text { margin: 0; font-size: 20px; font-style: italic; color: var(--muted); line-height: 1.4; }
.points { margin: 0; padding: 0; list-style: none; counter-reset: p; display: flex; flex-direction: column; gap: 8px; }
.points li {
  counter-increment: p; background: var(--surface); border-radius: 16px; padding: 14px 16px 14px 50px; position: relative; font-size: 18px; line-height: 1.45;
}
.points li::before {
  content: counter(p); position: absolute; left: 14px; top: 14px; width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 14px; display: grid; place-items: center;
}
.p-src { display: inline-block; margin-top: 6px; font-size: 13px; color: var(--accent); text-decoration: none; font-weight: 600; }
span.p-src { color: var(--muted); font-weight: 400; }
.t-answer {
  margin-top: 10px; border-radius: var(--radius); padding: 18px 20px;
  background: linear-gradient(135deg, #7b93ff, #4a5fd6); color: #fff;
}
.t-answer .kind { color: rgba(255,255,255,.8); margin-bottom: 6px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; }
.t-answer p { margin: 0; font-size: 21px; font-weight: 650; line-height: 1.35; }
.t-visits { text-align: center; margin-top: 12px; }
.add-box { margin-top: 12px; }
.point-edit { background: var(--surface); border-radius: 14px; padding: 8px; }
.point-edit textarea { min-height: 70px; border: 0; background: transparent; padding: 6px; }
.point-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; padding: 0 6px 2px; }
.tabs button { font-size: 14px; padding: 10px 4px; }

/* ---------- Lista de recursos ---------- */
.rtools { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.search {
  display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--surface-2);
  border-radius: 14px; padding: 0 12px;
}
.search:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }
.search input { flex: 1; border: 0; background: transparent; color: var(--text); font: inherit; padding: 12px 0; outline: none; min-width: 0; }
.chips-scroll {
  display: flex; flex-wrap: wrap; gap: 8px; padding: 2px 0;
}
.chips-scroll::-webkit-scrollbar { display: none; }
.chips-scroll .chip { flex: none; font: inherit; font-size: 14px; font-weight: 600; padding: 7px 12px; }
.rcount { color: var(--muted); font-size: 14px; margin: 2px 4px 8px; }
.ritem { align-items: flex-start; }
.ritem .t1 { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.ritem .t2 { white-space: normal; display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; margin-top: 2px; }
.ritem .t3 { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 13px; margin-top: 6px; }
.ritem .emos { letter-spacing: 2px; }

/* ---------- Guía paso a paso ---------- */
.guide-btn {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; cursor: pointer;
  background: linear-gradient(135deg, #7b93ff, #4a5fd6); color: #fff; border: 0; border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 14px; font: inherit;
}
.guide-btn:active { transform: scale(.98); }
.guide-btn .gi { font-size: 30px; }
.guide-btn b { display: block; font-size: 18px; }
.guide-btn small { display: block; opacity: .85; font-size: 14px; }
.guide-btn .go { margin-left: auto; font-size: 28px; opacity: .8; }
.pkg-hint {
  display: block; margin-bottom: 12px; padding: 12px 14px; border-radius: 14px; text-decoration: none;
  border: 1px dashed var(--surface-2); color: var(--muted); font-size: 15px;
}
.dots { display: flex; gap: 6px; justify-content: center; margin: 0 0 14px; }
.dots i { width: 26px; height: 5px; border-radius: 3px; background: var(--surface-2); }
.dots i.done { background: var(--accent); opacity: .5; }
.dots i.now { background: var(--accent); }
.guide-card.still { animation: none; }
.guide-card .g-big { font-size: 23px; line-height: 1.35; font-weight: 600; margin: 4px 0 14px; }
.g-body p { margin: 0 0 8px; font-size: 18px; color: var(--text); }
.g-highlight {
  margin: 14px 0; padding: 14px; border-radius: 14px; text-align: center; font-weight: 800; letter-spacing: .02em;
  background: color-mix(in srgb, var(--accent) 18%, transparent); color: var(--text); font-size: 18px;
}
.g-dialog { margin-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.g-dialog .q, .g-dialog .a { padding: 10px 14px; border-radius: 16px; max-width: 85%; font-size: 18px; }
.g-dialog .q { background: var(--surface-2); align-self: flex-start; font-style: italic; }
.g-dialog .a { background: var(--accent); color: #fff; align-self: flex-end; font-weight: 600; }
.g-group { margin-bottom: 12px; }
.g-group h3 { margin: 0 0 8px; font-size: 14px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.g-group .chip { font: inherit; font-size: 16px; }
.scale { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin: 8px 0 16px; }
.lvl {
  aspect-ratio: 1; border-radius: 14px; border: 2px solid transparent; font: inherit; font-size: 22px; font-weight: 700;
  background: color-mix(in srgb, var(--c) 35%, var(--surface-2)); color: var(--text); cursor: pointer;
}
.lvl.on { background: var(--c); color: #1b1e2b; border-color: var(--text); transform: scale(1.06); }
.g-scale-q { margin-top: 18px; font-weight: 600; }
.g-options { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.g-opt { background: var(--surface-2); border-radius: 16px; padding: 14px; cursor: pointer; border: 2px solid transparent; font-size: 17px; }
.g-opt.on { border-color: var(--accent); }
.g-opt.rec { border-color: color-mix(in srgb, var(--accent) 60%, transparent); }
.g-rec { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); font-weight: 700; margin-bottom: 6px; }
.g-actions { margin-top: 10px; }
.g-actions .chip { font: inherit; font-size: 15px; }
.g-nav { margin-top: 14px; }
.guide-done { text-align: center; margin-bottom: 12px; }
.guide-done .big-emoji { font-size: 56px; }
.g-levels { display: flex; justify-content: center; align-items: center; gap: 12px; font-size: 22px; color: var(--muted); margin: 8px 0; }
.g-levels span { background: var(--c); color: #1b1e2b; font-weight: 800; width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; font-size: 26px; }
.guide-stat { text-decoration: none; }
.spark { display: flex; gap: 6px; align-items: flex-end; height: 40px; margin-top: 8px; }
.spark span { display: flex; gap: 1px; align-items: flex-end; height: 100%; }
.spark i { width: 6px; border-radius: 2px; }
.spark i.b { background: var(--bad); opacity: .7; }
.spark i.a { background: var(--good); }

/* ---------- Lecturas ---------- */
.read-more { margin-top: 16px; background: transparent; border: 1px solid var(--surface-2); color: var(--accent); }
.toc { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 4px; }
.toc a {
  background: var(--surface); color: var(--text); text-decoration: none; font-weight: 600; font-size: 14px;
  padding: 6px 12px; border-radius: 999px;
}
.frag { background: var(--surface); border-radius: 16px; padding: 16px 18px; margin-bottom: 10px; scroll-margin-top: 90px; }
.section-title { scroll-margin-top: 80px; }
.frag-ref { color: var(--accent); font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.frag-text { white-space: pre-wrap; font-size: 17px; line-height: 1.55; }
.frag.target { outline: 2px solid var(--accent); }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 24px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-weight: 600;
  width: max-content; max-width: calc(100% - 32px); text-align: center;
  animation: fadeIn .2s ease; z-index: 10;
}
