/* ============ CSS Variables & Themes ============ */
:root {
  --bg: #f5f0eb;
  --bg-card: #ffffff;
  --bg-sidebar: #faf8f5;
  --text: #2c2416;
  --text-secondary: #6b5e4a;
  --text-muted: #9b8e7a;
  --border: #e0d5c1;
  --accent: #8b6914;
  --accent-light: #c9a84c;
  --accent-dark: #6b4f0e;
  --success: #4a7c59;
  --success-bg: #e8f5e9;
  --danger: #c0392b;
  --danger-bg: #fdecea;
  --overlay: rgba(0,0,0,0.5);
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', monospace;
}

[data-theme="dark"] {
  --bg: #1a1814;
  --bg-card: #25221c;
  --bg-sidebar: #1f1c16;
  --text: #e8e0d0;
  --text-secondary: #b8a88a;
  --text-muted: #7a6e5a;
  --border: #3d3528;
  --accent: #d4af37;
  --accent-light: #e8cc6e;
  --accent-dark: #b8960f;
  --success: #6abf7b;
  --success-bg: #1e3522;
  --danger: #e74c3c;
  --danger-bg: #3a1f1c;
  --overlay: rgba(0,0,0,0.7);
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
}

/* ============ Base Reset ============ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  scroll-behavior: smooth;
  height: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
  line-height: 1.6;
  overflow-x: hidden;
}

/* ============ Password Gate ============ */
.password-gate {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  transition: opacity 0.5s, visibility 0.5s;
}

.password-gate.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.gate-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  width: 90%;
  max-width: 400px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: fadeInUp 0.6s ease;
}

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

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

.gate-card h1 {
  font-size: 1.5rem;
  margin-bottom: 0.3rem;
  color: var(--text);
}

.gate-card .subtitle {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
}

.gate-input-group {
  display: flex;
  gap: 0.5rem;
}

.gate-input-group input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  background: var(--bg);
  color: var(--text);
  transition: border var(--transition);
  outline: none;
  font-family: var(--font);
}

.gate-input-group input:focus {
  border-color: var(--accent);
}

.gate-input-group button {
  padding: 0.75rem 1.5rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  cursor: pointer;
  transition: background var(--transition), transform 0.15s;
  font-weight: 600;
  white-space: nowrap;
}

.gate-input-group button:hover {
  background: var(--accent-dark);
  transform: scale(1.02);
}

.gate-input-group button:active {
  transform: scale(0.98);
}

.gate-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 0.75rem;
  min-height: 1.2em;
}

.gate-ban-timer {
  color: var(--danger);
  font-weight: 600;
  font-size: 0.9rem;
  margin-top: 0.5rem;
}

/* ============ Main Layout ============ */
.app-container {
  display: flex;
  min-height: 100vh;
  position: relative;
}

/* Sidebar */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  transition: transform var(--transition), background var(--transition);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 100;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-header .logo {
  font-size: 1.8rem;
}

.sidebar-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  line-height: 1.3;
}

/* Section list in sidebar */
.section-list {
  list-style: none;
  flex: 1;
}

.section-list li {
  margin-bottom: 0.25rem;
}

.section-btn {
  width: 100%;
  text-align: left;
  padding: 0.7rem 1rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all var(--transition);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--font);
}

.section-btn:hover {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border);
}

.section-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}

.section-btn .count {
  font-size: 0.75rem;
  opacity: 0.7;
  background: rgba(0,0,0,0.1);
  padding: 0.15rem 0.5rem;
  border-radius: 1rem;
}

.section-btn.active .count {
  background: rgba(255,255,255,0.25);
}

/* Announcements in sidebar */
.sidebar-announcements {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.sidebar-announcements h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.announcement-mini {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.5rem;
  font-size: 0.78rem;
  color: var(--text-secondary);
  transition: all var(--transition);
}

.announcement-mini strong {
  display: block;
  color: var(--text);
  margin-bottom: 0.2rem;
}

/* Dark mode toggle */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 1rem;
  padding: 0.5rem;
  cursor: pointer;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.85rem;
  transition: all var(--transition);
  font-family: var(--font);
}

.theme-toggle:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Main content */
.main-content {
  flex: 1;
  padding: 2rem;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

/* Top bar (mobile) */
.top-bar {
  display: none;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.menu-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text);
  padding: 0.25rem;
  line-height: 1;
}

/* ============ Quiz Area ============ */
.quiz-header {
  margin-bottom: 2rem;
}

.section-title {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

.progress-info {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.progress-bar-wrap {
  flex: 1;
  min-width: 120px;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.4s ease;
}

/* Mode switch */
.mode-switch {
  display: flex;
  gap: 0;
  margin-bottom: 1.5rem;
  background: var(--bg-sidebar);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow: hidden;
  width: fit-content;
}

.mode-btn {
  padding: 0.6rem 1.4rem;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition);
  font-family: var(--font);
}

.mode-btn.active {
  background: var(--accent);
  color: #fff;
}

/* ============ Question Number Navigator ============ */
.question-nav {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.6rem 0.8rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

.question-nav-scroll {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.5rem;
}

.qn-dot {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  transition: all 0.2s ease;
  flex-shrink: 0;
  user-select: none;
}

.qn-dot:hover {
  transform: scale(1.12);
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
}

.qn-dot.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 6px rgba(139, 105, 20, 0.35);
}

.qn-dot.done {
  background: var(--success-bg);
  border-color: var(--success);
  color: var(--success);
}

.qn-dot.wrong {
  background: var(--danger-bg);
  border-color: var(--danger);
  color: var(--danger);
}

.qn-dot.done.active {
  background: var(--success);
  color: #fff;
}

.qn-dot.wrong.active {
  background: var(--danger);
  color: #fff;
}

.question-nav-legend {
  display: flex;
  gap: 1rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  align-items: center;
  flex-wrap: wrap;
}

.legend-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 3px;
  margin-right: 0.2rem;
  vertical-align: middle;
}

.legend-not-done {
  background: var(--bg);
  border: 2px solid var(--border);
}

.legend-done {
  background: var(--success-bg);
  border: 2px solid var(--success);
}

.legend-wrong {
  background: var(--danger-bg);
  border: 2px solid var(--danger);
}

/* Question card */
.question-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
  transition: all var(--transition);
  animation: fadeInUp 0.35s ease;
}

.question-type-badge {
  display: inline-block;
  padding: 0.2rem 0.7rem;
  border-radius: 1rem;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 1rem;
}

.badge-single {
  background: #e3f2fd;
  color: #1565c0;
}

.badge-multiple {
  background: #fce4ec;
  color: #c62828;
}

.badge-judge {
  background: #fff3e0;
  color: #e65100;
}

[data-theme="dark"] .badge-single {
  background: #1a2744;
  color: #64b5f6;
}

[data-theme="dark"] .badge-multiple {
  background: #3a1a24;
  color: #ef5350;
}

[data-theme="dark"] .badge-judge {
  background: #3a2a14;
  color: #ffb74d;
}

.question-text {
  font-size: 1.15rem;
  font-weight: 500;
  line-height: 1.7;
  margin-bottom: 1.5rem;
  color: var(--text);
}

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

.option-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  background: var(--bg);
  font-size: 0.95rem;
}

.option-item:hover {
  border-color: var(--accent-light);
  background: var(--bg-card);
}

.option-item.selected {
  border-color: var(--accent);
  background: rgba(139, 105, 20, 0.05);
}

[data-theme="dark"] .option-item.selected {
  background: rgba(212, 175, 55, 0.1);
}

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

.option-item.wrong {
  border-color: var(--danger);
  background: var(--danger-bg);
}

.option-radio {
  width: 22px;
  height: 22px;
  border: 2px solid var(--border);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all var(--transition);
}

.option-item.type-multiple .option-radio {
  border-radius: 4px;
}

.option-item.selected .option-radio {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.option-radio::after {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: transparent;
  transition: all var(--transition);
}

.option-item.selected .option-radio::after {
  background: #fff;
}

.option-item.type-multiple .option-radio::after {
  content: '✓';
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 0;
  width: auto;
  height: auto;
  background: transparent;
}

.option-item.correct .option-radio {
  border-color: var(--success);
  background: var(--success);
}

.option-item.wrong .option-radio {
  border-color: var(--danger);
  background: var(--danger);
}

.option-letter {
  font-weight: 700;
  color: var(--text-muted);
  width: 1.5em;
}

.option-text {
  flex: 1;
}

.option-icon {
  font-size: 1.1rem;
  display: none;
}

.option-item.correct .option-icon.correct-icon,
.option-item.wrong .option-icon.wrong-icon {
  display: inline;
}

/* Action buttons */
.question-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
  flex-wrap: wrap;
}

.btn {
  padding: 0.7rem 1.5rem;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--font);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

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

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

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

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

.btn-outline:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-success {
  background: var(--success);
  color: #fff;
}

.btn-success:hover {
  filter: brightness(1.1);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 0.5rem;
}

.btn-ghost:hover {
  color: var(--text);
}

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

/* ============ Section Transition Overlay ============ */
.section-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0.25s;
}

.section-overlay.show {
  opacity: 1;
  visibility: visible;
}

.section-overlay-content {
  background: var(--bg-card);
  padding: 2.5rem 3rem;
  border-radius: var(--radius);
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.4s ease;
}

@keyframes popIn {
  0% { transform: scale(0.8); opacity: 0; }
  70% { transform: scale(1.05); }
  100% { transform: scale(1); opacity: 1; }
}

.section-overlay-content .icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.section-overlay-content h3 {
  color: var(--accent);
  font-size: 1.2rem;
}

.section-overlay-content p {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

/* ============ Confirm Dialog ============ */
.confirm-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 5000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0.25s;
}

.confirm-overlay.show {
  opacity: 1;
  visibility: visible;
}

.confirm-dialog {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 2rem 1.75rem;
  width: 90%;
  max-width: 380px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: popIn 0.35s ease;
}

.confirm-icon {
  font-size: 2.5rem;
  margin-bottom: 0.5rem;
}

.confirm-dialog h3 {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.confirm-dialog p {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 1.5rem;
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

.confirm-actions .btn {
  min-width: 100px;
}

/* ============ Reset Buttons in Nav Legend ============ */
.nav-legend-spacer {
  flex: 1;
}

.btn-reset {
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.68rem;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: var(--font);
  white-space: nowrap;
}

.btn-reset:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-bg);
}

.btn-reset-all:hover {
  border-color: var(--danger);
  color: #fff;
  background: var(--danger);
}

/* ============ Mobile Sidebar Overlay ============ */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 150;
}

/* ============ Responsive Design ============ */

/* Tablet */
@media (max-width: 900px) {
  .sidebar {
    width: 260px;
    min-width: 260px;
  }
  .main-content {
    padding: 1.5rem;
  }
}

/* Mobile */
@media (max-width: 768px) {
  .app-container {
    display: block;
  }

  .top-bar {
    display: flex;
    width: 100%;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: 280px;
    min-width: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
    z-index: 200;
    transition: transform var(--transition);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    display: block;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s;
  }

  .sidebar-overlay.show {
    opacity: 1;
    visibility: visible;
  }

  .main-content {
    padding: 1rem;
    max-width: 100%;
    width: 100%;
  }

  .question-card {
    padding: 1.25rem;
  }

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

  .option-item {
    padding: 0.75rem 0.85rem;
    font-size: 0.9rem;
  }

  .question-actions {
    flex-direction: column;
  }

  .btn {
    justify-content: center;
    width: 100%;
  }

  .mode-switch {
    width: 100%;
  }

  .mode-btn {
    flex: 1;
    text-align: center;
  }

  .question-nav {
    padding: 0.5rem;
  }

  .question-nav-scroll {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.25rem;
  }

  .qn-dot {
    width: 36px;
    height: 36px;
    font-size: 0.82rem;
  }

  .gate-card {
    padding: 1.5rem;
  }
}

/* Small phones */
@media (max-width: 400px) {
  .question-card {
    padding: 1rem;
  }

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

  .section-title {
    font-size: 1.2rem;
  }

  .progress-info {
    font-size: 0.75rem;
  }
}

/* ============ Scrollbar ============ */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ============ Utility ============ */
.hidden {
  display: none !important;
}

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

.mt-2 {
  margin-top: 1rem;
}
