:root {
  --bg: #14161a;
  --surface: #1e2126;
  --surface-2: #262a31;
  --border: #33383f;
  --text: #e8e9eb;
  --text-dim: #9aa0a8;
  --accent: #5b8def;
  --green: #3fb27f;
  --red: #e0575b;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button {
  font-family: inherit;
  cursor: pointer;
}

input, select {
  font-family: inherit;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 15px;
}

/* Checkboxen/Radios dürfen die obige Text-Input-Optik NICHT erben (kein
   Padding/Rahmen/Hintergrund) - sonst verzerrt das ihre native Box und sie
   verrutschen relativ zu ihrem Label-Text. */
input[type="checkbox"], input[type="radio"] {
  all: revert;
  width: 16px;
  height: 16px;
  padding: 0;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--accent);
}

textarea.card-textarea {
  font-family: inherit;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 15px;
  width: 100%;
  resize: vertical;
  min-height: 90px;
  line-height: 1.4;
}

/* --- Auth --- */
.auth-wrapper {
  max-width: 380px;
  margin: 10vh auto;
  padding: 32px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.auth-wrapper h1 { text-align: center; margin-bottom: 24px; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form h2 { margin: 0 0 8px; font-size: 18px; color: var(--text-dim); }
.auth-form button[type="submit"] {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 10px;
  font-size: 15px;
  margin-top: 4px;
}
.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  text-decoration: underline;
  padding: 0;
  font-size: 14px;
}
.switch-text { font-size: 14px; color: var(--text-dim); text-align: center; }
.hidden { display: none !important; }
.error { color: var(--red); text-align: center; min-height: 20px; font-size: 14px; }

/* --- Layout --- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 20px; margin: 0; }
.container { max-width: 900px; margin: 0 auto; padding: 24px; }

/* --- Deck grid --- */
.deck-create {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
}
.deck-create input { flex: 1; }
.deck-create button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 10px 18px;
}

.deck-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 16px;
}
.deck-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  transition: border-color 0.15s, background 0.15s;
}
.deck-card h3 { margin: 0; min-width: 0; overflow-wrap: break-word; }
.deck-card-header { display: flex; align-items: center; gap: 6px; margin-bottom: 10px; }
.deck-card-header h3 { flex: 1; }
.deck-drag-handle {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  padding: 4px 2px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  flex-shrink: 0;
}
.deck-drag-handle:active { cursor: grabbing; }
.deck-card.deck-dragging { opacity: 0.55; box-shadow: 0 4px 14px rgba(0,0,0,0.4); }
.deck-card.drop-target {
  border-color: var(--accent);
  background: rgba(91, 141, 239, 0.12);
}
.deck-stats { display: flex; gap: 10px; font-size: 13px; color: var(--text-dim); margin-bottom: 14px; }
.deck-stats span.stat-safe { color: var(--green); }
.deck-stats span.stat-unsafe { color: var(--red); }
.deck-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.deck-actions button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 13px;
}
.deck-actions button.danger { color: var(--red); }
.deck-actions button.primary { background: var(--accent); border-color: var(--accent); color: white; }

/* --- Modal --- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%; max-width: 420px;
  position: relative;
}
.modal-close-x {
  position: absolute;
  top: 14px;
  right: 14px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
}
.modal-close-x:hover { background: var(--surface-2); color: var(--text); }

/* --- Global loading overlay --- */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 999;
}
.loading-overlay.hidden { display: none; }
.loading-spinner {
  width: 42px;
  height: 42px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
.modal h2 { margin-top: 0; }
.modal .field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.modal .field label { font-size: 13px; color: var(--text-dim); }
.modal .field input, .modal .field select { width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal-actions button { border-radius: 6px; padding: 8px 16px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text); }
.modal-actions button.primary { background: var(--accent); border-color: var(--accent); color: white; }
.modal-actions button.danger { background: var(--red); border-color: var(--red); color: white; }
.modal-actions button:disabled { opacity: .5; cursor: not-allowed; }
.modal .hint { font-size: 13px; color: var(--text-dim); margin-top: -6px; }

/* --- Card list / editor --- */
.card-list { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.card-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.card-row .card-preview { font-size: 14px; flex: 1; min-width: 0; }
.card-row-main { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.drag-handle {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  padding: 4px 2px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  flex-shrink: 0;
}
.drag-handle:active { cursor: grabbing; }
.card-number {
  flex-shrink: 0;
  min-width: 24px;
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
}
.card-row.dragging {
  opacity: 0.6;
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
body.no-select { user-select: none; -webkit-user-select: none; }
.card-row .card-preview .type-tag {
  font-size: 11px;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  margin-right: 8px;
}
.badge-status { font-size: 11px; padding: 2px 8px; border-radius: 10px; margin-left: 8px; }
.badge-sicher { background: rgba(63,178,127,0.15); color: var(--green); }
.badge-unsicher { background: rgba(224,87,91,0.15); color: var(--red); }
.badge-neu { background: rgba(154,160,168,0.15); color: var(--text-dim); }

.option-row { display: flex; gap: 8px; align-items: flex-start; margin-bottom: 8px; }
.option-row input[type="checkbox"] { margin-top: 12px; }
.option-row textarea.option-text { flex: 1; min-height: 44px; }

/* --- Study mode --- */
.study-wrapper { max-width: 640px; margin: 0 auto; padding: 24px; }
.study-progress { text-align: center; color: var(--text-dim); margin-bottom: 16px; font-size: 14px; }
.flip-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  font-size: 20px;
  cursor: pointer;
  user-select: none;
}
.flip-card .side-label { position: absolute; top: 12px; left: 16px; font-size: 12px; color: var(--text-dim); }
.flip-card-wrap { position: relative; }

.quiz-options { display: flex; flex-direction: column; gap: 10px; margin-top: 20px; }
.quiz-option {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  text-align: left;
  color: var(--text);
  font-size: 15px;
}
.quiz-option.selected { border-color: var(--accent); }
.quiz-option.correct { border-color: var(--green); background: rgba(63,178,127,0.1); }
.quiz-option.incorrect { border-color: var(--red); background: rgba(224,87,91,0.1); }

.study-controls {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin-top: 28px;
  flex-wrap: wrap;
}
.study-controls button {
  border-radius: 8px;
  padding: 10px 20px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
}
.study-controls button.good { border-color: var(--green); color: var(--green); }
.study-controls button.bad { border-color: var(--red); color: var(--red); }
.study-controls button.next { background: var(--accent); border-color: var(--accent); color: white; }

.setup-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.setup-box .field { margin-bottom: 16px; }
.setup-box label { display: block; margin-bottom: 8px; color: var(--text-dim); font-size: 14px; }
.radio-group, .checkbox-group { display: flex; gap: 16px; flex-wrap: wrap; }

.empty-state { text-align: center; color: var(--text-dim); padding: 60px 20px; }

.back-link { color: var(--text-dim); text-decoration: none; font-size: 14px; }
.cta-link { color: var(--accent); font-weight: 600; }

/* --- Breadcrumb --- */
.breadcrumb { font-size: 13px; color: var(--text-dim); margin-bottom: 4px; }
.breadcrumb .crumb { color: var(--text-dim); text-decoration: none; }
.breadcrumb .crumb:hover { color: var(--accent); }
.breadcrumb .crumb.current { color: var(--text); }
.breadcrumb .crumb-sep { margin: 0 4px; }

/* --- Sections --- */
.section-block { margin-bottom: 40px; }
.section-heading { font-size: 16px; color: var(--text-dim); margin-bottom: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.section-header-row { display: flex; align-items: center; justify-content: space-between; }
.btn-learn {
  background: var(--accent);
  color: white;
  text-decoration: none;
  border-radius: 6px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
}
.empty-state.small { padding: 24px 16px; font-size: 14px; }

/* --- Archive tile --- */
.archive-card { border-color: #4a3d1f; background: linear-gradient(180deg, var(--surface), #201d16); }

/* --- Image picker (in modals) --- */
.image-field { margin-bottom: 4px; }
.image-picker { display: flex; align-items: center; gap: 12px; }
.image-preview {
  width: 72px; height: 72px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
.image-preview.empty {
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--text-dim); text-align: center;
}
.image-picker-actions { display: flex; flex-direction: column; gap: 4px; align-items: flex-start; }
.paste-hint { font-size: 11px; color: var(--text-dim); }
.image-picker { border-radius: 8px; padding: 4px; outline: none; }
.image-picker:focus { box-shadow: 0 0 0 2px var(--accent); }
.danger-link { color: var(--red); }
.option-block { margin-bottom: 14px; }

/* --- Card images (study mode / previews) --- */
.card-image {
  max-width: 100%;
  max-height: 260px;
  border-radius: 8px;
  display: block;
  margin: 0 auto 12px;
  object-fit: contain;
}
.card-text { text-align: center; white-space: pre-wrap; }

/* --- Code blocks (highlight.js) --- */
.code-block {
  text-align: left;
  background: #1a1c20;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 0;
  max-width: 100%;
}
.code-block code {
  font-family: "SF Mono", Menlo, Consolas, "Courier New", monospace;
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre;
}
.quiz-option .code-block { width: 100%; }

/* --- Code-Toggle Checkbox (in Editor-Modals) --- */
.code-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
  cursor: pointer;
}
.code-toggle input { margin: 0; }
.quiz-option .option-image { max-height: 140px; margin-bottom: 8px; }
.quiz-option { display: flex; flex-direction: column; align-items: center; }
.quiz-option span { white-space: pre-wrap; text-align: center; }

/* --- Responsive: Tablet --- */
@media (max-width: 900px) {
  .container, .study-wrapper { padding: 16px; }
  .deck-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}

/* --- Responsive: Mobile --- */
@media (max-width: 600px) {
  .topbar {
    padding: 14px 16px;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-start;
  }
  .topbar h1 { font-size: 18px; }
  .topbar > a, .topbar > button { align-self: flex-start; }
  .btn-learn { width: 100%; text-align: center; box-sizing: border-box; }

  .breadcrumb { font-size: 12px; overflow-wrap: break-word; }

  .container, .study-wrapper { padding: 12px; }

  .auth-wrapper {
    margin: 6vh 16px;
    padding: 24px 20px;
    max-width: none;
  }

  .deck-create { flex-direction: column; }
  .deck-create button { padding: 12px; }

  .deck-grid { grid-template-columns: 1fr; gap: 12px; }
  .deck-card { padding: 16px; }
  .deck-actions { flex-direction: column; }
  .deck-actions button {
    width: 100%;
    padding: 12px;
    font-size: 14px;
  }
  .deck-drag-handle { font-size: 20px; padding: 6px 8px; }

  .section-header-row { flex-direction: column; align-items: stretch; gap: 10px; }

  .modal-overlay { align-items: flex-end; }
  .modal {
    max-width: none;
    width: 100%;
    border-radius: var(--radius) var(--radius) 0 0;
    padding: 20px;
    max-height: 90vh;
    overflow-y: auto;
  }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions button { width: 100%; padding: 12px; }

  .card-row { flex-direction: column; align-items: stretch; gap: 10px; }
  .card-row .deck-actions { flex-direction: row; }
  .card-row .deck-actions button { width: auto; flex: 1; padding: 10px; }
  .drag-handle { font-size: 22px; padding: 6px 8px; }

  .option-row { flex-wrap: wrap; }
  .option-row textarea.option-text { min-width: 0; flex-basis: 100%; order: 3; }
  .option-row input[type="checkbox"] { margin-top: 0; order: 1; }
  .option-row .remove-option { order: 2; margin-left: auto; }
  .option-block { padding-bottom: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }

  .image-picker { flex-direction: column; align-items: flex-start; }
  .image-preview { width: 100%; height: 140px; }
  .image-picker-actions { width: 100%; }

  .code-block { padding: 12px; }
  .code-block code { font-size: 12.5px; }

  .flip-card { min-height: 180px; padding: 24px 20px; font-size: 18px; }
  .card-image { max-height: 180px; }
  .quiz-option { padding: 14px 16px; font-size: 15px; }

  .study-controls { flex-direction: column; }
  .study-controls button { width: 100%; padding: 14px; font-size: 15px; }

  .setup-box { padding: 18px; }
  .radio-group, .checkbox-group { flex-direction: column; gap: 10px; }

  #start-btn { width: 100%; padding: 14px !important; }
}

/* Größere Touch-Targets generell */
@media (pointer: coarse) {
  button { min-height: 40px; }
  input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; }
}
