:root {
  --bg-color: #f8fafc;
  --card-bg: #ffffff;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #e0e7ff;
  --success: #10b981;
  --success-light: #d1fae5;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --border: #e2e8f0;
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow: 0 4px 20px -2px rgba(15, 23, 42, 0.08);
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Telegram Native Theme Auto-adapt */
body.telegram-dark {
  --bg-color: var(--tg-theme-bg-color, #17212b);
  --card-bg: var(--tg-theme-secondary-bg-color, #232e3c);
  --text-primary: var(--tg-theme-text-color, #ffffff);
  --text-secondary: var(--tg-theme-hint-color, #8b98a5);
  --primary: var(--tg-theme-button-color, #5288c1);
  --primary-hover: #4172a6;
  --primary-light: rgba(82, 136, 193, 0.2);
  --border: rgba(255, 255, 255, 0.1);
  --shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.4);
}

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

body {
  font-family: var(--font-family);
  background-color: var(--bg-color);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
}

/* App Container */
.app-container {
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: 85px; /* for bottom navbar */
  flex: 1;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary), #a855f7);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: #fff;
  box-shadow: 0 4px 10px rgba(99, 102, 241, 0.3);
}

.brand-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--card-bg);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 12px;
  z-index: 100;
  backdrop-filter: blur(10px);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  padding: 4px 12px;
  border-radius: var(--radius-sm);
}

.nav-item .icon {
  font-size: 20px;
}

.nav-item.active {
  color: var(--primary);
  background: var(--primary-light);
}

/* Card Styles */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
}

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

.btn-primary:active {
  transform: scale(0.98);
}

.btn-secondary {
  background: var(--primary-light);
  color: var(--primary);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
}

.btn-sm {
  padding: 8px 12px;
  font-size: 12px;
  width: auto;
}

/* Inputs */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input, .form-textarea, .form-select {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}

.form-input:focus, .form-textarea:focus, .form-select:focus {
  border-color: var(--primary);
}

/* Search Bar */
.search-box {
  position: relative;
  margin-bottom: 16px;
}

.search-box input {
  padding-left: 38px;
}

.search-box .icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
}

/* Quiz List Items */
.quiz-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  margin-bottom: 10px;
  cursor: pointer;
  background: var(--card-bg);
  transition: all 0.15s ease-in-out;
}

.quiz-item:active {
  transform: scale(0.99);
  border-color: var(--primary);
}

.quiz-info h4 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}

.quiz-meta {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  gap: 12px;
}

/* Runner UI */
.runner-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}

.timer-bar-container {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin-bottom: 20px;
  overflow: hidden;
}

.timer-bar {
  height: 100%;
  background: var(--primary);
  width: 100%;
  transition: width 1s linear, background-color 0.3s;
}

.timer-bar.warning {
  background: #f59e0b;
}

.timer-bar.danger {
  background: var(--danger);
}

.question-card {
  margin-bottom: 20px;
}

.question-text {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
}

.options-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.option-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--card-bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  color: var(--text-primary);
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
}

.option-btn:active {
  transform: scale(0.99);
}

.option-btn.selected {
  border-color: var(--primary);
  background: var(--primary-light);
}

.option-btn.correct {
  border-color: var(--success);
  background: var(--success-light);
  color: #065f46;
  font-weight: 600;
}

.option-btn.wrong {
  border-color: var(--danger);
  background: var(--danger-light);
  color: #991b1b;
}

.explanation-box {
  margin-top: 16px;
  padding: 14px;
  background: var(--primary-light);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text-primary);
  border-left: 4px solid var(--primary);
}

/* Result Screen */
.result-card {
  text-align: center;
  padding: 30px 20px;
}

.result-trophy {
  font-size: 60px;
  margin-bottom: 12px;
  animation: bounce 1s infinite alternate;
}

@keyframes bounce {
  from { transform: translateY(0); }
  to { transform: translateY(-8px); }
}

.score-badge {
  display: inline-block;
  font-size: 32px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 8px;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 200;
}

.modal-content {
  background: var(--card-bg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  border-radius: var(--radius-md);
  padding: 24px;
  overflow-y: auto;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: #1e293b;
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  z-index: 300;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}
