@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Noto+Sans+TC:wght@300;400;500;700&display=swap');

:root {
  --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #0c0a09 100%);
  --panel-bg: rgba(30, 41, 59, 0.7);
  --border-color: rgba(255, 255, 255, 0.08);
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-glow: rgba(99, 102, 241, 0.35);
  
  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.15);
  --success-border: rgba(16, 185, 129, 0.3);
  --success-glow: rgba(16, 185, 129, 0.4);
  
  --danger: #f43f5e;
  --danger-bg: rgba(244, 63, 94, 0.15);
  --danger-border: rgba(244, 63, 94, 0.3);
  --danger-glow: rgba(244, 63, 94, 0.4);
  
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.15);
  
  --font-sans: 'Inter', 'Noto Sans TC', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --transition-smooth: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font-sans);
  background: var(--bg-gradient);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: rgba(15, 23, 42, 0.5);
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.2);
}

/* Header */
header {
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-badge {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: white;
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1.25rem;
  box-shadow: 0 0 15px var(--primary-glow);
}

.brand-text h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

.brand-text p {
  font-size: 0.75rem;
  color: var(--text-secondary);
}

.header-stats {
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.stat-chip {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: 30px;
  padding: 0.4rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.stat-chip span.value {
  color: var(--text-primary);
  font-weight: 600;
}

/* Main Container */
.app-container {
  max-width: 1400px;
  width: 100%;
  margin: 1.5rem auto;
  padding: 0 1.5rem;
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: 1.5rem;
  flex: 1;
}

/* Sidebar & Control Bar */
.control-panel {
  grid-column: span 2;
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 1.25rem;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.2);
}

.filters-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.select-custom {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.6rem 1rem;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  cursor: pointer;
  transition: var(--transition-smooth);
}

.select-custom:focus {
  border-color: var(--primary);
  box-shadow: 0 0 10px var(--primary-glow);
}

.search-wrapper {
  position: relative;
  min-width: 260px;
}

.search-input {
  width: 100%;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 0.6rem 1rem 0.6rem 2.25rem;
  border-radius: 10px;
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: var(--transition-smooth);
}

.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 10px var(--primary-glow);
}

.search-icon {
  position: absolute;
  left: 0.8rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.mode-toggle-group {
  display: flex;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border-color);
  padding: 0.25rem;
  border-radius: 10px;
}

.mode-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 0.45rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: var(--transition-smooth);
}

.mode-btn.active {
  background: var(--primary);
  color: white;
  box-shadow: 0 4px 12px var(--primary-glow);
}

/* Left Panel: Quiz Area */
.quiz-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  min-width: 0;
}

.card {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  transition: var(--transition-smooth);
}

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

.meta-tags {
  display: flex;
  gap: 0.5rem;
}

.tag {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  text-transform: uppercase;
}

.tag-id {
  background: rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.3);
}

.tag-subject {
  background: rgba(139, 92, 246, 0.15);
  color: #c7d2fe;
  border: 1px solid rgba(139, 92, 246, 0.3);
}

.tag-year {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.btn-bookmark {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.4rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  transition: var(--transition-smooth);
}

.btn-bookmark:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--warning);
}

.btn-bookmark.active {
  color: var(--warning);
  transform: scale(1.1);
  filter: drop-shadow(0 0 5px rgba(245, 158, 11, 0.4));
}

.question-stem {
  font-size: 1.15rem;
  line-height: 1.6;
  font-weight: 500;
  color: var(--text-primary);
}

/* Options */
.options-list {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.option-item {
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.1rem 1.25rem;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: var(--transition-smooth);
}

.option-item:hover {
  border-color: rgba(255, 255, 255, 0.2);
  background: rgba(15, 23, 42, 0.6);
  transform: translateY(-1px);
}

.option-prefix {
  width: 26px;
  height: 26px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.85rem;
  flex-shrink: 0;
  transition: var(--transition-smooth);
}

.option-text {
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text-secondary);
  transition: var(--transition-smooth);
}

/* States */
.option-item.selected {
  border-color: var(--primary);
  background: rgba(99, 102, 241, 0.08);
}
.option-item.selected .option-prefix {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}
.option-item.selected .option-text {
  color: var(--text-primary);
}

/* Correct Answer Highlights */
.option-item.correct {
  border-color: var(--success) !important;
  background: var(--success-bg) !important;
  box-shadow: 0 0 15px var(--success-glow);
}
.option-item.correct .option-prefix {
  background: var(--success) !important;
  border-color: var(--success) !important;
  color: white !important;
}
.option-item.correct .option-text {
  color: var(--text-primary) !important;
}

/* Incorrect Answer Highlights */
.option-item.incorrect {
  border-color: var(--danger) !important;
  background: var(--danger-bg) !important;
  box-shadow: 0 0 15px var(--danger-glow);
}
.option-item.incorrect .option-prefix {
  background: var(--danger) !important;
  border-color: var(--danger) !important;
  color: white !important;
}
.option-item.incorrect .option-text {
  color: var(--text-primary) !important;
}

/* Navigation Controls (Prev, Next) */
.quiz-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  padding: 0.75rem 1.5rem;
  border-radius: 10px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: var(--transition-smooth);
}

.btn-secondary:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border-color: rgba(255, 255, 255, 0.2);
}

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

.btn-primary {
  background: var(--primary);
  border: none;
  color: white;
  padding: 0.75rem 1.8rem;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  box-shadow: 0 4px 12px var(--primary-glow);
  transition: var(--transition-smooth);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  box-shadow: 0 6px 16px var(--primary-glow);
  transform: translateY(-1px);
}

.btn-submit-exam {
  background: var(--success);
  box-shadow: 0 4px 12px var(--success-glow);
}
.btn-submit-exam:hover {
  background: #0d9488;
  box-shadow: 0 6px 16px var(--success-glow);
}

/* Explanations Panel */
.explanation-panel {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  animation: fadeIn 0.35s ease-out;
}

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

.exp-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.05rem;
}

.exp-correct-label {
  background: var(--success-bg);
  color: #6ee7b7;
  border: 1px solid var(--success-border);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
}

.explanation-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.explanation-list li {
  list-style: none;
  font-size: 0.925rem;
  line-height: 1.6;
  color: var(--text-secondary);
  border-left: 2.5px solid rgba(255, 255, 255, 0.15);
  padding-left: 0.75rem;
}

.explanation-list li.correct-explanation {
  border-left-color: var(--success);
}

.concepts-box {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1rem;
  margin-top: 0.5rem;
}

.concepts-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: #c7d2fe;
  margin-bottom: 0.5rem;
}

.concepts-list {
  padding-left: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.concepts-list li {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* Right Panel: Side Panels */
.side-panel {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* Stats Card */
.stats-card {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
}

.progress-bar-container {
  height: 8px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #6366f1 0%, #8b5cf6 100%);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.small-stat-box {
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.75rem;
  text-align: center;
}

.small-stat-box .label {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.small-stat-box .value {
  font-size: 1.15rem;
  font-weight: 700;
}

.value.correct-val { color: var(--success); }
.value.incorrect-val { color: var(--danger); }

/* Navigation Grid Card */
.nav-grid-card {
  background: var(--panel-bg);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex: 1;
}

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

.nav-grid-header h3 {
  font-size: 1rem;
  font-weight: 700;
}

.grid-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 0.75rem;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.75rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
}

.dot.unanswered { background: rgba(255, 255, 255, 0.1); border: 1px solid rgba(255, 255, 255, 0.2); }
.dot.answered-p { background: var(--primary); }
.dot.correct-dot { background: var(--success); }
.dot.incorrect-dot { background: var(--danger); }
.dot.bookmark-dot { background: var(--warning); }

.grid-scroll {
  overflow-y: auto;
  max-height: 350px;
  padding-right: 0.25rem;
}

.question-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.5rem;
}

.grid-item {
  aspect-ratio: 1;
  background: rgba(15, 23, 42, 0.4);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  position: relative;
  transition: var(--transition-smooth);
}

.grid-item:hover {
  background: rgba(255, 255, 255, 0.05);
  border-color: rgba(255, 255, 255, 0.3);
  color: var(--text-primary);
}

.grid-item.active {
  border-color: var(--primary) !important;
  box-shadow: 0 0 8px var(--primary-glow);
  color: var(--text-primary);
  font-weight: 700;
}

.grid-item.answered {
  background: rgba(99, 102, 241, 0.2);
  border-color: rgba(99, 102, 241, 0.4);
  color: #c7d2fe;
}

.grid-item.correct {
  background: rgba(16, 185, 129, 0.2) !important;
  border-color: rgba(16, 185, 129, 0.4) !important;
  color: #a7f3d0 !important;
}

.grid-item.incorrect {
  background: rgba(244, 63, 94, 0.2) !important;
  border-color: rgba(244, 63, 94, 0.4) !important;
  color: #fecdd3 !important;
}

.grid-item.bookmarked::after {
  content: '';
  position: absolute;
  top: 3px;
  right: 3px;
  width: 6px;
  height: 6px;
  background: var(--warning);
  border-radius: 50%;
  box-shadow: 0 0 4px rgba(245, 158, 11, 0.6);
}

/* Exam Score Screen */
.score-screen {
  text-align: center;
  padding: 3rem 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.score-radial {
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(30, 41, 59, 0.9) 60%, transparent 100%),
              conic-gradient(var(--primary) 0%, rgba(255, 255, 255, 0.05) 0%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 30px var(--primary-glow);
  border: 4px solid var(--border-color);
}

.score-radial .pct {
  font-size: 2.25rem;
  font-weight: 700;
}

.score-radial .lbl {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.score-details {
  font-size: 1.05rem;
  color: var(--text-secondary);
  max-width: 450px;
  line-height: 1.6;
}

.score-details span.highlight {
  color: var(--text-primary);
  font-weight: 600;
}

/* Responsive adjustments */
@media (max-width: 960px) {
  .app-container {
    grid-template-columns: 1fr;
  }
  .control-panel {
    grid-column: span 1;
  }
}

@media (max-width: 480px) {
  header {
    padding: 1rem;
    flex-direction: column;
    gap: 0.75rem;
    align-items: flex-start;
  }
  .header-stats {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 0.25rem;
  }
  .control-panel {
    flex-direction: column;
    align-items: stretch;
  }
  .search-wrapper {
    min-width: unset;
  }
  .card {
    padding: 1.25rem;
  }
  .question-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}
