/* ==============================
   Base & Theme
   ============================== */
:root {
  --color-bg-gradient: linear-gradient(135deg, #eaf1f8, #f7fafc);
  --color-card: #ffffff;
  --color-text: #1f2937;
  --color-muted: #6b7280;
  --color-primary: #0f4c81; /* deep navy */
  --color-primary-light: #1e5f98;
  --color-accent: #06b6d4; /* cyan */
  --color-success: #16a34a;
  --color-danger: #dc2626;
  --radius: 8px;
  --shadow: 0 4px 12px rgba(0,0,0,0.05);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg-gradient);
  color: var(--color-text);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

/* ==============================
   Layout & Containers
   ============================== */
.site-header, .site-footer {
  background: var(--color-primary);
  color: #fff;
  padding: 1rem 2rem;
  text-align: center;
}
.brand-placeholder {
  font-size: 1.25rem;
  font-weight: 600;
}
.quiz-container {
  max-width: 900px;
  margin: 2rem auto;
  padding: 0 1rem;
}
.subtitle {
  color: var(--color-muted);
  font-size: 0.95rem;
  margin-bottom: 1rem;
}

/* ==============================
   Panels
   ============================== */
.setup-panel, .quiz-panel, .result-panel {
  background: var(--color-card);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  animation: fadeIn 0.4s ease;
  transition: transform 0.25s ease, box-shadow 0.25s ease;
}
.setup-panel:hover, .quiz-panel:hover, .result-panel:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.08);
}

/* ==============================
   Form Styles
   ============================== */
.form-grid {
  display: grid;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
@media (min-width: 600px) {
  .form-grid {
    grid-template-columns: repeat(4, 1fr);
    align-items: end;
  }
}
label {
  font-weight: 500;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
input, select {
  padding: 0.6rem;
  border: 1px solid #cbd5e1;
  border-radius: var(--radius);
  font-size: 1rem;
  height: 42px;
}
input::placeholder { color: #9ca3af; }
.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}
.checkbox input { width: 18px; height: 18px; }

/* ==============================
   Tooltip
   ============================== */
.tooltip-container { position: relative; display: inline-block; }
.tooltip-icon {
  font-size: 0.9rem; cursor: pointer; margin-left: 4px; color: var(--color-accent);
}
.tooltip-text {
  visibility: hidden; background: var(--color-primary); color: #fff; text-align: left;
  border-radius: var(--radius); padding: 0.5rem; position: absolute; z-index: 10;
  width: 260px; bottom: 125%; left: 50%; transform: translateX(-50%);
  opacity: 0; transition: opacity 0.3s; font-size: 0.85rem; line-height: 1.4;
  box-shadow: 0 6px 16px rgba(0,0,0,0.18);
}
.tooltip-container:hover .tooltip-text,
.tooltip-container:focus-within .tooltip-text { visibility: visible; opacity: 1; }

/* ==============================
   Buttons
   ============================== */
button {
  cursor: pointer; border: none; border-radius: var(--radius);
  font-size: 1rem; padding: 0.6rem 1rem; transition: background 0.2s, transform 0.1s;
  height: 42px; -webkit-appearance: none; appearance: none;
}
button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover, .btn-primary:focus { background: var(--color-primary-light); }
.btn-secondary { background: #e2e8f0; color: var(--color-text); }
.btn-secondary:hover, .btn-secondary:focus { background: #cbd5e1; }

/* Improve tap highlight on iOS */
* { -webkit-tap-highlight-color: rgba(15,76,129,0.15); }

/* ==============================
   Quiz Header & Progress
   ============================== */
.quiz-header { display: flex; justify-content: space-between; margin-bottom: 0.5rem; }
.badge {
  background: var(--color-accent); color: #fff; padding: 0.25rem 0.75rem;
  border-radius: 999px; font-size: 0.85rem;
}
.progress-text { font-size: 0.85rem; color: var(--color-muted); }
.progress-bar {
  background: #e5e7eb; height: 6px; border-radius: var(--radius);
  overflow: hidden; margin-bottom: 1rem;
}
.progress-bar div { height: 100%; background: var(--color-primary); width: 0; transition: width 0.3s ease; }

/* ==============================
   Question & Answers
   ============================== */
.question-card { margin-bottom: 1rem; }
.question-text {
  font-weight: 600; margin-bottom: 1rem; line-height: 1.4; word-break: break-word;
}

/* Answer list & buttons — mobile-safe multi-line */
.answers-list { display: grid; gap: 0.7rem; }
.answers-list button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  text-align: left;
  color: var(--color-text);
  border: 1px solid #ddd;
  background: #fff;
  padding: 1rem 1rem;
  transition: background-color 0.25s ease, transform 0.15s ease, box-shadow 0.15s ease;
  white-space: normal;
  line-height: 1.4;
  overflow-wrap: anywhere;
  word-break: break-word;
  min-height: 56px;
  border-radius: 12px;
}
.answers-list button:hover:not(:disabled),
.answers-list button:focus:not(:disabled) {
  background: #f3f4f6;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}
.answers-list button.correct {
  border-color: var(--color-success);
  background: #ecfdf5;
  animation: fadeIn 0.4s ease;
}
.answers-list button.incorrect {
  border-color: var(--color-danger);
  background: #fef2f2;
  animation: fadeIn 0.4s ease;
}
.answers-list button.clicked { transform: scale(0.96); }

.explanation {
  font-size: 0.95rem; color: var(--color-text);
  background: #f1f5f9; border: 1px solid #e2e8f0; border-radius: var(--radius);
  padding: 0.9rem; margin-top: 0.9rem; animation: fadeIn 0.4s ease;
}

/* Why this matters block */
.why-matters {
  font-size: 0.9rem; color: var(--color-text);
  background: #eef9fd; border: 1px solid #c7e7f4; border-left: 4px solid var(--color-accent);
  border-radius: var(--radius); padding: 0.8rem 0.9rem; margin-top: 0.7rem; animation: fadeIn 0.4s ease;
}

/* ==============================
   Quiz Actions (aligned one row)
   ============================== */
.quiz-actions {
  display: flex;
  align-items: stretch;
  gap: 0.6rem;
  margin-top: 1rem;
  flex-wrap: nowrap;            /* keep one line */
}

/* Left button (Back to Setup) takes half the row */
.quiz-actions > #backSetup {
  flex: 1 1 50%;
  min-width: 0;
  height: 44px;
  white-space: nowrap;          /* avoid line breaks */
}

/* Right side holds Skip + Next and takes the other half */
.quiz-actions .right-buttons {
  flex: 1 1 50%;
  min-width: 0;
  display: flex;
  gap: 0.6rem;
}

/* Skip and Next split that half evenly */
.quiz-actions .right-buttons > button {
  flex: 1 1 0;
  min-width: 0;
  height: 44px;
  white-space: nowrap;          /* avoid line breaks */
}

/* ==============================
   Results
   ============================== */
.result-panel { animation: slideUp 0.5s ease; }
.result-panel h2 { margin-top: 0; }
.score { font-size: 1.5rem; font-weight: 700; margin: 0.5rem 0; }
.meta { color: var(--color-muted); margin-top: 0.25rem; margin-bottom: 0.5rem; }

/* Result buttons: equal widths on desktop, full-width stack on mobile */
.result-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}
.result-actions button {
  flex: 1 1 0;
  min-width: 180px;
  height: 44px;
}

/* ==============================
   Printable summary
   ============================== */
.printable {
  background: #fff;
  color: #000;
  padding: 1.25rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-top: 1rem;
}
.printable h1 { font-size: 1.3rem; margin-bottom: 0.5rem; }
.printable h2 { font-size: 1.1rem; margin: 0.75rem 0 0.5rem; }
.printable .meta { color: #374151; margin-bottom: 0.75rem; }
.printable .qcard {
  border: 1px solid #e5e7eb; border-radius: 8px; padding: 0.75rem; margin: 0.5rem 0;
}
.printable .qcard .small { color: #374151; font-size: 0.9rem; }

/* Print rules: hide everything except printable */
@media print {
  body { background: #fff; }
  .site-header, .site-footer, .setup-panel, .quiz-panel, .result-panel { display: none !important; }
  .printable { display: block !important; box-shadow: none; padding: 0; margin: 0; }
}

/* ==============================
   Footer
   ============================== */
.site-footer p { font-size: 0.85rem; }

/* ==============================
   Animations
   ============================== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==============================
   Mobile tweaks
   ============================== */
@media (max-width: 520px) {
  .answers-list { gap: 0.6rem; }
  .answers-list button { padding: 0.9rem; min-height: 54px; }
  .quiz-container { margin: 1.25rem auto; }

  /* result buttons: stack full-width */
  .result-actions { flex-direction: column; }
  .result-actions button { width: 100%; min-width: 0; }

  /* tighten action row fonts a touch */
  .quiz-actions > #backSetup,
  .quiz-actions .right-buttons > button {
    font-size: 0.95rem;
    padding: 0.55rem 0.6rem;
    height: 42px;
  }
}
