/* Responsive chapter-page layer. Desktop presentation remains in each page's
   design-source markup; this file gives phones and tablets a native layout. */

html,
body,
x-dc,
x-dc > div {
  max-width: 100%;
}

html,
body {
  overflow-x: clip;
}

x-dc {
  display: block;
}

.chapter-header a:focus-visible,
.chapter-sidebar a:focus-visible,
.chapter-next a:focus-visible,
.chapter-footer a:focus-visible {
  outline: 2px solid #7a2a1f;
  outline-offset: 4px;
}

@media (max-width: 900px) {
  body {
    min-width: 0;
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
  }

  .chapter-header {
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center !important;
    gap: 10px !important;
    padding-top: max(10px, env(safe-area-inset-top)) !important;
    padding-right: max(18px, env(safe-area-inset-right)) !important;
    padding-bottom: 10px !important;
    padding-left: max(18px, env(safe-area-inset-left)) !important;
    font-size: 10px !important;
    letter-spacing: .13em !important;
  }

  .chapter-header > a:first-child,
  .chapter-header > span:last-child a[aria-current="page"] {
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .chapter-header > span:nth-child(2) {
    min-width: 0;
    text-align: center;
    white-space: nowrap;
    font-size: 9.5px;
    letter-spacing: .2em !important;
  }

  .chapter-header > span:last-child {
    display: block !important;
    min-width: 0;
  }

  .chapter-header > span:last-child a {
    display: none;
  }

  .chapter-header > span:last-child a[aria-current="page"] {
    color: #7a2a1f;
    white-space: nowrap;
  }

  .chapter-hero {
    min-height: calc(100svh - 65px);
    padding-top: clamp(52px, 9svh, 82px) !important;
    padding-right: max(20px, env(safe-area-inset-right)) !important;
    padding-bottom: clamp(52px, 9svh, 82px) !important;
    padding-left: max(20px, env(safe-area-inset-left)) !important;
    box-sizing: border-box;
    display: flex;
    align-items: center;
  }

  .chapter-hero > div:first-child {
    top: 34px !important;
    right: -26px !important;
    font-size: clamp(170px, 56vw, 260px) !important;
  }

  .chapter-hero > div:last-child {
    width: 100%;
    min-width: 0;
  }

  .chapter-hero > div:last-child > div:first-child {
    min-width: 0;
    max-width: 100%;
    font-size: 10.5px !important;
  }

  .chapter-hero > div:last-child > div:first-child > span:nth-child(2) {
    width: calc(var(--stream-chars) * 1ch + 1.1ch) !important;
    max-width: calc(100% - 88px);
    animation: none !important;
    text-overflow: clip;
  }

  .chapter-hero h1 {
    max-width: 100%;
    margin-top: 26px !important;
    font-size: clamp(48px, 10.5vw, 72px) !important;
    line-height: .98 !important;
    letter-spacing: -.02em !important;
    overflow-wrap: normal;
    text-wrap: balance;
  }

  .chapter-hero h1 + div {
    margin-top: 20px !important;
    max-width: 34rem;
    font-size: 19px !important;
    line-height: 1.35;
    text-wrap: pretty;
  }

  .chapter-hero h1 + div + p {
    margin-top: 34px !important;
    max-width: 36rem !important;
    font-size: 18px !important;
    line-height: 1.62 !important;
    text-wrap: pretty;
  }

  .chapter-body {
    display: block !important;
    width: 100%;
    max-width: 760px !important;
    padding-top: 46px !important;
    padding-right: max(20px, env(safe-area-inset-right)) !important;
    padding-bottom: 64px !important;
    padding-left: max(20px, env(safe-area-inset-left)) !important;
    box-sizing: border-box;
  }

  .chapter-sidebar {
    position: static !important;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 20px;
    align-items: end;
    margin-bottom: 56px;
    padding-bottom: 22px;
    border-bottom: 1px solid rgba(28, 26, 23, .35);
  }

  .chapter-sidebar > div:first-child {
    grid-column: 1;
  }

  .chapter-sidebar > div:nth-child(2) {
    grid-column: 1;
    margin-top: 8px !important;
    font-size: 24px !important;
    line-height: 1.08;
  }

  .chapter-sidebar > div:nth-child(3) {
    display: none;
  }

  .chapter-sidebar > div:last-child {
    grid-column: 2;
    grid-row: 1 / span 2;
    margin-top: 0 !important;
    gap: 0 !important;
  }

  .chapter-sidebar > div:last-child a {
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    white-space: nowrap;
  }

  .chapter-content {
    min-width: 0;
    width: 100%;
  }

  .chapter-content > div:first-child > div:nth-child(2) > div,
  .chapter-content #paper > div:nth-child(2) > div {
    display: block !important;
    padding: 24px 0 !important;
  }

  .chapter-content > div:first-child > div:nth-child(2) > div > span:first-child,
  .chapter-content #paper > div:nth-child(2) > div > span:first-child {
    display: block;
    margin-bottom: 9px;
    font-size: 11px !important;
  }

  .chapter-content > div:first-child > div:nth-child(2) > div > span:last-child,
  .chapter-content #paper > div:nth-child(2) > div > span:last-child {
    display: block;
    min-width: 0;
  }

  .chapter-content > div:first-child > div:nth-child(2) > div > span:last-child > span:first-child {
    font-size: 27px !important;
    line-height: 1.08;
    text-wrap: balance;
  }

  .chapter-content > div:first-child > div:nth-child(2) > div > span:last-child > span:not(:first-child) {
    font-size: 16px !important;
    line-height: 1.5;
    text-wrap: pretty;
  }

  .chapter-content > div:first-child > p {
    margin-top: 20px !important;
    font-size: 16px !important;
    line-height: 1.6 !important;
  }

  .chapter-content #work,
  .chapter-content #paper {
    margin-top: 76px !important;
  }

  .chapter-content #work > div:not(:first-child) {
    padding: 34px 0 38px !important;
  }

  .chapter-content #work > div:not(:first-child) > div {
    display: grid !important;
    grid-template-columns: 28px minmax(0, 1fr);
    align-items: start !important;
    gap: 10px !important;
  }

  .chapter-content #work > div:not(:first-child) > div > span:last-child {
    min-width: 0;
    font-size: 30px !important;
    line-height: 1.08;
    text-wrap: balance;
  }

  .chapter-content #work > div:not(:first-child) > p {
    margin: 16px 0 0 38px !important;
    max-width: none !important;
    font-size: 17px !important;
    line-height: 1.65 !important;
    text-wrap: pretty;
  }

  .chapter-content #paper > div:nth-child(2) > div > span:last-child {
    font-size: 20px !important;
    line-height: 1.35;
  }

  .chapter-next > a {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px 18px !important;
    padding-top: 34px !important;
    padding-right: max(20px, env(safe-area-inset-right)) !important;
    padding-bottom: 34px !important;
    padding-left: max(20px, env(safe-area-inset-left)) !important;
    box-sizing: border-box;
  }

  .chapter-next > a > span:first-child {
    grid-column: 1 / -1;
  }

  .chapter-next > a > span:nth-child(2) {
    min-width: 0;
    font-size: 32px !important;
    line-height: 1.08;
    text-wrap: balance;
  }

  .chapter-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 16px;
    padding-top: 24px !important;
    padding-right: max(20px, env(safe-area-inset-right)) !important;
    padding-bottom: max(28px, env(safe-area-inset-bottom)) !important;
    padding-left: max(20px, env(safe-area-inset-left)) !important;
  }

  [data-reveal] {
    transition-duration: .7s !important;
  }
}

@media (max-width: 560px) {
  .chapter-header {
    grid-template-columns: auto minmax(0, 1fr) auto;
    padding-right: max(14px, env(safe-area-inset-right)) !important;
    padding-left: max(14px, env(safe-area-inset-left)) !important;
  }

  .chapter-header > span:nth-child(2) {
    font-size: 0;
    letter-spacing: 0 !important;
  }

  .chapter-header > span:nth-child(2)::after {
    content: "J. R. BRENNAN";
    font-size: 9px;
    letter-spacing: .16em;
  }

  .chapter-header > span:last-child a[aria-current="page"] {
    font-size: 9.5px;
  }

  .chapter-hero h1 {
    font-size: clamp(44px, 13vw, 58px) !important;
  }

  .chapter-sidebar {
    display: block;
  }

  .chapter-sidebar > div:last-child {
    display: flex !important;
    flex-wrap: wrap;
    gap: 0 18px !important;
    margin-top: 18px !important;
  }

  .chapter-sidebar > div:last-child a {
    justify-content: flex-start;
  }

  .chapter-content #work > div:not(:first-child) > div > span:last-child {
    font-size: 28px !important;
  }

  .chapter-content #work > div:not(:first-child) > p {
    margin-left: 0 !important;
  }
}

@media (max-width: 390px) {
  .chapter-header > span:nth-child(2) {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .chapter-hero {
    padding-right: max(18px, env(safe-area-inset-right)) !important;
    padding-left: max(18px, env(safe-area-inset-left)) !important;
  }

  .chapter-body {
    padding-right: max(18px, env(safe-area-inset-right)) !important;
    padding-left: max(18px, env(safe-area-inset-left)) !important;
  }
}

@media (max-width: 900px) and (orientation: landscape) and (max-height: 560px) {
  .chapter-hero {
    min-height: auto;
    padding-top: 44px !important;
    padding-bottom: 44px !important;
  }

  .chapter-hero h1 {
    font-size: clamp(44px, 8vw, 64px) !important;
  }

  .chapter-hero h1 + div + p {
    max-width: 44rem !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chapter-hero [data-anim],
  .chapter-hero [data-anim] span,
  .chapter-content [data-reveal] {
    animation: none !important;
    transition: none !important;
    opacity: 1 !important;
    transform: none !important;
  }
}
