/* =========================================
   ICAN Exam Prep - Mobile-first stylesheet
   Vanilla CSS, no frameworks
   ========================================= */

:root {
  --ican-green: #0a8043;
  --ican-green-dark: #066632;
  --ican-green-light: #e6f5ec;
  --bg: #ffffff;
  --bg-soft: #f7f8fa;
  --text: #1c1f23;
  --text-muted: #5a6470;
  --border: #e3e6ea;
  --border-strong: #c8ccd3;
  --success: #0a8043;
  --danger: #c0392b;
  --warning: #b7791f;
  --info: #2b6cb0;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.08);
  --radius: 10px;
  --radius-sm: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --max-w: 768px;
}

[data-theme="dark"] {
  --bg: #0f1419;
  --bg-soft: #1a2027;
  --text: #e6e9ed;
  --text-muted: #8a96a6;
  --border: #2a323b;
  --border-strong: #3a4250;
  --ican-green-light: #14291f;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.4);
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  overflow-x: hidden;
  max-width: 100vw;
  width: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  font-size: 16px;
  min-height: 100vh;
  transition: background-color 0.2s, color 0.2s;
  overflow-x: hidden;
  max-width: 100vw;
  width: 100%;
  word-wrap: break-word;
  overflow-wrap: break-word;
  position: relative;
}

main, .container, .card, .paper-item, .question-card, .quiz-option,
.option, .results, .results-breakdown, .question-list, .quiz-options,
.quiz-header, .quiz-stat, .quiz-progress, .question-text,
.question-num, .options {
  max-width: 100%;
  overflow-wrap: break-word;
  word-wrap: break-word;
  min-width: 0;
}

/* Layout */
.container {
  max-width: var(--max-w);
  margin: 0 auto;
  padding: 16px;
}

/* Header */
.app-header {
  background: var(--ican-green);
  color: #fff;
  padding: 14px 16px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow);
}

.app-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0;
  max-width: var(--max-w);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
  text-decoration: none;
  color: #fff;
}

.brand-mark {
  width: 32px;
  height: 32px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.85rem;
  letter-spacing: 0.5px;
}

.theme-toggle {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.1rem;
  display: grid;
  place-items: center;
  transition: background 0.15s;
}

.theme-toggle:hover {
  background: rgba(255, 255, 255, 0.25);
}

.theme-toggle:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* Hero */
.hero {
  padding: 24px 0 16px;
  text-align: center;
  max-width: 100%;
  overflow-wrap: break-word;
}

.hero h1 {
  font-size: 1.5rem;
  font-weight: 800;
  margin-bottom: 8px;
  letter-spacing: -0.01em;
  max-width: 100%;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.hero p {
  color: var(--text-muted);
  font-size: 0.95rem;
  max-width: 100%;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

/* Section heading */
.section-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 18px 0 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.section-title .badge {
  font-size: 0.7rem;
  background: var(--ican-green-light);
  color: var(--ican-green);
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 700;
}

/* Cards grid */
.cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  margin-top: 12px;
}

@media (min-width: 540px) {
  .cards {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 720px) {
  .cards {
    grid-template-columns: repeat(3, 1fr);
  }
}

.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-decoration: none;
  color: var(--text);
  display: block;
  transition: transform 0.12s, box-shadow 0.12s, border-color 0.12s;
  box-shadow: var(--shadow);
}

.card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: var(--ican-green);
}

.card:focus-visible {
  outline: 2px solid var(--ican-green);
  outline-offset: 2px;
}

.card-level {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ican-green);
  font-weight: 700;
  margin-bottom: 6px;
}

.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 6px;
  max-width: 100%;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.card-desc {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
  max-width: 100%;
  overflow-wrap: break-word;
  word-wrap: break-word;
}

.card-meta {
  margin-top: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.card-arrow {
  color: var(--ican-green);
  font-weight: 700;
}

/* Paper list */
.paper-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.paper-item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow);
  transition: border-color 0.12s, transform 0.12s;
}

@media (min-width: 540px) {
  .paper-item {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.paper-item:hover {
  border-color: var(--ican-green);
  transform: translateX(2px);
}

.paper-item:focus-visible {
  outline: 2px solid var(--ican-green);
  outline-offset: 2px;
}

.paper-info {
  flex: 1;
  min-width: 0;
  max-width: 100%;
}

.paper-code {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--ican-green);
  background: var(--ican-green-light);
  padding: 2px 8px;
  border-radius: 4px;
  display: inline-block;
  margin-bottom: 4px;
}

.paper-name {
  font-weight: 600;
  font-size: 0.95rem;
  word-wrap: break-word;
}

.paper-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  flex-wrap: wrap;
  max-width: 100%;
}

@media (max-width: 539px) {
  .paper-actions {
    width: 100%;
  }
  .paper-actions .btn-icon {
    flex: 1;
    text-align: center;
  }
}

.paper-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.paper-diets {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.diet-line {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  color: var(--text-muted);
  padding: 2px 0;
  gap: 8px;
}

.diet-line .diet-label {
  font-weight: 600;
}

.diet-line .diet-counts {
  font-variant-numeric: tabular-nums;
}

.btn-icon.disabled {
  background: var(--bg-soft);
  color: var(--text-muted);
  border: 1px solid var(--border);
  cursor: not-allowed;
  opacity: 0.6;
}

.diet-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 12px 0;
  max-width: 100%;
}

.diet-chip {
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  color: var(--text);
  text-decoration: none;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
  line-height: 1.3;
  flex: 0 1 auto;
  min-width: 0;
  max-width: 100%;
}

.diet-chip.active {
  background: var(--ican-green);
  color: #fff;
  border-color: var(--ican-green);
}

.diet-chip:hover:not(.active) {
  border-color: var(--ican-green);
  color: var(--ican-green);
}

.btn-icon {
  background: var(--ican-green);
  color: #fff;
  border: none;
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  text-decoration: none;
  display: inline-block;
  text-align: center;
  transition: background 0.15s;
}

.btn-icon:hover {
  background: var(--ican-green-dark);
}

.btn-icon.secondary {
  background: var(--bg-soft);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-icon.secondary:hover {
  background: var(--ican-green-light);
  color: var(--ican-green);
  border-color: var(--ican-green);
}

/* Breadcrumb */
.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 14px 0 6px;
  flex-wrap: wrap;
}

.breadcrumb a {
  color: var(--ican-green);
  text-decoration: none;
  font-weight: 600;
}

.breadcrumb a:hover {
  text-decoration: underline;
}

.breadcrumb .sep {
  color: var(--border-strong);
}

/* Question card */
.question-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 14px;
}

.question-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.question-num {
  font-size: 0.75rem;
  color: var(--ican-green);
  font-weight: 700;
  margin-bottom: 6px;
}

.question-text {
  font-weight: 600;
  margin-bottom: 12px;
  line-height: 1.5;
}

.options {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.option {
  padding: 10px 12px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  line-height: 1.4;
}

.option-letter {
  font-weight: 700;
  color: var(--ican-green);
  flex-shrink: 0;
}

.explanation {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--ican-green-light);
  border-left: 3px solid var(--ican-green);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--text);
}

.explanation strong {
  display: block;
  margin-bottom: 4px;
  color: var(--ican-green-dark);
}

[data-theme="dark"] .explanation strong {
  color: var(--ican-green);
}

/* Quiz mode */
.quiz-header {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin: 14px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.quiz-stat {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.quiz-stat strong {
  color: var(--text);
  font-weight: 700;
}

.quiz-progress {
  width: 100%;
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
}

.quiz-progress-bar {
  height: 100%;
  background: var(--ican-green);
  transition: width 0.3s ease;
}

.quiz-options {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}

.quiz-option {
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  font-size: 0.95rem;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  text-align: left;
  font-family: inherit;
  color: var(--text);
  transition: border-color 0.12s, background 0.12s;
  width: 100%;
  line-height: 1.4;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.quiz-option:hover:not(:disabled) {
  border-color: var(--ican-green);
  background: var(--ican-green-light);
}

.quiz-option:focus-visible {
  outline: 2px solid var(--ican-green);
  outline-offset: 2px;
}

.quiz-option .option-letter {
  width: 28px;
  height: 28px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.quiz-option.correct {
  border-color: var(--ican-green);
  background: var(--ican-green-light);
}

.quiz-option.correct .option-letter {
  background: var(--ican-green);
  color: #fff;
  border-color: var(--ican-green);
}

.quiz-option.incorrect {
  border-color: var(--danger);
  background: rgba(192, 57, 43, 0.08);
}

.quiz-option.incorrect .option-letter {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.quiz-option:disabled {
  cursor: default;
}

.quiz-feedback {
  margin-top: 16px;
  padding: 14px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  display: none;
}

.quiz-feedback.show {
  display: block;
}

.quiz-feedback.correct {
  background: var(--ican-green-light);
  border-left: 3px solid var(--ican-green);
}

.quiz-feedback.incorrect {
  background: rgba(192, 57, 43, 0.08);
  border-left: 3px solid var(--danger);
}

.quiz-feedback-title {
  font-weight: 700;
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.quiz-feedback-body {
  margin-top: 6px;
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: pre-wrap;
  line-height: 1.4;
  max-width: 100%;
}

.quiz-feedback-wrong {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
}

.quiz-feedback-wrong strong {
  color: var(--danger);
  display: block;
  margin-bottom: 2px;
}

.explanation-wrong-list {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  font-size: 0.85rem;
  color: var(--text-muted);
}

.explanation-wrong-row {
  margin-bottom: 4px;
  line-height: 1.4;
}

.explanation-wrong-row strong {
  color: var(--ican-green-dark);
  margin-right: 4px;
}

.quiz-actions {
  margin-top: 16px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  background: var(--ican-green);
  color: #fff;
  border: none;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  font-family: inherit;
  text-decoration: none;
  display: inline-block;
  text-align: center;
  transition: background 0.15s;
  flex: 1;
  min-width: 120px;
}

.btn:hover {
  background: var(--ican-green-dark);
}

.btn:focus-visible {
  outline: 2px solid var(--ican-green);
  outline-offset: 2px;
}

.btn.outline {
  background: transparent;
  color: var(--ican-green);
  border: 1.5px solid var(--ican-green);
}

.btn.outline:hover {
  background: var(--ican-green-light);
}

/* Results */
.results {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px 16px;
  text-align: center;
  box-shadow: var(--shadow);
  margin-top: 16px;
}

.results-score {
  font-size: 2.6rem;
  font-weight: 800;
  color: var(--ican-green);
  margin: 12px 0 4px;
  line-height: 1;
}

.results-score-label {
  color: var(--text-muted);
  margin-bottom: 8px;
  font-size: 0.9rem;
}

.results-message {
  margin: 12px 0 16px;
  font-size: 0.95rem;
  line-height: 1.5;
}

.results-breakdown {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 16px 0;
  padding: 12px;
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
}

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

.result-item-num {
  font-size: 1.4rem;
  font-weight: 800;
  display: block;
}

.result-item-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.result-item.correct .result-item-num {
  color: var(--ican-green);
}

.result-item.incorrect .result-item-num {
  color: var(--danger);
}

/* Search */
.search-box {
  position: relative;
  margin: 14px 0;
}

.search-input {
  width: 100%;
  padding: 12px 14px 12px 40px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--text);
  transition: border-color 0.15s;
}

.search-input:focus {
  outline: none;
  border-color: var(--ican-green);
}

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

.search-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 6px 0 14px;
}

mark {
  background: #fef3c7;
  color: var(--text);
  padding: 0 2px;
  border-radius: 2px;
}

[data-theme="dark"] mark {
  background: #5a4a1f;
  color: #fef3c7;
}

/* Empty state */
.empty {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 2.5rem;
  margin-bottom: 8px;
  opacity: 0.5;
}

/* Footer */
.app-footer {
  margin-top: 30px;
  padding: 20px 16px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Print */
@media print {
  .app-header,
  .app-footer,
  .theme-toggle,
  .breadcrumb,
  .paper-actions,
  .quiz-header,
  .quiz-options,
  .quiz-actions {
    display: none !important;
  }

  body {
    background: #fff;
    color: #000;
    font-size: 12pt;
  }

  .question-card {
    page-break-inside: avoid;
    box-shadow: none;
    border: 1px solid #ddd;
  }

  .explanation {
    background: #f0f0f0 !important;
    border-color: #666 !important;
  }

  a {
    color: inherit;
    text-decoration: none;
  }
}