/* ============================================================
   Ernährungsberater Lernapp — Stylesheet
   Helles, modernes Design · iOS PWA optimiert
   ============================================================ */

:root {
  --bg-primary:     #f4f6f9;
  --bg-secondary:   #ffffff;
  --bg-card:        #ffffff;
  --bg-card-hover:  #f0fdf4;
  --accent:         #16a34a;
  --accent-light:   #dcfce7;
  --accent-hover:   #15803d;
  --accent-red:     #dc2626;
  --accent-red-light: #fee2e2;
  --text-primary:   #111827;
  --text-secondary: #6b7280;
  --text-muted:     #9ca3af;
  --border:         #e5e7eb;
  --shadow-sm:      0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md:      0 4px 16px rgba(0,0,0,0.10);
  --radius:         14px;
  --radius-sm:      10px;

  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  overflow: hidden;
}

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

/* ============================================================
   SCREENS
   ============================================================ */

.screen {
  display: none;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.screen.active {
  display: flex;
}

/* ============================================================
   PASSWORD SCREEN
   ============================================================ */

#screen-password {
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #f0fdf4 0%, #dcfce7 50%, #f0fdf4 100%);
}

.password-container {
  width: 100%;
  max-width: 360px;
  padding: 32px 24px;
  text-align: center;
}

.app-logo {
  width: 80px;
  height: 80px;
  background: var(--accent);
  border-radius: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  box-shadow: 0 8px 24px rgba(22,163,74,0.35);
}

.app-logo i {
  font-size: 36px;
  color: #ffffff;
}

.password-container h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
}

.subtitle {
  color: var(--text-secondary);
  margin-bottom: 36px;
  font-size: 15px;
}

.password-form {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow-md);
}

.password-form label {
  display: block;
  text-align: left;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.input-wrapper {
  position: relative;
  margin-bottom: 16px;
}

.input-wrapper input {
  width: 100%;
  padding: 13px 44px 13px 14px;
  background: var(--bg-primary);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(22,163,74,0.12);
}

#toggle-password {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  line-height: 1;
  font-size: 16px;
}

.btn-primary {
  width: 100%;
  padding: 14px;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  letter-spacing: 0.01em;
}

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

.error-msg {
  margin-top: 12px;
  color: var(--accent-red);
  font-size: 14px;
}

.hidden {
  display: none !important;
}

/* ============================================================
   APP HEADER
   ============================================================ */

.app-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 13px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 0 var(--border);
  flex-shrink: 0;
}

.app-header h1 {
  font-size: 19px;
  font-weight: 700;
  flex: 1;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 10px;
}

.app-header h1 i {
  color: var(--accent);
  font-size: 18px;
}

.header-title {
  font-size: 16px;
  font-weight: 600;
  flex: 1;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.header-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 17px;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: background 0.15s, color 0.15s;
  min-width: 38px;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active {
  background: var(--bg-primary);
  color: var(--text-primary);
}

.icon-refresh {
  transition: transform 0.5s;
}

.icon-refresh.spinning {
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

/* ============================================================
   OFFLINE BANNER
   ============================================================ */

.offline-banner {
  background: #fef3c7;
  color: #92400e;
  text-align: center;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 500;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

/* ============================================================
   LIST CONTAINER
   ============================================================ */

.list-container {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 16px 32px;
}

/* Loading spinner */
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 0;
  color: var(--text-muted);
  gap: 16px;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ============================================================
   BOOK CARD
   ============================================================ */

.book-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  cursor: pointer;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s, transform 0.1s, background 0.15s;
  display: flex;
  align-items: center;
  gap: 14px;
}

.book-card:active {
  background: var(--bg-card-hover);
  transform: scale(0.98);
  box-shadow: none;
}

.book-icon {
  width: 48px;
  height: 48px;
  background: var(--accent-light);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.book-icon i {
  font-size: 20px;
  color: var(--accent);
}

.book-info {
  flex: 1;
  min-width: 0;
}

.book-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  word-break: break-word;
  overflow-wrap: break-word;
}

.book-meta {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 3px;
}

.book-arrow i {
  color: var(--text-muted);
  font-size: 14px;
  flex-shrink: 0;
}

/* ============================================================
   CHAPTER ROW
   ============================================================ */

.chapter-row {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  cursor: pointer;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.15s, transform 0.1s, background 0.15s;
  display: flex;
  align-items: center;
  gap: 12px;
}

.chapter-row:active {
  background: var(--bg-card-hover);
  transform: scale(0.98);
  box-shadow: none;
}

.chapter-status-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 16px;
  color: var(--text-muted);
}

.chapter-status-icon.done {
  background: var(--accent-light);
  color: var(--accent);
}

.chapter-status-icon.in-progress {
  background: #dbeafe;
  color: #2563eb;
}

.chapter-info {
  flex: 1;
  min-width: 0;
}

.chapter-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  /* Fix: langer Text ohne Leerzeichen umbricht statt zu überlaufen */
  word-break: break-word;
  overflow-wrap: anywhere;
  hyphens: auto;
}

.chapter-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-downloaded {
  background: #dbeafe;
  color: #1d4ed8;
}

.badge-completed {
  background: var(--accent-light);
  color: var(--accent);
}

.badge-progress {
  background: #ede9fe;
  color: #7c3aed;
}

.chapter-arrow i {
  color: var(--text-muted);
  font-size: 13px;
  flex-shrink: 0;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: var(--text-muted);
}

.empty-state i {
  font-size: 44px;
  margin-bottom: 16px;
  color: var(--border);
  display: block;
}

.empty-state p {
  font-size: 15px;
  line-height: 1.6;
}

/* ============================================================
   PLAYER
   ============================================================ */

#screen-player {
  background: var(--bg-primary);
}

.player-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 24px 32px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  gap: 22px;
}

.player-artwork {
  width: 120px;
  height: 120px;
  background: var(--accent);
  border-radius: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 12px 32px rgba(22,163,74,0.30);
  margin-top: 4px;
  flex-shrink: 0;
}

.player-artwork i {
  font-size: 48px;
  color: #ffffff;
}

.player-info {
  text-align: center;
  width: 100%;
}

.player-book-name {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  margin-bottom: 6px;
}

.player-chapter-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  word-break: break-word;
  overflow-wrap: anywhere;
  hyphens: auto;
}

/* Seek bar */
.progress-container {
  width: 100%;
}

.progress-bar-wrapper {
  position: relative;
  height: 24px;
  display: flex;
  align-items: center;
  margin-bottom: 4px;
}

.seek-bar {
  width: 100%;
  height: 5px;
  -webkit-appearance: none;
  appearance: none;
  border-radius: 3px;
  outline: none;
  cursor: pointer;
  --pct: 0%;
  background: linear-gradient(
    to right,
    var(--accent) 0%,
    var(--accent) var(--pct),
    var(--border) var(--pct),
    var(--border) 100%
  );
}

.seek-bar::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 0 3px rgba(22,163,74,0.15);
}

.time-display {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Controls */
.player-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  width: 100%;
}

.control-btn {
  border: none;
  cursor: pointer;
  transition: transform 0.1s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
}

.control-btn:active {
  transform: scale(0.9);
}

.control-btn.primary {
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 24px;
  box-shadow: 0 6px 18px rgba(22,163,74,0.35);
}

.control-btn.secondary {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 18px;
  border: 1.5px solid var(--border);
}

.skip-label {
  font-size: 9px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

/* Speed buttons */
.speed-controls {
  width: 100%;
}

.speed-label {
  font-size: 12px;
  color: var(--text-muted);
  display: block;
  margin-bottom: 8px;
  text-align: center;
  font-weight: 500;
}

.speed-buttons {
  display: flex;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
}

.speed-btn {
  padding: 5px 12px;
  background: var(--bg-card);
  color: var(--text-secondary);
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  font-weight: 500;
}

.speed-btn.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* Download section */
.player-download-section {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.btn-action {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 28px;
  border-radius: var(--radius-sm);
  border: 1.5px solid;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  min-width: 200px;
}

.btn-action:active {
  transform: scale(0.97);
}

.btn-action:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-download {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent);
}

.btn-delete {
  background: var(--accent-red-light);
  color: var(--accent-red);
  border-color: var(--accent-red);
}

.download-status {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
}

/* Completion badge */
.completion-badge {
  background: var(--accent-light);
  border: 1.5px solid var(--accent);
  color: var(--accent);
  border-radius: 24px;
  padding: 8px 20px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ============================================================
   SCROLLBAR
   ============================================================ */

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
