/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface2: #0f3460;
  --accent: #e94560;
  --accent2: #4a9eff;
  --success: #4caf50;
  --warning: #ff9800;
  --error: #f44336;
  --text: #e0e0e0;
  --text-muted: #888;
  --border: #2a2a4a;
  --radius: 8px;
  --font: 'Segoe UI', system-ui, sans-serif;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

/* ===== Utility ===== */
.hidden { display: none !important; }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: opacity 0.15s, transform 0.1s;
}
.btn:active { transform: scale(0.97); }
.btn:hover { opacity: 0.88; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--surface2); color: var(--text); }
.btn-success { background: var(--success); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-danger { background: var(--error); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 16px; }

input[type="text"], input[type="number"], input[type="password"], select {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 12px;
  font-size: 14px;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
}
input[type="text"]:focus, input[type="number"]:focus, input[type="password"]:focus, select:focus {
  border-color: var(--accent2);
}
select option { background: var(--surface); }

/* ===== Views ===== */
.view {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* ===== User Select ===== */
.user-select {
  max-width: 480px;
  margin: 60px auto;
}
.user-select-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.user-select h1 {
  font-size: 2rem;
  color: var(--accent);
}
.user-select .subtitle {
  color: var(--text-muted);
  margin-bottom: 32px;
}
.user-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 28px;
}
.user-list .btn {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  font-size: 15px;
}
.user-list .btn:hover { border-color: var(--accent2); }
.new-user-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.new-user-row {
  display: flex;
  gap: 10px;
}
.new-user-row input { flex: 1; }
.pwd-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===== Password Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  min-width: 300px;
  max-width: 90vw;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-box h3 {
  font-size: 1rem;
  margin-bottom: 4px;
}
.modal-box input {
  width: 100%;
}
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 4px;
}

/* ===== Session Config ===== */
.session-config {
  max-width: 600px;
  margin: 0 auto;
}
.session-config header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 28px;
}
.session-config header h2 { font-size: 1.4rem; }
.config-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.config-card h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 14px;
}
.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}
.form-row:last-child { margin-bottom: 0; }
.form-row label { font-size: 14px; color: var(--text); flex: 1; }
.form-row select, .form-row input[type="number"] { min-width: 120px; }

/* toggle */
.toggle {
  display: flex;
  background: var(--surface2);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.toggle label {
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.2s, color 0.2s;
  user-select: none;
}
.toggle input { display: none; }
.toggle input:checked + label {
  background: var(--accent2);
  color: #fff;
}

/* checkbox rows */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  cursor: pointer;
  font-size: 14px;
}
.checkbox-row:last-child { margin-bottom: 0; }
.checkbox-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent2);
  cursor: pointer;
}

.live-count {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  text-align: center;
  font-size: 15px;
  color: var(--accent2);
  font-weight: 600;
  margin-bottom: 16px;
}

.config-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ===== Training View ===== */
.training-view {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.training-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 52px;
}
.training-header .progress-info {
  font-size: 14px;
  color: var(--text-muted);
}
.header-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.training-header .feedback {
  font-size: 14px;
  font-weight: 700;
  text-align: center;
}
.feedback.correct { color: var(--success); }
.feedback.incorrect { color: var(--error); }

.training-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.question-panel {
  padding: 16px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.question-meta {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.question-text {
  font-size: 1.1rem;
  font-weight: 500;
  line-height: 1.4;
}

.answers-panel {
  flex: 1;
  overflow-y: auto;
  padding: 12px 20px;
  display: grid;
  grid-template-columns: 48px 48px 1fr;
  gap: 8px;
  align-content: start;
}

.ans-btn {
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  padding: 0;
}
.answer-text {
  flex: 1;
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.4;
  transition: background 0.2s, border-color 0.2s;
}
.answer-text.wrong {
  background: rgba(244, 67, 54, 0.15);
  border-color: var(--error);
  color: var(--error);
}
.answer-text.correct-reveal {
  background: rgba(76, 175, 80, 0.15);
  border-color: var(--success);
  color: var(--success);
}

.training-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  gap: 10px;
}

/* ===== Stats View ===== */
.stats-view {
  max-width: 900px;
  margin: 0 auto;
}
.stats-view header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 24px;
}
.stats-view header h2 { font-size: 1.4rem; }

.stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.stats-table th, .stats-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.stats-table th {
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.stats-table tr:hover td { background: var(--surface); }
.stats-table td:first-child { color: var(--accent2); font-weight: 600; }

.stats-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 4px;
}
.stats-bar-fill {
  height: 100%;
  background: var(--accent2);
  border-radius: 3px;
}

/* ===== Help View ===== */
.help-view {
  max-width: 640px;
  margin: 0 auto;
}
.help-view header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}
.help-view header h2 { font-size: 1.4rem; }
.help-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.help-card h3 {
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.help-card p {
  font-size: 14px;
  line-height: 1.6;
  margin-bottom: 10px;
}
.help-card p:last-child { margin-bottom: 0; }
.help-card ul {
  padding-left: 20px;
  font-size: 14px;
  line-height: 1.6;
}
.help-card li { margin-bottom: 8px; }
.help-card li:last-child { margin-bottom: 0; }

/* ===== Responsive / Landscape optimiert ===== */
@media (min-width: 768px) {
  .training-body {
    flex-direction: row;
  }
  .question-panel {
    width: 40%;
    border-bottom: none;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 20px 24px;
  }
  .answers-panel {
    padding: 16px 24px;
  }
  .question-text { font-size: 1.15rem; }
}

@media (max-width: 767px) {
  .view { padding: 16px; }
  .training-header { flex-wrap: wrap; gap: 6px; }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
