/* All CSS variables are defined in /theme.css — do not add :root variables here */

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  padding: clamp(1.5rem, 3vw, 3rem);
  font-family: var(--font-body, 'Inter', system-ui, sans-serif);
  background:
    radial-gradient(circle at 20% 20%, var(--bg-accent), transparent 60%),
    radial-gradient(circle at 80% 10%, var(--bg-accent-2), transparent 55%),
    linear-gradient(160deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
  color: var(--text-main);
  line-height: 1.6;
}

.app-shell {
  max-width: 1200px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
  gap: clamp(1.5rem, 4vw, 3rem);
  align-items: start;
}

.sidebar {
  position: sticky;
  top: clamp(1rem, 2vw, 2rem);
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 1rem;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  max-height: calc(100vh - 4rem);
  overflow: auto;
}

.sidebar-header h1 {
  margin: 0.5rem 0 0.75rem 0;
  font-size: clamp(1.3rem, 2.8vw, 1.75rem);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.sidebar-subtitle {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin: 0;
}

.sidebar-section h2 {
  margin: 0 0 0.75rem 0;
  font-size: 1rem;
  color: var(--text-accent);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.question-search {
  margin-bottom: 1rem;
}

.question-search input {
  width: 100%;
  padding: 0.6rem 0.8rem;
  background: var(--surface-input);
  border: 1px solid var(--border-soft);
  border-radius: 0.5rem;
  color: var(--text-main);
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.question-search input::placeholder {
  color: var(--text-muted);
}

.question-search input:focus {
  outline: none;
  border-color: var(--focus-ring);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.question-link.search-match {
  background: var(--accent-soft);
  border-color: var(--accent-strong);
}

.search-highlight {
  background: var(--status-warning-soft);
  border-radius: 2px;
  padding: 0 1px;
}

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

.topic-group {
  border: 1px solid var(--border-soft);
  border-radius: 0.75rem;
  padding: 0.5rem 0.75rem;
  background: var(--surface-strong);
}

.topic-group summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-accent);
  list-style: none;
}

.topic-group summary::-webkit-details-marker {
  display: none;
}

.topic-questions {
  margin-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.question-link {
  text-align: left;
  border: 1px solid transparent;
  background: var(--surface-muted);
  color: var(--text-main);
  padding: 0.55rem 0.75rem;
  min-height: var(--touch-min, 2.75rem);
  border-radius: 0.6rem;
  font-size: 0.85rem;
  line-height: 1.4;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.question-link:hover {
  border-color: var(--button-border-hover);
}

.question-link.active {
  background: var(--accent-soft);
  border-color: var(--accent-strong);
}

.card-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 1.25rem;
  padding: clamp(1.5rem, 3vw, 2.5rem);
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.card-type-badge {
  background: var(--badge-bg);
  color: var(--text-accent);
  padding: 0.35rem 0.85rem;
  border-radius: 0.375rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  width: fit-content;
}

.card-type-badge.practice {
  background: linear-gradient(135deg, var(--status-info) 0%, var(--status-info) 100%);
  color: white;
}

.card-header {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
}

.card-question {
  font-size: clamp(1.5rem, 4vw, 2.25rem);
  line-height: 1.3;
  margin: 0;
  font-weight: 700;
  color: var(--text-main);
  text-align: left;
}

.card-answer {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  text-align: left;
  max-height: 2000px;
  opacity: 1;
  transition: max-height 0.4s ease, opacity 0.3s ease;
  overflow: hidden;
}

.card-answer.is-hidden {
  max-height: 0;
  opacity: 0;
  padding: 0;
  margin: 0;
}

.answer-text {
  font-size: clamp(1rem, 2.5vw, 1.25rem);
  line-height: 1.7;
  margin: 0;
  color: var(--text-accent);
}

.answer-list {
  font-size: clamp(1rem, 2.5vw, 1.2rem);
  line-height: 1.8;
  margin: 0.5rem 0;
  padding-left: 1.5rem;
  color: var(--text-accent);
}

.answer-list li {
  margin: 0.5rem 0;
  padding-left: 0.25rem;
}

.answer-list li::marker {
  color: var(--good-color);
}

.table-wrapper {
  margin: 1rem 0;
  overflow-x: auto;
  border-radius: 0.5rem;
  border: 1px solid var(--code-border);
}

.answer-table {
  width: 100%;
  border-collapse: collapse;
  font-size: clamp(0.85rem, 2vw, 1rem);
  background: var(--code-bg);
}

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

.answer-table th {
  background: var(--table-header-bg);
  color: var(--text-accent);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.85em;
  letter-spacing: 0.05em;
}

.answer-table tbody tr:hover {
  background: var(--table-row-hover);
}

.answer-table tbody tr:last-child td {
  border-bottom: none;
}

.code-wrapper {
  position: relative;
  background: var(--code-bg);
  border: 1px solid var(--code-border);
  border-radius: 0.5rem;
  overflow: hidden;
  margin: 0.5rem 0;
}

.code-wrapper.good {
  border-left: 4px solid var(--good-color);
}

.code-wrapper.bad {
  border-left: 4px solid var(--bad-color);
}

.code-badge {
  display: inline-block;
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 0 0 0.375rem 0;
  position: absolute;
  top: 0;
  right: 0;
  z-index: 1;
}

.code-badge.good {
  background: var(--good-color);
  color: white;
}

.code-badge.bad {
  background: var(--bad-color);
  color: white;
}

pre {
  margin: 0;
  padding: 3rem 1.25rem 1.25rem 1.25rem;
  overflow-x: auto;
  font-family: 'JetBrains Mono', 'Consolas', 'Monaco', monospace;
  font-size: clamp(0.8rem, 1.8vw, 0.95rem);
  line-height: 1.6;
}

code {
  font-family: inherit;
  color: var(--code-text, var(--text-main));
}

/* Syntax highlighting is handled by highlight.js CDN themes (github-dark / github) */
code[class*="language-"],
pre[class*="language-"] {
  color: var(--code-text, var(--text-main));
  background: none;
  font-family: 'JetBrains Mono', 'Consolas', 'Monaco', monospace;
  text-align: left;
  white-space: pre;
  word-spacing: normal;
  word-break: normal;
  word-wrap: normal;
  line-height: 1.6;
  tab-size: 4;
}

.answer-check {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
  border-radius: 0.85rem;
  background: var(--surface-strong);
  border: 1px solid var(--border-soft);
}

.answer-check label {
  font-weight: 600;
  color: var(--text-accent);
}

.answer-check textarea {
  resize: vertical;
  width: 100%;
  min-height: 120px;
  border-radius: 0.75rem;
  border: 1px solid var(--border-soft);
  background: var(--surface-input);
  color: var(--text-main);
  padding: 0.75rem 0.9rem;
  font-size: 0.95rem;
  font-family: var(--font-body, 'Inter', system-ui, sans-serif);
}

.answer-check textarea:focus {
  outline: 2px solid var(--focus-ring);
  border-color: transparent;
}

.check-result {
  min-height: 1.4rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.check-result[data-tone="good"] {
  color: var(--good-color);
}

.check-result[data-tone="okay"] {
  color: var(--status-info-text, var(--status-info));
}

.check-result[data-tone="warning"] {
  color: var(--warn-color);
}

.card-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
}

.card-actions .btn {
  min-height: var(--touch-min, 2.75rem);
  padding: 0.6rem 1rem;
}

.btn {
  padding: 0.65rem 1rem;
  min-height: var(--touch-min, 2.75rem);
  border-radius: var(--radius-md, 0.75rem);
  border: 1px solid var(--border-soft);
  background: var(--button-bg);
  color: var(--text-main);
  cursor: pointer;
  font-weight: 600;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.2s ease;
}

.btn:hover {
  border-color: var(--button-border-hover);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn.primary {
  background: var(--primary, linear-gradient(135deg, var(--accent-soft), var(--accent-strong)));
  border-color: var(--accent-strong);
}

.btn.primary:focus {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.btn.primary:active {
  background: var(--primary, var(--accent-strong));
}

.btn.ghost {
  background: transparent;
}

.theme-switcher {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.theme-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  font-weight: 600;
}

.theme-select {
  background: var(--bg-secondary);
  color: var(--text-main);
  border: 1px solid var(--border-soft);
  border-radius: 0.65rem;
  padding: 0.5rem 0.75rem;
  font-weight: 600;
}

:root[data-theme='light'] .answer-table th {
  color: var(--text-accent);
}

:root[data-theme='light'] code,
:root[data-theme='light'] pre,
:root[data-theme='light'] code[class*="language-"],
:root[data-theme='light'] pre[class*="language-"] {
  color: var(--code-text, var(--text-main));
}

/* Wide screen optimization */
@media (min-width: 1024px) {
  .app-shell {
    max-width: 1400px;
    gap: clamp(2rem, 4vw, 3.5rem);
  }

  .card-panel {
    padding: 2.5rem;
  }

  .sidebar {
    padding: 1.75rem;
    gap: 1.75rem;
  }
}

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    max-height: none;
  }
}

.card-meta {
  margin: 0;
  font-size: clamp(0.75rem, 2vw, 0.9rem);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: left;
}

/* Scrollbar styling for code blocks */
pre::-webkit-scrollbar {
  height: 8px;
}

pre::-webkit-scrollbar-track {
  background: var(--bg-primary);
  border-radius: 4px;
}

pre::-webkit-scrollbar-thumb {
  background: var(--code-border);
  border-radius: 4px;
}

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

@media (max-width: 768px) {
  body {
    padding: 1.5rem 1rem;
  }

  .card-question {
    font-size: 1.5rem;
  }

  .answer-text {
    font-size: 1rem;
  }

  pre {
    padding: 2.5rem 1rem 1rem 1rem;
    font-size: 0.8rem;
  }

  .code-badge {
    font-size: 0.75rem;
    padding: 0.3rem 0.6rem;
  }
}

@media (max-width: 640px) {
  .sidebar {
    padding: 1rem;
    gap: 1rem;
  }

  .sidebar-header h1 {
    font-size: 1.2rem;
  }

  .sidebar-section h2 {
    font-size: 0.9rem;
  }

  .card-panel {
    padding: 1.25rem;
    gap: 1.25rem;
  }

  .card-question {
    font-size: 1.35rem;
  }

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

  .card-actions {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.5rem;
  }
}

@media (max-width: 480px) {
  body {
    padding: 0.75rem 0.5rem;
  }

  .card-type-badge {
    font-size: 0.65rem;
    padding: 0.25rem 0.65rem;
  }

  .card-question {
    font-size: 1.25rem;
  }

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

  pre {
    font-size: 0.8rem;
  }

  .card-meta {
    letter-spacing: 0.1em;
  }

  .card-actions {
    grid-template-columns: 1fr;
  }

  .card-actions .btn {
    width: 100%;
  }

  .answer-check textarea {
    width: 100%;
    min-height: 100px;
  }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
  .card-panel,
  * {
    transition-duration: 0.01ms !important;
  }
}

/* Print styles */
@media print {
  body {
    background: white;
    color: black;
  }

  .card-panel,
  .sidebar {
    background: white;
    color: black;
    border-color: #ccc;
  }

  .code-wrapper {
    border: 1px solid #ccc;
    page-break-inside: avoid;
  }

  pre {
    background: #f5f5f5;
  }

  code {
    color: black;
  }
}

.global-nav {
  margin-bottom: 1.5rem;
}

.global-nav__inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.75rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 0.9rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
}

.global-nav__home {
  font-weight: 600;
  color: var(--text-main);
  text-decoration: none;
}

.global-nav__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  background: var(--surface-strong);
  color: var(--text-main);
  text-decoration: none;
}

.global-nav__icon svg {
  width: 17px;
  height: 17px;
}

.global-nav__icon:hover {
  border-color: var(--accent-strong);
  color: var(--text-main);
}

.global-nav__links {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  align-items: center;
}

.global-nav__label {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.global-nav__links a {
  color: var(--text-accent);
  text-decoration: none;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  border: 1px solid transparent;
  font-size: 0.85rem;
}

.global-nav__links a:hover {
  border-color: var(--border-soft);
  color: var(--text-main);
}

/* ============================================================================
   Multiple-Choice Question (MCQ) Practice Styles
   ============================================================================ */

.mcq-hidden-el {
  display: none !important;
}

.practice-mcq {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.practice-mcq-hint {
  margin: 0 0 0.25rem 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.practice-mcq-option {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  min-height: 44px;
  background: var(--surface-strong, var(--bg-card));
  border: 2px solid var(--border-soft);
  border-radius: 0.75rem;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
  user-select: none;
}

.practice-mcq-option:hover {
  border-color: var(--button-border-hover, var(--border-soft));
  background: var(--surface-muted, var(--bg-card));
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.practice-mcq-option:has(input:checked) {
  border-color: var(--accent-strong, #3b82f6);
  background: var(--accent-soft, rgba(59, 130, 246, 0.1));
  box-shadow: 0 0 0 2px var(--accent-soft, rgba(59, 130, 246, 0.15));
}

.practice-mcq-option:has(input:focus-visible) {
  outline: 2px solid var(--focus-ring, #3b82f6);
  outline-offset: 2px;
}

.practice-mcq-option input[type="radio"],
.practice-mcq-option input[type="checkbox"] {
  width: 0;
  height: 0;
  opacity: 0;
  position: absolute;
  pointer-events: none;
}

.practice-mcq-letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  min-width: 2rem;
  border-radius: 0.5rem;
  background: var(--surface-muted, var(--bg-card));
  border: 1px solid var(--border-soft);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--text-accent);
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.practice-mcq-option:has(input:checked) .practice-mcq-letter {
  background: var(--accent-strong, #3b82f6);
  color: white;
  border-color: var(--accent-strong, #3b82f6);
}

.practice-mcq-text {
  flex: 1;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-main);
}

/* MCQ Correct/Incorrect Feedback */
.practice-mcq-option.mcq-correct {
  border-color: var(--good-color, #22c55e);
  background: rgba(34, 197, 94, 0.1);
}

.practice-mcq-option.mcq-correct .practice-mcq-letter {
  background: var(--good-color, #22c55e);
  color: white;
  border-color: var(--good-color, #22c55e);
}

.practice-mcq-option.mcq-incorrect {
  border-color: var(--bad-color, #ef4444);
  background: rgba(239, 68, 68, 0.1);
}

.practice-mcq-option.mcq-incorrect .practice-mcq-letter {
  background: var(--bad-color, #ef4444);
  color: white;
  border-color: var(--bad-color, #ef4444);
}

/* Disabled state after check/reveal */
.practice-mcq-option:has(input:disabled) {
  cursor: default;
  opacity: 0.85;
}

.practice-mcq-option:has(input:disabled):hover {
  box-shadow: none;
}

/* Light theme adjustments */
:root[data-theme='light'] .practice-mcq-option.mcq-correct {
  background: rgba(34, 197, 94, 0.08);
}

:root[data-theme='light'] .practice-mcq-option.mcq-incorrect {
  background: rgba(239, 68, 68, 0.08);
}

:root[data-theme='light'] .practice-mcq-option:has(input:checked) {
  background: rgba(59, 130, 246, 0.08);
}

/* MCQ responsive */
@media (max-width: 480px) {
  .practice-mcq-option {
    padding: 0.6rem 0.75rem;
    gap: 0.5rem;
  }

  .practice-mcq-letter {
    width: 1.75rem;
    height: 1.75rem;
    min-width: 1.75rem;
    font-size: 0.8rem;
  }

  .practice-mcq-text {
    font-size: 0.9rem;
  }
}
