@layer reset, tokens, base, layout, components, states, responsive, print;

@font-face {
  font-family: "STIX Two Text";
  src: url("/stix-two-variable.ttf") format("truetype");
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
}

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  body, h1, h2, h3, p, figure, ul, dl, dd { margin: 0; }
  button, input, textarea { font: inherit; }
  img { max-width: 100%; height: auto; display: block; }
  button, a, input, textarea { -webkit-tap-highlight-color: transparent; }
  [hidden] { display: none !important; }
}

@layer tokens {
  :root {
    color-scheme: light;
    --paper: #f7f3ea;
    --ink: #382d26;
    --muted: #685749;
    --clay: #87412d;
    --clay-deep: #682f20;
    --sun: #f0d478;
    --oat: #efe5cf;
    --water: #dce7e2;
    --white: #fffdf8;
    --line: #cebea5;
    --edge: #8b7a66;
    --display: "STIX Two Text", Georgia, serif;
    --body: Arial, "Helvetica Neue", sans-serif;
  }
}

@layer base {
  html { scroll-padding-block: 24px; }
  body { background: var(--paper); color: var(--ink); font: 18px/1.65 var(--body); }
  h1, h2, h3 { font-family: var(--display); font-weight: 500; line-height: 1.13; }
  p + p { margin-top: 1em; }
  a { color: var(--clay); text-decoration-thickness: 1px; text-underline-offset: .2em; }
  button { cursor: pointer; }
  input, textarea { color: var(--ink); background: var(--white); }
  textarea { width: 100%; resize: vertical; padding: 16px; border: 1.5px solid var(--edge); border-radius: 12px; }
  ::selection { color: var(--ink); background: var(--sun); }
}

@layer layout {
  .masthead, .guide__layout, .footer { max-width: 1456px; margin-inline: auto; }
  .masthead { padding: 32px 48px; display: flex; justify-content: space-between; align-items: center; gap: 24px; }
  .guide__layout { display: grid; grid-template-columns: 244px minmax(0, 1fr); gap: 72px; padding: 44px 48px 80px; border-top: 2px solid var(--line); }
  .guide__main { grid-column: 2; grid-row: 1; min-width: 0; }
  .page-index { grid-column: 1; grid-row: 1; position: sticky; top: 24px; align-self: start; max-height: calc(100vh - 48px); overflow-y: auto; scrollbar-color: var(--line) transparent; scrollbar-width: thin; padding-right: 10px; padding-bottom: 8px; }
  .sheet { max-width: 880px; }
  .sheet__header { margin-bottom: 44px; }
  .sheet__reading { max-width: 66ch; }
  .reading { margin-block: 48px; }
  .footer { padding: 36px 48px 44px; border-top: 2px solid var(--line); display: grid; grid-template-columns: 1fr 1fr; gap: 36px; }
}

@layer components {
  .skip-link { position: fixed; z-index: 5; left: 20px; top: 12px; padding: 12px 18px; background: var(--ink); color: var(--white); border-radius: 8px; transform: translateY(-180%); font-size: 16px; }
  .masthead__brand { color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: 15px; min-height: 56px; }
  .masthead__symbol { display: grid; place-items: center; height: 58px; width: 58px; flex: 0 0 58px; font: 50px/1 var(--display); background: var(--sun); color: var(--clay); border-radius: 50%; }
  .masthead__name { font: 500 25px/1.2 var(--display); }
  .masthead__caption { display: block; margin-top: 6px; font: 16px/1.3 var(--body); color: var(--muted); }
  .masthead__index { display: flex; align-items: center; gap: 18px; padding: 10px 0 10px 16px; min-height: 48px; font-size: 16px; white-space: nowrap; }
  .page-index__title { font: 500 26px/1.2 var(--display); margin: 3px 0 28px; }
  .page-index__group + .page-index__group { margin-top: 24px; }
  .page-index__heading { font: 500 19px/1.3 var(--display); margin-bottom: 6px; color: var(--muted); }
  .page-index__list { list-style: none; padding: 0; }
  .page-index__link { min-height: 46px; display: flex; align-items: center; padding: 10px 12px; border-radius: 12px; color: var(--ink); text-decoration: none; font-size: 16px; line-height: 1.4; }
  .page-index__top { display: flex; align-items: center; min-height: 48px; padding: 12px; font-size: 16px; margin-top: 22px; }
  .sheet__category { color: var(--muted); font-size: 16px; margin-bottom: 18px; display: flex; align-items: center; gap: 12px; }
  .sheet__category::before { content: ""; width: 27px; height: 12px; background: var(--sun); border-radius: 50%; transform: rotate(-20deg); }
  .sheet__title { font-size: clamp(48px, 5.6vw, 78px); line-height: 1.04; letter-spacing: -.035em; max-width: 18ch; text-wrap: balance; }
  .guide--home .sheet__title { font-size: clamp(52px, 6.2vw, 88px); max-width: 18ch; }
  .sheet__lead { font-size: 21px; line-height: 1.6; margin-top: 28px; max-width: 56ch; color: var(--muted); }
  .comparison__columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); background: var(--oat); border-radius: 24px 56px 24px 24px; overflow: hidden; }
  .comparison__side { padding: 30px; }
  .comparison__side--answer { background: var(--water); }
  .comparison__title { font-family: var(--display); font-weight: 500; line-height: 1.13; font-size: 29px; margin-bottom: 16px; }
  .comparison__title + p { margin-top: 0; }
  .comparison__side p:not(.comparison__title) { font-size: 18px; line-height: 1.6; }
  .comparison__caption { font-size: 16px; color: var(--muted); margin-top: 16px; padding-left: 22px; border-left: 4px solid var(--sun); line-height: 1.6; }
  .reading__title { font-size: 36px; letter-spacing: -.02em; margin-bottom: 20px; }
  .reading p { max-width: 66ch; }
  .worksheet { background: var(--white); border: 2px solid var(--line); padding: 34px; border-radius: 24px; margin-top: 52px; }
  .worksheet__heading { display: flex; justify-content: space-between; align-items: center; gap: 18px; }
  .worksheet__title { font-family: var(--display); font-weight: 500; line-height: 1.13; font-size: 36px; letter-spacing: -.02em; }
  .worksheet__mark { font: 42px/1 var(--display); color: var(--clay); }
  .worksheet__intro { color: var(--muted); margin-top: 16px; font-size: 16px; }
  .worksheet__field { margin-top: 30px; }
  .worksheet__label { display: block; font-size: 18px; font-weight: 600; }
  .worksheet__hint { font-size: 16px; color: var(--muted); margin: 6px 0 12px; line-height: 1.5; }
  .worksheet__input { min-height: 112px; line-height: 1.6; }
  .button { display: inline-flex; justify-content: center; align-items: center; gap: 24px; min-height: 50px; padding: 12px 20px; border: 2px solid var(--clay); border-radius: 30px; background: var(--clay); color: var(--white); font-size: 16px; line-height: 1.5; text-decoration: none; }
  .button--quiet { color: var(--clay); background: transparent; }
  .worksheet__print { margin-top: 24px; }
  .place { margin-block: 52px; }
  .place__frame { overflow: hidden; border-radius: 100px 24px 24px; aspect-ratio: 4 / 3; background: var(--oat); }
  .place__image { width: 100%; height: 100%; object-fit: cover; }
  .place__caption { font-size: 16px; margin-top: 14px; color: var(--muted); }
  .sources { padding: 30px 32px; margin-top: 48px; background: var(--oat); border-radius: 24px; }
  .sources__heading { font-size: 28px; margin-bottom: 16px; }
  .sources__date { font-size: 16px; color: var(--muted); margin-bottom: 18px; }
  .sources__list { padding: 0; list-style: none; }
  .sources__item + .sources__item { margin-top: 16px; }
  .sources__link { font-size: 16px; display: flex; gap: 20px; justify-content: space-between; align-items: center; min-height: 48px; padding-block: 10px; line-height: 1.5; }
  .sources__caption { color: var(--muted); font-size: 16px; line-height: 1.5; }
  .next-sheet { margin-top: 36px; }
  .next-sheet__link { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 24px; padding: 28px 30px; background: var(--sun); color: var(--ink); text-decoration: none; border-radius: 24px 24px 48px 24px; }
  .next-sheet__eyebrow { grid-column: 1; font-size: 16px; }
  .next-sheet__title { grid-column: 1; font: 500 34px/1.2 var(--display); }
  .next-sheet__arrow { grid-column: 2; grid-row: 1 / 3; align-self: center; font-size: 34px; }
  .footer__statement { font-size: 16px; max-width: 48ch; line-height: 1.6; }
  .footer__links { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: flex-end; gap: 4px 22px; }
  .footer__link { display: inline-flex; align-items: center; font-size: 16px; min-height: 48px; padding-block: 10px; }
  .cost-sheet { padding-top: 4px; margin-top: 48px; }
  .cost-sheet h2 { font-size: 36px; margin-bottom: 18px; }
  .cost-sheet__quotes { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin-top: 30px; }
  .cost-sheet__quote { min-width: 0; border: 2px solid var(--line); border-radius: 22px; padding: 20px; margin: 0; background: var(--white); }
  .cost-sheet__legend { font: 500 31px/1.2 var(--display); padding: 0 12px; }
  .cost-sheet__field { margin-bottom: 22px; }
  .cost-sheet__label { display: block; font-size: 16px; line-height: 1.5; margin-bottom: 8px; }
  .cost-sheet__amount { position: relative; }
  .cost-sheet__currency { position: absolute; inset: 11px auto auto 14px; color: var(--muted); }
  .cost-sheet__input, .cost-sheet__period { display: block; min-width: 0; width: 100%; min-height: 50px; padding: 10px 12px 10px 32px; font-size: 18px; border: 1.5px solid var(--edge); border-radius: 10px; }
  .cost-sheet__period { padding-left: 12px; font-size: 16px; }
  .cost-sheet__input::placeholder, .cost-sheet__period::placeholder { color: var(--muted); opacity: 1; }
  .cost-sheet__sums { border-top: 2px solid var(--line); padding-top: 20px; }
  .cost-sheet__sum + .cost-sheet__sum { margin-top: 20px; }
  .cost-sheet__sum dt { font-size: 16px; }
  .cost-sheet__sum dd { margin-top: 4px; }
  .cost-sheet__total { font-family: var(--display); font-size: 26px; line-height: 1.2; }
  .cost-sheet__status { color: var(--muted); font-size: 16px; margin-top: 20px; line-height: 1.5; }
  .cost-sheet__error { font-size: 16px; color: var(--clay-deep); margin-block: 18px; }
}

@layer states {
  :focus-visible { outline: 3px solid var(--clay); outline-offset: 4px; }
  .skip-link:focus { transform: none; }
  .page-index__link[aria-current="page"] { background: var(--sun); color: var(--ink); font-weight: 600; }
  .page-index__link:hover { background: var(--oat); }
  .page-index__link[aria-current="page"]:hover { background: var(--sun); }
  .button:hover { background: var(--clay-deep); border-color: var(--clay-deep); color: var(--white); }
  .sources__link:hover, .footer__link:hover, .masthead__index:hover { text-decoration-thickness: 2px; }
  .next-sheet__link:hover { background: #e8c75e; }
  .cost-sheet__input[aria-invalid="true"] { border-color: var(--clay-deep); outline: 2px solid var(--clay-deep); }
  .guide__main:focus { outline: none; }
}

@layer responsive {
  @media (max-width: 1150px) and (min-width: 851px) {
    .masthead, .footer { padding-inline: 32px; }
    .guide__layout { grid-template-columns: 212px minmax(0, 1fr); gap: 40px; padding-inline: 32px; }
    .comparison__side { padding: 24px; }
    .cost-sheet__quotes { grid-template-columns: 1fr; }
  }
  @media (max-width: 850px) {
    .masthead { padding: 22px 24px; }
    .guide__layout { display: flex; flex-direction: column; gap: 54px; padding: 36px 24px 48px; }
    .guide__main { order: 0; }
    .page-index { position: static; order: 1; max-height: none; overflow: visible; padding: 28px 0 0; border-top: 2px solid var(--line); width: 100%; }
    .page-index__nav { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 28px; }
    .page-index__title, .page-index__top { grid-column: 1 / -1; margin: 0; }
    .page-index__group + .page-index__group { margin: 0; }
    .sheet, .sheet__reading { max-width: 100%; }
    .sheet__title { font-size: clamp(46px, 8vw, 66px); }
    .guide--home .sheet__title { font-size: clamp(50px, 9vw, 72px); }
    .footer { padding: 28px 24px; grid-template-columns: 1fr; gap: 20px; }
    .footer__links { justify-content: flex-start; }
  }
  @media (max-width: 550px) {
    .masthead { padding: 18px 20px; gap: 10px; align-items: center; }
    .masthead__brand { gap: 10px; }
    .masthead__symbol { width: 36px; height: 44px; flex-basis: 36px; font-size: 35px; background: transparent; }
    .masthead__name { font-size: 20px; }
    .masthead__caption { font-size: 16px; max-width: 20ch; }
    .masthead__index { padding-left: 8px; gap: 8px; white-space: normal; max-width: 78px; line-height: 1.4; }
    .guide__layout { padding: 30px 20px 40px; }
    .sheet__category { margin-bottom: 20px; }
    .sheet__header { margin-bottom: 32px; }
    .sheet__lead { font-size: 19px; line-height: 1.65; margin-top: 24px; }
    .comparison__columns { grid-template-columns: 1fr; border-radius: 20px 42px 20px 20px; }
    .comparison__side { padding: 26px; }
    .comparison__title { font-size: 29px; }
    .reading { margin-block: 38px; }
    .reading__title { font-size: 33px; }
    .worksheet { padding: 26px 22px; margin-top: 40px; }
    .worksheet__title { font-size: 32px; }
    .worksheet__mark { display: none; }
    .worksheet__field { margin-top: 26px; }
    .worksheet__input { min-height: 132px; }
    .worksheet__print { width: 100%; gap: 18px; }
    .sources { padding: 26px 24px; margin-top: 38px; }
    .sources__heading { font-size: 28px; }
    .place__frame { border-radius: 64px 20px 20px; }
    .next-sheet__link { padding: 24px; gap: 8px 16px; }
    .next-sheet__title { font-size: 30px; }
    .next-sheet__arrow { font-size: 28px; }
    .page-index__nav { grid-template-columns: 1fr; gap: 26px; }
    .page-index__title { font-size: 30px; }
    .page-index__heading { font-size: 23px; }
    .page-index__link { min-height: 48px; padding-inline: 14px; }
    .cost-sheet__quotes { grid-template-columns: 1fr; gap: 28px; }
    .cost-sheet h2 { font-size: 33px; }
    .cost-sheet__quote { padding: 22px; }
    .footer { padding-inline: 20px; }
    .footer__links { flex-direction: column; gap: 0; }
  }
  @media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
  }
}

@layer print {
  @media print {
    @page { margin: 18mm; }
    body { color: #000; background: #fff; font-size: 16px; }
    .page-index, .masthead__index, .skip-link, .footer__links, .next-sheet, .place, .button { display: none; }
    .masthead { padding: 0 0 20px; }
    .masthead__symbol { background: none; }
    .guide__layout { display: block; padding: 24px 0; border-color: #aaa; }
    .sheet__title, .guide--home .sheet__title { font-size: 40px; }
    .sheet__lead { font-size: 18px; }
    .comparison__side, .sources { background: #f5f5f5; }
    .comparison, .worksheet__field, .cost-sheet__quote, .sources__item { break-inside: avoid; }
    .worksheet { padding: 24px; border-color: #aaa; }
    .worksheet__input { min-height: 140px; border-color: #777; }
    .cost-sheet__quotes { grid-template-columns: 1fr 1fr; }
    .cost-sheet__quote { padding: 16px; }
    .cost-sheet__total { font-size: 22px; }
    .footer { display: block; padding: 20px 0 0; border-color: #aaa; }
  }
}
