@layer reset, base, layout, components, utilities;

@layer reset {
  *,
  *::before,
  *::after {
    box-sizing: border-box;
  }

  html {
    min-width: 320px;
    scroll-behavior: smooth;
  }

  body,
  h1,
  h2,
  h3,
  p,
  ul,
  ol,
  dl,
  dd,
  figure,
  blockquote {
    margin: 0;
  }

  img,
  svg {
    display: block;
    max-width: 100%;
  }

  button,
  input,
  select,
  textarea {
    font: inherit;
  }
}

@layer base {
  :root {
    color-scheme: light;
    --paper: #f5f0e5;
    --paper-strong: #fffdf7;
    --ink: #13221d;
    --ink-soft: #405049;
    --line: #c9c5b8;
    --line-dark: #829087;
    --yellow: #f4c54d;
    --yellow-soft: #fbe8a9;
    --green: #177455;
    --green-soft: #dceee5;
    --red: #ad3e35;
    --red-soft: #f6dfda;
    --blue: #205f7a;
    --shadow: 0 18px 50px rgb(19 34 29 / 0.11);
    --sans: "Avenir Next", Avenir, "Segoe UI", "Trebuchet MS", sans-serif;
    --serif: Charter, "Iowan Old Style", "Palatino Linotype", Georgia, serif;
    --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  }

  body {
    min-width: 320px;
    background: var(--paper);
    color: var(--ink);
    font-family: var(--sans);
    font-size: 1rem;
    line-height: 1.6;
    text-rendering: optimizeLegibility;
  }

  a {
    color: currentColor;
    text-decoration-thickness: 0.09em;
    text-underline-offset: 0.18em;
  }

  a:hover {
    text-decoration-thickness: 0.15em;
  }

  :focus-visible {
    outline: 4px solid var(--yellow);
    outline-offset: 4px;
  }

  ::selection {
    background: var(--yellow);
    color: var(--ink);
  }

  h1,
  h2,
  h3 {
    font-weight: 750;
    letter-spacing: -0.035em;
    line-height: 1.04;
  }

  h1 {
    font-size: clamp(2.65rem, 7vw, 6.7rem);
  }

  h2 {
    font-size: clamp(2rem, 4vw, 3.8rem);
  }

  h3 {
    font-size: clamp(1.25rem, 2vw, 1.7rem);
  }

  .prose p + p,
  .prose p + ul,
  .prose ul + p,
  .prose h2 + p,
  .prose h3 + p,
  .prose h2 + ul,
  .prose h3 + ul {
    margin-top: 1rem;
  }

  .prose h2 {
    margin-top: 3.5rem;
  }

  .prose h3 {
    margin-top: 2.25rem;
  }

  .prose ul,
  .prose ol {
    padding-left: 1.25rem;
  }
}

@layer layout {
  .shell {
    width: min(100% - 2rem, 1180px);
    margin-inline: auto;
  }

  .narrow {
    width: min(100% - 2rem, 780px);
    margin-inline: auto;
  }

  .site-header {
    border-bottom: 1px solid rgb(19 34 29 / 0.2);
    background: rgb(245 240 229 / 0.94);
    backdrop-filter: blur(14px);
  }

  .site-nav {
    min-height: 74px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
  }

  .nav-links {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: clamp(0.8rem, 2.4vw, 2rem);
    font-size: 0.92rem;
    font-weight: 700;
  }

  .hero {
    min-height: calc(100svh - 75px);
    display: grid;
    grid-template-columns: minmax(0, 1.18fr) minmax(300px, 0.82fr);
    align-items: center;
    gap: clamp(3rem, 7vw, 7rem);
    padding-block: clamp(4rem, 9vw, 8rem);
  }

  .section {
    padding-block: clamp(4.5rem, 9vw, 8rem);
  }

  .section + .section {
    border-top: 1px solid var(--line);
  }

  .section-heading {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(240px, 0.55fr);
    gap: 2rem;
    align-items: end;
    margin-bottom: clamp(2.5rem, 5vw, 4.5rem);
  }

  .state-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    border-block: 1px solid var(--ink);
  }

  .trust-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: clamp(2rem, 5vw, 5rem);
  }

  .page-hero {
    padding-block: clamp(4rem, 8vw, 7rem);
    border-bottom: 1px solid var(--line);
  }

  .page-hero-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(270px, 0.52fr);
    gap: clamp(2.5rem, 7vw, 7rem);
    align-items: end;
  }

  .content-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(240px, 0.4fr);
    gap: clamp(3rem, 7vw, 7rem);
  }

  .site-footer {
    padding-block: 3rem;
    background: var(--ink);
    color: var(--paper);
  }

  .footer-grid {
    display: grid;
    grid-template-columns: 1.25fr 0.75fr;
    gap: 3rem;
    align-items: end;
  }
}

@layer components {
  .skip-link {
    position: fixed;
    z-index: 100;
    top: 0.75rem;
    left: 0.75rem;
    padding: 0.7rem 1rem;
    transform: translateY(-180%);
    background: var(--ink);
    color: var(--paper);
    font-weight: 800;
  }

  .skip-link:focus {
    transform: translateY(0);
  }

  .brand {
    display: inline-flex;
    align-items: center;
    gap: 0.72rem;
    font-weight: 850;
    letter-spacing: -0.025em;
    text-decoration: none;
  }

  .brand-mark {
    width: 31px;
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    rotate: 45deg;
    border: 2px solid var(--ink);
    border-radius: 6px;
    background: var(--yellow);
  }

  .brand-mark::after {
    content: "";
    width: 5px;
    height: 13px;
    border-radius: 999px;
    background: var(--ink);
    rotate: -45deg;
    box-shadow: 5px 5px 0 -1px var(--ink);
  }

  .eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    margin-bottom: 1.35rem;
    font-family: var(--mono);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  .eyebrow::before {
    content: "";
    width: 2.2rem;
    height: 0.22rem;
    background: var(--yellow);
  }

  .hero-copy {
    max-width: 760px;
  }

  .hero-copy h1 {
    max-width: 11ch;
  }

  .hero-copy > p,
  .page-lede {
    max-width: 62ch;
    margin-top: 1.6rem;
    color: var(--ink-soft);
    font-family: var(--serif);
    font-size: clamp(1.15rem, 2vw, 1.4rem);
    line-height: 1.55;
  }

  .action-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.9rem;
    margin-top: 2rem;
  }

  .button {
    min-height: 50px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
    border: 2px solid var(--ink);
    border-radius: 7px;
    padding: 0.78rem 1.15rem;
    background: var(--ink);
    color: var(--paper-strong);
    font-weight: 800;
    line-height: 1.1;
    text-decoration: none;
    cursor: pointer;
    transition: transform 150ms ease, box-shadow 150ms ease, background 150ms ease;
  }

  .button:hover {
    transform: translateY(-2px);
    box-shadow: 4px 4px 0 var(--yellow);
  }

  .button-secondary {
    background: transparent;
    color: var(--ink);
  }

  .button-yellow {
    background: var(--yellow);
    color: var(--ink);
  }

  .button[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
  }

  .hero-road {
    position: relative;
    min-height: 520px;
    overflow: hidden;
    border-radius: 50% 50% 0 0 / 18% 18% 0 0;
    background: var(--ink);
    box-shadow: var(--shadow);
  }

  .hero-road::before {
    content: "";
    position: absolute;
    inset: 0 49% 0 auto;
    width: 8px;
    background: repeating-linear-gradient(to bottom, var(--yellow) 0 55px, transparent 55px 95px);
  }

  .hero-road::after {
    content: "";
    position: absolute;
    inset: 0 auto 0 18%;
    width: 3px;
    background: var(--paper);
    box-shadow: calc(clamp(300px, 25vw, 420px) * 0.64) 0 0 var(--paper);
    opacity: 0.78;
  }

  .road-sign {
    position: absolute;
    z-index: 1;
    top: 15%;
    left: 50%;
    width: min(58%, 250px);
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    translate: -50% 0;
    rotate: 45deg;
    border: 8px solid var(--paper-strong);
    border-radius: 22px;
    background: var(--yellow);
    color: var(--ink);
    box-shadow: 0 12px 0 rgb(0 0 0 / 0.18);
  }

  .road-sign-copy {
    rotate: -45deg;
    text-align: center;
  }

  .road-sign-copy strong {
    display: block;
    font-size: clamp(2.6rem, 5vw, 4.2rem);
    line-height: 0.9;
  }

  .road-sign-copy span {
    display: block;
    margin-top: 0.55rem;
    font-family: var(--mono);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
  }

  .road-note {
    position: absolute;
    z-index: 2;
    right: 1.25rem;
    bottom: 1.25rem;
    max-width: 220px;
    border-left: 4px solid var(--yellow);
    padding: 0.85rem 1rem;
    background: var(--paper-strong);
    color: var(--ink);
    font-size: 0.86rem;
    font-weight: 700;
  }

  .state-link {
    min-height: 260px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    gap: 2rem;
    padding: clamp(1.5rem, 3vw, 2.4rem);
    text-decoration: none;
    transition: background 150ms ease, color 150ms ease;
  }

  .state-link + .state-link {
    border-left: 1px solid var(--ink);
  }

  .state-link:hover,
  .state-link:focus-visible {
    background: var(--ink);
    color: var(--paper);
  }

  .state-abbr {
    font-family: var(--mono);
    font-size: 0.8rem;
    font-weight: 800;
    letter-spacing: 0.1em;
  }

  .state-link h3 {
    font-size: clamp(2rem, 3.8vw, 3.3rem);
  }

  .state-link p {
    max-width: 30ch;
    color: var(--ink-soft);
  }

  .state-link:hover p,
  .state-link:focus-visible p {
    color: inherit;
  }

  .arrow-link {
    display: inline-flex;
    align-items: center;
    gap: 0.65rem;
    font-weight: 850;
  }

  .arrow-link::after {
    content: "→";
    font-size: 1.3em;
  }

  .trust-item {
    border-top: 5px solid var(--ink);
    padding-top: 1.25rem;
  }

  .trust-item strong {
    display: block;
    margin-bottom: 0.65rem;
    font-size: 1.08rem;
  }

  .trust-item p {
    color: var(--ink-soft);
  }

  .notice {
    border-left: 6px solid var(--yellow);
    padding: 1.25rem 1.4rem;
    background: var(--paper-strong);
  }

  .notice strong {
    display: block;
    margin-bottom: 0.35rem;
  }

  .quotable-answer {
    max-width: 76ch;
    margin-top: 2rem;
    border-top: 1px solid var(--line-dark);
    padding-top: 1.2rem;
    color: var(--ink-soft);
    font-family: var(--serif);
    font-size: 1.08rem;
  }

  .sample-question {
    border-top: 5px solid var(--ink);
    padding-top: 1.25rem;
  }

  .sample-question h2 {
    font-size: clamp(1.45rem, 3vw, 2.2rem);
    line-height: 1.2;
  }

  .sample-question ol {
    display: grid;
    gap: 0.5rem;
    margin-block: 1.25rem;
    padding-left: 1.6rem;
  }

  .sample-question p + p {
    margin-top: 1rem;
  }

  .fact-list {
    display: grid;
    gap: 0;
    border-top: 1px solid var(--ink);
  }

  .fact-list > div {
    display: grid;
    grid-template-columns: minmax(105px, 0.65fr) minmax(0, 1fr);
    gap: 1rem;
    padding-block: 1rem;
    border-bottom: 1px solid var(--line-dark);
  }

  .fact-list dt {
    font-family: var(--mono);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  .fact-list dd {
    font-weight: 700;
  }

  .quiz-shell {
    padding-block: clamp(3rem, 7vw, 6rem);
  }

  .quiz-intro {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(250px, 0.45fr);
    gap: clamp(2.5rem, 6vw, 6rem);
    align-items: start;
  }

  .mode-list {
    display: grid;
    gap: 0.8rem;
    margin-top: 2rem;
  }

  .mode-button {
    width: 100%;
    min-height: 76px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    border: 2px solid var(--ink);
    border-radius: 8px;
    padding: 1rem 1.1rem;
    background: var(--paper-strong);
    color: var(--ink);
    text-align: left;
    cursor: pointer;
  }

  .mode-button:hover {
    background: var(--yellow-soft);
  }

  .mode-button strong,
  .mode-button span {
    display: block;
  }

  .mode-button span {
    color: var(--ink-soft);
    font-size: 0.88rem;
  }

  .mode-count {
    flex: 0 0 auto;
    font-family: var(--mono);
    font-size: 0.82rem;
    font-weight: 850;
  }

  .text-button {
    min-height: 44px;
    margin-top: 0.65rem;
    border: 0;
    padding: 0;
    background: transparent;
    color: var(--ink);
    font-weight: 800;
    text-decoration: underline;
    text-decoration-thickness: 0.09em;
    text-underline-offset: 0.18em;
    cursor: pointer;
  }

  .quiz-panel {
    max-width: 780px;
    margin-inline: auto;
  }

  .quiz-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.8rem;
    font-family: var(--mono);
    font-size: 0.76rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  .progress-track {
    height: 8px;
    overflow: hidden;
    border-radius: 99px;
    background: #d7d2c6;
  }

  .progress-fill {
    width: var(--progress, 0%);
    height: 100%;
    border-radius: inherit;
    background: var(--green);
    transition: width 220ms ease;
  }

  .question-block {
    padding-block: clamp(2.2rem, 5vw, 4rem);
  }

  .question-topic {
    margin-bottom: 0.8rem;
    color: var(--green);
    font-family: var(--mono);
    font-size: 0.75rem;
    font-weight: 850;
    letter-spacing: 0.07em;
    text-transform: uppercase;
  }

  .question-title {
    max-width: 25ch;
    font-size: clamp(1.8rem, 4.3vw, 3rem);
    line-height: 1.12;
  }

  .choice-list {
    display: grid;
    gap: 0.8rem;
    margin-top: 2rem;
  }

  .choice-fieldset {
    min-width: 0;
    margin: 0;
    border: 0;
    padding: 0;
  }

  .choice {
    position: relative;
    width: 100%;
    min-height: 64px;
    display: grid;
    grid-template-columns: 2.25rem minmax(0, 1fr) auto;
    gap: 0.85rem;
    align-items: center;
    border: 2px solid var(--ink);
    border-radius: 8px;
    padding: 0.85rem 1rem;
    background: var(--paper-strong);
    color: var(--ink);
    text-align: left;
    cursor: pointer;
    transition: translate 130ms ease, background 130ms ease;
  }

  .choice:not(:has(input:disabled)):hover {
    translate: 4px 0;
    background: var(--yellow-soft);
  }

  .choice:has(.choice-input:focus-visible) {
    outline: 4px solid var(--yellow);
    outline-offset: 4px;
  }

  .choice-input {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
  }

  .choice-key {
    width: 2.25rem;
    height: 2.25rem;
    display: grid;
    place-items: center;
    border: 1px solid var(--line-dark);
    border-radius: 5px;
    font-family: var(--mono);
    font-size: 0.8rem;
    font-weight: 850;
  }

  .choice:has(input:disabled) {
    cursor: default;
  }

  .choice-state {
    grid-column: 2 / -1;
    font-family: var(--mono);
    font-size: 0.72rem;
    font-weight: 850;
    letter-spacing: 0.02em;
  }

  .choice.is-correct {
    border-color: var(--green);
    background: var(--green-soft);
  }

  .choice.is-incorrect {
    border-color: var(--red);
    background: var(--red-soft);
  }

  .choice.is-muted {
    border-color: var(--line);
    color: var(--ink-soft);
  }

  .feedback {
    margin-top: 1.4rem;
    border-left: 6px solid var(--green);
    padding: 1.2rem 1.35rem;
    background: var(--green-soft);
    animation: feedback-in 180ms ease both;
  }

  .feedback.is-incorrect {
    border-color: var(--red);
    background: var(--red-soft);
  }

  .feedback-title {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 1.08rem;
  }

  .feedback p + p {
    margin-top: 0.65rem;
  }

  .correct-answer {
    font-weight: 750;
  }

  .source-link {
    display: inline-flex;
    margin-top: 0.8rem;
    font-size: 0.9rem;
    font-weight: 800;
  }

  .quiz-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 1.25rem;
  }

  .result-score {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
    margin-block: 1rem 1.5rem;
  }

  .result-score strong {
    font-size: clamp(4rem, 12vw, 8rem);
    letter-spacing: -0.08em;
    line-height: 0.9;
  }

  .topic-results {
    display: grid;
    gap: 0;
    margin-top: 2rem;
    border-top: 1px solid var(--line-dark);
  }

  .topic-result {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 1rem;
    padding-block: 0.8rem;
    border-bottom: 1px solid var(--line);
  }

  .missed-summary {
    margin-top: 2rem;
    border-top: 1px solid var(--line-dark);
    padding-top: 1.25rem;
  }

  .missed-summary h3 {
    font-size: 1.2rem;
  }

  .missed-summary ol {
    display: grid;
    gap: 0.55rem;
    margin-top: 0.9rem;
    padding-left: 1.4rem;
  }

  .review-note {
    margin-top: 2rem;
    color: var(--ink-soft);
    font-size: 0.92rem;
  }

  .loading-state,
  .error-state {
    padding: 2rem;
    border: 1px solid var(--line-dark);
    background: var(--paper-strong);
  }

  .legal-heading {
    max-width: 14ch;
  }

  .legal-dialog {
    width: min(100% - 2rem, 980px);
    max-width: none;
    max-height: min(90dvh, 900px);
    margin: auto;
    overflow: hidden;
    border: 2px solid var(--ink);
    border-radius: 10px;
    padding: 0;
    background: var(--paper);
    color: var(--ink);
    box-shadow: 0 28px 90px rgb(0 0 0 / 0.34);
  }

  .legal-dialog::backdrop {
    background: rgb(19 34 29 / 0.74);
  }

  .legal-dialog-bar {
    position: sticky;
    z-index: 2;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 66px;
    border-bottom: 1px solid var(--line-dark);
    padding: 0.75rem 1rem;
    background: var(--paper-strong);
  }

  .legal-dialog-bar h2 {
    overflow: hidden;
    font-size: clamp(1rem, 2vw, 1.25rem);
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .dialog-close {
    min-width: 72px;
    min-height: 44px;
    border: 2px solid var(--ink);
    border-radius: 6px;
    padding: 0.45rem 0.8rem;
    background: var(--yellow);
    color: var(--ink);
    font-weight: 850;
    cursor: pointer;
  }

  .legal-dialog-content {
    max-height: calc(min(90dvh, 900px) - 66px);
    overflow: auto;
    overscroll-behavior: contain;
  }

  .legal-dialog-document .page-hero {
    padding-block: clamp(2.5rem, 6vw, 4.5rem);
  }

  .legal-dialog-document .section {
    padding-block: clamp(2.5rem, 6vw, 4.5rem);
  }

  .footer-brand {
    font-size: clamp(1.7rem, 4vw, 3rem);
    font-weight: 850;
    letter-spacing: -0.045em;
  }

  .footer-copy {
    max-width: 64ch;
    margin-top: 1rem;
    color: #c7d0ca;
    font-family: var(--serif);
  }

  .footer-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.75rem 1.4rem;
    font-size: 0.9rem;
    font-weight: 750;
  }

  @keyframes feedback-in {
    from {
      opacity: 0;
      transform: translateY(8px);
    }
  }
}

@layer utilities {
  [hidden] {
    display: none !important;
  }

  .visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0 0 0 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
  }

  .text-soft {
    color: var(--ink-soft);
  }

  .mt-1 {
    margin-top: 1rem;
  }

  .mt-2 {
    margin-top: 2rem;
  }
}

@media (max-width: 840px) {
  .hero,
  .page-hero-grid,
  .content-grid,
  .quiz-intro {
    grid-template-columns: 1fr;
  }

  .hero {
    min-height: auto;
  }

  .hero-road {
    min-height: 440px;
  }

  .section-heading {
    grid-template-columns: 1fr;
    align-items: start;
  }

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

  .state-link {
    min-height: 210px;
  }

  .state-link + .state-link {
    border-top: 1px solid var(--ink);
    border-left: 0;
  }

  .trust-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .site-nav {
    min-height: 66px;
  }

  .nav-links a:not(.nav-primary) {
    display: none;
  }

  .nav-primary {
    font-size: 0.84rem;
  }

  .hero-road {
    min-height: 390px;
  }

  .hero-road::after {
    right: 16%;
    left: 16%;
    width: auto;
    border-inline: 3px solid var(--paper);
    background: none;
    box-shadow: none;
  }

  .road-sign {
    width: 205px;
  }

  .footer-grid {
    grid-template-columns: 1fr;
  }

  .footer-links {
    justify-content: flex-start;
  }

  .action-row .button {
    width: 100%;
  }

  .fact-list > div {
    grid-template-columns: 1fr;
    gap: 0.25rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
