:root {
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
  --primary: #34c759;
  --primary-gradient: linear-gradient(180deg, #54E28E 0%, #34c759 100%);
  --secondary: #f2f2f7;
  --border: rgba(0, 0, 0, 0.08);
  --foreground: #1c1c1e;
  --muted-foreground: #8e8e93;
  --card-bg: rgba(255, 255, 255, 0.95);
  --glass-bg: rgba(255, 255, 255, 0.7);
  --glass-border: rgba(255, 255, 255, 0.4);
}

#quiz-hero-container {
  width: 100%;
  min-height: 550px;
  display: block;
  position: relative;
  z-index: 10;
}

.quiz-card {
  background: var(--card-bg);
  backdrop-filter: blur(20px);
  border-radius: var(--radius-lg);
  border: 1px solid var(--glass-border);
  box-shadow: 0px 20px 40px 0px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  aspect-ratio: 16 / 10;
  max-height: 85vh;
  width: 100%;
  font-family: 'Inter', sans-serif;
  color: var(--foreground);
  transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

/* Header */
.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 32px;
  background: rgba(255, 255, 255, 0.8);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.header-title {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.header-left,
.header-right {
  width: auto;
  min-width: 40px;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: opacity 0.2s;
}

.header-left:hover,
.header-right:hover {
  opacity: 0.7;
}

.header-right {
  justify-content: flex-end;
  gap: 16px;
}

/* Select Screen */
.select-screen .subject-list {
  padding: 32px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  flex: 1;
  overflow-y: auto;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
}

.subject-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.subject-item:hover {
  transform: translateY(-2px);
  box-shadow: 0px 4px 12px 0px rgba(0, 0, 0, 0.05);
  border-color: var(--primary);
}

.subject-icon {
  width: 48px;
  height: 48px;
  background: var(--secondary);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.subject-icon img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

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

.subject-chevron {
  flex-shrink: 0;
  font-size: 12px;
  color: var(--muted-foreground);
}

.subject-name {
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 6px;
  line-height: 1.2;
}

.subject-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: var(--muted-foreground);
}

.progress-mini {
  width: 60px;
  height: 6px;
  background: var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.progress-mini-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 10px;
}

/* Quiz Logic */
.quiz-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #fff;
  overflow-y: auto;
  min-width: 0;
  transition: all 0.3s ease;
}

.header-progress {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 0 40px;
}

.progress-bar {
  width: 100%;
  max-width: 400px;
  height: 8px;
  background: var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--foreground);
  border-radius: 10px;
  transition: width 0.4s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.question-body {
  padding: 40px 60px;
  flex: 1;
  overflow-y: auto;
}

.question-text {
  font-size: 17px;
  line-height: 1.6;
  font-weight: 400;
  margin-bottom: 32px;
  color: var(--foreground);
}

.question-text table {
  width: 100%;
  margin-bottom: 16px;
}

.options-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.option-item {
  padding: 20px 24px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  background: #fff;
  position: relative;
  font-size: 15px;
  line-height: 1.4;
}

.option-item:hover:not(.selected):not(.correct):not(.wrong) {
  background: var(--secondary);
  border-color: var(--muted-foreground);
}

.option-item.selected {
  border: 2px solid var(--primary);
  background: #f0fbf3;
}

.option-item.correct {
  border: 2px solid #34c759;
  background: #f0fbf3;
}

.option-item.wrong {
  border: 2px solid #fb3748;
  background: #fff0f0;
}

/* Footer */
.quiz-footer {
  padding: 20px 40px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 88px;
}

.quiz-footer.result-correct {
  background: #effaf3;
}

.quiz-footer.result-wrong {
  background: #fff5f5;
}

.footer-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.feedback {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}

.btn-pembahasan {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s;
}

.btn-pembahasan:hover:not(:disabled) {
  background: var(--secondary);
}

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

.btn-next {
  padding: 14px 40px;
  border-radius: var(--radius-sm);
  background: var(--primary-gradient);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  border: none;
  cursor: pointer;
  box-shadow: 0px 4px 12px 0px rgba(52, 199, 89, 0.2);
  transition: all 0.2s;
}

.btn-next:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0px 6px 16px 0px rgba(52, 199, 89, 0.3);
}

.btn-next:disabled {
  background: var(--border);
  box-shadow: none;
  color: var(--muted-foreground);
  cursor: not-allowed;
}

/* ====== Sidebar Pembahasan ====== */
.quiz-sidebar {
  position: absolute;
  top: 0;
  right: 0;
  width: 480px;
  height: 100%;
  background: #fff;
  border-left: 1px solid var(--border);
  z-index: 30;
  transform: translateX(100%);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  box-shadow: -10px 0 30px rgba(0, 0, 0, 0.05);
}

.quiz-card.with-sidebar .quiz-sidebar {
  transform: translateX(0);
}

.quiz-card.with-sidebar .quiz-main {
  margin-right: 480px;
}

.sidebar-header {
  padding: 24px 32px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  display: flex;
  align-items: center;
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
  flex-shrink: 0;
}

.sidebar-header div {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
}

/* Sidebar body: flex column with scrollable content + fixed bottom input */
.sidebar-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 30px;
  min-height: 0;
}

.pembahasan-text {
  line-height: 1.6;
  font-size: 15px;
  color: var(--foreground);
}

.pembahasan-text b {
  font-weight: 700;
}

/* Ica AI Section */
.ica-ai-section {
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.ica-avatar {
  width: 56px;
  height: 56px;
  background: linear-gradient(135deg, #ff5099, #ff2d85);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 28px;
  margin-bottom: 16px;
  box-shadow: 0px 4px 12px 0px rgba(255, 45, 133, 0.3);
}

.ica-name {
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 6px;
}

.ica-desc {
  font-size: 13px;
  color: var(--muted-foreground);
  max-width: 220px;
  line-height: 1.4;
}

/* Chat Date Separator */
.chat-date-separator {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 24px 0 16px;
}

.chat-date-line {
  flex: 1;
  height: 1px;
  background: var(--border);
}

.chat-date-separator span {
  font-size: 11px;
  color: var(--muted-foreground);
  font-weight: 400;
  white-space: nowrap;
}

/* Chat Bubbles */
.chat-bubble-user {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.chat-bubble-user-text {
  background: var(--secondary);
  border-radius: 16px;
  padding: 8px 16px;
  max-width: 80%;
  font-size: 13px;
  line-height: 1.4;
  color: var(--foreground);
}

.chat-bubble-ica {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 12px;
}

.ica-mini-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.chat-bubble-ica-content {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 85%;
}

.chat-bubble-ica-meta {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-bubble-ica-text {
  font-size: 13px;
  line-height: 1.4;
  color: var(--foreground);
}

.ica-chat-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.ica-chat-option-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #f8f9fb;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--foreground);
  cursor: pointer;
  line-height: 1.4;
  transition: background 0.15s, border-color 0.15s;
}

.ica-chat-option-btn:hover {
  background: #eef0f4;
  border-color: #c5c8ce;
}

.ica-chat-list-item {
  display: block;
}

.chat-bubble-ica-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted-foreground);
  font-size: 14px;
}

.chat-source-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  background: #f8f9fb;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 10px;
  font-weight: 500;
  cursor: pointer;
  color: var(--foreground);
}

/* Chat Input Area (fixed at bottom of sidebar) */
.chat-input-area {
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  background: #fff;
  flex-shrink: 0;
}

.chat-input-bar {
  display: flex;
  align-items: center;
  background: var(--secondary);
  border-radius: 24px;
  padding: 8px 12px;
  gap: 8px;
}

.chat-img-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--muted-foreground);
  cursor: pointer;
  font-size: 16px;
  flex-shrink: 0;
  transition: all 0.2s;
}

.chat-img-btn:hover {
  color: var(--foreground);
  background: rgba(255,255,255,0.6);
}

.chat-input-bar input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 14px;
  font-family: 'Inter', sans-serif;
  color: var(--foreground);
}

.chat-input-bar input::placeholder {
  color: var(--muted-foreground);
}

.chat-input-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
}

/* Auto Mode */
.chat-auto-mode-wrap {
  position: relative;
}

.chat-auto-mode-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 12px;
  font-weight: 500;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  color: var(--foreground);
  transition: all 0.2s;
}

.chat-auto-mode-btn:hover {
  background: var(--secondary);
}

.chat-auto-chevron {
  font-size: 10px;
  transition: transform 0.2s;
}

.chat-auto-chevron.open {
  transform: rotate(180deg);
}

/* Auto Mode Dropdown (opens upward) */
.auto-mode-dropdown {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  width: 280px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0px 8px 32px 0px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  z-index: 50;
  padding: 8px 0;
  animation: dropdownIn 0.15s ease-out;
}

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

.auto-mode-option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 20px;
  cursor: pointer;
  transition: background 0.15s;
}

.auto-mode-option:hover {
  background: var(--secondary);
}

.auto-mode-option-text {
  flex: 1;
  min-width: 0;
}

.auto-mode-option-label {
  font-size: 14px;
  font-weight: 600;
  color: var(--foreground);
  line-height: 1.4;
}

.auto-mode-option-desc {
  font-size: 12px;
  color: var(--muted-foreground);
  line-height: 1.3;
}

/* Send Button */
.chat-send-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: not-allowed;
  background: var(--secondary);
  color: var(--muted-foreground);
  transition: all 0.2s;
}

.chat-send-btn.active {
  background: var(--primary);
  color: #fff;
  cursor: pointer;
}

.chat-send-btn.active:hover {
  opacity: 0.9;
}

/* ====== Phase 2: True/False Styles ====== */
.tf-statements {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.tf-statement-block {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tf-statement-label {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  font-size: 16px;
  line-height: 1.5;
  color: var(--foreground);
}

.tf-numeral {
  font-weight: 600;
  min-width: 24px;
  flex-shrink: 0;
}

.tf-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-left: 36px;
}

.tf-option-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 15px;
}

.tf-option-item:hover:not(.selected):not(.correct):not(.wrong) {
  background: var(--secondary);
}

.tf-option-item.selected {
  border: 2px solid var(--primary);
  background: #f0fbf3;
}

.tf-option-item.correct {
  border: 2px solid #34c759;
  background: #f0fbf3;
}

.tf-option-item.wrong {
  border: 2px solid #fb3748;
  background: #fff0f0;
}

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

.tf-radio.active {
  border-color: #34c759;
  background: #34c759;
}

.tf-radio-inner {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: transparent;
}

.tf-radio.active .tf-radio-inner {
  background: #fff;
}

.btn-periksa {
  margin-top: 16px;
  width: 100%;
  height: 48px;
  border-radius: var(--radius-sm);
  border: none;
  color: #fff;
  font-weight: 600;
  font-size: 16px;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  background: linear-gradient(180deg, #54E28E 0%, #34c759 100%);
  transition: all 0.2s;
}

.btn-periksa:hover {
  transform: translateY(-1px);
  box-shadow: 0px 4px 12px 0px rgba(52, 199, 89, 0.3);
}

/* ====== Phase 3: CTA Modal ====== */
#cta-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.cta-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
}

.cta-card {
  position: relative;
  background: #fff;
  border-radius: 40px;
  box-shadow: 0px 32px 64px -12px rgba(0, 0, 0, 0.14);
  max-width: 440px;
  width: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 48px 40px;
  animation: ctaIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

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

.cta-title {
  font-family: 'Inter', sans-serif;
  font-size: 26px;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: -0.02em;
  color: var(--foreground);
  margin-bottom: 16px;
}

.cta-desc {
  font-family: 'Inter', sans-serif;
  font-size: 17px;
  font-weight: 400;
  line-height: 1.5;
  color: var(--foreground);
  margin-bottom: 40px;
}

.cta-buttons {
  display: flex;
  flex-direction: column;
  width: 100%;
  gap: 16px;
  align-items: center;
}

.cta-btn-primary {
  width: 100%;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 20px;
  background: #ff2d85;
  color: #fff;
  font-family: 'Inter', sans-serif;
  font-size: 20px;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.2s;
}

.cta-btn-primary:hover {
  opacity: 0.95;
}

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

.cta-btn-secondary {
  padding: 8px 24px;
  background: transparent;
  border: none;
  color: var(--muted-foreground);
  font-family: 'Inter', sans-serif;
  font-size: 18px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.2s;
}

.cta-btn-secondary:hover {
  color: var(--foreground);
}

/* ====== KaTeX overrides ====== */
.question-text .katex-display {
  margin: 16px 0;
  overflow-x: auto;
}

.pembahasan-text .katex-display {
  margin: 12px 0;
  overflow-x: auto;
}

/* ====== Responsive ====== */
@media (max-width: 992px) {
  .quiz-card {
    aspect-ratio: auto;
    height: 600px;
  }

  .quiz-card.with-sidebar {
    flex-direction: column;
  }

  .quiz-card.with-sidebar .quiz-main {
    margin-right: 0;
  }

  .quiz-sidebar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    max-height: none;
    border-left: none;
    border-top: none;
    transform: none;
    box-shadow: none;
    z-index: 30;
  }

  .quiz-card.with-sidebar .quiz-sidebar {
    transform: none;
  }

  .question-body {
    padding: 24px 20px;
  }

  .quiz-footer {
    padding: 16px 20px;
    flex-wrap: wrap;
    gap: 12px;
  }

  .quiz-header {
    padding: 12px 16px;
  }

  .sidebar-scroll {
    padding: 20px;
  }

  .chat-input-area {
    padding: 10px 12px;
  }
}

@media (max-width: 768px) {
  .question-body {
    padding: 20px 16px;
  }

  .quiz-footer {
    padding: 12px 16px;
  }

  .btn-next {
    padding: 12px 24px;
  }

  .btn-pembahasan {
    padding: 10px 14px;
    font-size: 13px;
  }

  .cta-card {
    padding: 36px 24px;
    border-radius: 28px;
  }

  .cta-title {
    font-size: 22px;
  }

  .cta-desc {
    font-size: 15px;
    margin-bottom: 28px;
  }

  .cta-btn-primary {
    height: 56px;
    font-size: 18px;
    border-radius: 16px;
  }

  .tf-options {
    margin-left: 0;
  }
}
