:root {
  color-scheme: light;
  --ink: #1d1b18;
  --muted: #6f6a60;
  --paper: #f7f3ea;
  --panel: #fffdf8;
  --line: #ddd4c5;
  --teal: #156f7a;
  --red: #e23d28;
  --gold: #c99322;
  --green: #2f7d4b;
  --shadow: 0 18px 42px rgba(49, 42, 31, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(21, 111, 122, 0.08), transparent 34%),
    linear-gradient(180deg, #fcfaf4 0%, var(--paper) 45%, #efe8da 100%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
input {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  max-width: 1500px;
  margin: 0 auto;
  padding: 28px clamp(16px, 3vw, 36px) 18px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 4.6rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--teal);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.source-pill {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(255, 253, 248, 0.72);
  color: var(--muted);
  font-size: 0.85rem;
}

.shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.52fr);
  gap: 22px;
  max-width: 1500px;
  margin: 0 auto;
  padding: 0 clamp(16px, 3vw, 36px) 42px;
}

.quiz-panel,
.result-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.9);
  box-shadow: var(--shadow);
}

.quiz-panel {
  min-width: 0;
}

.quiz-head {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  padding: 22px;
  border-bottom: 1px solid var(--line);
}

.quiz-head h2,
.result-card h2,
.result-card h3 {
  margin: 0;
  line-height: 1.1;
  letter-spacing: 0;
}

.quiz-head h2 {
  font-size: clamp(1.35rem, 2vw, 2rem);
}

.quiz-head p,
.result-card p {
  margin: 8px 0 0;
  color: var(--muted);
}

.progress-block {
  width: 132px;
  flex: 0 0 132px;
  text-align: right;
  font-size: 1.35rem;
  font-weight: 800;
}

.progress-track {
  height: 8px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7dece;
}

#progressBar {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--teal), var(--gold), var(--red));
  transition: width 160ms ease;
}

.toolbar {
  display: flex;
  gap: 10px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
}

.text-button,
.legend-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf0;
  color: var(--ink);
  cursor: pointer;
}

.text-button {
  min-height: 38px;
  padding: 8px 12px;
  font-weight: 700;
}

.text-button:hover,
.legend-item:hover {
  border-color: var(--teal);
}

.question-list {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.question-card {
  border: 1px solid var(--line);
  border-left: 5px solid #c99322;
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
}

.question-card.answered {
  border-left-color: var(--green);
}

.question-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.question-card h3 {
  margin: 8px 0 14px;
  font-size: clamp(1rem, 1.3vw, 1.14rem);
  line-height: 1.35;
  letter-spacing: 0;
}

.answer-row {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.answer-choice {
  position: relative;
  display: grid;
  align-content: center;
  min-height: 70px;
  border: 1px solid #d9cfbe;
  border-radius: 8px;
  padding: 9px;
  background: #faf6ed;
  cursor: pointer;
  text-align: center;
  transition: border-color 120ms ease, background 120ms ease, color 120ms ease;
}

.answer-choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.answer-letter {
  display: block;
  color: var(--teal);
  font-size: 1.1rem;
  font-weight: 900;
}

.answer-text {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: clamp(0.68rem, 0.8vw, 0.78rem);
  font-weight: 700;
  line-height: 1.12;
}

.answer-choice:has(input:checked) {
  border-color: var(--teal);
  background: #e7f2f0;
  color: var(--ink);
}

.answer-choice:has(input:focus-visible) {
  outline: 3px solid rgba(21, 111, 122, 0.28);
  outline-offset: 2px;
}

.result-panel {
  min-width: 0;
}

.result-sticky {
  position: sticky;
  top: 14px;
  display: grid;
  gap: 14px;
}

.result-card {
  padding: 18px;
}

.primary-result {
  border-top: 5px solid var(--red);
}

.primary-result h2 {
  font-size: clamp(1.2rem, 2vw, 1.8rem);
}

#resultSummary span {
  color: var(--muted);
}

.match-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.match-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 12px;
  align-items: center;
}

.match-name {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
  font-weight: 800;
}

.match-score {
  color: var(--muted);
  font-weight: 800;
}

.match-bar {
  grid-column: 1 / -1;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e8dfce;
}

.match-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--gold));
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.section-title span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.pca-wrap {
  margin-top: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9f7f1;
}

#pcaCanvas {
  display: block;
  width: 100%;
}

.map-note {
  font-size: 0.82rem;
}

.legend-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-top: 12px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 48px;
  padding: 8px;
  text-align: left;
}

.legend-item strong,
.legend-item small {
  display: block;
}

.legend-item small {
  color: var(--muted);
  font-size: 0.76rem;
}

.dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  flex: 0 0 11px;
  border-radius: 999px;
}

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

  .result-sticky {
    position: static;
  }

  .legend-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .topbar,
  .quiz-head {
    align-items: stretch;
    flex-direction: column;
    justify-content: flex-start;
  }

  .source-pill,
  .progress-block {
    width: auto;
    flex: 0 0 auto;
    text-align: left;
  }

  .answer-row {
    grid-template-columns: 1fr;
  }

  .answer-choice {
    grid-template-columns: 36px minmax(0, 1fr);
    align-items: center;
    min-height: 48px;
    text-align: left;
  }

  .answer-text {
    margin-top: 0;
    font-size: 0.86rem;
  }

  .legend-list {
    grid-template-columns: 1fr;
  }
}
