/* ---------- Self-hosted fonts (no external requests, ever) ---------- */
@font-face {
  font-family: 'Inter';
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url('/fonts/inter-variable-latin.woff2') format('woff2-variations');
}
@font-face {
  font-family: 'Playfair Display';
  font-style: normal;
  font-weight: 400 900;
  font-display: swap;
  src: url('/fonts/playfair-display-variable-latin.woff2') format('woff2-variations');
}

/* ---------- Design tokens ----------
   Palette is deliberately built on rojo y gualda — the red and gold of the
   Spanish flag — rather than a generic "Mediterranean" terracotta, so the
   Spanish identity reads immediately without needing a cultural footnote. */
:root {
  --rojo: #c8102e;
  --rojo-dark: #93081f;
  --gualda: #e8a930;
  --gualda-dark: #b9820f;
  --olive: #5c7a4f;
  --wine: #7a2331;
  --cream: #fbf3e6;
  --cream-deep: #f3e4cc;
  --ink: #2c2019;

  --bg: var(--cream);
  --bg-elevated: #fffaf1;
  --text: var(--ink);
  --text-muted: #6b5c4d;
  --border: #e6d3b3;
  --accent: var(--rojo);
  --accent-contrast: #fff;
  --accent-2: var(--gualda-dark);
  --success: var(--olive);
  --success-bg: #e7efdf;
  --error: var(--wine);
  --error-bg: #f5e0e2;
  --radius: 18px;
  --shadow: 0 8px 24px rgba(80, 45, 20, 0.12), 0 2px 6px rgba(80, 45, 20, 0.08);
  --font-display: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

:root[data-theme='dark'] {
  --bg: #21120f;
  --bg-elevated: #2c1a16;
  --text: #f4e9db;
  --text-muted: #c9a98f;
  --border: #4a2b26;
  --cream-deep: #3a211c;
  --accent: #e8495f;
  --accent-contrast: #2a0d12;
  --accent-2: #f0bf5c;
  --success: #8fb87a;
  --success-bg: #2c3924;
  --error: #e2837a;
  --error-bg: #3f2622;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #21120f;
    --bg-elevated: #2c1a16;
    --text: #f4e9db;
    --text-muted: #c9a98f;
    --border: #4a2b26;
    --cream-deep: #3a211c;
    --accent: #e8495f;
    --accent-contrast: #2a0d12;
    --accent-2: #f0bf5c;
    --success: #8fb87a;
    --success-bg: #2c3924;
    --error: #e2837a;
    --error-bg: #3f2622;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.45);
  }
}

* {
  box-sizing: border-box;
}

/* Author-stylesheet display rules below (form { display: flex }, etc.) would
   otherwise beat the UA [hidden] rule regardless of specificity, since
   author-normal always wins over UA-normal in the cascade. Force it back. */
[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* Decorative strip in the flag colors: a small repeating diagonal band,
   built purely from CSS gradients — no image requests. */
.flag-strip {
  height: 10px;
  width: 100%;
  background-image: repeating-linear-gradient(
    45deg,
    var(--rojo) 0 6px,
    var(--gualda) 6px 12px
  );
  opacity: 0.9;
}

#app {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  max-width: 560px;
  margin: 0 auto;
  position: relative;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 10px;
  gap: 12px;
}

.brand {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.5rem;
  margin: 0;
  letter-spacing: 0.01em;
  color: var(--text);
}
.brand span {
  color: var(--accent);
  font-style: italic;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.9rem;
  color: var(--text-muted);
  min-width: 0;
}

#user-badge {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 45vw;
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  padding: 6px;
  line-height: 1;
  border-radius: 10px;
}
.icon-btn:hover {
  background: var(--cream-deep);
}

.view {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 8px 20px 32px;
  gap: 20px;
}
.view[hidden] {
  display: none;
}

/* ---------- Buttons & inputs ---------- */
button {
  font-family: var(--font-body);
  cursor: pointer;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 999px;
  padding: 15px 28px;
  font-size: 1.05rem;
  font-weight: 600;
  min-height: 52px;
  transition: transform 0.08s ease, box-shadow 0.15s ease, opacity 0.15s ease;
}
.btn:active {
  transform: scale(0.97);
}
.btn-primary {
  background: var(--accent);
  color: var(--accent-contrast);
  box-shadow: 0 4px 14px rgba(193, 82, 46, 0.35);
  width: 100%;
}
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-secondary {
  background: transparent;
  color: var(--accent-2);
  border: 2px solid var(--accent-2);
  width: 100%;
}
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  font-weight: 500;
  padding: 10px 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
}
.field input {
  font-family: var(--font-body);
  font-size: 1.1rem;
  padding: 14px 16px;
  border-radius: 14px;
  border: 2px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  min-height: 52px;
}
.field input:focus {
  outline: none;
  border-color: var(--accent);
}

.error-message {
  background: var(--error-bg);
  color: var(--error);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 500;
}

.success-message {
  background: var(--success-bg);
  color: var(--success);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 500;
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.9rem;
  padding: 4px;
  text-align: center;
  text-decoration: underline;
}

.auth-form-intro {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin: 0;
}

.hero {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 4px;
}
.hero h2 {
  font-family: var(--font-display);
  font-size: 1.8rem;
  margin: 0;
}
.hero-tagline {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin: 0;
  font-style: italic;
}
.hero-lead {
  color: var(--text-muted);
  margin: 0;
  line-height: 1.5;
}
.hero-features {
  list-style: none;
  margin: 4px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
}
.hero-features li {
  font-size: 0.92rem;
  padding-left: 22px;
  position: relative;
}
.hero-features li::before {
  content: '✓';
  position: absolute;
  left: 0;
  color: var(--success);
  font-weight: 700;
}

/* ---------- Auth view ---------- */
#view-auth {
  justify-content: center;
  align-items: stretch;
  gap: 24px;
}
.auth-intro {
  text-align: center;
}
.auth-intro h2 {
  font-family: var(--font-display);
  font-size: 1.6rem;
  margin: 0 0 6px;
}
.auth-intro p {
  color: var(--text-muted);
  margin: 0;
}

.legend {
  font-size: 0.78rem !important;
  line-height: 1.5;
  margin-top: 8px !important;
}

.tabs {
  display: flex;
  background: var(--cream-deep);
  border-radius: 999px;
  padding: 4px;
}
.tabs button {
  flex: 1;
  border: none;
  background: transparent;
  padding: 10px;
  border-radius: 999px;
  font-weight: 600;
  color: var(--text-muted);
}
.tabs button.active {
  background: var(--bg-elevated);
  color: var(--accent);
  box-shadow: var(--shadow);
}

form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------- Levels view ---------- */
.levels-grid {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.level-card {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
  width: 100%;
}
.level-card-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}
.level-name {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 700;
}
.level-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
}
.progress-bar {
  height: 8px;
  border-radius: 999px;
  background: var(--cream-deep);
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--gualda), var(--accent));
  border-radius: 999px;
  transition: width 0.4s ease;
}
.level-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ---------- Exercise view ---------- */
.exercise-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.badge {
  display: inline-block;
  background: var(--accent-2);
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
  letter-spacing: 0.03em;
}
:root[data-theme='dark'] .badge {
  color: var(--accent-contrast);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) .badge {
    color: var(--accent-contrast);
  }
}
.category-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.exercise-scroll {
  display: flex;
  flex-direction: column;
  gap: 20px;
  flex: 1;
}

.exercise-card {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  flex: 1;
}

/* Pinned to the bottom of the viewport so the primary action (Comprobar /
   Siguiente) is always reachable without scrolling, however long the
   sentence or feedback text gets — the single most-tapped control in the
   whole app shouldn't require a scroll-then-tap on every card. */
.action-bar {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  margin: 0 -20px -32px;
  padding: 14px 20px calc(14px + env(safe-area-inset-bottom, 0px));
  z-index: 5;
}

.sentence {
  font-family: var(--font-display);
  font-size: 1.5rem;
  line-height: 1.6;
  margin: 0;
}

.blank-wrap {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  margin: 0 4px;
}

#answer-input {
  font-family: var(--font-body);
  font-size: 1.3rem;
  font-weight: 600;
  text-align: center;
  border: none;
  border-bottom: 3px solid var(--accent);
  background: transparent;
  color: var(--accent);
  width: 11ch;
  padding: 2px 4px 6px;
}
#answer-input:focus {
  outline: none;
  border-bottom-color: var(--accent-2);
}
#answer-input.state-correct {
  color: var(--success);
  border-bottom-color: var(--success);
}
#answer-input.state-incorrect {
  color: var(--error);
  border-bottom-color: var(--error);
}

.infinitive-tag {
  font-family: var(--font-body);
  font-size: 0.72rem;
  color: var(--text-muted);
  font-style: italic;
  margin-top: 2px;
}

.accent-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}
.accent-bar button {
  min-width: 40px;
  min-height: 40px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--cream-deep);
  color: var(--text);
  font-size: 1.05rem;
  font-weight: 600;
}
.accent-bar button:active {
  background: var(--accent);
  color: #fff;
}

.hint-toggle {
  align-self: center;
  font-size: 0.85rem;
  color: var(--accent-2);
  background: none;
  border: none;
  font-weight: 600;
  text-decoration: underline;
  padding: 4px;
}
.hint-box {
  background: var(--cream-deep);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.hint-box[hidden] {
  display: none;
}

/* ---------- Feedback panel ---------- */
.feedback {
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow);
  animation: slide-up 0.25s ease;
}
.feedback.is-correct {
  background: var(--success-bg);
  border: 1px solid var(--success);
}
.feedback.is-incorrect {
  background: var(--error-bg);
  border: 1px solid var(--error);
}
.feedback-headline {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.1rem;
}
.feedback.is-correct .feedback-headline {
  color: var(--success);
}
.feedback.is-incorrect .feedback-headline {
  color: var(--error);
}
.feedback-answer {
  font-size: 0.95rem;
}
.feedback-answer strong {
  font-family: var(--font-display);
  font-size: 1.15rem;
}
.feedback-explanation {
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.feedback-note {
  font-size: 0.82rem;
  color: var(--accent-2);
  font-weight: 600;
}

@keyframes slide-up {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ---------- Stats mini ---------- */
.stats-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}
.stats-pill {
  flex: none;
  background: var(--cream-deep);
  border-radius: 12px;
  padding: 8px 14px;
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}
.stats-pill b {
  color: var(--text);
}

/* ---------- Help ---------- */
.help-content {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 24px 22px 28px;
}
.help-content h2 {
  font-family: var(--font-display);
  font-size: 1.5rem;
  margin: 0 0 16px;
}
.help-content h3 {
  font-family: var(--font-display);
  font-size: 1.1rem;
  color: var(--accent);
  margin: 22px 0 8px;
}
.help-content h3:first-of-type {
  margin-top: 0;
}
.help-content p,
.help-content li {
  font-size: 0.92rem;
  line-height: 1.6;
  color: var(--text);
}
.help-content ul {
  margin: 8px 0;
  padding-left: 20px;
}
.help-content li {
  margin-bottom: 6px;
}
.help-content em {
  font-style: italic;
  color: var(--accent-2);
}

footer.app-footer {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 10px 20px 22px;
}
footer.app-footer p {
  margin: 0 0 8px;
}
.footer-nav {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 14px;
}
.footer-nav .btn-link {
  font-size: 0.72rem;
  text-decoration: underline;
  padding: 2px;
}

@media (min-width: 640px) {
  .sentence {
    font-size: 1.7rem;
  }
}

/* ---------- Bug-report modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(44, 32, 25, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 20;
}
.modal {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  max-width: 420px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.modal h2 {
  font-family: var(--font-display);
  margin: 0;
  font-size: 1.3rem;
}
.modal textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  font-family: var(--font-body);
  font-size: 0.95rem;
  resize: vertical;
  min-height: 100px;
  box-sizing: border-box;
}
.modal textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
