/* ====== Fábula · sistema de diseño ====== */
:root {
  --ciruela: #7A3B8F;
  --ciruela-700: #633073;
  --ciruela-100: #F1E6F4;
  --ambar: #F2A541;
  --ambar-600: #D98A22;
  --jade: #2E9E7B;
  --jade-100: #DCF1EA;
  --papel: #FBF7F0;
  --papel-2: #FFFFFF;
  --tinta: #211D2E;
  --tinta-60: #5B5667;
  --tinta-30: #9D99A6;
  --linea: #E7E0D6;
  --rojo: #D1485B;

  /* estados de palabra (azul = nueva, amarillo = aprendiendo, como LingQ) */
  --st-nuevo-bg: #D4E6FB;
  --st-nuevo-ln: #5B9BE8;
  --st-fam1-bg: #FCE39B;
  --st-fam2-bg: #FDEEBE;
  --st-fam3-bg: #FEF6DC;
  --st-guardado-ln: #7A3B8F;

  --sombra: 0 1px 2px rgba(33,29,46,.06), 0 8px 24px rgba(33,29,46,.07);
  --radio: 16px;
  --radio-s: 10px;
  --max: 1080px;
  --sans: 'Inter', system-ui, -apple-system, sans-serif;
  --serif: 'Fraunces', Georgia, 'Times New Roman', serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  background: var(--papel);
  color: var(--tinta);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--ciruela); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; line-height: 1.15; margin: 0 0 .4em; }
img { max-width: 100%; }

/* ====== Botones ====== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  border: 0; border-radius: 999px; padding: .72rem 1.4rem; font-size: .98rem; font-weight: 600;
  background: var(--ciruela); color: #fff; transition: transform .08s ease, background .15s, box-shadow .15s;
  box-shadow: 0 4px 14px rgba(122,59,143,.28);
}
.btn:hover { background: var(--ciruela-700); }
.btn:active { transform: translateY(1px); }
.btn.secondary { background: transparent; color: var(--ciruela); box-shadow: none; border: 1.5px solid var(--linea); }
.btn.secondary:hover { border-color: var(--ciruela); background: var(--ciruela-100); }
.btn.ghost { background: transparent; color: var(--tinta-60); box-shadow: none; }
.btn.ghost:hover { background: #0000000a; }
.btn.amber { background: var(--ambar); color: #4a2d00; box-shadow: 0 4px 14px rgba(242,165,65,.35); }
.btn.amber:hover { background: var(--ambar-600); }
.btn.small { padding: .45rem .9rem; font-size: .86rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ====== Barra superior ====== */
.topbar {
  position: sticky; top: 0; z-index: 30; background: rgba(251,247,240,.86);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--linea);
}
.topbar-in { max-width: var(--max); margin: 0 auto; padding: .7rem 1.2rem; display: flex; align-items: center; gap: 1rem; }
.brand { display: flex; align-items: center; gap: .6rem; font-family: var(--serif); font-weight: 600; font-size: 1.35rem; color: var(--tinta); }
.brand .mark { width: 34px; height: 34px; border-radius: 9px; background: var(--ciruela); color: #fff; display: grid; place-items: center; font-size: 1.1rem; box-shadow: 0 3px 10px rgba(122,59,143,.3); }
.brand .mark svg { width: 20px; height: 20px; }
.nav { display: flex; gap: .3rem; margin-left: 1rem; }
.nav a { padding: .45rem .8rem; border-radius: 999px; color: var(--tinta-60); font-weight: 500; font-size: .95rem; }
.nav a.active, .nav a:hover { color: var(--ciruela); background: var(--ciruela-100); }
.spacer { flex: 1; }
.lang-pill { display: inline-flex; align-items: center; gap: .4rem; padding: .35rem .7rem; border-radius: 999px; border: 1.5px solid var(--linea); background: #fff; font-weight: 600; font-size: .9rem; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--jade); color: #fff; display: grid; place-items: center; font-weight: 700; cursor: pointer; }

/* ====== Layout ====== */
.page { max-width: var(--max); margin: 0 auto; padding: 1.8rem 1.2rem 4rem; }
.row { display: flex; gap: 1rem; flex-wrap: wrap; }
.muted { color: var(--tinta-60); }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 2rem 0 1rem; }
.section-title h2 { margin: 0; font-size: 1.5rem; }
.card { background: var(--papel-2); border: 1px solid var(--linea); border-radius: var(--radio); box-shadow: var(--sombra); }

/* ====== Auth / landing ====== */
.landing { min-height: 100vh; display: grid; grid-template-columns: 1.05fr .95fr; }
.landing .hero { padding: 3rem clamp(1.5rem, 5vw, 5rem); display: flex; flex-direction: column; justify-content: center; background:
  radial-gradient(1200px 500px at -10% -10%, #fff6e6 0, transparent 55%),
  radial-gradient(900px 500px at 110% 110%, var(--ciruela-100) 0, transparent 55%),
  var(--papel); }
.landing .hero h1 { font-size: clamp(2.4rem, 5vw, 3.6rem); }
.landing .hero .accent { color: var(--ciruela); font-style: italic; }
.landing .lead { font-size: 1.2rem; color: var(--tinta-60); max-width: 30rem; margin-bottom: 1.6rem; }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; margin: 1.4rem 0; }
.chip { padding: .4rem .9rem; border-radius: 999px; background: #fff; border: 1px solid var(--linea); font-size: .9rem; font-weight: 600; color: var(--tinta-60); }
.landing .panel { background: var(--papel-2); display: flex; align-items: center; justify-content: center; padding: 2rem; border-left: 1px solid var(--linea); }
.auth-box { width: 100%; max-width: 380px; }
.auth-box h2 { font-size: 1.7rem; }
.field { margin-bottom: 1rem; }
.field label { display: block; font-size: .88rem; font-weight: 600; margin-bottom: .35rem; color: var(--tinta-60); }
.field input, .field select, .field textarea {
  width: 100%; padding: .72rem .9rem; border: 1.5px solid var(--linea); border-radius: var(--radio-s);
  font-size: 1rem; font-family: inherit; background: #fff; color: var(--tinta); transition: border .15s;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--ciruela); }
.auth-switch { text-align: center; margin-top: 1rem; font-size: .92rem; color: var(--tinta-60); }
.auth-switch button { background: none; border: 0; color: var(--ciruela); font-weight: 600; cursor: pointer; }
.form-error { background: #fdeaed; color: var(--rojo); padding: .6rem .8rem; border-radius: var(--radio-s); font-size: .9rem; margin-bottom: 1rem; }

/* ====== Dashboard ====== */
.greeting h1 { font-size: 2rem; }
.grid { display: grid; gap: 1rem; }
.grid.lang-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.lang-card { padding: 1.3rem; cursor: pointer; transition: transform .1s, box-shadow .15s; position: relative; overflow: hidden; }
.lang-card:hover { transform: translateY(-3px); box-shadow: 0 10px 30px rgba(33,29,46,.12); }
.lang-card .flag { font-size: 2.2rem; }
.lang-card h3 { font-size: 1.3rem; margin: .5rem 0 .2rem; }
.lang-card .level { font-size: .82rem; color: var(--tinta-60); text-transform: capitalize; }
.lang-stats { display: flex; gap: 1rem; margin-top: 1rem; }
.lang-stat b { display: block; font-size: 1.4rem; font-family: var(--serif); }
.lang-stat span { font-size: .75rem; color: var(--tinta-60); }
.statbar { display: flex; gap: 1rem; flex-wrap: wrap; }
.statbox { flex: 1; min-width: 140px; padding: 1.2rem; text-align: left; }
.statbox .big { font-family: var(--serif); font-size: 2.2rem; line-height: 1; }
.statbox .lbl { color: var(--tinta-60); font-size: .9rem; margin-top: .3rem; }
.statbox .ico { font-size: 1.4rem; }
.add-lang { border: 2px dashed var(--linea); background: transparent; box-shadow: none; display: grid; place-items: center; min-height: 160px; color: var(--tinta-60); font-weight: 600; }
.add-lang:hover { border-color: var(--ciruela); color: var(--ciruela); }

/* ====== Biblioteca ====== */
.lib-tabs { display: flex; gap: .4rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.lib-tabs button { padding: .5rem 1rem; border-radius: 999px; border: 1.5px solid var(--linea); background: #fff; font-weight: 600; font-size: .9rem; color: var(--tinta-60); }
.lib-tabs button.active { background: var(--ciruela); color: #fff; border-color: var(--ciruela); }
.text-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.text-card { cursor: pointer; display: flex; flex-direction: column; overflow: hidden; transition: transform .1s, box-shadow .15s; }
.text-card:hover { transform: translateY(-3px); box-shadow: 0 10px 30px rgba(33,29,46,.12); }
.text-card .tc-body { padding: 1rem 1.2rem 1.2rem; display: flex; flex-direction: column; flex: 1; }
.thumb { height: 92px; display: flex; align-items: center; justify-content: center; position: relative; color: #fff; }
.thumb > span:first-child { font-family: var(--serif); font-size: 2.6rem; font-weight: 600; opacity: .92; }
.thumb-principiante { background: linear-gradient(135deg, #2E9E7B, #53b596); }
.thumb-intermedio { background: linear-gradient(135deg, #C98A2A, #e0a63f); }
.thumb-avanzado { background: linear-gradient(135deg, #7A3B8F, #a059b4); }
.thumb-new { position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,.42); color: #fff; font-size: .72rem; font-weight: 700; padding: .18rem .5rem; border-radius: 999px; }
.text-card .cat { font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--ciruela); }
.text-card h3 { font-size: 1.2rem; margin: .4rem 0 .5rem; }
.text-card .excerpt { color: var(--tinta-60); font-size: .92rem; flex: 1; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.text-meta { display: flex; gap: .6rem; align-items: center; margin-top: 1rem; font-size: .8rem; color: var(--tinta-60); flex-wrap: wrap; }
.badge { padding: .2rem .6rem; border-radius: 999px; font-weight: 600; font-size: .75rem; }
.badge.principiante { background: var(--jade-100); color: #1d6e55; }
.badge.intermedio { background: #fef0d6; color: #9a6a12; }
.badge.avanzado { background: #f6e0e4; color: #a63548; }
.progress-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--jade); display: inline-block; }
.prog-bar { height: 5px; background: var(--linea); border-radius: 999px; margin-top: .8rem; overflow: hidden; }
.prog-bar i { display: block; height: 100%; background: var(--jade); }

/* ====== Lector ====== */
.reader-top { position: sticky; top: 0; z-index: 20; background: rgba(251,247,240,.9); backdrop-filter: blur(8px); border-bottom: 1px solid var(--linea); }
.reader-top-in { max-width: 820px; margin: 0 auto; padding: .7rem 1.2rem; display: flex; align-items: center; gap: .8rem; }
.reader-top h2 { font-size: 1.05rem; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-wrap { max-width: 820px; margin: 0 auto; padding: 1.5rem 1.2rem 7rem; }
.reader-body { font-family: var(--serif); font-size: 1.42rem; line-height: 2.1; }
.reader-body.size-s { font-size: 1.2rem; line-height: 2; }
.reader-body.size-l { font-size: 1.65rem; line-height: 2.15; }
.tok { cursor: pointer; border-radius: 5px; padding: 1px 1px; transition: background .1s; }
.tok.w-nuevo { background: var(--st-nuevo-bg); box-shadow: inset 0 -2px 0 var(--st-nuevo-ln); }
.tok.w-familiar { background: var(--st-fam1-bg); box-shadow: inset 0 -2px 0 #e7bf5a; }
.tok.w-familiar.lvl2 { background: var(--st-fam2-bg); }
.tok.w-familiar.lvl3 { background: var(--st-fam3-bg); }
.tok.w-guardado { background: var(--st-fam1-bg); box-shadow: inset 0 -3px 0 var(--st-guardado-ln); }
.tok.w-conocido { background: transparent; }
.tok:hover { background: var(--ciruela-100); }
.tok.sel { outline: 2px solid var(--ciruela); outline-offset: 1px; }
.reader-body.sv .sv-sentence { position: relative; padding: .5rem .6rem .5rem 2.4rem; border-radius: 10px; margin: .2rem 0; transition: background .12s; }
.reader-body.sv .sv-sentence:hover { background: #fff; box-shadow: var(--sombra); }
.sv-play { position: absolute; left: .5rem; top: 50%; transform: translateY(-50%); border: 0; background: transparent; font-size: 1rem; opacity: .35; cursor: pointer; }
.reader-body.sv .sv-sentence:hover .sv-play { opacity: 1; }
#sentBtn.on, #fontBtn.on { background: var(--ciruela-100); color: var(--ciruela); }
.reader-pager { display: flex; align-items: center; justify-content: space-between; margin-top: 2rem; gap: 1rem; }
.pageinfo { font-size: .9rem; color: var(--tinta-60); }

/* Panel de palabra */
.wordpanel { position: fixed; right: 0; bottom: 0; left: 0; z-index: 40; background: var(--papel-2); border-top: 1px solid var(--linea); box-shadow: 0 -8px 30px rgba(33,29,46,.12); transform: translateY(110%); transition: transform .22s cubic-bezier(.2,.8,.2,1); }
.wordpanel.open { transform: translateY(0); }
.wordpanel-in { max-width: 820px; margin: 0 auto; padding: 1.2rem 1.2rem 1.4rem; }
.wp-head { display: flex; align-items: center; gap: .8rem; }
.wp-term { font-family: var(--serif); font-size: 1.8rem; font-weight: 600; }
.wp-speak { width: 42px; height: 42px; border-radius: 50%; border: 1.5px solid var(--linea); background: #fff; display: grid; place-items: center; font-size: 1.1rem; }
.wp-speak:hover { border-color: var(--ciruela); background: var(--ciruela-100); }
.wp-trans { font-size: 1.15rem; margin: .7rem 0; color: var(--tinta); min-height: 1.4em; }
.wp-trans .loading { color: var(--tinta-30); font-style: italic; }
.wp-context { font-size: .92rem; color: var(--tinta-60); font-style: italic; border-left: 3px solid var(--ambar); padding-left: .8rem; margin: .6rem 0 1rem; }
.status-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.status-btn { flex: 1; min-width: 92px; padding: .6rem; border-radius: var(--radio-s); border: 1.5px solid var(--linea); background: #fff; font-weight: 600; font-size: .88rem; display: flex; flex-direction: column; align-items: center; gap: .2rem; }
.status-btn .d { width: 12px; height: 12px; border-radius: 50%; }
.status-btn[data-s="nuevo"] .d { background: var(--st-nuevo-ln); }
.status-btn[data-s="familiar"] .d { background: #e7bf5a; }
.status-btn[data-s="conocido"] .d { background: var(--jade); }
.status-btn[data-s="guardado"] .d { background: var(--ciruela); }
.status-btn.active { border-color: var(--ciruela); background: var(--ciruela-100); color: var(--ciruela-700); }
.wp-close { position: absolute; top: .8rem; right: 1rem; background: none; border: 0; font-size: 1.4rem; color: var(--tinta-30); }

/* ====== Repaso ====== */
.review-stage { max-width: 560px; margin: 2rem auto; text-align: center; }
.flashcard { background: var(--papel-2); border: 1px solid var(--linea); border-radius: 22px; box-shadow: var(--sombra); padding: 3rem 2rem; min-height: 260px; display: flex; flex-direction: column; justify-content: center; align-items: center; }
.flashcard .term { font-family: var(--serif); font-size: 2.6rem; font-weight: 600; }
.flashcard .answer { margin-top: 1.2rem; font-size: 1.4rem; color: var(--ciruela); }
.flashcard .ctx { margin-top: 1rem; font-size: .95rem; color: var(--tinta-60); font-style: italic; }
.grade-row { display: flex; gap: .5rem; margin-top: 1.4rem; }
.grade-row button { flex: 1; padding: .8rem .4rem; border-radius: var(--radio-s); border: 0; font-weight: 700; font-size: .9rem; color: #fff; }
.g0 { background: #d1485b; } .g1 { background: #e08a2b; } .g2 { background: #2e9e7b; } .g3 { background: #3b86c9; }
.review-progress { font-size: .9rem; color: var(--tinta-60); margin-bottom: 1rem; }

/* ====== Estadísticas ====== */
.bars { display: flex; align-items: flex-end; gap: 4px; height: 160px; padding: 1rem 0; }
.bars .b { flex: 1; background: var(--ciruela-100); border-radius: 4px 4px 0 0; position: relative; min-height: 2px; }
.bars .b i { position: absolute; bottom: 0; left: 0; right: 0; background: var(--ciruela); border-radius: 4px 4px 0 0; }
.legend { display: flex; gap: 1.2rem; flex-wrap: wrap; margin-top: .5rem; font-size: .85rem; color: var(--tinta-60); }
.legend span { display: inline-flex; align-items: center; gap: .4rem; }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; }
.vocab-bar { display: flex; height: 26px; border-radius: 999px; overflow: hidden; border: 1px solid var(--linea); }
.vocab-bar div { display: flex; align-items: center; justify-content: center; color: #fff; font-size: .75rem; font-weight: 700; }

/* ====== Modal ====== */
.modal-bg { position: fixed; inset: 0; background: rgba(33,29,46,.5); display: grid; place-items: center; z-index: 60; padding: 1rem; }
.modal { background: var(--papel-2); border-radius: var(--radio); width: 100%; max-width: 480px; padding: 1.6rem; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal h3 { font-size: 1.4rem; }
.modal-actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1.2rem; }

/* ====== Toast ====== */
.toast { position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%); background: var(--tinta); color: #fff; padding: .7rem 1.2rem; border-radius: 999px; font-size: .92rem; z-index: 80; box-shadow: 0 8px 24px rgba(0,0,0,.25); }

/* ====== Empty ====== */
.empty { text-align: center; padding: 3rem 1rem; color: var(--tinta-60); }
.empty .big-emoji { font-size: 3rem; display: block; margin-bottom: .6rem; }

/* ====== Responsive ====== */
@media (max-width: 860px) {
  .landing { grid-template-columns: 1fr; }
  .landing .panel { border-left: 0; border-top: 1px solid var(--linea); }
  .nav { display: none; }
  .reader-body { font-size: 1.25rem; line-height: 1.95; }
}
.mobile-nav { display: none; }
@media (max-width: 860px) {
  .mobile-nav { display: flex; position: fixed; bottom: 0; left: 0; right: 0; background: var(--papel-2); border-top: 1px solid var(--linea); z-index: 50; }
  .mobile-nav a { flex: 1; text-align: center; padding: .6rem; font-size: .7rem; color: var(--tinta-60); display: flex; flex-direction: column; align-items: center; gap: .15rem; }
  .mobile-nav a.active { color: var(--ciruela); }
  .mobile-nav a .mi { font-size: 1.3rem; }
  .page { padding-bottom: 5.5rem; }
}
