:root {
  --bg: #fcf9f8;
  --paper: #ffffff;
  --ink: #18181b;
  --muted: #71717a;
  --line: #e9e4e2;
  --accent: #cf433f;
  --accent-soft: #fdf0ef;
  --gold: #fbc12d;
  --gold-soft: #fcd46a;
  --ok: #15803d;
  --ok-soft: #dcf3e3;
  --bad: #b91c1c;
  --bad-soft: #fbe1e1;
  --m: #2563eb;
  --f: #dc2626;
  --n: #16a34a;
  --radius: 14px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
}
button { font: inherit; cursor: pointer; color: inherit; }
button:disabled { cursor: default; }
.hidden { display: none !important; }

.top {
  display: flex; flex-wrap: wrap; gap: 16px;
  align-items: center; justify-content: space-between;
  max-width: 880px; margin: 0 auto; padding: 28px 20px 8px;
}
.brand { display: flex; gap: 14px; align-items: center; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--ink); color: var(--bg);
  display: grid; place-items: center;
  font-family: Fraunces, serif; font-weight: 700; font-size: 24px;
}
h1 { font-family: Fraunces, serif; font-size: 26px; margin: 0; }
.sub { margin: 0; color: var(--muted); font-size: 14px; }
h2 { font-family: Fraunces, serif; font-size: 19px; margin: 22px 0 10px; }

.levels { display: flex; gap: 6px; }
.levels button {
  border: 1px solid var(--line); background: var(--paper);
  padding: 7px 14px; border-radius: 999px; font-weight: 600;
}
.levels button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.levels button:disabled { opacity: .45; cursor: not-allowed; }

main { max-width: 880px; margin: 0 auto; padding: 8px 20px 40px; }
.panel {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 20px; padding: 6px 22px 22px;
}
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.link { background: none; border: 0; color: var(--accent); font-weight: 600; padding: 6px 0; }
.chip-actions { display: flex; gap: 12px; }

.chapters { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.chap {
  text-align: left; border: 1px solid var(--line); background: #fff;
  border-radius: 12px; padding: 9px 11px; font-size: 13.5px;
  display: flex; gap: 8px; align-items: flex-start;
}
.chap .n { font-weight: 700; min-width: 32px; color: var(--muted); }
.chap.on { border-color: var(--accent); background: var(--accent-soft); }
.chap.on .n { color: var(--accent); }
.chap .c { color: var(--muted); font-size: 12px; display: block; }
.check { display: flex; gap: 8px; align-items: center; margin-top: 12px; font-size: 14px; color: var(--muted); }

.modes { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.mode {
  border: 1px solid var(--line); background: #fff; border-radius: 12px;
  padding: 12px; text-align: left;
}
.mode b { display: block; font-size: 15px; }
.mode span { color: var(--muted); font-size: 12.5px; }
.mode.on { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }

.options { display: flex; align-items: center; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.opt-label { font-size: 14px; color: var(--muted); min-width: 80px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 8px 12px; font-size: 13.5px; }
.seg button.on { background: var(--ink); color: var(--bg); }

.start-row { margin-top: 22px; }
.count { color: var(--muted); margin: 0; }
.primary {
  background: var(--accent); color: #fff; border: 0;
  padding: 12px 22px; border-radius: 12px; font-weight: 600;
}
.primary:disabled { opacity: .4; }
.secondary {
  background: #fff; border: 1px solid var(--line);
  padding: 11px 18px; border-radius: 12px; font-weight: 600;
}

.progress { flex: 1; height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; min-width: 120px; }
.bar { height: 100%; width: 0; background: var(--accent); transition: width .25s; }
.score { font-size: 14px; color: var(--muted); min-width: 70px; text-align: right; }

#stage { padding-top: 18px; }
.prompt-tag { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.prompt {
  font-family: Fraunces, serif; font-size: 34px; margin: 6px 0 4px;
  word-break: break-word;
}
.hint { color: var(--muted); font-size: 14px; }
.ex { margin-top: 10px; color: var(--muted); font-style: italic; font-size: 14.5px; }
.ex div { margin: 2px 0; }
.g-m { color: var(--m); } .g-f { color: var(--f); } .g-n { color: var(--n); }

.card {
  border: 1px solid var(--line); border-radius: var(--radius);
  min-height: 220px; padding: 26px; background: #fff;
  display: flex; flex-direction: column; justify-content: center; cursor: pointer;
}
.card .answer { border-top: 1px dashed var(--line); margin-top: 14px; padding-top: 14px; }
.card .answer .prompt { font-size: 26px; }
.actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.actions button { flex: 1; min-width: 120px; }
.btn-ok { background: var(--ok-soft); color: var(--ok); border: 1px solid #b9e3c6; padding: 12px; border-radius: 12px; font-weight: 600; }
.btn-bad { background: var(--bad-soft); color: var(--bad); border: 1px solid #f2c2c2; padding: 12px; border-radius: 12px; font-weight: 600; }

.choices { display: grid; gap: 8px; margin-top: 18px; }
.choice {
  text-align: left; background: #fff; border: 1px solid var(--line);
  border-radius: 12px; padding: 13px 15px; font-size: 16px;
}
.choice.ok { background: var(--ok-soft); border-color: var(--ok); }
.choice.bad { background: var(--bad-soft); border-color: var(--bad); }
.arts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 18px; }
.arts .choice { text-align: center; font-weight: 700; font-size: 20px; }

.type-row { display: flex; gap: 8px; margin-top: 18px; }
.type-row input {
  flex: 1; font: inherit; font-size: 18px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff;
}
.umlauts { display: flex; gap: 6px; margin-top: 8px; }
.umlauts button { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 4px 10px; }
.feedback { margin-top: 14px; padding: 12px 14px; border-radius: 12px; }
.feedback.ok { background: var(--ok-soft); color: var(--ok); }
.feedback.bad { background: var(--bad-soft); color: var(--bad); }
.feedback b { color: var(--ink); }

.done { text-align: center; padding: 30px 0 10px; }
.done .big { font-family: Fraunces, serif; font-size: 48px; margin: 0; }
.missed { text-align: left; margin-top: 18px; }
.missed li { margin: 4px 0; }

#search { flex: 1; font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; min-width: 200px; }
.list-ch { font-family: Fraunces, serif; margin: 20px 0 6px; font-size: 17px; }
.list-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 14.5px; }
.list-row .es { color: var(--muted); }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 0 20px 30px; }

@media (max-width: 560px) {
  .prompt { font-size: 28px; }
  .list-row { grid-template-columns: 1fr; gap: 2px; }
}
.ex .tilde { color: var(--accent); font-style: normal; }
.ex .fill, .ctx .fill { color: var(--accent); font-style: normal; }
.ctx { margin-top: 10px; font-size: 16px; font-style: italic; color: var(--muted); line-height: 1.45; }
.alt { margin-top: 6px; font-size: 13px; color: var(--muted); }
.say {
  border: 0; background: none; cursor: pointer;
  font-size: .62em; vertical-align: middle; margin-left: 8px;
  padding: 2px 4px; border-radius: 8px; opacity: .75;
}
.say:hover { opacity: 1; background: var(--accent-soft); }
.list-row .say, .feedback .say, .hint .say { font-size: 14px; }

/* ---------- tutor IA ---------- */
.why {
  display: inline-block; margin-top: 10px; margin-right: 8px;
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  border-radius: 999px; padding: 6px 12px; font-size: 13.5px; font-weight: 600;
}
.feedback .why { display: block; margin-top: 10px; }
.why:hover { border-color: var(--accent); color: var(--accent); }
.chat-fab {
  position: fixed; right: 20px; bottom: 20px; z-index: 50;
  width: 56px; height: 56px; border-radius: 50%; border: 0;
  background: var(--ink); color: #fff; font-size: 24px;
  box-shadow: 0 6px 20px rgba(0,0,0,.18);
}
.chat-panel {
  position: fixed; right: 20px; bottom: 88px; z-index: 50;
  width: min(400px, calc(100vw - 24px)); height: min(560px, calc(100vh - 110px));
  background: var(--paper); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 12px 40px rgba(0,0,0,.18);
  display: flex; flex-direction: column; overflow: hidden;
}
.chat-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.chat-head b { font-family: Fraunces, serif; font-size: 17px; }
.chat-head-actions { display: flex; align-items: center; gap: 10px; }
.chat-x { border: 0; background: none; font-size: 16px; color: var(--muted); }
.chat-lock { padding: 20px 16px; }
.chat-lock p { margin: 0 0 10px; }
.chat-lock input { flex: 1; font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; }
.chat-main { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-ctx { font-size: 12.5px; color: var(--muted); background: var(--accent-soft); padding: 6px 14px; }
.chat-log { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.chat-empty { color: var(--muted); font-size: 14px; margin: auto 0; }
.msg { max-width: 88%; padding: 9px 12px; border-radius: 14px; font-size: 14.5px; line-height: 1.45; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--ink); color: #fff; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; background: #fff; border: 1px solid var(--line); }
.msg p { margin: 0 0 6px; } .msg p:last-child { margin-bottom: 0; }
.msg ul { margin: 4px 0 6px; padding-left: 18px; } .msg li { margin: 2px 0; }
.msg code { background: var(--bg); padding: 1px 4px; border-radius: 4px; }
.typing span { display: inline-block; width: 6px; height: 6px; margin: 0 2px; border-radius: 50%; background: var(--muted); animation: blink 1s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }
.chat-form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.chat-form textarea { flex: 1; resize: none; min-height: 44px; font: inherit; font-size: 15px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; max-height: 120px; }
.chat-form .primary { padding: 0 16px; }
@media (max-width: 560px) {
  .chat-panel { right: 12px; left: 12px; width: auto; bottom: 84px; height: calc(100vh - 100px); }
}

/* ---------- cuentas ---------- */
.top-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.account { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.acct-btn { border: 1px solid var(--ink); background: var(--paper); padding: 7px 14px; border-radius: 999px; font-weight: 600; }
.acct-mail { color: var(--muted); max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal { position: fixed; inset: 0; z-index: 60; background: rgba(31,29,26,.35); display: grid; place-items: center; padding: 16px; }
.modal-card { background: var(--paper); border-radius: 18px; padding: 20px 22px; width: min(440px, 100%); box-shadow: 0 12px 40px rgba(0,0,0,.2); }
.modal-card input { flex: 1; font: inherit; padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px; }
.login-tabs { margin: 4px 0 14px; width: 100%; }
.login-tabs button { flex: 1; }
.login-form { display: flex; flex-direction: column; gap: 10px; }
.login-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; color: var(--muted); }
.login-form input { font: inherit; color: var(--ink); padding: 11px 12px; border: 1px solid var(--line); border-radius: 12px; }
.login-form .primary { margin-top: 4px; }
.login-form .link { align-self: flex-start; font-size: 13.5px; }
.login-ok { color: var(--ok); } .login-err { color: var(--bad); }
.pass-wrap { position: relative; display: flex; }
.pass-wrap input { flex: 1; padding-right: 44px; }
.eye {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  border: 0; background: none; font-size: 17px; padding: 4px 6px; border-radius: 8px;
  opacity: .45; filter: grayscale(1);
}
.eye:hover { opacity: .8; }
.eye.on { opacity: 1; filter: none; }
.srs-info { margin-top: 6px; }

/* ---------- ordenar frase / escribir frase ---------- */
.mode.locked { opacity: .6; }
.order-line {
  min-height: 58px; margin-top: 16px; padding: 10px; border: 2px dashed var(--line); border-radius: 14px;
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; background: #fff;
}
.order-line.ok { border-color: var(--ok); border-style: solid; background: var(--ok-soft); }
.order-line.bad { border-color: var(--bad); border-style: solid; background: var(--bad-soft); }
.order-ph { color: var(--muted); font-size: 14px; }
.order-punct { font-size: 18px; font-weight: 600; margin-left: -4px; }
.order-bank { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 10px;
  padding: 8px 12px; font-size: 17px; box-shadow: 0 2px 0 var(--line);
}
.chip.used { visibility: hidden; }
.order-line .chip { background: var(--paper); }
.sentence-inp {
  width: 100%; margin-top: 16px; font: inherit; font-size: 18px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 12px; resize: vertical; background: #fff;
}
.feedback.ai { color: var(--ink); }
.feedback.ai p { margin: 0 0 6px; } .feedback.ai ul { margin: 4px 0; padding-left: 18px; }

/* ---------- progreso ---------- */
.progress-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.pstat { background: var(--paper); border: 1px solid var(--line); border-radius: 16px; padding: 12px 14px; display: flex; flex-direction: column; }
.pbig { font-family: Fraunces, serif; font-size: 24px; font-weight: 700; }
.plbl { font-size: 12.5px; color: var(--muted); }
.chap-body { flex: 1; min-width: 0; }
.cbar { position: relative; display: block; height: 4px; margin-top: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.cbar-seen, .cbar-m { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 99px; }
.cbar-seen { background: var(--gold-soft); }
.cbar-m { background: var(--ok); }
/* casos */
.case-sent { font-size: 28px; }
.gap { color: var(--accent); border-bottom: 2px solid var(--accent); padding: 0 4px; }
.case-opts { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 10px; margin-top: 18px; }
.case-opts .choice { text-align: center; font-weight: 700; font-size: 19px; }
/* dictado */
.dict-btns { display: flex; gap: 10px; align-items: center; margin: 14px 0 8px; flex-wrap: wrap; }
.dict-play, .dict-slow { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 12px 18px; font-size: 18px; font-weight: 600; }
.dict-play { background: var(--ink); color: #fff; border-color: var(--ink); }
@media (max-width: 560px) { .pbig { font-size: 20px; } .case-sent { font-size: 22px; } }

/* ---------- tamaño de ronda ---------- */
.round-ctl { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 260px; max-width: 520px; }
.round-ctl input[type=range] { flex: 1; accent-color: var(--accent); }
.round-ctl input[type=number] { width: 72px; font: inherit; padding: 7px 8px; border: 1px solid var(--line); border-radius: 10px; text-align: center; }
.round-all { padding: 7px 12px; font-size: 13.5px; white-space: nowrap; }
.round-all.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.round-note { width: 100%; padding-left: 92px; margin-top: -6px; font-size: 12.5px; }
@media (max-width: 560px) { .round-note { padding-left: 0; } }
#levels .lvl-n { font-weight: 400; opacity: .75; }

/* ---------- pantallas anchas: práctica y progreso a la izquierda, capítulos a la derecha ---------- */
.plevels { display: none; }
.plevel { display: grid; grid-template-columns: 34px 1fr 42px; align-items: center; gap: 8px; font-size: 13px; margin-top: 6px; }
.plevel b { font-weight: 600; }
.plevel .pct { text-align: right; color: var(--muted); }
.plevel .cbar { margin: 0; height: 6px; }
@media (min-width: 1100px) {
  body:has(#setup:not(.hidden)) .top, main:has(#setup:not(.hidden)) { max-width: 1320px; }
  main:has(#setup:not(.hidden)) {
    display: grid; grid-template-columns: 340px minmax(0, 1fr); column-gap: 16px;
    grid-template-areas: "opts chaps" "prog chaps" "rest chaps";
    grid-template-rows: auto auto 1fr; align-items: start;
  }
  main:has(#setup:not(.hidden)) #setup { display: contents; }
  .setup-opts, .setup-chaps {
    background: var(--paper); border: 1px solid var(--line); border-radius: 20px; padding: 6px 20px 20px;
  }
  .setup-opts { grid-area: opts; }
  .setup-chaps { grid-area: chaps; }
  main:has(#setup:not(.hidden)) #progressBar { grid-area: prog; margin: 14px 0 0; }
  .setup-chaps .chapters { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .setup-opts .modes { grid-template-columns: 1fr 1fr; gap: 6px; }
  .setup-opts .mode { padding: 9px 10px; }
  .setup-opts .mode b { font-size: 14px; }
  .setup-opts .mode span { display: none; }
  .setup-opts .options { flex-direction: column; align-items: stretch; gap: 6px; }
  .setup-opts .seg { display: flex; }
  .setup-opts .seg button { flex: 1; padding: 8px 6px; }
  .setup-opts .round-ctl { min-width: 0; max-width: none; flex-wrap: wrap; }
  .setup-opts .round-ctl input[type=range] { flex: 1 1 100%; }
  .setup-opts .round-all { flex: 1; }
  .setup-opts .round-note { padding-left: 0; margin-top: 0; }
  .setup-opts .start-row { flex-direction: column; align-items: stretch; margin-top: 18px; }
  .setup-opts .start-row .primary { width: 100%; }
  main:has(#setup:not(.hidden)) .progress-strip { grid-template-columns: 1fr 1fr; }
  main:has(#setup:not(.hidden)) .pstat-lvl { display: none; }
  main:has(#setup:not(.hidden)) .plevels { display: block; grid-column: 1 / -1; background: var(--paper); border: 1px solid var(--line); border-radius: 16px; padding: 10px 14px 12px; }
  .plevels .plbl { display: block; }
}
