.hn-back.hn-back {
    --back-ink: #374151;
    --back-hover: #f3f4f6;
    display: inline-grid;
    place-items: center;
    box-sizing: border-box;
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    margin-inline-start: -10px;
    padding: 0;
    color: var(--back-ink);
    background: transparent;
    border: 0;
    border-radius: 50%;
    box-shadow: none;
    text-decoration: none;
    cursor: pointer;
    touch-action: manipulation;
    transition: background-color 150ms ease;
}

:is(.dark, [data-theme="dark"], [data-nav-theme="dark"]) .hn-back.hn-back {
    --back-ink: #d1d5db;
    --back-hover: #1f2937;
}

.hn-back.hn-back:active,
.hn-back.hn-back:focus-visible {
    background: var(--back-hover);
}

.hn-back.hn-back:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
}

@media (hover: hover) {
    .hn-back.hn-back:hover { background: var(--back-hover); }
}

@media (prefers-reduced-motion: reduce) {
    .hn-back.hn-back { transition: none; }
}

/* The ticket list is visible alongside the conversation on desktop. */
#stBack.hn-back {
    display: none;
    margin: 4px 8px 0;
}

@media (max-width: 760px) {
    #stBack.hn-back { display: inline-grid; }
}

.hn-page-header {
    --header-bg: #fff;
    --header-border: #e5e7eb;
    --theme-ink: #6b7280;
    --theme-border: #e5e7eb;
    --theme-hover: #f3f4f6;
    position: sticky;
    top: 0;
    z-index: 30;
    background-color: var(--header-bg);
    border-bottom: 1px solid var(--header-border);
    transition: background-color 200ms ease, border-color 200ms ease;
}

html.dark .hn-page-header {
    --header-bg: #111827;
    --header-border: #1f2937;
    --theme-ink: #9ca3af;
    --theme-border: #374151;
    --theme-hover: #1f2937;
}

.hn-page-header-inner {
    box-sizing: border-box;
    max-width: 64rem;
    height: 56px;
    padding-inline: 16px;
    margin-inline: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

@media (min-width: 640px) {
    .hn-page-header-inner { padding-inline: 24px; }
}

.hn-page-header .hn-theme-toggle {
    box-sizing: border-box;
    display: grid;
    place-items: center;
    position: relative;
    flex: 0 0 40px;
    width: 40px;
    min-height: 0;
    height: 40px;
    padding: 0;
    border: 1px solid var(--theme-border);
    border-radius: 50%;
    background: transparent;
    color: var(--theme-ink);
    cursor: pointer;
    touch-action: manipulation;
    transition: background-color 180ms ease, color 180ms ease, border-color 180ms ease;
}

.hn-page-header .hn-theme-toggle:is(:hover,:active) { background-color: var(--theme-hover); }
.hn-page-header .hn-theme-toggle:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }

.hn-theme-toggle svg {
    position: absolute;
    inset: 0;
    margin: auto;
    width: 20px;
    height: 20px;
    transition: opacity 180ms ease, transform 220ms ease;
}

.hn-theme-sun, html.dark .hn-theme-moon { opacity: 0; transform: rotate(-35deg) scale(.65); }
.hn-theme-moon, html.dark .hn-theme-sun { opacity: 1; transform: none; }
html.dark .hn-theme-moon { opacity: 0; transform: rotate(35deg) scale(.65); }

@media (prefers-reduced-motion: reduce) {
    .hn-page-header, .hn-page-header .hn-theme-toggle, .hn-theme-toggle svg { transition: none; }
}

@property --hn-theme-radius {
    syntax: "<length>";
    inherits: false;
    initial-value: 0px;
}

/* Capture the final colors and icon before revealing the new theme. */
html.hn-theme-reveal,
html.hn-theme-reveal :where(*) {
    transition: none !important;
}

html.hn-theme-reveal::view-transition-group(root),
html.hn-theme-reveal::view-transition-old(root),
html.hn-theme-reveal::view-transition-new(root) {
    animation: none;
    mix-blend-mode: normal;
}

html.hn-theme-reveal::view-transition-image-pair(root) {
    isolation: isolate;
}

html.hn-theme-reveal.dark::view-transition-new(root),
html.hn-theme-reveal:not(.dark)::view-transition-old(root) {
    z-index: 1;
    mask-image: radial-gradient(circle at var(--hn-theme-center),
        #000 calc(var(--hn-theme-radius) - var(--hn-theme-edge)),
        transparent var(--hn-theme-radius));
    animation: hn-theme-radius 400ms cubic-bezier(.42, 0, .36, 1) both;
}

html.hn-theme-reveal:not(.dark)::view-transition-old(root) {
    animation-direction: reverse;
}

@keyframes hn-theme-radius {
    from { --hn-theme-radius: 0px; }
    to { --hn-theme-radius: var(--hn-theme-end); }
}
