/* Konjuga — warm, readable, mobile-first */

:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --ink: #2b2620;
  --muted: #6f675c;
  --line: #e5ddd0;
  --brand: #c0392b;
  --brand-ink: #ffffff;
  --brand-soft: #fbeae7;
  --gold: #b8860b;
  --ok: #2e7d32;
  --ok-soft: #e8f5e9;
  --warn: #9a6b00;
  --warn-soft: #fff8e1;
  --bad: #c62828;
  --bad-soft: #fdecea;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(43, 38, 32, .08), 0 4px 14px rgba(43, 38, 32, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1d1a16;
    --surface: #292420;
    --ink: #f0eae1;
    --muted: #a89e90;
    --line: #3d362e;
    --brand: #e05a4a;
    --brand-soft: #3a2723;
    --gold: #d9a520;
    --ok: #66bb6a;
    --ok-soft: #223a25;
    --warn: #e0b23e;
    --warn-soft: #3a3320;
    --bad: #ef6e63;
    --bad-soft: #402625;
    --shadow: 0 1px 3px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.55;
}

main {
  max-width: 880px;
  margin: 0 auto;
  padding: 1.25rem 1rem 4rem;
}

h1 { font-size: 1.7rem; line-height: 1.25; }
h1 em { color: var(--brand); font-style: italic; }
h2 { font-size: 1.2rem; margin: 1.6rem 0 .7rem; }
h3 { font-size: 1.02rem; margin: .9rem 0 .4rem; }

/* ---------- top bar ---------- */

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  gap: .5rem; flex-wrap: wrap;
  padding: .6rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand {
  font-size: 1.05rem; font-weight: 700;
  background: none; border: none; color: var(--ink); cursor: pointer;
}

.topbar-stats { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.stat { font-size: .85rem; color: var(--muted); white-space: nowrap; }
.stat #xp, .stat #streak { color: var(--ink); font-weight: 700; }
.level-badge {
  background: var(--brand-soft); color: var(--brand);
  font-weight: 700; padding: .15rem .6rem; border-radius: 999px;
}

/* ---------- hero ---------- */

.hero { padding: 1.4rem 0 .4rem; }
.hero p { color: var(--muted); margin: .6rem 0 1rem; max-width: 46rem; }

/* ---------- buttons ---------- */

.btn {
  font: inherit; cursor: pointer;
  border-radius: 10px; border: 1px solid transparent;
  padding: .5rem 1rem; font-weight: 600;
  transition: filter .12s, transform .05s;
}
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost {
  background: transparent; color: var(--ink); border-color: var(--line);
}
.btn.ghost:hover { background: var(--brand-soft); }
.btn.big { padding: .7rem 1.3rem; font-size: 1rem; }
.btn.small { padding: .3rem .7rem; font-size: .85rem; }
.hidden { display: none !important; }

/* ---------- level picker ---------- */

.level-picker {
  display: grid; gap: .6rem;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.level-chip {
  font: inherit; cursor: pointer; text-align: left;
  background: var(--surface); color: var(--ink);
  border: 2px solid var(--line); border-radius: var(--radius);
  padding: .7rem .8rem;
  display: flex; flex-direction: column; gap: .1rem;
  transition: border-color .15s, background .15s;
}
.level-chip:hover { border-color: var(--brand); }
.level-chip.selected { border-color: var(--brand); background: var(--brand-soft); }
.chip-cefr { font-weight: 800; font-size: 1.15rem; color: var(--brand); }
.chip-name { font-weight: 600; }
.chip-duo { font-size: .75rem; color: var(--muted); }

/* ---------- cards / topics ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem;
}

.topic-grid {
  display: grid; gap: .9rem;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.topic-head { display: flex; align-items: center; gap: .5rem; }
.topic-icon { font-size: 1.3rem; }
.topic-level-desc { color: var(--muted); font-size: .88rem; margin: .4rem 0 .7rem; }
.acc-text { color: var(--muted); font-size: .8rem; margin: .35rem 0 .8rem; }
.card-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.drill-card { border-style: dashed; }
.hint { color: var(--muted); }

/* ---------- progress bars ---------- */

.progress-track {
  height: 8px; border-radius: 999px;
  background: var(--line); overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0;
  background: var(--brand);
  border-radius: 999px;
  transition: width .3s ease;
}
.big-track { margin: .6rem 0 1rem; }

/* ---------- lesson ---------- */

.lesson-body { margin: .8rem 0 1.2rem; overflow-x: auto; }
.lesson-body p { margin: .5rem 0; }
.lesson-body ul { margin: .5rem 0 .5rem 1.3rem; }
.lesson-body table {
  border-collapse: collapse; margin: .6rem 0; width: 100%; min-width: 340px;
  font-size: .92rem;
}
.lesson-body th, .lesson-body td {
  border: 1px solid var(--line); padding: .35rem .6rem; text-align: left;
}
.lesson-body th { background: var(--brand-soft); color: var(--brand); }

/* ---------- practice ---------- */

.practice-head {
  display: flex; align-items: center; gap: .8rem; flex-wrap: wrap;
  margin-top: .6rem;
}
.practice-head h2 { margin: 0; flex: 1; font-size: 1.05rem; }
.practice-progress { color: var(--muted); font-variant-numeric: tabular-nums; }

.question-card { margin-bottom: 1rem; }
.question { font-size: 1.15rem; margin-bottom: .9rem; }

.choices { display: grid; gap: .55rem; }
.choice {
  font: inherit; font-size: 1rem; text-align: left; cursor: pointer;
  background: var(--bg); color: var(--ink);
  border: 2px solid var(--line); border-radius: 10px;
  padding: .6rem .9rem;
  transition: border-color .12s, background .12s;
}
.choice:hover:not(:disabled) { border-color: var(--brand); }
.choice:disabled { cursor: default; opacity: .95; }
.choice.correct { border-color: var(--ok); background: var(--ok-soft); }
.choice.wrong { border-color: var(--bad); background: var(--bad-soft); }

.type-row { display: flex; gap: .5rem; flex-wrap: wrap; }
#type-input {
  flex: 1; min-width: 200px;
  font: inherit; font-size: 1.05rem;
  padding: .55rem .8rem;
  border: 2px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink);
}
#type-input:focus { outline: none; border-color: var(--brand); }

.accent-row { display: flex; gap: .35rem; margin-top: .55rem; flex-wrap: wrap; }
.accent-btn {
  font: inherit; font-size: 1rem; cursor: pointer;
  width: 2.2rem; height: 2.2rem;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink);
}
.accent-btn:hover { background: var(--brand-soft); border-color: var(--brand); }

.fb {
  margin-top: .9rem; padding: .7rem .9rem;
  border-radius: 10px; font-size: .95rem;
}
.fb.ok { background: var(--ok-soft); color: var(--ok); }
.fb.almost { background: var(--warn-soft); color: var(--warn); }
.fb.bad { background: var(--bad-soft); color: var(--bad); }

/* ---------- results ---------- */

.results-card { text-align: center; margin-top: 2rem; padding: 2rem 1.4rem; }
.results-card h2 { margin: 0 0 .6rem; font-size: 1.5rem; }
.results-card p { color: var(--muted); max-width: 34rem; margin: 0 auto; }
.results-adaptive { margin: 1rem 0 .2rem; }
.results-actions {
  display: flex; gap: .7rem; justify-content: center; flex-wrap: wrap;
  margin-top: 1.2rem;
}

/* ---------- misc ---------- */

.view { display: none; }
.view.active { display: block; }
.foot { margin-top: 2.5rem; text-align: center; }

/* ---------- account & sync ---------- */

.account-area { display: inline-flex; gap: .4rem; align-items: center; }

#auth-email {
  font: inherit; font-size: 1rem; width: 100%;
  padding: .5rem .8rem; margin: .6rem 0;
  border: 2px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink);
}
#auth-email:focus { outline: none; border-color: var(--brand); }

/* ---------- tense lab / toolkit ---------- */

.lab-intro { color: var(--muted); font-size: .92rem; margin: -.3rem 0 .9rem; max-width: 46rem; }

.lvl-tag {
  display: inline-block; font-size: .68rem; font-weight: 800;
  color: var(--brand); background: var(--brand-soft);
  border-radius: 6px; padding: .05rem .4rem; vertical-align: middle;
}

.toolkit-body { display: grid; gap: .9rem; margin-top: .9rem; }
.tk-section h3 { margin-top: 0; }
.tk-section table { border-collapse: collapse; width: 100%; margin: .5rem 0; font-size: .9rem; }
.tk-section th, .tk-section td { border: 1px solid var(--line); padding: .35rem .6rem; text-align: left; }
.tk-section th { background: var(--brand-soft); color: var(--brand); }
.tk-section ul { margin: .4rem 0 .6rem 1.3rem; }
.tk-acro li { margin: .15rem 0; }
.tk-warn { font-size: .88rem; color: var(--muted); }

/* timeline */
.tl { display: grid; gap: .55rem; margin-top: .7rem; }
.tl-row {
  display: grid; gap: .15rem .8rem; align-items: center;
  grid-template-columns: 10rem 1fr;
}
.tl-name { font-weight: 700; font-size: .88rem; }
.tl-ex { grid-column: 2; color: var(--muted); font-size: .8rem; }
.tl-track {
  position: relative; height: 14px;
  border-bottom: 2px solid var(--line);
}
.tl-now {
  position: absolute; left: 60%; top: -3px; bottom: -6px;
  width: 2px; background: var(--gold);
}
.tl-track::after {
  content: "ahora"; position: absolute; left: 60%; top: -14px;
  transform: translateX(-50%);
  font-size: .6rem; color: var(--gold); font-weight: 700;
}
.tl-dot {
  position: absolute; bottom: -5px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--brand); transform: translateX(-50%);
}
.tl-dot.on-now { left: 60%; }
.tl-dot.faded { opacity: .35; }
.tl-dot.ghost { background: transparent; border: 2px dashed var(--brand); }
.tl-wave, .tl-span {
  position: absolute; bottom: -3px; height: 6px; border-radius: 999px;
}
.tl-wave {
  background: repeating-linear-gradient(90deg, var(--brand) 0 6px, transparent 6px 10px);
}
.tl-span { background: var(--brand); opacity: .55; }
.tl-mood {
  border-bottom: none; font-size: .78rem; color: var(--muted); font-style: italic;
  height: auto;
}
.tl-mood::after { content: none; }

@media (max-width: 560px) {
  .tl-row { grid-template-columns: 1fr; }
  .tl-ex { grid-column: 1; }
}

/* cloze / story mode */
.cloze-title { margin: 0 0 .2rem; }
.cloze-note { color: var(--muted); font-size: .88rem; margin-bottom: .8rem; }
.cloze-text { line-height: 2.3; font-size: 1.05rem; }
.cloze-blank { display: inline-block; white-space: nowrap; margin: 0 .15rem; }
.cloze-blank input {
  font: inherit; font-size: 1rem; width: 9.5rem;
  padding: .15rem .5rem;
  border: none; border-bottom: 2px solid var(--brand);
  border-radius: 6px 6px 0 0;
  background: var(--bg); color: var(--ink); text-align: center;
}
.cloze-blank input:focus { outline: none; background: var(--brand-soft); }
.cloze-hint { color: var(--muted); font-size: .72rem; margin-left: .25rem; }
.cloze-blank input.cloze-ok { border-color: var(--ok); background: var(--ok-soft); color: var(--ok); }
.cloze-blank input.cloze-almost { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); }
.cloze-blank input.cloze-bad { border-color: var(--bad); background: var(--bad-soft); color: var(--bad); }
#cloze-submit { margin-top: .9rem; }
.cloze-misses { margin: .6rem 0 0 1.2rem; font-size: .9rem; }
.cloze-misses li { margin: .25rem 0; }

/* per-blank mistake review */
.cloze-review { margin-top: .8rem; }
.cloze-review-head { margin: 0 0 .4rem; font-size: .95rem; }
.cloze-review-list { margin: 0 0 .6rem 1.2rem; padding: 0; }
.cloze-review-list li {
  margin: 0 0 .7rem; padding: .5rem .7rem;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
}
.cloze-review-list p { margin: .15rem 0; font-size: .9rem; }
.cr-context { color: var(--muted); font-style: italic; }
.cr-hint { font-style: normal; font-size: .8rem; }
.cr-got { color: var(--bad); text-decoration: line-through; }
.cr-ans { color: var(--ok); }
.cr-exp { color: var(--muted); }
.cloze-fixnote { margin: .5rem 0 0; font-size: .88rem; color: var(--muted); }

/* review card highlight */
.review-due { border-color: var(--gold); }

/* make verb endings pop in lesson & toolkit tables (form-focused salience) */
.lesson-body td b, .tk-section td b { color: var(--brand); }

/* sentence-frame drill hint line */
.drill-hint { color: var(--muted); font-weight: 400; display: inline-block; margin-top: .3rem; }
.drill-hint b { color: var(--brand); }

/* ---------- profile & avatars ---------- */

/* Avatars are inline SVG characters on pastel discs; the disc colour comes
   from each avatar's data (AVATARS in app.js), set as an inline background. */

.avatar-btn svg, .avatar-choice svg {
  width: 76%; height: 76%; display: block; pointer-events: none;
  transition: transform 0.15s ease;
}

.avatar-btn {
  font: inherit; cursor: pointer;
  width: 2.5rem; height: 2.5rem;
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--line); border-radius: 50%;
  padding: 0; position: relative; overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), border-color 0.15s, box-shadow 0.15s;
}
.avatar-btn:hover {
  border-color: var(--brand);
  transform: scale(1.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, .45);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.modal-card { max-width: 26rem; width: 100%; }
.modal-hint { font-size: .85rem; margin: .3rem 0 .8rem; }
#profile-name {
  font: inherit; font-size: 1rem; width: 100%;
  padding: .5rem .8rem; margin-bottom: .8rem;
  border: 2px solid var(--line); border-radius: 10px;
  background: var(--bg); color: var(--ink);
}
#profile-name:focus { outline: none; border-color: var(--brand); }
.avatar-grid {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: .5rem;
  margin-bottom: 1rem;
}
.avatar-choice {
  font: inherit; cursor: pointer;
  aspect-ratio: 1;
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--line); border-radius: 50%;
  padding: 0; position: relative; overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275), border-color 0.15s, box-shadow 0.15s;
}
.avatar-choice:hover {
  border-color: var(--brand);
  transform: scale(1.12);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
}
.avatar-choice:hover svg {
  transform: scale(1.12) rotate(5deg);
}
.avatar-choice.selected {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft), 0 4px 12px rgba(0, 0, 0, 0.2);
  animation: av-pulse 2s infinite ease-in-out;
}

/* Bouncy click animation */
.avatar-choice.clicked {
  animation: av-bounce 0.4s ease;
}

@keyframes av-pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--brand-soft), 0 4px 12px rgba(0, 0, 0, 0.2); }
  50% { box-shadow: 0 0 0 5px var(--brand-soft), 0 6px 16px rgba(0, 0, 0, 0.25); }
}

@keyframes av-bounce {
  0% { transform: scale(1); }
  30% { transform: scale(0.85); }
  50% { transform: scale(1.2) rotate(-8deg); }
  75% { transform: scale(0.95) rotate(4deg); }
  100% { transform: scale(1.12); }
}
.modal-actions { justify-content: flex-end; }

/* ---------- question flags ---------- */

.flag-wrap { margin-top: .6rem; }
.flag-link {
  font: inherit; font-size: .8rem; cursor: pointer;
  background: none; border: none; color: var(--muted);
  text-decoration: underline; text-underline-offset: 2px; padding: 0;
}
.flag-link:hover { color: var(--brand); }
.flag-form { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.flag-reason, .flag-comment {
  font: inherit; font-size: .85rem;
  padding: .3rem .5rem;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--ink);
}
.flag-comment { flex: 1; min-width: 140px; }
.flag-done { font-size: .82rem; color: var(--muted); }
.flag-done a { color: var(--brand); }

/* ---------- footer fine print ---------- */

.fineprint { font-size: .75rem; color: var(--muted); margin-top: .8rem; }

/* ---------- tense reference links & popup ---------- */

.tense-link {
  font: inherit; cursor: pointer;
  background: none; border: none; padding: 0;
  color: inherit;
  text-decoration: underline dotted var(--brand);
  text-decoration-thickness: 2px; text-underline-offset: 3px;
}
.tense-link:hover { color: var(--brand); }
.tense-card { max-width: 30rem; }
.tense-card h3 { margin-bottom: .5rem; }
.tense-card p { margin: .45rem 0; font-size: .92rem; }
.tense-en { color: var(--muted); font-weight: 400; font-size: .85rem; }
.tense-irreg { color: var(--warn); font-size: .85rem; }
.endings-title { margin-bottom: .2rem; }
.endings-table {
  border-collapse: collapse; font-size: .9rem; margin: .3rem 0 .5rem;
}
.endings-table th, .endings-table td {
  border: 1px solid var(--line); padding: .25rem .6rem; text-align: left;
}
.endings-table th { color: var(--muted); font-weight: 600; }
.endings-table td:first-child { color: var(--muted); }

/* ---------- progressive hints ---------- */

.hint-area { margin-top: .8rem; }
.hint-item {
  margin-top: .5rem; padding: .55rem .8rem;
  background: var(--brand-soft); border-radius: 10px;
  font-size: .88rem; line-height: 1.45;
}
.hint-xp { font-weight: 400; font-size: .82rem; }
.choice.eliminated { opacity: .35; text-decoration: line-through; }
