:root {
  --ink: #291318;
  --muted: #755c62;
  --red: #b7162c;
  --red-dark: #770e20;
  --cream: #fff9f4;
  --teal: #247b80;
  --line: rgba(146, 31, 47, 0.18);
  --shadow: 0 24px 58px rgba(89, 20, 30, 0.16);
  font-family: "Trebuchet MS", "Avenir Next", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: #fff6f2;
}

button, a { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.quiz-shell {
  width: min(1020px, calc(100% - 24px));
  margin: 0 auto;
  padding: 22px 0 42px;
}

.utility-nav {
  display: flex;
  gap: 8px;
  margin-bottom: 18px;
}

.utility-nav a,
.dialog-actions a {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--red-dark);
  background: rgba(255, 255, 255, 0.92);
  font-weight: 850;
  text-decoration: none;
}

.quiz-panel {
  padding: clamp(16px, 3vw, 32px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
}

.quiz-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
}

.title-lockup {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 16px;
}

.title-mark {
  width: 72px;
  height: 72px;
  flex: 0 0 72px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--red);
  box-shadow: 0 12px 24px rgba(188, 23, 48, 0.18);
  font-size: 2.8rem;
  font-weight: 900;
}

.eyebrow,
.dialog-kicker {
  display: block;
  margin-bottom: 5px;
  color: var(--red);
  font-size: 0.76rem;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1, h2, p { margin: 0; }
h1 { font-size: clamp(2rem, 5.5vw, 3.8rem); line-height: 0.96; }
.quiz-header p { margin-top: 7px; color: var(--muted); font-weight: 650; }

.score-chip {
  min-width: 112px;
  padding: 12px 16px;
  border-left: 4px solid var(--red);
  color: var(--muted);
  background: var(--cream);
}

.score-chip span { display: block; font-size: 0.72rem; font-weight: 900; text-transform: uppercase; }
.score-chip strong { display: block; margin-top: 2px; color: var(--ink); font-size: 1.6rem; }

.progress-row { margin-bottom: 20px; }
.progress-labels {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}
.progress-row p { color: var(--muted); font-size: 0.82rem; font-weight: 900; text-transform: uppercase; }
.timer-label { display: flex; align-items: baseline; gap: 6px; }
.timer-label strong { min-width: 2.4ch; color: var(--teal); font-size: 1rem; text-align: right; }
.progress-track { height: 8px; overflow: hidden; border-radius: 4px; background: #f0ded9; }
.progress-track span { display: block; height: 100%; width: 0; background: var(--teal); transition: width 260ms ease; }
.timer-track { height: 5px; margin-top: 6px; overflow: hidden; border-radius: 3px; background: #f0ded9; }
.timer-track span { display: block; height: 100%; width: 100%; background: var(--red); transform-origin: left center; }
.timer-track.is-urgent span { background: #d54623; }
.timer-track.is-expired span { background: var(--muted); }
.timer-label.is-urgent strong { color: #d54623; }

.question-stage {
  padding: clamp(18px, 4vw, 38px);
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--cream);
}

.question-number {
  display: block;
  margin-bottom: 10px;
  color: var(--red);
  font-size: 1rem;
  font-weight: 900;
  letter-spacing: 0.12em;
}

.question-stage h2 {
  max-width: 26ch;
  font-size: clamp(1.6rem, 4vw, 2.65rem);
  line-height: 1.08;
  outline: none;
}

.answer-list {
  display: grid;
  gap: 10px;
  margin-top: 24px;
}

.answer-button {
  width: 100%;
  min-height: 58px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 8px 16px 8px 8px;
  border: 2px solid rgba(117, 92, 98, 0.2);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  text-align: left;
  font-weight: 800;
  cursor: pointer;
  transition: border-color 150ms ease, background-color 150ms ease, transform 150ms ease;
  touch-action: manipulation;
}

.answer-button:hover:not(:disabled),
.answer-button:focus-visible {
  border-color: var(--red);
  transform: translateY(-1px);
  outline: none;
}

.answer-letter {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--red-dark);
  background: #f8e9e5;
}

.answer-button.is-correct { color: #145f54; border-color: #3f9d83; background: #eefaf5; }
.answer-button.is-correct .answer-letter { color: #fff; background: #247b68; }
.answer-button.is-wrong { color: #8b1728; border-color: #cf3d51; background: #fff0f1; }
.answer-button.is-wrong .answer-letter { color: #fff; background: #b7162c; }
.answer-button:disabled { cursor: default; }

.feedback-row {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 18px;
}

#feedbackMessage { color: var(--muted); font-weight: 750; }
#feedbackMessage.is-correct { color: #176c5c; }
#feedbackMessage.is-wrong { color: #9b2334; }

#nextButton,
.dialog-actions button {
  min-height: 46px;
  padding: 0 18px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  background: var(--red);
  font-weight: 900;
  cursor: pointer;
}

.result-dialog {
  width: min(700px, calc(100% - 24px));
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  padding: clamp(18px, 4vw, 34px);
  border: 0;
  border-radius: 8px;
  color: var(--ink);
  background: #fffaf6;
  box-shadow: 0 30px 90px rgba(41, 7, 13, 0.36);
}

.result-dialog::backdrop { background: rgba(31, 5, 10, 0.76); }
.result-dialog h2 { font-size: clamp(2rem, 7vw, 4rem); line-height: 0.98; }
.result-copy > p:last-child { margin-top: 12px; color: var(--muted); line-height: 1.6; }

.result-score {
  display: flex;
  align-items: baseline;
  gap: 12px;
  margin-top: 14px;
}

.result-score strong { color: var(--red); font-size: clamp(2.2rem, 8vw, 4.5rem); }
.result-score span { color: var(--muted); font-weight: 800; }

.result-media {
  width: min(100%, 320px);
  min-height: 220px;
  margin: 22px auto 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f2e5e0;
}

.result-media[hidden] { display: none; }
.result-media iframe { display: block; max-width: 100%; }

.dialog-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 22px;
}

@media (max-width: 680px) {
  .quiz-shell { width: min(100% - 16px, 1020px); padding-top: 10px; }
  .quiz-header { align-items: flex-start; }
  .title-mark { width: 56px; height: 56px; flex-basis: 56px; font-size: 2rem; }
  .score-chip { min-width: 86px; padding: 9px 10px; }
  .score-chip strong { font-size: 1.25rem; }
  .question-stage { padding: 18px 14px; }
  .feedback-row { align-items: stretch; flex-direction: column; }
  #nextButton { width: 100%; }
}

@media (max-width: 480px) {
  .quiz-header { display: grid; grid-template-columns: 1fr; }
  .score-chip { width: 100%; display: flex; align-items: center; justify-content: space-between; border-left: 0; border-bottom: 3px solid var(--red); }
  .score-chip strong { margin-top: 0; }
  .result-score { align-items: flex-start; flex-direction: column; gap: 0; }
  .dialog-actions { align-items: stretch; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
