:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #818cf8;
  --secondary: #ec4899;
  --success: #10b981;
  --success-light: #34d399;
  --warning: #f59e0b;
  --danger: #ef4444;
  --bg-dark: #0f172a;
  --bg-card: #1e293b;
  --bg-input: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --glass: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.1);
  --glow: 0 0 20px rgba(99, 102, 241, 0.3);
}

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

body {
  font-family: 'Inter', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
}

/* Background gradient */
body::before {
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background:
    radial-gradient(circle at 20% 20%, rgba(99, 102, 241, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(236, 72, 153, 0.1) 0%, transparent 50%);
  pointer-events: none;
  z-index: -1;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1rem;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 2rem;
}

h1 {
  font-size: 2.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary-light), var(--secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.5rem;
}

.subtitle {
  color: var(--text-secondary);
  font-size: 1.1rem;
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: 1rem;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
  backdrop-filter: blur(10px);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 1.25rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: 0.75rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: var(--glow);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 0 30px rgba(99, 102, 241, 0.5);
}

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

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
}

.btn-success {
  background: linear-gradient(135deg, var(--success), #059669);
  color: white;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

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

/* Forms */
.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--glass-border);
  border-radius: 0.5rem;
  color: var(--text-primary);
  font-size: 1rem;
  transition: border-color 0.2s;
}

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

/* File Upload */
.upload-zone {
  border: 2px dashed var(--glass-border);
  border-radius: 1rem;
  padding: 2rem;
  text-align: center;
  transition: all 0.3s ease;
  cursor: pointer;
}

.upload-zone:hover,
.upload-zone.dragover {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.1);
}

.upload-zone .icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

.upload-zone p {
  color: var(--text-secondary);
}

/* Quiz Bank List */
.bank-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.bank-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  background: var(--glass);
  border: 1px solid var(--glass-border);
  border-radius: 0.75rem;
  transition: all 0.2s;
}

.bank-item:hover {
  border-color: var(--primary);
}

.bank-info h3 {
  font-size: 1rem;
  margin-bottom: 0.25rem;
}

.bank-info .meta {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.bank-actions {
  display: flex;
  gap: 0.5rem;
}

/* Quiz Interface */
.quiz-container {
  display: none;
}

.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-input);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 1rem;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  transition: width 0.3s ease;
}

.type-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background: var(--primary);
  color: white;
  border-radius: 1rem;
  font-size: 0.875rem;
  font-weight: 600;
}

/* Question Card */
.question-card {
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: 1rem;
  padding: 2rem;
  margin-bottom: 1.5rem;
}

.question-number {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

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

.question-hint {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-style: italic;
  margin-bottom: 1rem;
}

/* Options */
.options-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

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

.option-btn:hover {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.1);
}

.option-btn.selected {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.2);
}

.option-btn.correct {
  border-color: var(--success);
  background: rgba(16, 185, 129, 0.2);
}

.option-btn.incorrect {
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.2);
}

/* Toggle buttons for S/A */
.toggle-group {
  display: flex;
  gap: 1rem;
}

.toggle-btn {
  flex: 1;
  padding: 1rem;
  background: var(--glass);
  border: 2px solid var(--glass-border);
  border-radius: 0.75rem;
  color: var(--text-primary);
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

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

.toggle-btn.selected {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.2);
}

.toggle-btn.correct {
  border-color: var(--success);
  background: rgba(16, 185, 129, 0.2);
}

.toggle-btn.incorrect {
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.2);
}

.toggle-btn:disabled,
.option-btn:disabled {
  cursor: not-allowed;
  opacity: 0.9;
}

/* Answer Feedback */
.answer-feedback {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding: 1rem;
  border-radius: 0.75rem;
  font-size: 1.1rem;
  font-weight: 500;
  animation: fadeSlideIn 0.3s ease;
}

.answer-feedback.correct {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid var(--success);
  color: var(--success-light);
}

.answer-feedback.incorrect {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid var(--danger);
  color: #fca5a5;
}

.answer-feedback .feedback-icon {
  font-size: 1.5rem;
}

.answer-feedback .feedback-text strong {
  color: var(--success-light);
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Word Bank */
.word-bank {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 1rem;
  background: var(--glass);
  border-radius: 0.75rem;
  margin-bottom: 1rem;
}

.word-bank-item {
  padding: 0.5rem 1rem;
  background: var(--bg-input);
  border-radius: 0.5rem;
  font-weight: 500;
}

.word-bank-item.used {
  opacity: 0.4;
  text-decoration: line-through;
}

/* Text Input Answer */
.answer-input {
  width: 100%;
  max-width: 300px;
  padding: 0.75rem 1rem;
  background: var(--bg-input);
  border: 2px solid var(--glass-border);
  border-radius: 0.5rem;
  color: var(--text-primary);
  font-size: 1.1rem;
  transition: border-color 0.2s;
}

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

/* Results */
.results-container {
  display: none;
  text-align: center;
}

.score-circle {
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin: 2rem auto;
  box-shadow: 0 0 40px rgba(99, 102, 241, 0.4);
}

.score-value {
  font-size: 3rem;
  font-weight: 700;
}

.score-label {
  font-size: 1rem;
  opacity: 0.9;
}

.results-summary {
  margin: 2rem 0;
  padding: 1rem;
  background: var(--glass);
  border-radius: 0.75rem;
}

/* Navigation */
.quiz-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 1.5rem;
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--glass-border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

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

/* Toast Notifications */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  padding: 1rem 1.5rem;
  background: var(--bg-card);
  border: 1px solid var(--glass-border);
  border-radius: 0.75rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  animation: slideIn 0.3s ease;

  /* Flex layout for close button */
  display: flex;
  align-items: center;
  gap: 1rem;
  min-width: 300px;
  max-width: 90vw;
}

.toast-message {
  flex: 1;
}

.toast-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0 0.25rem;
  line-height: 1;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.toast-close:hover {
  opacity: 1;
  color: var(--text-primary);
}

.toast.success {
  border-color: var(--success);
}

.toast.error {
  border-color: var(--danger);
  /* Make error toast slightly more visible */
  background: rgba(30, 41, 59, 0.95);
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* Admin Dashboard */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.admin-table th,
.admin-table td {
  padding: 0.75rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--glass-border);
}

.admin-table th {
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--glass);
}

.admin-table tr:hover {
  background: rgba(99, 102, 241, 0.05);
}

.admin-tab-btn {
  margin-right: 0.5rem;
}

.admin-tab-btn.active {
  background: var(--primary);
  color: white;
}

/* Utility text colors */
.text-success {
  color: var(--success);
}

.text-danger {
  color: var(--danger);
}

.text-muted {
  color: var(--text-muted);
}

/* Badge */
.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  font-size: 0.7rem;
  border-radius: 0.25rem;
  margin-left: 0.5rem;
  vertical-align: middle;
}

/* Responsive */
@media (max-width: 640px) {
  h1 {
    font-size: 1.75rem;
  }

  .options-grid {
    grid-template-columns: 1fr;
  }

  .container {
    padding: 1rem;
  }

  .admin-table {
    font-size: 0.8rem;
  }

  .admin-table th,
  .admin-table td {
    padding: 0.5rem 0.25rem;
  }
}