/* GROL Study Pro - Modern Colorful Mobile-First UI */

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --accent: #ec4899;
  --accent-dark: #db2777;
  --success: #10b981;
  --success-dark: #059669;
  --danger: #ef4444;
  --danger-dark: #dc2626;
  --warning: #f59e0b;
  --bg: #f0f0f5;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-light: #64748b;
  --text-lighter: #94a3b8;
  --border: #e2e8f0;
  --shadow: 0 4px 24px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.12);
  --radius: 16px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --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;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* Header */
.app-header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  padding: calc(16px + var(--safe-top)) 20px 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 20px rgba(99, 102, 241, 0.3);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  font-size: 1.4rem;
  font-weight: 800;
  color: white;
  letter-spacing: -0.5px;
}

.header-stats {
  display: flex;
  gap: 8px;
}

.streak-badge {
  background: rgba(255,255,255,0.25);
  padding: 6px 12px;
  border-radius: 20px;
  color: white;
  font-size: 0.85rem;
  font-weight: 600;
  backdrop-filter: blur(10px);
}

.flame {
  font-size: 1rem;
}

/* Main Content */
.main-content {
  flex: 1;
  padding: 20px 16px 180px;
  overflow-y: auto;
}

/* Home View */
.home-hero {
  text-align: center;
  padding: 20px 0;
}

.home-hero h2 {
  font-size: 1.8rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.home-hero p {
  color: var(--text-light);
  font-size: 1rem;
  margin-bottom: 32px;
}

.element-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 28px 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  transition: transform 0.2s, box-shadow 0.2s;
  position: relative;
  overflow: hidden;
}

/*
.element-card:active {
  transform: scale(0.98);
}
*/

.element-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 5px;
}

.element-card.el1::before {
  background: linear-gradient(90deg, #6366f1, #818cf8);
}

.element-card.el3::before {
  background: linear-gradient(90deg, #ec4899, #f472b6);
}

.element-card.stats::before {
  background: linear-gradient(90deg, #10b981, #34d399);
}

.element-card h3 {
  font-size: 1.3rem;
  font-weight: 700;
  margin-bottom: 6px;
}

.element-card .subtitle {
  color: var(--text-light);
  font-size: 0.9rem;
  margin-bottom: 16px;
}

.element-card .card-stats {
  display: flex;
  gap: 20px;
}

.card-stat {
  text-align: center;
}

.card-stat .num {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
}

.element-card.el3 .card-stat .num {
  color: var(--accent);
}

.element-card.stats .card-stat .num {
  color: var(--success);
}

.card-stat .label {
  font-size: 0.75rem;
  color: var(--text-lighter);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Flashcard */
.card-container {
  perspective: 1000px;
}

.flashcard {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px 20px;
  box-shadow: var(--shadow-lg);
  margin-bottom: 16px;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.flashcard.shake {
  animation: shake 0.4s;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

.flashcard.success {
  border: 2px solid var(--success);
}

.flashcard.error {
  border: 2px solid var(--danger);
}

.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.card-badge {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}

.card-badge.el3 {
  background: linear-gradient(135deg, var(--accent) 0%, #f472b6 100%);
}

.card-topic {
  color: var(--text-lighter);
  font-size: 0.75rem;
  font-weight: 500;
}

.card-progress {
  font-size: 0.8rem;
  color: var(--text-light);
  font-weight: 600;
}

.question-text {
  font-size: 1.1rem;
  line-height: 1.6;
  font-weight: 600;
  margin-bottom: 20px;
  color: var(--text);
}

/* Answer Options */
.answers {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.answer-option {
  background: var(--card-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-height: 56px;
  font-size: 0.95rem;
  line-height: 1.4;
  text-align: left;
}

.answer-option:active {
  transform: scale(0.98);
}

.answer-option:hover {
  border-color: var(--primary-light);
  background: #f5f3ff;
}

.answer-letter {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-light);
  transition: all 0.2s;
}

.answer-option:hover .answer-letter {
  background: var(--primary-light);
  color: white;
}

.answer-option.correct {
  border-color: var(--success);
  background: #ecfdf5;
}

.answer-option.correct .answer-letter {
  background: var(--success);
  color: white;
}

.answer-option.incorrect {
  border-color: var(--danger);
  background: #fef2f2;
}

.answer-option.incorrect .answer-letter {
  background: var(--danger);
  color: white;
}

.answer-option.disabled {
  opacity: 0.6;
  cursor: default;
}

.answer-text {
  flex: 1;
  padding-top: 4px;
}

/* Feedback Banner */
.feedback {
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin-top: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideIn 0.3s ease;
}

.feedback.correct {
  background: #ecfdf5;
  color: var(--success-dark);
  border: 1px solid #a7f3d0;
}

.feedback.incorrect {
  background: #fef2f2;
  color: var(--danger-dark);
  border: 1px solid #fecaca;
}

/* Next Button */
.next-btn {
  display: block;
  width: 100%;
  padding: 16px;
  margin-top: 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
  animation: slideIn 0.3s ease;
}

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

/* Session badge on home cards */
.card-header-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 4px;
}

.session-badge {
  background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
  border: 1px solid #bae6fd;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  text-align: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.15s;
}

.session-badge:active {
  transform: scale(0.95);
}

.session-badge-progress {
  font-size: 1.1rem;
  font-weight: 800;
  color: #0284c7;
  line-height: 1.2;
}

.session-badge-label {
  font-size: 0.7rem;
  font-weight: 600;
  color: #0284c7;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Card action buttons */
.card-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

.btn-primary, .btn-secondary, .btn-ghost {
  flex: 1;
  padding: 12px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s;
  text-align: center;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: white;
  box-shadow: 0 2px 6px rgba(99, 102, 241, 0.25);
}

.btn-secondary {
  background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
  color: #0284c7;
  border: 1px solid #bae6fd;
}

.btn-ghost {
  background: var(--bg);
  color: var(--text-light);
  border: 1px solid var(--border);
}

.btn-primary:active, .btn-secondary:active, .btn-ghost:active {
  transform: scale(0.96);
}

/* Progress bar on home cards */
.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  margin-top: 14px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-light));
  border-radius: 3px;
  transition: width 0.3s;
}

.element-card.el3 .progress-fill {
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
}

.element-card.el3 .session-badge {
  background: linear-gradient(135deg, #fdf2f8, #fce7f3);
  border-color: #fbcfe8;
}

.element-card.el3 .session-badge-progress,
.element-card.el3 .session-badge-label {
  color: #c026d3;
}

.element-card.el3 .btn-secondary {
  background: linear-gradient(135deg, #fdf2f8, #fce7f3);
  color: #c026d3;
  border-color: #fbcfe8;
}

/* Loading */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

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

.loading p {
  color: var(--text-light);
}

/* Stats View */
.stats-header {
  text-align: center;
  margin-bottom: 24px;
}

.stats-header h2 {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 4px;
}

.stats-header p {
  color: var(--text-light);
  font-size: 0.9rem;
}

.stat-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  padding: 20px 16px;
  box-shadow: var(--shadow);
  text-align: center;
}

.stat-card .value {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
  margin-bottom: 4px;
}

.stat-card .value.primary { color: var(--primary); }
.stat-card .value.success { color: var(--success); }
.stat-card .value.danger { color: var(--danger); }
.stat-card .value.accent { color: var(--accent); }

.stat-card .label {
  font-size: 0.75rem;
  color: var(--text-lighter);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

/* Chart */
.chart-container {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.chart-title {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 16px;
  color: var(--text);
}

.chart {
  width: 100%;
  height: 160px;
  position: relative;
}

.chart-bars {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 120px;
  padding-bottom: 4px;
}

.chart-bar {
  flex: 1;
  min-width: 0;
  border-radius: 4px 4px 0 0;
  background: linear-gradient(180deg, var(--primary-light) 0%, var(--primary) 100%);
  transition: height 0.3s ease;
  position: relative;
  cursor: pointer;
  min-height: 2px;
}

.chart-bar:hover::after,
.chart-bar:active::after {
  content: attr(data-value) '%';
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.chart-labels {
  display: flex;
  gap: 4px;
  margin-top: 4px;
}

.chart-label {
  flex: 1;
  text-align: center;
  font-size: 0.6rem;
  color: var(--text-lighter);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Category/Question Lists */
.stats-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.section-title {
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title .icon {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  background: var(--primary-light);
  color: white;
  font-size: 0.7rem;
}

.difficulty-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.difficulty-row:last-child {
  border-bottom: none;
}

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

.difficulty-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.difficulty-meta {
  font-size: 0.75rem;
  color: var(--text-lighter);
}

.difficulty-bar {
  width: 60px;
  height: 6px;
  border-radius: 3px;
  background: var(--border);
  overflow: hidden;
  flex-shrink: 0;
}

.difficulty-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}

.difficulty-pct {
  font-size: 0.85rem;
  font-weight: 700;
  min-width: 36px;
  text-align: right;
}

/* Element selector for stats */
.element-selector {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.element-tab {
  flex: 1;
  padding: 10px;
  border-radius: var(--radius-xs);
  border: 2px solid var(--border);
  background: var(--card-bg);
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
  color: var(--text-light);
}

.element-tab.active {
  border-color: var(--primary);
  color: var(--primary);
  background: #f5f3ff;
}

.element-tab.active.el3 {
  border-color: var(--accent);
  color: var(--accent);
  background: #fdf2f8;
}

/* Mode Toggle Switch */
.mode-toggle-container {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card-bg);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  margin-bottom: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.mode-toggle-info {
  flex: 1;
}

.mode-toggle-label {
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text);
}

.mode-toggle-desc {
  font-size: 0.8rem;
  color: var(--text-light);
  margin-top: 2px;
}

.toggle-switch {
  width: 50px;
  height: 30px;
  border-radius: 15px;
  background: #d1d5db;
  position: relative;
  cursor: pointer;
  transition: background 0.25s;
  flex-shrink: 0;
}

.toggle-switch.on {
  background: var(--primary);
}

.toggle-knob {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: white;
  position: absolute;
  top: 3px;
  left: 3px;
  transition: left 0.25s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-switch.on .toggle-knob {
  left: 23px;
}

.mode-toggle-state {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  min-width: 70px;
  text-align: right;
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 600px;
  display: flex;
  background: var(--card-bg);
  padding: 8px 0 calc(8px + var(--safe-bottom));
  box-shadow: 0 -2px 20px rgba(0,0,0,0.06);
  z-index: 100;
  border-top: 1px solid var(--border);
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 4px;
  border: none;
  background: none;
  color: var(--text-lighter);
  cursor: pointer;
  transition: color 0.2s;
  font-size: 0.7rem;
  font-weight: 600;
  min-height: 48px;
}

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

.nav-item[data-view="element3"].active {
  color: var(--accent);
}

.nav-item[data-view="stats"].active {
  color: var(--success);
}

.nav-item svg {
  transition: transform 0.2s;
}

.nav-item.active svg {
  transform: scale(1.1);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-light);
}

.empty-state .icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 1.1rem;
  margin-bottom: 8px;
  color: var(--text);
}

.empty-state p {
  font-size: 0.85rem;
}

/* Responsive - iPad */
@media (min-width: 768px) {
  #app {
    max-width: 800px;
  }

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

  .flashcard {
    padding: 32px;
  }

  .question-text {
    font-size: 1.25rem;
  }

  .answer-option {
    padding: 20px 24px;
    font-size: 1rem;
  }

  .home-hero h2 {
    font-size: 2.2rem;
  }
}

/* Responsive - Desktop */
@media (min-width: 1024px) {
  #app {
    max-width: 900px;
  }

  .main-content {
    padding: 32px 24px 120px;
  }
}

/* Utility */
.fade-in {
  animation: fadeIn 0.3s ease;
}

.no-attempts {
  text-align: center;
  padding: 20px;
  color: var(--text-lighter);
  font-size: 0.85rem;
}
