/* ── Custom Properties ────────────────────────────────────────────────────── */
:root {
  --bg:          #0d0d1a;
  --card:        #16162a;
  --surface:     #1e1e38;
  --border:      #2a2a4a;
  --accent:      #7c6af5;
  --accent-dim:  rgba(124, 106, 245, 0.15);
  --text:        #dde1f0;
  --muted:       #7a84a0;
  --success:     #22c55e;
  --success-bg:  rgba(34, 197, 94, 0.12);
  --error:       #ef4444;
  --error-bg:    rgba(239, 68, 68, 0.12);
  --warning:     #f59e0b;
  --warning-bg:  rgba(245, 158, 11, 0.12);
  --blue:        #60a5fa;
  --blue-bg:     rgba(96, 165, 250, 0.12);
  --radius:      16px;
  --radius-sm:   10px;
}

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

html, body { height: 100%; overscroll-behavior: none; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── App Shell ────────────────────────────────────────────────────────────── */
#app {
  height: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
}

#screen-home,
#screen-study,
#screen-done,
#screen-settings {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#screen-home { overflow: hidden; }

/* ── Home ─────────────────────────────────────────────────────────────────── */
.home-header {
  padding: 2rem 1.5rem 0.75rem;
  text-align: center;
  flex-shrink: 0;
}

.home-title {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-bottom: 0.5rem;
}

.title-khmer {
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
  letter-spacing: 0.05em;
}

.title-sub {
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.today-count {
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}

/* ── Lektions-Liste ───────────────────────────────────────────────────────── */
.lesson-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.lektion-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.8rem 1rem;
  border-radius: var(--radius);
  border: 1.5px solid var(--border);
  background: var(--surface);
  text-align: left;
  width: 100%;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  font-family: inherit;
  font-size: inherit;
  color: var(--text);
}

.lektion-card--active {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.lektion-card--active:active { background: rgba(124, 106, 245, 0.25); }

.lektion-card--mastered {
  border-color: var(--success);
  background: var(--success-bg);
}
.lektion-card--mastered:active { background: rgba(34, 197, 94, 0.2); }

.lektion-card--locked {
  opacity: 0.38;
  cursor: pointer;
}

.lektion-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex: 1;
  min-width: 0;
}

.lektion-num {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.04em;
  flex-shrink: 0;
  width: 22px;
}
.lektion-card--active  .lektion-num { color: var(--accent); }
.lektion-card--mastered .lektion-num { color: var(--success); }

.lektion-info {
  display: flex;
  flex-direction: column;
  gap: 0.12rem;
  min-width: 0;
}

.lektion-name {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lektion-desc {
  font-size: 0.73rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lektion-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.3rem;
  flex-shrink: 0;
}

.lektion-status {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
}
.lektion-status--done   { color: var(--success); font-size: 1.05rem; }
.lektion-status--locked { font-size: 0.85rem; }

.lektion-bar {
  width: 56px;
  height: 4px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}
.lektion-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
  transition: width 0.3s;
}
.lektion-card--mastered .lektion-fill { background: var(--success); }

/* ── Home Footer ──────────────────────────────────────────────────────────── */
.home-footer {
  padding: 0.6rem 1rem 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  flex-shrink: 0;
}

.btn-wiederholung {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.65rem 1.5rem;
  min-height: 48px;
  width: 100%;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  font-family: inherit;
}
.btn-wiederholung.has-due {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}
.btn-wiederholung.has-due:active { background: rgba(124, 106, 245, 0.25); }
.btn-wiederholung:disabled { opacity: 0.35; cursor: default; }

.home-footer-row {
  display: flex;
  gap: 0.45rem;
}
.home-footer-row .btn-ghost { flex: 1; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn-ghost {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.6rem 1.5rem;
  min-height: 48px;
  transition: border-color 0.15s, color 0.15s;
}
.btn-ghost:active { color: var(--text); border-color: var(--accent); }

a.btn-ghost {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  text-decoration: none;
  line-height: 1.3;
}

.btn-back {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0.5rem 0.75rem;
  min-height: 48px;
  min-width: 80px;
  text-align: left;
  transition: color 0.15s;
}
.btn-back:active { color: var(--text); }

.btn-primary {
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  padding: 0.75rem 1.5rem;
  min-height: 52px;
  transition: opacity 0.15s;
}
.btn-primary:active { opacity: 0.85; }

.btn-reveal {
  display: block;
  width: calc(100% - 2rem);
  margin: 0.75rem 1rem 0;
  background: var(--surface);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--accent);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  min-height: 56px;
  flex-shrink: 0;
  transition: background 0.15s;
}
.btn-reveal:active { background: var(--accent-dim); }

.btn-danger {
  background: var(--error-bg);
  border: 1.5px solid var(--error);
  border-radius: var(--radius-sm);
  color: var(--error);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 0.75rem 1.25rem;
  min-height: 52px;
  transition: background 0.15s;
}
.btn-danger:active { background: rgba(239,68,68,0.25); }

/* ── Study Screen ─────────────────────────────────────────────────────────── */
.study-header {
  display: flex;
  align-items: center;
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid var(--border);
  min-height: 56px;
  flex-shrink: 0;
}

.mode-label {
  flex: 1;
  font-size: 0.8rem;
  color: var(--muted);
  text-align: center;
  padding: 0 0.5rem;
}

.queue-progress {
  font-size: 0.8rem;
  color: var(--muted);
  min-width: 60px;
  text-align: right;
  padding-right: 0.5rem;
}

/* Alle Karten-Container füllen den verfügbaren Platz als Flex-Spalte */
#card-phase1,
#card-flip,
#card-mc,
#card-zahlen {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

/* ── Phasen-Badge ─────────────────────────────────────────────────────────── */
.phase-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 0.25rem 0.65rem;
  border-radius: 99px;
  align-self: center;
  flex-shrink: 0;
}

.phase-neu        { background: rgba(96, 165, 250, 0.15); color: #60a5fa; }
.phase-erkennen   { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.phase-wiederholen{ background: rgba(34, 197, 94, 0.15);  color: #22c55e; }

/* ── Karte ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  margin: 0.75rem 1rem;
  padding: 1.5rem 1.5rem 1.75rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 180px;
  flex: 1;
  gap: 1rem;
  position: relative;  /* Für absolut positionierten ▶-Button */
}

/* ▶ Aussprache-Button, oben rechts in der Karte */
.btn-audio {
  position: absolute;
  top: 0.7rem;
  right: 0.7rem;
  width: 34px;
  height: 34px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 50%;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.btn-audio:active { background: var(--accent-dim); border-color: var(--accent); }

.card-label {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.card-main {
  font-size: clamp(1.4rem, 6vw, 2.2rem);
  font-weight: 700;
  line-height: 1.3;
  color: var(--text);
  word-break: break-word;
}

.card-khmer {
  /* Systemschriften mit Khmer-Unterstützung auf Android/iOS/macOS/Windows –
     keine externe Schrift nötig, Browser fallen bei fehlender Abdeckung
     ohnehin automatisch auf eine vorhandene Khmer-fähige Schrift zurück. */
  font-family: 'Noto Sans Khmer', 'Khmer Sangam MN', 'Leelawadee UI', sans-serif;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--muted);
  margin-top: -0.6rem;
  word-break: break-word;
}
.khmer-hidden .card-khmer { display: none; }

.card-answer {
  font-size: clamp(1.1rem, 4.5vw, 1.7rem);
  font-weight: 600;
  color: var(--accent);
  padding-top: 1.1rem;
  border-top: 1px solid var(--border);
  width: 100%;
  text-align: center;
}

/* ── Phase 1: Einprägen ───────────────────────────────────────────────────── */
.phase1-actions {
  display: flex;
  gap: 0.75rem;
  padding: 0 1rem;
  flex-shrink: 0;
}

.btn-phase1-again {
  flex: 1;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  min-height: 60px;
  transition: border-color 0.15s;
}
.btn-phase1-again:active { border-color: var(--accent); color: var(--text); }

.btn-phase1-got {
  flex: 2;
  background: var(--success-bg);
  border: 1.5px solid var(--success);
  border-radius: var(--radius-sm);
  color: var(--success);
  cursor: pointer;
  font-size: 1rem;
  font-weight: 700;
  min-height: 60px;
  transition: background 0.15s;
}
.btn-phase1-got:active { background: rgba(34, 197, 94, 0.25); }

/* ── Bewertungs-Buttons ───────────────────────────────────────────────────── */
.rating-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  padding: 0.75rem 1rem 0;
  flex-shrink: 0;
}

.rating-btn {
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 700;
  min-height: 56px;
  padding: 0.5rem 0.2rem;
  transition: opacity 0.15s;
  letter-spacing: 0.01em;
  line-height: 1.2;
}
.rating-btn:active { opacity: 0.75; }

.rating-wrong { background: var(--error-bg);   color: var(--error);   }
.rating-hard  { background: var(--warning-bg); color: var(--warning); }
.rating-good  { background: var(--success-bg); color: var(--success); }
.rating-easy  { background: var(--blue-bg);    color: var(--blue);    }

/* ── Multiple Choice ──────────────────────────────────────────────────────── */
.mc-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  padding: 0 1rem;
  flex-shrink: 0;
}

.mc-option {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  min-height: 72px;
  padding: 0.75rem;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
  line-height: 1.35;
}
.mc-option:not([disabled]):active { border-color: var(--accent); background: var(--accent-dim); }
.mc-option.correct { background: var(--success-bg); border-color: var(--success); color: var(--success); font-weight: 700; }
.mc-option.wrong   { background: var(--error-bg);   border-color: var(--error);   color: var(--error);   }

/* ── Zahlen-Drill ─────────────────────────────────────────────────────────── */
.zahlen-row {
  display: flex;
  gap: 0.6rem;
  padding: 0 1rem;
  flex-shrink: 0;
}

#zahlen-input {
  flex: 1;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1.6rem;
  font-weight: 700;
  padding: 0.6rem 1rem;
  text-align: center;
  -moz-appearance: textfield;
}
#zahlen-input::-webkit-outer-spin-button,
#zahlen-input::-webkit-inner-spin-button { -webkit-appearance: none; }
#zahlen-input:focus { outline: none; border-color: var(--accent); }

.btn-submit { flex-shrink: 0; padding: 0.6rem 1.5rem; font-size: 1.2rem; }

.zahlen-feedback {
  font-size: 0.95rem;
  font-weight: 600;
  min-height: 2.5rem;
  padding: 0.5rem 1rem 0;
  text-align: center;
  flex-shrink: 0;
}
.zahlen-feedback.correct { color: var(--success); }
.zahlen-feedback.wrong   { color: var(--error);   }

.study-counter { padding: 0.75rem 1rem 1rem; flex-shrink: 0; }

/* ── Done Screen ──────────────────────────────────────────────────────────── */
.done-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  flex: 1;
  padding: 2rem;
  text-align: center;
}

.done-check  { font-size: 3.5rem; line-height: 1; color: var(--success); }
.done-title  { font-size: 1.5rem; font-weight: 700; }

.done-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 320px;
  margin-top: 0.5rem;
}

.done-menu-link {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0.5rem;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.done-coffee-link {
  font-size: 0.78rem;
  opacity: 0.75;
  margin-top: -0.5rem;
}
.done-coffee-link:active { opacity: 1; }

.home-coffee-link {
  text-align: center;
  font-size: 0.78rem;
  opacity: 0.75;
}
.home-coffee-link:active { opacity: 1; }

/* ── Einstellungen ────────────────────────────────────────────────────────── */
.settings-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid var(--border);
  min-height: 56px;
  flex-shrink: 0;
}
.settings-header h2 { font-size: 1.1rem; font-weight: 700; }

.settings-body { flex: 1; overflow-y: auto; padding: 0.5rem 1rem 2rem; }

.settings-section {
  padding: 1.25rem 0;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.settings-section h3 {
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.settings-hint { font-size: 0.85rem; color: var(--muted); }

.backup-status {
  margin-top: 0.5rem;
  color: var(--error);
}

.settings-toggle {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.95rem;
  cursor: pointer;
  padding: 0.4rem 0;
  min-height: 40px;
}
.settings-toggle input[type="checkbox"] {
  width: 20px; height: 20px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.settings-input {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 1.1rem;
  padding: 0.6rem 1rem;
  max-width: 120px;
}
.settings-input:focus { outline: none; border-color: var(--accent); }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  z-index: 100;
}

.modal-box {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 340px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-text {
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.5;
  margin-bottom: 1.25rem;
}

.modal-hint {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.45;
  margin-top: -0.75rem;
  margin-bottom: 1.25rem;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
}
.modal-actions .btn-ghost,
.modal-actions .btn-primary,
.modal-actions .btn-danger {
  flex: 1;
  min-height: 48px;
  padding: 0.6rem 1rem;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (min-width: 480px) {
  #app { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}
@media (min-height: 700px) {
  .home-header { padding-top: 3.5rem; }
}
