/* ============================================================
   LernBox – Karteikarten-Trainer
   Design-Tokens (Light als Basis, Dark via prefers-color-scheme)
   ============================================================ */

:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #eeebe2;
  --text: #21302d;
  --text-muted: #64716d;
  --border: #ddd8cc;
  --primary: #0d7a6f;
  --primary-strong: #0a5f57;
  --primary-soft: #d9efec;
  --accent: #e2963a;
  --danger: #c0453e;
  --danger-soft: #f7e2e0;
  --success: #2e8b57;
  --success-soft: #ddefe4;
  --shadow: 0 2px 10px rgba(33, 48, 45, 0.08);
  --radius: 14px;
  --radius-small: 8px;
  --font: "Manrope", "Segoe UI", system-ui, -apple-system, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14201e;
    --surface: #1d2b29;
    --surface-2: #243532;
    --text: #e8ede9;
    --text-muted: #9cada8;
    --border: #33453f;
    --primary: #3db3a4;
    --primary-strong: #55c7b8;
    --primary-soft: #1c3d38;
    --accent: #e8a959;
    --danger: #e0736b;
    --danger-soft: #3d2725;
    --success: #58b482;
    --success-soft: #21382d;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.55;
}

h1, h2, h3 {
  line-height: 1.2;
  font-weight: 800;
  margin: 0 0 0.5rem;
}

h1 { font-size: 1.7rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.15rem; }

p { margin: 0 0 0.75rem; }

img { max-width: 100%; }

kbd {
  font-family: inherit;
  font-size: 0.78em;
  padding: 0.1em 0.4em;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface-2);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Header / Footer ---------- */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.7rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
  color: var(--text);
}

.brand-name {
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.app-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 1rem;
  margin-top: auto;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
}

.link-button {
  background: none;
  border: none;
  padding: 0.25rem 0.4rem;
  font: inherit;
  color: var(--text-muted);
  text-decoration: underline;
  cursor: pointer;
}

.link-button:hover { color: var(--text); }

/* ---------- Layout ---------- */

#main {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}

.view-center {
  display: flex;
  justify-content: center;
}

.subtitle {
  color: var(--text-muted);
  max-width: 60ch;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1rem;
  min-height: 44px;
  border-radius: var(--radius-small);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}

.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(0.98); }

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn:focus-visible,
.link-button:focus-visible,
input:focus-visible,
textarea:focus-visible,
.flashcard:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.btn-primary:hover { background: var(--primary-strong); }

.btn-ghost {
  background: transparent;
}

.btn-small {
  min-height: 36px;
  padding: 0.35rem 0.7rem;
  font-size: 0.9rem;
}

.btn-success {
  background: var(--success);
  border-color: var(--success);
  color: #ffffff;
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

.btn-danger-ghost {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}

.key-hint {
  font-weight: 400;
  opacity: 0.85;
  font-size: 0.8rem;
}

/* ---------- Statistiken ---------- */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin: 1.25rem 0;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--primary);
}

.stat-label {
  color: var(--text-muted);
  font-size: 0.82rem;
}

.trend-bars {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 26px;
  margin-top: 0.4rem;
}

.trend-bars span {
  flex: 1;
  min-width: 4px;
  border-radius: 2px 2px 0 0;
  background: var(--primary);
  opacity: 0.85;
}

.trend-bars span.trend-empty {
  background: var(--border);
  height: 3px !important;
}

/* ---------- Dashboard ---------- */

.dashboard-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.deck-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.9rem;
}

.deck-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 6px solid var(--primary);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.deck-card-top {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
}

.deck-card-emoji { font-size: 1.6rem; }

.deck-card-title {
  font-weight: 800;
  font-size: 1.05rem;
}

.deck-card-desc {
  color: var(--text-muted);
  font-size: 0.88rem;
  margin: 0;
}

.deck-card-due {
  font-size: 0.9rem;
}

.deck-card-due strong { color: var(--primary); }

.box-bars {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 34px;
}

.box-bar {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  gap: 2px;
  font-size: 0.62rem;
  color: var(--text-muted);
}

.box-bar i {
  display: block;
  width: 100%;
  min-height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--primary);
  opacity: 0.8;
}

.deck-card-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.empty-hint {
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: 1rem;
}

/* ---------- Deck-Detail ---------- */

.deck-header {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  margin: 1rem 0 0.75rem;
}

.deck-emoji-big { font-size: 2.2rem; }

.deck-desc { color: var(--text-muted); margin: 0; }

.deck-meta {
  color: var(--text-muted);
  font-size: 0.82rem;
  margin: 0.15rem 0 0;
}

.deck-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
}

.search-row { margin-bottom: 0.75rem; }

input, textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  padding: 0.55rem 0.7rem;
  width: 100%;
}

input[type="color"] {
  padding: 0.15rem;
  height: 44px;
  cursor: pointer;
}

input[type="file"] { padding: 0.4rem; }

textarea { resize: vertical; }

.card-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.card-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.card-row-main {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.card-row-front { font-weight: 700; white-space: pre-wrap; }
.card-row-back { color: var(--text-muted); white-space: pre-wrap; }

.card-row-hint {
  color: var(--accent);
  font-size: 0.82rem;
}

.card-row-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.box-badge {
  background: var(--primary-soft);
  color: var(--primary-strong);
  border-radius: 99px;
  padding: 0.1rem 0.6rem;
  font-weight: 700;
}

.box-badge.due-now {
  background: var(--accent);
  color: #ffffff;
}

.card-row-actions {
  margin-left: auto;
  display: flex;
  gap: 0.35rem;
}

/* ---------- Lern-Session ---------- */

.session-top {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.progress {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
  min-width: 200px;
}

#progress-label {
  font-weight: 800;
  white-space: nowrap;
}

.progress-bar {
  flex: 1;
  height: 10px;
  border-radius: 99px;
  background: var(--surface-2);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: 99px;
  transition: width 0.25s ease;
}

.flashcard-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.flashcard {
  width: 100%;
  max-width: 560px;
  min-height: 280px;
  border: none;
  background: transparent;
  padding: 0;
  cursor: pointer;
  perspective: 1200px;
  font: inherit;
  color: inherit;
  border-radius: var(--radius);
}

.flashcard-inner {
  position: relative;
  display: block;
  width: 100%;
  min-height: 280px;
  transform-style: preserve-3d;
  transition: transform 0.5s ease;
}

.flashcard.flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.flashcard-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 1.5rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow-wrap: anywhere;
}

.flashcard-back {
  transform: rotateY(180deg);
  background: var(--primary-soft);
}

.face-label {
  position: absolute;
  top: 0.8rem;
  left: 1rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.face-text {
  font-size: 1.35rem;
  font-weight: 700;
  text-align: center;
  white-space: pre-wrap;
}

.face-hint {
  color: var(--accent);
  font-size: 0.9rem;
  text-align: center;
}

.flip-help {
  color: var(--text-muted);
  font-size: 0.82rem;
  margin: 0;
}

@media (prefers-reduced-motion: reduce) {
  .flashcard-inner { transition: none; }
  .progress-fill { transition: none; }
  .btn { transition: none; }
  .btn:active { transform: none; }
}

.answer-buttons {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

.answer-buttons .btn {
  flex: 1;
  max-width: 270px;
  min-height: 54px;
  flex-direction: column;
  gap: 0.1rem;
}

.session-box-info {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.82rem;
  margin-top: 0.75rem;
}

/* ---------- Session-Ende ---------- */

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem 1.5rem;
  text-align: center;
  max-width: 480px;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.summary-emoji { font-size: 3rem; }

.summary-rate {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
  margin: 0;
}

.summary-message { font-weight: 700; margin: 0; }

.summary-details {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ---------- Werbe-Slot ---------- */

.ad-slot {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 0 1rem 1rem;
}

.ad-slot .ad-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 70px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

/* ---------- Modals ---------- */

.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  padding: 1.4rem;
  width: min(92vw, 460px);
  max-height: 88vh;
  overflow-y: auto;
}

.modal-wide { width: min(94vw, 620px); }

.modal::backdrop {
  background: rgba(10, 18, 16, 0.55);
  backdrop-filter: blur(2px);
}

.modal label {
  display: block;
  font-weight: 700;
  font-size: 0.85rem;
  margin: 0.8rem 0 0.25rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.2rem;
}

.modal-help {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.premium-list {
  margin: 0.5rem 0 0.75rem;
  padding-left: 1.2rem;
}

.premium-list li { margin-bottom: 0.3rem; }

.premium-price { font-size: 1.05rem; }

.todo-note {
  background: var(--surface-2);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-small);
  padding: 0.6rem 0.8rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ---------- Hilfe / Erste Schritte ---------- */

.help-btn {
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 50%;
  font-size: 1rem;
  font-weight: 800;
  color: var(--text-muted);
}

.help-btn:hover { color: var(--text); }

.help-steps {
  margin: 0.5rem 0 0.75rem;
  padding-left: 1.3rem;
}

.help-steps li {
  margin-bottom: 0.6rem;
}

.help-steps li strong { color: var(--primary-strong); }

.help-subtitle {
  margin: 1rem 0 0.35rem;
}

.help-know {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.help-know li { margin-bottom: 0.35rem; }

.import-preview {
  margin-top: 1rem;
  font-size: 0.88rem;
}

.import-preview table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.5rem;
}

.import-preview th,
.import-preview td {
  text-align: left;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.import-preview th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.import-note { color: var(--text-muted); }
.import-warn { color: var(--danger); }

code {
  background: var(--surface-2);
  border-radius: 4px;
  padding: 0.05em 0.35em;
  font-size: 0.88em;
}

/* ---------- Responsive (ab Tablet) ---------- */

@media (min-width: 640px) {
  h1 { font-size: 2rem; }

  .stats-grid { grid-template-columns: repeat(4, 1fr); }

  .deck-grid { grid-template-columns: repeat(2, 1fr); }

  .card-row {
    flex-direction: row;
    align-items: flex-start;
    justify-content: space-between;
  }

  .card-row-main { flex: 1; }

  .card-row-footer {
    flex-direction: column;
    align-items: flex-end;
    gap: 0.4rem;
  }

  .card-row-actions { margin-left: 0; }
}
