/*
 * Agentic English Tutor - Mobile-First Styles
 * For 6th Class Polish Students
 */

:root {
  --primary: #4F46E5;
  --primary-dark: #4338CA;
  --secondary: #10B981;
  --danger: #EF4444;
  --warning: #F59E0B;
  --bg: #F9FAFB;
  --card-bg: #FFFFFF;
  --text: #1F2937;
  --text-light: #6B7280;
  --border: #E5E7EB;
  --success-bg: #D1FAE5;
  --error-bg: #FEE2E2;
  --radius: 12px;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

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

/* Header */
header {
  background: var(--primary);
  color: white;
  padding: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 600px;
  margin: 0 auto;
}

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

.locale-selector,
.model-selector {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='white' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 24px;
}

.locale-selector:focus,
.model-selector:focus {
  outline: none;
  border-color: white;
}

.locale-selector option,
.model-selector option {
  background: var(--primary);
  color: white;
}

/* Flag selector styling */
.locale-selector {
  font-size: 1.2rem;
  min-width: 60px;
  text-align: center;
}

.locale-selector option {
  font-size: 1.4rem;
  padding: 8px;
}

.model-selector {
  background-color: rgba(255, 200, 50, 0.3);
  border-color: rgba(255, 200, 50, 0.5);
}

header h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

.mode-badge {
  background: rgba(255, 255, 255, 0.2);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.mode-description {
  text-align: center;
  font-size: 0.8rem;
  opacity: 0.9;
  margin-top: 8px;
  max-width: 600px;
  margin-left: auto;
  margin-right: auto;
}

/* Main Content */
main {
  flex: 1;
  padding: 16px;
  padding-bottom: 80px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

.screen {
  display: none;
}

.screen.active {
  display: block;
}

/* Cards */
.welcome-card,
.question-card,
.feedback-card,
.results-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

/* Welcome Screen */
.welcome-card h2 {
  font-size: 1.5rem;
  margin-bottom: 16px;
  text-align: center;
}

.bilingual {
  text-align: center;
  margin-bottom: 24px;
}

.bilingual .en {
  display: block;
  font-size: 1.1rem;
  color: var(--text);
}

.bilingual .pl {
  display: block;
  font-size: 0.9rem;
  color: var(--text-light);
  font-style: italic;
}

.topic-select,
.difficulty-select {
  margin-bottom: 20px;
}

.topic-select label,
.difficulty-select label {
  display: block;
  font-weight: 500;
  margin-bottom: 8px;
  font-size: 0.9rem;
}

#topic-dropdown {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  background: white;
  cursor: pointer;
}

#topic-dropdown:focus {
  outline: none;
  border-color: var(--primary);
}

.difficulty-buttons {
  display: flex;
  gap: 8px;
}

.diff-btn {
  flex: 1;
  padding: 10px 8px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: white;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.diff-btn:hover {
  border-color: var(--primary);
}

.diff-btn.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Buttons */
.primary-btn {
  width: 100%;
  padding: 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  margin-top: 16px;
}

.primary-btn:hover {
  background: var(--primary-dark);
}

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

.secondary-btn {
  width: 100%;
  padding: 16px;
  background: white;
  color: var(--primary);
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

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

/* Quiz Screen */
.quiz-progress {
  margin-bottom: 20px;
}

.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-fill {
  height: 100%;
  background: var(--secondary);
  transition: width 0.3s ease;
}

#progress-text {
  font-size: 0.85rem;
  color: var(--text-light);
  text-align: center;
  display: block;
}

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

.question-type {
  display: inline-block;
  background: var(--primary);
  color: white;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 16px;
}

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

.prompt-en {
  font-size: 1.2rem;
  font-weight: 500;
  margin-bottom: 8px;
}

.prompt-pl {
  font-size: 0.95rem;
  color: var(--text-light);
  font-style: italic;
}

/* Options for multiple choice */
.options-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.options-container.hidden {
  display: none;
}

.option-btn {
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: white;
  text-align: left;
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
}

.option-btn:hover {
  border-color: var(--primary);
  background: #F5F3FF;
}

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

.option-btn.correct {
  border-color: var(--secondary);
  background: var(--success-bg);
}

.option-btn.incorrect {
  border-color: var(--danger);
  background: var(--error-bg);
}

/* Text input */
.text-input-container {
  margin-bottom: 16px;
}

.answer-input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  transition: border-color 0.2s;
}

.answer-input:focus {
  outline: none;
  border-color: var(--primary);
}

/* Feedback */
.feedback-card {
  text-align: center;
}

.feedback-card.hidden {
  display: none;
}

.feedback-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.feedback-icon.correct {
  color: var(--secondary);
}

.feedback-icon.incorrect {
  color: var(--danger);
}

.feedback-text {
  font-size: 1rem;
  margin-bottom: 8px;
}

.feedback-text.pl {
  color: var(--text-light);
  font-style: italic;
  font-size: 0.9rem;
}

.citation-box {
  background: #F3F4F6;
  padding: 12px;
  border-radius: 8px;
  margin: 16px 0;
  text-align: left;
  font-size: 0.85rem;
}

.citation-box strong {
  display: block;
  margin-bottom: 4px;
  color: var(--text-light);
}

/* Results Screen */
.results-card {
  text-align: center;
}

.results-icon {
  font-size: 4rem;
  margin-bottom: 16px;
}

.results-card h2 {
  font-size: 1.5rem;
  margin-bottom: 24px;
}

.results-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin-bottom: 24px;
}

.stat {
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-light);
}

.results-message {
  font-size: 1rem;
  margin-bottom: 8px;
}

.results-message.pl {
  color: var(--text-light);
  font-style: italic;
  font-size: 0.9rem;
}

.results-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 24px;
}

/* Break Overlay */
.break-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.break-overlay.hidden {
  display: none;
}

.break-content {
  background: white;
  padding: 32px;
  border-radius: var(--radius);
  text-align: center;
  max-width: 400px;
  width: 100%;
}

.break-icon {
  font-size: 4rem;
  margin-bottom: 16px;
}

.break-content h2 {
  margin-bottom: 16px;
}

.break-content .en {
  font-size: 1rem;
  margin-bottom: 4px;
}

.break-content .pl {
  font-size: 0.9rem;
  color: var(--text-light);
  font-style: italic;
  margin-bottom: 24px;
}

/* Control Bar */
#control-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  z-index: 100;
}

.control-btn {
  padding: 10px 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.control-btn:hover {
  background: var(--bg);
  border-color: var(--primary);
}

/* Responsive */
@media (min-width: 768px) {
  main {
    padding: 24px;
    padding-bottom: 100px;
  }

  .welcome-card,
  .question-card,
  .feedback-card,
  .results-card {
    padding: 32px;
  }

  .difficulty-buttons {
    gap: 12px;
  }

  .results-actions {
    flex-direction: row;
    justify-content: center;
  }

  .results-actions button {
    width: auto;
    min-width: 180px;
  }
}

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

.screen.active {
  animation: slideIn 0.3s ease;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.feedback-icon {
  animation: pulse 0.5s ease;
}

/* Loading state */
.loading {
  opacity: 0.6;
  pointer-events: none;
}

.loading::after {
  content: '...';
  animation: dots 1s infinite;
}

@keyframes dots {
  0%, 20% { content: '.'; }
  40% { content: '..'; }
  60%, 100% { content: '...'; }
}

/* ==========================================
   Biology Chapter Selection
   ========================================== */

.chapter-selection {
  max-width: 600px;
  margin: 0 auto;
}

.chapter-selection h2 {
  text-align: center;
  font-size: 1.5rem;
  margin-bottom: 8px;
}

.chapter-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin: 24px 0;
}

.chapter-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  border: 2px solid transparent;
  position: relative;
}

.chapter-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 16px -4px rgb(0 0 0 / 0.15);
  border-color: var(--primary);
}

.chapter-card.locked {
  opacity: 0.5;
  cursor: not-allowed;
}

.chapter-icon {
  font-size: 2.5rem;
  margin-bottom: 8px;
}

.chapter-card h3 {
  font-size: 1rem;
  margin-bottom: 4px;
  color: var(--text);
}

.chapter-card p {
  font-size: 0.8rem;
  color: var(--text-light);
}

/* Progress ring */
.progress-ring {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
}

.progress-ring svg {
  transform: rotate(-90deg);
  width: 36px;
  height: 36px;
}

.progress-ring .ring-bg {
  fill: none;
  stroke: var(--border);
  stroke-width: 3;
}

.progress-ring .ring-progress {
  fill: none;
  stroke: var(--secondary);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 88; /* 2 * PI * 14 */
  stroke-dashoffset: 88;
  transition: stroke-dashoffset 0.5s ease;
}

/* Mastery badges */
.mastery-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 0.65rem;
  font-weight: 600;
  margin-top: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.mastery-badge.not_started {
  background: #F3F4F6;
  color: #6B7280;
}

.mastery-badge.in_progress {
  background: #FEF3C7;
  color: #92400E;
}

.mastery-badge.learning {
  background: #DBEAFE;
  color: #1E40AF;
}

.mastery-badge.mastered {
  background: #D1FAE5;
  color: #065F46;
}

/* Exploration unlocked indicator */
.exploration-badge {
  position: absolute;
  top: -6px;
  left: -6px;
  background: var(--warning);
  color: white;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
}

.exploration-badge.hidden {
  display: none;
}

/* Progress summary */
.progress-summary {
  display: flex;
  justify-content: center;
  gap: 32px;
  margin: 24px 0;
  padding: 16px;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

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

.summary-value {
  display: block;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--primary);
}

.summary-label {
  font-size: 0.8rem;
  color: var(--text-light);
}

/* ==========================================
   Feedback Modal
   ========================================== */

.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-overlay.hidden {
  display: none;
}

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

.modal-content h2 {
  text-align: center;
  margin-bottom: 20px;
  font-size: 1.25rem;
}

/* Star rating */
.rating-section {
  margin-bottom: 20px;
}

.rating-section label,
.feedback-section label {
  display: block;
  font-weight: 500;
  margin-bottom: 8px;
  font-size: 0.9rem;
  color: var(--text);
}

.star-rating {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.star-btn {
  background: none;
  border: none;
  font-size: 2rem;
  cursor: pointer;
  opacity: 0.3;
  transition: all 0.2s;
  padding: 4px;
}

.star-btn:hover,
.star-btn.active {
  opacity: 1;
  transform: scale(1.2);
}

.star-btn.active {
  filter: drop-shadow(0 0 4px gold);
}

/* Feedback buttons */
.feedback-section {
  margin-bottom: 16px;
}

.feedback-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.feedback-btn {
  flex: 1;
  min-width: calc(50% - 4px);
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: white;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s;
}

.feedback-btn:hover {
  border-color: var(--primary);
  background: #F5F3FF;
}

.feedback-btn.selected {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}

/* Comment textarea */
.feedback-section textarea {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: inherit;
  resize: vertical;
  min-height: 80px;
}

.feedback-section textarea:focus {
  outline: none;
  border-color: var(--primary);
}

/* Modal actions */
.modal-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.modal-actions button {
  flex: 1;
  margin-top: 0;
}

/* Curriculum selector styling */
.curriculum-selector {
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 6px;
  padding: 4px 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='white' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  padding-right: 24px;
}

.curriculum-selector:focus {
  outline: none;
  border-color: white;
}

.curriculum-selector option {
  background: var(--primary);
  color: white;
}

/* Responsive adjustments for chapter grid */
@media (min-width: 480px) {
  .chapter-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 600px) {
  .chapter-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Animation for chapter cards */
@keyframes cardAppear {
  from {
    opacity: 0;
    transform: scale(0.9);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.chapter-card {
  animation: cardAppear 0.3s ease backwards;
}

.chapter-card:nth-child(1) { animation-delay: 0.05s; }
.chapter-card:nth-child(2) { animation-delay: 0.1s; }
.chapter-card:nth-child(3) { animation-delay: 0.15s; }
.chapter-card:nth-child(4) { animation-delay: 0.2s; }
.chapter-card:nth-child(5) { animation-delay: 0.25s; }
.chapter-card:nth-child(6) { animation-delay: 0.3s; }
.chapter-card:nth-child(7) { animation-delay: 0.35s; }
