/* Шрифты */
@font-face {
    font-family: 'Literata';
    src: url('fonts/Literata-Light.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Basis Grotesque Mono Pro';
    src: url('fonts/BasisGrotesqueMonoPro-Regular.woff2') format('woff2');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

/* Базовый размер: 1rem = 12px */
html {
    font-size: 12px;
    height: 100%;
    overflow-x: hidden;
    overflow-y: visible;
}

/* Цвета и отступы */
:root {
    --grey: rgba(175, 177, 182, 1);
    --dark: rgba(29, 28, 31, 1);
    --bg-bottom: rgba(77, 78, 84, 1);
    --page-padding: 12px;
    --nav-left: 190px;
    --header-offset: calc(3rem + var(--page-padding) * 2);
    --card-center: 28.75rem;
    --card-near: 18rem;
    --card-far: 11.667rem;
    --radius-center: 0.833rem;
    --radius-near: 0.667rem;
    --radius-far: 0.5rem;
    --selection-bg: rgb(224, 255, 11);
    --selection-text: var(--dark);
    /* Progressive blur header (как на vshslv.com: панели с убывающим blur + маски-полосы) */
    --pb-height: 120px;
    --pb-blur: 3rem;
    --pb-ratio: 1.9;
    --pb-tint: rgba(29, 28, 31, 0.4);
}

/* Theme variables */
[data-theme="dark"] {
    --bg: oklch(17% 0.006 265);
    --bg-mid: oklch(20% 0.007 265);
    --bg-bottom: oklch(0.3678 0.009 265);
    --text: rgba(175, 177, 182, 1);
    --muted: rgba(120, 122, 128, 1);
    --border: rgba(175, 177, 182, 1);
    --card: #2a2a2a;
    --accent: rgba(175, 177, 182, 1);
}

[data-theme="light"] {
    --bg: oklch(0.98 0.002 265);
    --bg-mid: oklch(0.96 0.003 265);
    --bg-bottom: oklch(0.92 0.004 265);
    --text: rgba(55, 58, 63, 1);
    --muted: rgba(100, 103, 110, 1);
    --border: rgba(180, 182, 188, 1);
    --card: rgba(245, 245, 247, 1);
    --accent: rgba(55, 58, 63, 1);
}

/* Default to dark theme if no data-theme attribute */
:root:not([data-theme]) {
    --bg: oklch(17% 0.006 265);
    --bg-mid: oklch(20% 0.007 265);
    --bg-bottom: oklch(0.3678 0.009 265);
    --text: rgba(175, 177, 182, 1);
    --muted: rgba(120, 122, 128, 1);
    --border: rgba(175, 177, 182, 1);
    --card: #2a2a2a;
    --accent: rgba(175, 177, 182, 1);
}

::selection {
    background: var(--selection-bg);
    color: var(--selection-text);
}

::-moz-selection {
    background: var(--selection-bg);
    color: var(--selection-text);
}

/* Базовые стили */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Literata', Georgia, serif;
    line-height: 1.6;
    color: var(--text);
    /* fallback для браузеров без OKLCH - темная тема */
    background: linear-gradient(
        180deg,
        rgb(27, 27, 29) 0vh,
        rgb(27, 27, 29) 65vh,
        rgb(61, 63, 68) 100vh
    );
    /* perceptual gradient */
    background: linear-gradient(
        180deg,
        var(--bg) 0vh,
        var(--bg-mid) 65vh,
        var(--bg-bottom) 100vh
    );
    height: 100vh;
    width: 100%;
    overflow-x: hidden;
    overflow-y: visible;
    display: flex;
    flex-direction: column;
}

/* Обёртка контента: на десктопе участвует в flex, на мобиле — скролл-контейнер */
.viewport-scroll {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

/* Fallback градиент для светлой темы (для браузеров без OKLCH). fixed — чтобы на мобиле не скроллился отдельно от контента. */
[data-theme="light"] body {
    background: linear-gradient(
        180deg,
        oklch(82% 0.012 255) 0vh,
        oklch(90% 0.008 95) 45vh,
        oklch(99% 0.002 95) 100vh
    );
    /* perceptual gradient */
    background: linear-gradient(
        180deg,
        rgb(205, 210, 218) 0vh,
        rgb(230, 233, 238) 45vh,
        rgb(255, 255, 255) 100vh
    );
    background-attachment: fixed;
}

a {
    color: inherit;
    text-decoration: none;
}

.link {
    line-height: 1;
    font-size: 1.15rem;
}

.text {
    font-family: 'Basis Grotesque Mono Pro', monospace;
    font-size: 1.15rem;
    line-height: 1;
    text-align: left;
    color: var(--text);
}

.link-flip {
    position: relative;
    display: inline-block;
    perspective: 1000px;
}

.link-flip__front,
.link-flip__back {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.6s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.6s ease;
    backface-visibility: hidden;
}

.link-flip__front {
    opacity: 1;
    transform: translateY(0) rotateX(0);
}

.link-flip__back {
    opacity: 0;
    transform: translateY(-50%) rotateX(90deg);
}

.link-flip:hover .link-flip__front {
    opacity: 0;
    transform: translateY(50%) rotateX(90deg);
}

.link-flip:hover .link-flip__back {
    opacity: 1;
    transform: translateY(0) rotateX(0);
}

.link-flip__ghost {
    visibility: hidden;
    display: inline-block;
}

.header__nav .link-flip__front,
.header__nav .link-flip__back {
    justify-content: flex-start;
}

.header__mail .link-flip__front,
.header__mail .link-flip__back {
    justify-content: flex-end;
}

/* Header — закреплён сверху на всех страницах */
.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: var(--page-padding);
}

/* Progressive blur: как на vshslv.com — N панелей с убывающим blur и масками-полосами для плавного перехода */
.header__pb {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: var(--pb-height);
    pointer-events: none;
    z-index: 0;
}

/* Только blur, без фона — как на рефе vshslv.com, цвета нет */
.header__pb-layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* Слой 1: самый сильный blur, маска сверху с мягким затуханием */
.header__pb-layer--1 {
    -webkit-backdrop-filter: blur(var(--pb-blur));
    backdrop-filter: blur(var(--pb-blur));
    -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 12%, transparent 40%);
    mask-image: linear-gradient(to bottom, #000 0%, #000 12%, transparent 40%);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
}

/* Слой 2–6: blur / ratio^i, маски с длинными переходами чтобы не было полос */
.header__pb-layer--2 {
    -webkit-backdrop-filter: blur(calc(var(--pb-blur) / var(--pb-ratio)));
    backdrop-filter: blur(calc(var(--pb-blur) / var(--pb-ratio)));
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, #000 8% 28%, transparent 48%);
    mask-image: linear-gradient(to bottom, transparent 0%, #000 8% 28%, transparent 48%);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
}

.header__pb-layer--3 {
    -webkit-backdrop-filter: blur(calc(var(--pb-blur) / (var(--pb-ratio) * var(--pb-ratio))));
    backdrop-filter: blur(calc(var(--pb-blur) / (var(--pb-ratio) * var(--pb-ratio))));
    -webkit-mask-image: linear-gradient(to bottom, transparent 15%, #000 25% 40%, transparent 58%);
    mask-image: linear-gradient(to bottom, transparent 15%, #000 25% 40%, transparent 58%);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
}

.header__pb-layer--4 {
    -webkit-backdrop-filter: blur(calc(var(--pb-blur) / (var(--pb-ratio) * var(--pb-ratio) * var(--pb-ratio))));
    backdrop-filter: blur(calc(var(--pb-blur) / (var(--pb-ratio) * var(--pb-ratio) * var(--pb-ratio))));
    -webkit-mask-image: linear-gradient(to bottom, transparent 28%, #000 38% 52%, transparent 68%);
    mask-image: linear-gradient(to bottom, transparent 28%, #000 38% 52%, transparent 68%);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
}

.header__pb-layer--5 {
    -webkit-backdrop-filter: blur(calc(var(--pb-blur) / (var(--pb-ratio) * var(--pb-ratio) * var(--pb-ratio) * var(--pb-ratio))));
    backdrop-filter: blur(calc(var(--pb-blur) / (var(--pb-ratio) * var(--pb-ratio) * var(--pb-ratio) * var(--pb-ratio))));
    -webkit-mask-image: linear-gradient(to bottom, transparent 40%, #000 50% 62%, transparent 78%);
    mask-image: linear-gradient(to bottom, transparent 40%, #000 50% 62%, transparent 78%);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
}

.header__pb-layer--6 {
    -webkit-backdrop-filter: blur(calc(var(--pb-blur) / (var(--pb-ratio) * var(--pb-ratio) * var(--pb-ratio) * var(--pb-ratio) * var(--pb-ratio))));
    backdrop-filter: blur(calc(var(--pb-blur) / (var(--pb-ratio) * var(--pb-ratio) * var(--pb-ratio) * var(--pb-ratio) * var(--pb-ratio))));
    -webkit-mask-image: linear-gradient(to bottom, transparent 50%, #000 58% 70%, transparent 88%);
    mask-image: linear-gradient(to bottom, transparent 50%, #000 58% 70%, transparent 88%);
    -webkit-mask-size: 100% 100%;
    mask-size: 100% 100%;
}

@supports not (backdrop-filter: blur(1px)) {
    .header__pb {
        background: linear-gradient(to bottom, var(--pb-tint) 0%, transparent 100%);
    }
    .header__pb-layer {
        display: none;
    }
}

/* Page loader — фон под шапкой (z-index ниже .header), шапка поверх лоадера */
.page-loader {
    position: fixed;
    inset: 0;
    z-index: 5;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    visibility: visible;
    opacity: 1;
    transition: opacity 0.25s ease, visibility 0.25s ease, transform 0.25s ease;
}
.page-loader.is-hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}
@media (prefers-reduced-motion: reduce) {
    .page-loader,
    .page-loader.is-hidden {
        transition: none;
    }
}
.page-loader__bg {
    position: absolute;
    inset: 0;
    background: rgb(224, 255, 11);
    z-index: -1;
}
.page-loader__header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: calc(var(--pb-height) + var(--page-padding));
    min-height: 5rem;
}
.page-loader__center {
    display: flex;
    align-items: center;
    justify-content: center;
}
.page-loader__text {
    display: inline-flex;
    flex-wrap: wrap;
    justify-content: center;
    font-family: 'Basis Grotesque Mono Pro', monospace;
    font-size: 1.15rem;
    line-height: 1;
    color: rgb(29, 28, 31);
}
.page-loader__char {
    display: inline-block;
    animation: page-loader-blur 2s ease-in-out infinite;
    animation-delay: calc(var(--i, 0) * 0.15s);
}
@media (prefers-reduced-motion: reduce) {
    .page-loader__char {
        animation: none;
        opacity: 1;
        filter: none;
    }
}
@keyframes page-loader-blur {
    0%, 100% {
        opacity: 0;
        filter: blur(10px);
    }
    50% {
        opacity: 1;
        filter: blur(0);
    }
}
@media (max-width: 768px) {
    .page-loader__header {
        display: none;
    }
    /* Убираем полосу фона лоадера под Safari: при скрытии сдвигаем оверлей вверх */
    .page-loader.is-hidden {
        transform: translateY(-100%);
    }
}

/* Lazy media reveal — плавное появление после загрузки */
.media-reveal {
    opacity: 0;
    transition: opacity 0.4s ease;
}
.media-reveal.is-ready {
    opacity: 1;
}
@media (prefers-reduced-motion: reduce) {
    .media-reveal,
    .media-reveal.is-ready {
        transition: none;
    }
}

.header__left,
.header__center,
.header__right {
    position: relative;
    z-index: 1;
}

.header__left {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.header__name {
    font-family: 'Basis Grotesque Mono Pro', monospace;
    text-decoration: none;
    color: inherit;
}

.header__nav {
    position: absolute;
    top: 0;
    left: calc(var(--nav-left) - var(--page-padding));
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    align-items: flex-start;
}

.header__nav a {
    font-family: 'Basis Grotesque Mono Pro', monospace;
}

.header__center {
    position: absolute;
    left: 50%;
    top: var(--page-padding);
    transform: translateX(-50%);
}

.header__logo {
    display: block;
}

.header__logo-media {
    display: block;
    line-height: 0;
}

.header__logo-media img,
.header__logo-media video {
    display: block;
    width: 5rem;
    height: 5rem;
    object-fit: contain;
}

.header__right {
    display: flex;
    gap: var(--page-padding);
}

.header__right a {
    font-family: 'Basis Grotesque Mono Pro', monospace;
}

.header__mail {
    display: inline-block;
    min-width: 6ch;
    text-align: right;
}

.header__nav a.is-active {
    text-decoration: line-through;
    pointer-events: none;
}

.header__nav a.is-active .link-flip__front,
.header__nav a.is-active .link-flip__back,
.header__nav a.is-active .link-flip__ghost {
    text-decoration: line-through;
}

.header__nav a.is-active .link-flip:hover .link-flip__front,
.header__nav a.is-active .link-flip:hover .link-flip__back {
    opacity: 1;
    transform: translateY(0) rotateX(0);
}

.header__nav a.is-active .link-flip:hover .link-flip__back {
    opacity: 0;
    transform: translateY(-50%) rotateX(90deg);
}

/* H1 — общий стиль заголовков (из about__text) */
h1, .h1 {
    font-size: 2.667rem;
    line-height: 3rem;
    font-weight: 400;
    color: var(--text);
    font-family: 'Literata', Georgia, serif;
    text-align: left;
    max-width: 100%;
}

/* H2 */
h2, .h2 {
    font-family: 'Literata', Georgia, serif;
    font-size: 2rem;
    font-weight: 400;
    font-style: normal;
    line-height: 2.3rem;
    text-align: left;
    color: var(--text);
}

/* Footer */
.footer {
    margin-top: 320px;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: flex-end;
    padding: var(--page-padding) 0;
    max-width: 960px;
    width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding-left: var(--page-padding);
    padding-right: var(--page-padding);
}

.footer__left {
    display: flex;
    gap: var(--page-padding);
}

.footer__center {
    text-align: center;
    font-family: 'Basis Grotesque Mono Pro', monospace;
    font-size: 14px;
    color: var(--text);
}

.footer__center svg {
    display: block;
    width: 120px;
    height: auto;
    margin: 0 auto;
    color: var(--text);
}

.footer__center svg path {
    fill: var(--text);
    stroke: var(--text);
    stroke-width: 0.35;
}

.footer__center svg text {
    fill: var(--text);
    font-family: 'Basis Grotesque Mono Pro', monospace;
    font-size: 1.15rem;
    transform: translateX(1.1rem);
}

.footer__right {
    display: flex;
    gap: var(--page-padding);
    align-items: center;
    justify-content: flex-end;
}

.footer a {
    font-family: 'Basis Grotesque Mono Pro', monospace;
    font-size: 1.15rem;
}

/* Main — по умолчанию не растягивается, футер скроллится вместе с контентом */
main {
    flex: none;
    display: flex;
    flex-direction: column;
    min-height: auto;
    overflow: visible;
    max-width: 960px;
    width: 100%;
    margin: 0 auto;
    padding: var(--header-offset) var(--page-padding) var(--page-padding);
}

/* Только на главной: main заполняет экран, карусель по центру, текст about прибит к низу */
body[data-page="index"] main {
    flex: 1;
    min-height: 0;
}

/* Carousel */
.carousel {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.carousel__focus {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.carousel__viewport {
    width: 100%;
    overflow: visible;
}

.carousel__track {
    list-style: none;
    display: flex;
    align-items: center;
    gap: 10px;
    overflow: visible;
    padding: 0;
    margin: 0;
    scroll-behavior: auto;
    will-change: transform;
}

.carousel__track > li {
    list-style: none;
    flex: 0 0 auto;
}


.carousel__track .card {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}

.carousel__track .card__box {
    width: var(--card-near);
    height: var(--card-near);
    border-radius: var(--radius-near);
    background-color: var(--card);
    overflow: hidden;
    transition: width 0.8s cubic-bezier(0.22, 1, 0.36, 1), height 0.8s cubic-bezier(0.22, 1, 0.36, 1), border-radius 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

.carousel__track .card--hover .card__box {
    width: var(--card-center);
    height: var(--card-center);
    border-radius: var(--radius-center);
}

.card__media {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    word-break: break-word;
}

.card__title {
    flex-shrink: 0;
    font-family: 'Literata', Georgia, serif;
    font-size: 1.5rem;
    font-weight: 400;
    text-align: center;
    color: var(--text);
    background: none;
    opacity: 0;
    max-height: 0;
    margin: 0;
    overflow: hidden;
    transform: translateY(-10px) scale(0.92);
    transform-origin: top center;
    transition: opacity 0.8s cubic-bezier(0.22, 1, 0.36, 1), transform 0.8s cubic-bezier(0.22, 1, 0.36, 1), max-height 0.8s cubic-bezier(0.22, 1, 0.36, 1), margin 0.8s cubic-bezier(0.22, 1, 0.36, 1);
}

.carousel__track .card--hover .card__title {
    opacity: 1;
    max-height: 3em;
    margin-top: 10px;
    transform: translateY(0) scale(1);
}

.card__media--text {
    text-align: center;
    padding: 1rem;
}

.card__media img,
.card__media video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: inherit;
    display: block;
}

/* Works page */
.works__title {
    padding-left: calc(var(--nav-left) - var(--page-padding));
    margin-top: 8.333rem;
    margin-bottom: 0;
}

.works {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 8.333rem;
}

.works__row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    width: 100%;
    font-family: 'Basis Grotesque Mono Pro', monospace;
    transition: opacity 0.3s ease;
}

.works__row .link-flip__front,
.works__row .link-flip__back,
.works__row .link-flip__ghost {
    display: grid;
    grid-template-columns: var(--year-col, 20ch) 1fr auto;
    column-gap: 12px;
    align-items: baseline;
    width: 100%;
    padding: 0;
}

.works__year,
.works__type {
    font-size: 14px;
    line-height: 1;
    color: var(--text);
    flex-shrink: 0;
}

.works__year {
    text-align: left;
    width: 4ch;
    grid-column: 1;
}

.works__type {
    text-align: right;
    grid-column: 3;
}

.works__work-title {
    grid-column: 2;
}

.works:hover .works__row:not(:hover) {
    opacity: 0.3;
}

.works__preview {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) !important;
    transform-origin: center center;
    z-index: 5;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.4s ease;
    max-width: 72vw;
    max-height: 56vh;
}

.works__preview.is-visible {
    opacity: 1;
    transition: opacity 0.4s ease;
}

.works__preview img,
.works__preview video {
    max-width: 100%;
    max-height: 56vh;
    object-fit: contain;
    display: block;
    border-radius: 12px;
    animation: works-preview-fade 0.4s ease;
}

@keyframes works-preview-fade {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(0.5rem);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in-up {
    opacity: 0;
    transform: translateY(0.5rem);
}

/* У ячеек архива до появления во вьюпорте не сдвигаем — только opacity, чтобы не было зазора */
.works__archive-cell.fade-in-up {
    transform: none;
}

.fade-in-up.is-visible {
    animation: fadeInUp 0.7s cubic-bezier(0.22, 1, 0.36, 1) forwards;
    opacity: 1;
    transform: translateY(0);
}

/* После завершения анимации (когда fade-in-up удален) */
.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.works__archive {
    margin-top: 16rem;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.works__archive-column {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.works__archive-cell {
    width: 100%;
    border-radius: 10px;
}

.works__archive-cell img,
.works__archive-cell video {
    width: 100%;
    height: auto;
    display: block;
    vertical-align: bottom;
    border-radius: 10px;
}

/* Projects page */
.projects__title {
    padding-left: calc(var(--nav-left) - var(--page-padding));
    margin-top: 8.333rem;
    margin-bottom: 0;
}

.projects__grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-top: 8.333rem;
}

.projects__card {
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 1.2rem 1.35rem 1.35rem 1.35rem;
    height: 30rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: transparent;
    transition: opacity 0.3s ease;
}

.projects__card:hover {
    opacity: 0.6;
}

.projects__card--soon {
    border-style: dashed;
}

.projects__card-title {
    font-family: 'Literata', Georgia, serif;
    font-size: 2.667rem;
    font-weight: 400;
    line-height: 3rem;
    color: var(--text);
    margin-bottom: 0.7rem;
}

.projects__card-role {
    font-family: 'Basis Grotesque Mono Pro', monospace;
    font-size: 1.15rem;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.projects__card-footer {
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    margin-top: auto;
}

.projects__card-description {
    font-family: 'Basis Grotesque Mono Pro', monospace;
    font-size: 1.15rem;
    line-height: 1.3;
    color: var(--text);
    flex: 1;
    min-width: 0;
    margin: 0;
}

.projects__card-icon {
    width: 6.667rem;
    height: 6.667rem;
    flex-shrink: 0;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.projects__card-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Books page */
.books__title {
    padding-left: calc(var(--nav-left) - var(--page-padding));
    margin-top: 8.333rem;
    margin-bottom: 0;
}

.books__list {
    display: flex;
    flex-direction: column;
    gap: 4rem;
    margin-top: 8.333rem;
}

.books__year-group {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.books__year-heading {
    display: none;
}

.books__year-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.books__row {
    display: grid;
    grid-template-columns: 24ch 11.667rem 1fr;
    gap: 1rem;
    align-items: flex-end;
}

.books__year {
    font-family: 'Basis Grotesque Mono Pro', monospace;
    font-size: 1.15rem;
    line-height: 1;
    color: var(--text);
}

.books__cover {
    width: 11.667rem;
    border-radius: 0.5rem;
    overflow: hidden;
}

.books__cover img {
    width: 100%;
    height: auto;
    display: block;
    vertical-align: bottom;
}

.books__meta {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}

.books__title-text {
    margin: 0;
}

.books__author {
    margin: 0;
}

/* Work page */
.work__header {
    padding-left: calc(var(--nav-left) - var(--page-padding));
    margin-top: 8.333rem;
    margin-bottom: 0;
}

.work__title {
    font-size: 2.667rem;
    line-height: 3rem;
    font-weight: 400;
    color: var(--text);
    font-family: 'Literata', Georgia, serif;
}

.work__content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin-top: 8.333rem;
}

.work__block {
    width: 100%;
}

.work__block--full img,
.work__block--full video {
    width: 100%;
    height: auto;
    display: block;
    vertical-align: bottom;
    border-radius: 10px;
}

.work__block--half {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.work__block--half .work__block-cell--empty {
    /* пустая левая колонка на десктопе */
}

.work__block--half .work__block-cell img,
.work__block--half .work__block-cell video {
    width: 100%;
    height: auto;
    display: block;
    vertical-align: bottom;
    border-radius: 10px;
}

.work__block--two {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.work__block--two .work__block-cell img,
.work__block--two .work__block-cell video {
    width: 100%;
    height: auto;
    display: block;
    vertical-align: bottom;
    border-radius: 10px;
}

.work__block--text-media {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.work__block--text-media.work__block--no-text {
    grid-template-columns: 1fr;
}

.work__block--text-media .work__block-cell img,
.work__block--text-media .work__block-cell video {
    width: 100%;
    height: auto;
    display: block;
    vertical-align: bottom;
    border-radius: 10px;
}

.work__block--text-media .work__block-text {
    font-family: 'Literata', Georgia, serif;
    font-size: 1.3rem;
    line-height: 1.4;
    color: var(--text);
    padding-right: 14rem;
}

.work__block-text p {
    margin: 0 0 0.7rem 0;
}

.work__block-text p:last-child {
    margin-bottom: 0;
}

.work__block--text {
    max-width: 50%;
    margin-bottom: 6rem;
}

.work__block--text .work__block-text {
    font-family: 'Literata', Georgia, serif;
    font-size: 1.2rem;
    line-height: 1.4;
    color: var(--text);
    padding-right: 14rem;
}

.work__block--intro {
    max-width: 100%;
    margin-bottom: 8rem;
}

.work__intro-heading {
    margin: 0 0 4rem 0;
}

.work__intro-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    align-items: start;
}

.work__intro-text {
    font-family: 'Literata', Georgia, serif;
    font-size: 1.3rem;
    line-height: 1.4;
    color: var(--text);
    padding-right: 14rem;
}

.work__intro-text p {
    margin: 0 0 0.7rem 0;
}

.work__intro-text p:last-child {
    margin-bottom: 0;
}

.work__intro-btn-wrap {
    margin-top: 2rem;
}

.work__intro-btn {
    display: inline-block;
    width: fit-content;
    padding: 1rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-far);
    font-family: 'Basis Grotesque Mono Pro', monospace;
    font-size: 1.15rem;
    color: var(--text);
}

.work__intro-meta-wrap {
    display: flex;
    gap: 2rem;
    align-items: start;
    padding-left: 14rem;
}

.work__intro-meta {
    display: grid;
    grid-template-columns: 10rem 20rem;
    gap: 0 1.5rem;
    margin: 0;
    font-family: 'Literata', Georgia, serif;
    font-size: 1.3rem;
    line-height: 1.4;
    color: var(--text);
}

.work__intro-meta dt {
    margin: 0 0 0.25rem 0;
    font-weight: 400;
}

.work__intro-meta dd {
    margin: 0 0 0.5rem 0;
}

.work__nav {
    display: flex;
    gap: 1rem;
    align-items: center;
    margin-top: 8.333rem;
    padding: 2rem 0;
}

.work__nav-cell {
    flex: 1 1 0;
    min-width: 0;
}

.work__nav-cell--prev {
    display: flex;
    justify-content: flex-start;
}

.work__nav-cell--next {
    display: flex;
    justify-content: flex-end;
}

.work__nav-prev,
.work__nav-next {
    width: fit-content;
    font-family: 'Literata', Georgia, serif;
    font-size: 2.667rem;
    line-height: 3rem;
    font-weight: 400;
    color: var(--text);
}

.work__nav-prev .link-flip__front,
.work__nav-prev .link-flip__back {
    justify-content: flex-start;
}

.work__nav-next .link-flip__front,
.work__nav-next .link-flip__back {
    justify-content: flex-end;
}

/* About — прибит к низу экрана */
.about {
    flex-shrink: 0;
    max-width: 640px;
}

/* About page */
body[data-page="about"] main.about-page {
    padding: var(--header-offset) var(--page-padding) var(--page-padding);
}

.about-page {
    max-width: 960px;
    width: 100%;
    margin: 0 auto;
}

.about-page__title {
    padding-left: calc(var(--nav-left) - var(--page-padding));
    margin-top: 8.333rem;
    margin-bottom: 0;
}

.about-page__intro {
    font-size: 2.667rem;
    line-height: 3rem;
    font-weight: 400;
    font-family: 'Literata', Georgia, serif;
    color: var(--text);
    margin: 8.333rem 0 2rem 0;
    text-align: left;
    width: 100%;
}

.about-page__tags {
    display: flex;
    width: 80vw;
    align-items: flex-start;
    align-content: flex-start;
    gap: 0.625rem;
    flex-wrap: wrap;
    margin-bottom: 12.5rem;
}

.about-page__tag {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-far);
}

.about-page__tag,
.about-page__col-title {
    font-family: 'Basis Grotesque Mono Pro', monospace;
    font-size: 1.15rem;
    color: var(--text);
}

.about-page__col-title {
    display: block;
    margin-bottom: 1rem;
}

.about-page__section-title {
    padding-left: calc(var(--nav-left) - var(--page-padding));
    margin-top: 12.5rem;
    margin-bottom: 8.4rem;
    font-size: 2.667rem;
    line-height: 3rem;
    font-weight: 400;
    font-family: 'Literata', Georgia, serif;
    color: var(--text);
}

.about-page__columns {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 8.333rem;
    align-items: start;
}

.about-page__cols-group {
    grid-column: 1 / 3;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}


.about-page__list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.about-page__list li {
    padding: 0.1rem 0;
}

.about-page__list li:last-child {
    border-bottom: none;
}

.about-page__list--no-title {
    padding-top: 2.8rem;
}

/* about-page__career — grid 4 колонки как в columns */
.about-page__career {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.2rem;
    align-items: start;
    margin-bottom: 2rem;
    width: 100%;
}

.about-page__career-row {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    align-items: baseline;
    width: 100%;
    padding: 0;
}

.about-page__career-row .career-year {
    grid-column: 1;
}

.about-page__career-row .career-role {
    grid-column: 2;
}

.about-page__career-row .career-company {
    grid-column: 3;
}

.about-page__career-row--header {
    margin-bottom: 1rem;
}

/* Mentoring page */
body[data-page="mentoring"] main.mentoring-page {
    padding: var(--header-offset) var(--page-padding) var(--page-padding);
}

.mentoring-page {
    max-width: 960px;
    width: 100%;
    margin: 0 auto;
}

.mentoring-page__title {
    padding-left: calc(var(--nav-left) - var(--page-padding));
    margin-top: 8.333rem;
    margin-bottom: 0;
    font-size: 2.667rem;
    line-height: 3rem;
    font-weight: 400;
    font-family: 'Literata', Georgia, serif;
    color: var(--text);
}

.mentoring-page__section {
    margin-top: 8.333rem;
}

.mentoring-page__section-title {
    padding-left: calc(var(--nav-left) - var(--page-padding));
    margin-bottom: 2rem;
    font-size: 2.667rem;
    line-height: 3rem;
    font-weight: 400;
    font-family: 'Literata', Georgia, serif;
    color: var(--text);
}

.mentoring-page__list {
    list-style: none;
    padding: 0;
    margin: 0;
    font-size: 1.5rem;
    line-height: 2rem;
    color: var(--text);
}

.mentoring-page__list li {
    padding: 0.5rem 0;
    padding-left: 1.5rem;
    position: relative;
}

.mentoring-page__list li::before {
    content: '—';
    position: absolute;
    left: 0;
    color: var(--muted);
}

.mentoring-page__list--topics li {
    margin-bottom: 1rem;
}

.mentoring-page__list--topics li::before {
    content: none;
}

.mentoring-page__list--topics li strong {
    font-family: 'Basis Grotesque Mono Pro', monospace;
    font-weight: 400;
}

.mentoring-page__intro {
    margin-top: 4rem;
}

.mentoring-page__intro p {
    font-size: 2rem;
    line-height: 2.5rem;
    font-family: 'Literata', Georgia, serif;
    color: var(--text);
}

.mentoring-page__formats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 2rem;
    margin-bottom: 2rem;
}

.mentoring-page__format {
    padding: 2rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-far);
    background: var(--card);
}

.mentoring-page__format-title {
    font-size: 1.5rem;
    font-family: 'Basis Grotesque Mono Pro', monospace;
    margin-bottom: 1rem;
    color: var(--text);
}

.mentoring-page__format p {
    font-size: 1.15rem;
    line-height: 1.6;
    margin-bottom: 1rem;
    color: var(--text);
}

.mentoring-page__format-price {
    font-family: 'Basis Grotesque Mono Pro', monospace;
    font-size: 1.15rem;
    color: var(--muted);
}

.mentoring-page__cta {
    display: inline-block;
    padding: 1rem 1rem;
    margin-bottom: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-far);
    font-family: 'Basis Grotesque Mono Pro', monospace;
    font-size: 1.15rem;
    color: var(--text);
}

.mentoring-page__cta-note {
    font-size: 1.3rem;
    color: var(--muted);
    max-width: 32rem;
}

.mentoring-page__reviews {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.mentoring-page__review {
    display: flex;
    flex-direction: column;
    padding: 1.2rem 1.35rem 1.35rem 1.35rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: transparent;
    margin: 0;
}

.mentoring-page__review p {
    font-size: 1.3rem;
    line-height: 1.5;
    margin: 0 0 1rem 0;
    color: var(--text);
}

.mentoring-page__review p:last-of-type {
    margin-bottom: 0;
}

.mentoring-page__review cite {
    margin-top: auto;
    padding-top: 2rem;
    font-style: normal;
    font-family: 'Basis Grotesque Mono Pro', monospace;
    font-size: 1.3rem;
    color: var(--muted);
}

.mentoring-page__bio p {
    font-size: 2.667rem;
    line-height: 3rem;
    font-weight: 400;
    font-family: 'Literata', Georgia, serif;
    margin-bottom: 1.5rem;
    color: var(--text);
}

.mentoring-page__bio a {
    text-decoration: underline;
    text-underline-offset: 0.2em;
}

.mentoring-page__links {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem 2rem;
    margin-top: 2rem;
    font-size: 1.15rem;
    color: var(--text);
}

.mentoring-page__links a {
    text-decoration: underline;
    text-underline-offset: 0.2em;
}

@media (max-width: 768px) {
    body[data-page="mentoring"] main.mentoring-page {
        padding: calc(var(--header-offset) * 0.6) var(--page-padding) var(--page-padding);
    }

    .mentoring-page__title {
        padding-left: 0;
        font-size: 2rem;
    }

    .mentoring-page__section-title {
        padding-left: 0;
        font-size: 2rem;
    }

    .mentoring-page__formats {
        grid-template-columns: 1fr;
    }

    .mentoring-page__reviews {
        grid-template-columns: 1fr;
    }

    .mentoring-page__intro p {
        font-size: 1.5rem;
    }

    .mentoring-page__bio p {
        font-size: 2rem;
        line-height: 2.5rem;
    }

    .mentoring-page__list {
        font-size: 1.25rem;
    }
}

.about-page__cv-btn {
    display: inline-block;
    width: fit-content;
    padding: 1rem 1rem;
    margin-left: calc((100% - 3rem) / 4 + 1rem);
    border: 1px solid var(--border);
    border-radius: var(--radius-far);
    font-family: 'Basis Grotesque Mono Pro', monospace;
    font-size: 1.15rem;
    color: var(--text);
}


/* Scale layout — контент растягивается по размеру вкладки */
body.scale-layout .header,
body.scale-layout main {
    max-width: none;
    width: 100%;
    padding-left: var(--page-padding);
    padding-right: var(--page-padding);
}

body.scale-layout .carousel__track {
    width: 100%;
    gap: 10px;
}

body.scale-layout .about {
    max-width: none;
    width: 100%;
}

body.scale-layout .footer {
    max-width: none;
    width: 100%;
}

/* Адаптивность */
@media (max-width: 768px) {
    /* Скролл внутри .viewport-scroll: контент не вылетает снизу, градиент фиксирован сзади. */
    html {
        height: auto;
        min-height: 100%;
        background-color: var(--bg);
        overflow-x: hidden;
        overflow-y: visible;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    html::-webkit-scrollbar {
        display: none;
    }
    html.page-projects {
        background-color: var(--bg);
    }
    body {
        position: relative;
        height: 100dvh;
        overflow: hidden;
        background: transparent;
    }
    .viewport-scroll {
        display: flex;
        flex-direction: column;
        flex: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: env(safe-area-inset-bottom, 0px);
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        padding-top: calc(env(safe-area-inset-top, 0px) + var(--header-offset));
        padding-bottom: 0;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }
    .viewport-scroll::-webkit-scrollbar {
        display: none;
    }
    /* Градиент фиксирован сзади на всю высоту экрана, не скроллится. */
    body::before {
        content: '';
        position: fixed;
        top: calc(-1 * env(safe-area-inset-top, 0px));
        left: 0;
        right: 0;
        bottom: calc(-1 * env(safe-area-inset-bottom, 0px));
        z-index: -1;
        transform: translateZ(0);
        -webkit-backface-visibility: hidden;
        background: linear-gradient(
            180deg,
            var(--bg) 0vh,
            var(--bg-mid) 65vh,
            var(--bg-bottom) 100dvh
        );
    }

    .header {
        position: fixed;
        top: env(safe-area-inset-top, 0px);
        left: 0;
        right: 0;
        flex-wrap: wrap;
        gap: 1.5rem;
        padding: var(--page-padding);
    }

    .header__name {
        display: none;
    }

    .header__right a:not(.header__mail) {
        display: none;
    }

    .header__center {
        position: absolute;
        left: 50%;
        top: var(--page-padding);
        transform: translateX(-50%);
    }

    .header__logo-media img,
    .header__logo-media video {
        width: 4rem;
        height: 4rem;
    }

    .header__left {
        flex: 1;
    }

    /* Блок Works/Projects/About: left: 0 чтобы совпадать с левым краем контента хедера (padding уже у .header) */
    .header__nav {
        left: 0;
    }

    .header__right {
        position: absolute;
        top: var(--page-padding);
        right: var(--page-padding);
        justify-content: flex-end;
    }

    main {
        flex: 1;
        min-height: 0;
        padding: var(--page-padding);
        padding-bottom: calc(var(--page-padding) + env(safe-area-inset-bottom, 0px));
        /* визуально под шапкой: отступ сверху даёт padding-top у .viewport-scroll; flex заполняет до футера */
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    /* На страницах с футером main не растягивается — футер идёт сразу под контентом, а не внизу экрана */
    body[data-page="works"] main,
    body[data-page="about"] main,
    body[data-page="projects"] main,
    body[data-page="books"] main,
    body[data-page="work"] main {
        flex: none;
        min-height: auto;
    }

    .carousel {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .carousel__track {
        padding: 1rem 0;
    }

    .carousel__track .card__box,
    .carousel__track .card--hover .card__box {
        width: var(--card-near);
        height: var(--card-near);
        border-radius: var(--radius-near);
    }

    .carousel__track .card__title {
        opacity: 1;
        max-height: none;
        min-height: 3em;
        margin-top: 10px;
        font-size: 14px;
        line-height: 1.2;
        transform: translateY(0) scale(1);
        overflow: visible;
    }

    h1, .h1 {
        font-size: 2rem;
        line-height: 2.333rem;
    }

    .about-page__intro,
    .about-page__section-title {
        font-size: 2rem;
        line-height: 2.333rem;
    }

    /* Works page — mobile */
    .works__title {
        padding-left: 0;
        margin-top: 8.333rem;
        text-align: center;
    }

    .works {
        margin-top: 8.333rem;
        gap: 12px;
    }

    .works__row .link-flip__front,
    .works__row .link-flip__back,
    .works__row .link-flip__ghost {
        display: grid;
        grid-template-rows: auto auto;
        grid-template-columns: auto 1fr;
        row-gap: 8px;
        column-gap: 12px;
        align-items: baseline;
        width: 100%;
    }

    /* Без флипа и превью на мобиле — один тап открывает страницу работы */
    .works__row .link-flip:hover .link-flip__front {
        opacity: 1;
        transform: translateY(0) rotateX(0);
    }
    .works__row .link-flip:hover .link-flip__back {
        opacity: 0;
        transform: translateY(-50%) rotateX(90deg);
    }
    .works:hover .works__row:not(:hover) {
        opacity: 1;
    }
    .works__preview {
        display: none !important;
    }

    .works__work-title {
        grid-row: 1;
        grid-column: 1 / -1;
        width: 100%;
        min-width: 0;
    }

    .works__year {
        grid-row: 2;
        grid-column: 1;
        width: fit-content;
    }

    .works__type {
        grid-row: 2;
        grid-column: 2;
        width: fit-content;
        text-align: left;
    }

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

    /* Projects page — mobile */
    .projects__title {
        padding-left: 0;
        margin-top: 8.333rem;
        text-align: center;
    }

    .projects__card-title {
        font-size: 2rem;
        line-height: 2.333rem;
    }

    .projects__grid {
        grid-template-columns: 1fr;
        margin-top: 8.333rem;
    }

    .projects__card {
        height: auto;
        min-height: 12rem;
    }

    .projects__card-footer {
        margin-top: 3rem;
    }

    /* Books page — mobile */
    .books__title {
        padding-left: 0;
        margin-top: 8.333rem;
        text-align: center;
    }

    .books__year-heading {
        display: block;
        font-family: 'Basis Grotesque Mono Pro', monospace;
        font-size: 1.15rem;
        color: var(--text);
    }

    .books__row {
        grid-template-columns: 11.667rem 1fr;
    }

    .books__year {
        display: none;
    }

    /* Work page — mobile */
    .work__header {
        padding-left: 0;
        text-align: center;
    }

    .work__title {
        font-size: 2rem;
        line-height: 2.333rem;
    }

    .work__block--half {
        grid-template-columns: 1fr;
    }

    .work__block--half .work__block-cell--empty {
        display: none;
    }

    .work__block--two,
    .work__block--text-media {
        grid-template-columns: 1fr;
    }

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

    .work__intro-text {
        max-width: 100%;
        min-width: 0;
        padding-right: 0;
        overflow-wrap: break-word;
        margin-bottom: 4rem;
    }

    .work__intro-text--empty {
        display: none;
    }

    .work__intro-meta-wrap {
        display: block;
        gap: 1rem;
        padding-left: 0;
    }

    .work__intro-meta {
        grid-template-columns: 1fr 1fr;
        gap: 0 1rem;
        min-width: 0;
    }

    .work__block--text-media .work__block-text {
        padding-right: 0;
        margin-bottom: 5rem;
    }

    .work__block--text-media {
        margin-bottom: 0;
    }

    .work__block--text {
        max-width: 100%;
    }

    .work__block--text .work__block-text {
        padding-right: 0;
    }

    .work__block--full,
    .work__block--two {
        margin-bottom: 0;
    }

    .work__nav {
        flex-direction: row;
        gap: 1rem;
        align-items: center;
    }

    .work__nav-prev,
    .work__nav-next {
        font-size: 2rem;
        line-height: 2.333rem;
    }

    /* About page — mobile */
    .about-page__title {
        padding-left: 0;
        text-align: center;
    }

    .about-page__tags {
        width: 80vw;
    }

    .about-page__columns {
        grid-template-columns: 1fr;
        gap: 2rem;
    }

    .about-page__cols-group {
        grid-column: 1;
        grid-template-columns: 1fr;
        margin-bottom: 0;
    }


    .about-page__list--no-title {
        padding-top: 0;
    }

    .about-page__cols-group .about-page__col:first-child {
        margin-bottom: 2rem;
    }

    .about-page__career {
        gap: 1rem;
    }

    .about-page__career-row {
        display: grid;
        grid-template-rows: auto auto;
        grid-template-columns: auto 1fr;
        row-gap: 8px;
        column-gap: 12px;
    }

    .about-page__career-row .career-role {
        grid-row: 1;
        grid-column: 1 / -1;
    }

    .about-page__career-row .career-year {
        grid-row: 2;
        grid-column: 1;
    }

    .about-page__career-row .career-company {
        grid-row: 2;
        grid-column: 2;
        text-align: left;
        font-family: 'Basis Grotesque Mono Pro', monospace;
        font-size: 1.15rem;
        line-height: 1;
    }

    .about-page__career-row--header {
        display: none;
    }

    .about-page__cv-btn {
        display: block;
        margin-left: auto;
        margin-right: auto;
        padding-left: 1rem;
    }

    /* Footer — mobile: как на десктопе, просто после контента */
    .footer {
        margin-top: 320px;
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto;
        row-gap: 1rem;
        align-items: flex-end;
        padding-bottom: calc(var(--page-padding) + env(safe-area-inset-bottom, 0px));
    }

    .footer__left {
        grid-row: 1;
        grid-column: 1 / -1;
        flex-direction: column;
        gap: 0.3rem;
        justify-content: center;
        align-items: center;
        justify-self: center;
    }

    .footer__center {
        grid-row: 2;
        grid-column: 1;
        text-align: center;
        justify-self: center;
    }

    .footer__right {
        grid-row: 2;
        grid-column: 2;
        justify-self: end;
    }
}

/* Theme transitions */
@media (prefers-reduced-motion: no-preference) {
    html {
        transition: background-color 0.2s ease, color 0.2s ease;
    }
    body {
        transition: background-color 0.2s ease, background-image 0.2s ease, color 0.2s ease;
    }
    /* Apply theme transitions only to elements without existing animations */
    /* Exclude .card, .card__box, .card__title, .works__row, .works__preview to preserve their original transitions */
    a:not(.card):not(.works__row),
    .text:not(.card__title),
    .link:not(.card),
    h1:not(.card__title),
    h2:not(.card__title),
    .h1:not(.card__title),
    .h2:not(.card__title),
    .footer__center,
    svg, svg path, svg text {
        transition: color 0.2s ease, background-color 0.2s ease, border-color 0.2s ease, fill 0.2s ease, stroke 0.2s ease;
    }
}

/* Theme toggle button (hidden from visitors) */
.theme-toggle {
    display: none;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    color: inherit;
    font-family: inherit;
    font-size: inherit;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    position: relative;
    line-height: 1;
}

.theme-toggle__icon {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    position: relative;
}

/* Sun icon (light mode) */
[data-theme="light"] .theme-toggle__icon::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0.7rem;
    height: 0.7rem;
    border-radius: 50%;
    border: 1.5px solid currentColor;
    transform: translate(-50%, -50%);
    opacity: 1;
    transition: opacity 0.2s ease;
}

[data-theme="light"] .theme-toggle__icon::after {
    opacity: 0;
}

/* Moon icon (dark mode) */
[data-theme="dark"] .theme-toggle__icon::before {
    opacity: 0;
}

[data-theme="dark"] .theme-toggle__icon::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 50%;
    border: 1.5px solid currentColor;
    border-right-color: transparent;
    border-bottom-color: transparent;
    transform: translate(-40%, -40%) rotate(-45deg);
    opacity: 1;
    transition: opacity 0.2s ease;
}

.theme-toggle:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: 2px;
    border-radius: 2px;
}
