@view-transition { navigation: auto; }

/* ── темы ──────────────────────────────────────────────────────────
   Все цвета идут через переменные, включая тени и растяжку у листа:
   иначе тёмная тема тянет за собой светлые пятна.

   Значения тёмной темы объявлены один раз (--d-*), а включаются двумя
   путями: по системной настройке и по явному выбору. Так набор цветов
   не разъезжается между двумя ветками.                              */

:root {
  color-scheme: light;

  --paper: #ffffff;
  --paper-2: #f1f4fa;
  --ink: #0a1020;
  --ink-2: #57617a;
  --ink-3: #7e879c;
  --rule: #dce2ed;
  --accent: #1445ff;
  --shadow: 10 16 32;
  --shadow-strength: 0.85;

  --d-paper: #0e1730;
  --d-paper-2: #17233f;
  --d-ink: #f1ede4;
  --d-ink-2: #9ba7c1;
  --d-ink-3: #66728f;
  --d-rule: #27324f;
  --d-accent: #ffb020;
  --d-shadow: 0 0 0;
  --d-shadow-strength: 2.2;
}

/* Пока выбор не сделан руками — идём за системой. Без JS тоже работает. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --paper: var(--d-paper);
    --paper-2: var(--d-paper-2);
    --ink: var(--d-ink);
    --ink-2: var(--d-ink-2);
    --ink-3: var(--d-ink-3);
    --rule: var(--d-rule);
    --accent: var(--d-accent);
    --shadow: var(--d-shadow);
    --shadow-strength: var(--d-shadow-strength);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --paper: var(--d-paper);
  --paper-2: var(--d-paper-2);
  --ink: var(--d-ink);
  --ink-2: var(--d-ink-2);
  --ink-3: var(--d-ink-3);
  --rule: var(--d-rule);
  --accent: var(--d-accent);
  --shadow: var(--d-shadow);
  --shadow-strength: var(--d-shadow-strength);
}

:root {
  --font: "Roboto", ui-sans-serif, system-ui, sans-serif;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);

  --pad: clamp(20px, 5vw, 72px);
  --measure: 1440px;

  --lift-1: 0 1px 2px rgb(var(--shadow) / calc(0.1 * var(--shadow-strength))),
    0 12px 28px -12px rgb(var(--shadow) / calc(0.28 * var(--shadow-strength)));
  --lift-2: 0 2px 4px rgb(var(--shadow) / calc(0.12 * var(--shadow-strength))),
    0 26px 48px -16px rgb(var(--shadow) / calc(0.36 * var(--shadow-strength)));
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  scrollbar-color: var(--ink-3) var(--paper-2);
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* Смена темы не должна щёлкать: включаем переходы только на время
   переключения, а не держим их на всех элементах постоянно. */
[data-theming] *,
[data-theming] *::before,
[data-theming] *::after {
  transition: background-color 300ms var(--ease-out), color 300ms var(--ease-out),
    border-color 300ms var(--ease-out), box-shadow 300ms var(--ease-out) !important;
}

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

.wrap {
  max-width: var(--measure);
  margin: 0 auto;
  padding: 0 var(--pad);
}

/* Крупный текст читается разреженным, поэтому с ростом кегля трекинг
   сжимаем, а плотность добираем осью ширины переменного Roboto. */
.display {
  font-weight: 800;
  font-stretch: 88%;
  font-size: clamp(2.6rem, 7.5vw, 6.5rem);
  line-height: 0.94;
  letter-spacing: -0.03em;
  margin: 0;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0 0.6em;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 0.8125rem;
  color: var(--ink-2);
}

.meta li + li::before { content: "/"; color: var(--ink-3); margin-right: 0.6em; }

/* ── иконки (remixicon, вшиты в разметку при сборке) ────────────── */

.i {
  width: 1.05em;
  height: 1.05em;
  flex: none;
  transition: transform 320ms var(--ease-out);
}

/* ── кнопки ────────────────────────────────────────────────────── */

.btn {
  --nudge: 4px;
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  gap: 0.55em;
  padding: 0.62em 1.1em;
  border: 1.5px solid var(--ink);
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.2;
  color: var(--ink);
  background: none;
  cursor: pointer;
  transition: color 260ms var(--ease-out), border-color 260ms var(--ease-out),
    transform 140ms var(--ease-out);
}

.btn::before {
  content: "";
  position: absolute;
  inset: -1px;
  z-index: -1;
  background: var(--ink);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 340ms var(--ease-out);
}

.btn:active { transform: scale(0.97); }

.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

@media (hover: hover) and (pointer: fine) {
  .btn:hover { color: var(--paper); }
  .btn:hover::before { transform: scaleX(1); }
  .btn:hover .i { transform: translateX(var(--nudge)); }
}

.btn--sm { padding: 0.42em 0.85em; font-size: 0.8125rem; }
.btn--back { --nudge: -4px; }

.btn--accent { border-color: var(--accent); color: var(--accent); }
.btn--accent::before { background: var(--accent); }

/* ── переключатель темы ────────────────────────────────────────── */

/* Кнопка живёт скриптом, поэтому без JS её просто нет — мёртвый
   переключатель хуже отсутствующего. Цвета при этом всё равно идут
   за системной настройкой. */
.toggle { display: none; }

[data-js] .toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1.5px solid var(--ink);
  background: none;
  color: var(--ink);
  cursor: pointer;
  overflow: hidden;
  isolation: isolate;
  transition: color 260ms var(--ease-out), border-color 260ms var(--ease-out),
    transform 140ms var(--ease-out);
}

.toggle::before {
  content: "";
  position: absolute;
  inset: -1px;
  z-index: -1;
  background: var(--ink);
  transform: scale(0.2);
  opacity: 0;
  transition: transform 340ms var(--ease-out), opacity 200ms var(--ease-out);
}

.toggle .i {
  position: absolute;
  width: 18px;
  height: 18px;
  transition: transform 300ms var(--ease-out), opacity 200ms var(--ease-out);
}

/* Кнопка показывает, куда переключит, а не где ты сейчас. */
.toggle .i--sun { opacity: 0; transform: rotate(-80deg) scale(0.6); }
.toggle .i--moon { opacity: 1; transform: none; }

[data-theme="dark"] .toggle .i--sun { opacity: 1; transform: none; }
[data-theme="dark"] .toggle .i--moon { opacity: 0; transform: rotate(80deg) scale(0.6); }

.toggle:active { transform: scale(0.94); }
.toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

@media (hover: hover) and (pointer: fine) {
  .toggle:hover { color: var(--paper); }
  .toggle:hover::before { transform: scale(1); opacity: 1; }
}

/* ── шапка ─────────────────────────────────────────────────────── */

.masthead {
  display: grid;
  grid-template-columns: 1fr;
  gap: clamp(20px, 3vw, 40px);
  padding: clamp(28px, 5vw, 64px) 0 clamp(40px, 7vw, 96px);
  border-bottom: 1.5px solid var(--ink);
}

@media (min-width: 900px) {
  .masthead { grid-template-columns: 1.4fr 1fr; align-items: end; }
}

.masthead__mark {
  margin: 0;
  font-weight: 900;
  font-stretch: 80%;
  font-size: clamp(3.5rem, 11vw, 9rem);
  line-height: 0.82;
  letter-spacing: -0.025em;
}

.masthead__side { display: grid; gap: 20px; justify-items: start; }

@media (min-width: 900px) {
  .masthead__side { justify-items: end; }
}

.masthead__note {
  margin: 0;
  max-width: 40ch;
  font-size: clamp(0.95rem, 1.4vw, 1.125rem);
  line-height: 1.45;
  color: var(--ink-2);
}

/* ── работа на главной ─────────────────────────────────────────── */

.piece {
  display: grid;
  gap: clamp(20px, 3vw, 44px);
  align-items: center;
  padding: clamp(48px, 8vw, 128px) 0;
  border-bottom: 1px solid var(--rule);
}

.piece:first-child { padding-top: clamp(32px, 4vw, 64px); }

@media (min-width: 900px) {
  .piece { grid-template-columns: minmax(260px, 1fr) minmax(0, 2.15fr); }

  /* Снимок выходит за поле набора — единственная вольность в сетке. */
  .piece__cover { margin-right: calc(-1 * var(--pad)); }
  .piece:nth-child(even) .piece__side { order: 2; }
  .piece:nth-child(even) .piece__cover {
    order: 1;
    margin-right: 0;
    margin-left: calc(-1 * var(--pad));
  }
}

.piece__no {
  display: block;
  font-size: clamp(2.5rem, 5vw, 4rem);
  font-weight: 200;
  line-height: 1;
  letter-spacing: -0.04em;
  color: var(--ink-3);
  margin-bottom: 0.1em;
}

.piece__title { margin: 0 0 0.55rem; }
.piece__side .btn { margin-top: 1.35rem; }

.piece__cover {
  display: block;
  position: relative;
  background: var(--paper-2);
  box-shadow: var(--lift-1);
  transition: box-shadow 320ms var(--ease-out);
}

.piece__cover img { display: block; width: 100%; height: auto; }

@media (hover: hover) and (pointer: fine) {
  .piece:hover .piece__cover { box-shadow: var(--lift-2); }
}

/* ── страница проекта ──────────────────────────────────────────── */

.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 20px;
  align-items: center;
  justify-content: space-between;
  padding: clamp(20px, 3vw, 36px) 0;
}

.lede { padding-bottom: clamp(24px, 4vw, 44px); }

.lede__title { margin-bottom: 0.75rem; }

.lede__row {
  display: flex;
  flex-wrap: wrap;
  gap: 14px 28px;
  align-items: center;
  justify-content: space-between;
  padding-top: 16px;
  border-top: 1.5px solid var(--ink);
}

.hero {
  display: block;
  width: 100%;
  background: var(--paper-2);
  box-shadow: var(--lift-1);
}

.hero img { display: block; width: 100%; height: auto; }

.section { padding: clamp(48px, 7vw, 104px) 0 0; }

.section__head {
  display: flex;
  align-items: baseline;
  gap: 14px;
  margin-bottom: clamp(16px, 2vw, 28px);
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule);
}

.section__head h2 {
  margin: 0;
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.section__head span { font-size: 0.8125rem; color: var(--ink-2); margin-left: auto; }

.langs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: clamp(16px, 2.5vw, 36px);
}

/* ── лист со снимком ───────────────────────────────────────────── */

.plate {
  margin: 0;
  position: relative;
  background: var(--paper-2);
  box-shadow: var(--lift-1);
}

.plate__view {
  position: relative;
  max-height: 660px;
  overflow-y: auto;
  overscroll-behavior-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--ink-3) transparent;
}

.plate--short .plate__view { max-height: none; overflow: visible; }

.plate__view img { display: block; width: 100%; height: auto; }

.plate__cap {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 8px 16px;
  flex-wrap: wrap;
  padding: 13px 18px 15px;
  border-top: 1px solid var(--rule);
  font-size: 0.75rem;
  line-height: 1.4;
  color: var(--ink-2);
}

.plate__cap b { font-weight: 500; color: var(--ink); }
.plate__cap .sp { flex: 1; min-width: 0; }

/* Край снимка уходит в бумагу — видно, что страница продолжается.
   Растяжка привязана к подписи, поэтому на неё не наползает.
   color-mix вместо transparent: иначе градиент идёт через серую муть. */
.plate:not(.plate--short) .plate__cap::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 100%;
  height: 56px;
  pointer-events: none;
  background: linear-gradient(
    to bottom,
    color-mix(in srgb, var(--paper-2), transparent 100%),
    var(--paper-2)
  );
}

.plate__cap a {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  color: var(--ink-2);
  border-bottom: 1px solid var(--rule);
  transition: color 200ms var(--ease-out), border-color 200ms var(--ease-out);
}

.plate__cap a .i { width: 0.95em; height: 0.95em; }

@media (hover: hover) and (pointer: fine) {
  .plate__cap a:hover { color: var(--accent); border-color: var(--accent); }
  .plate__cap a:hover .i { transform: translate(2px, -2px); }
}

.spread {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: clamp(16px, 2vw, 32px);
  margin-bottom: clamp(32px, 4vw, 64px);
}

@media (min-width: 900px) {
  .spread { grid-template-columns: minmax(0, 1fr) 280px; align-items: start; }
}

@media (max-width: 899px) {
  .spread .plate--mobile { max-width: 280px; }
}

/* ── подвал ────────────────────────────────────────────────────── */

.colophon {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 28px;
  align-items: center;
  justify-content: space-between;
  margin-top: clamp(48px, 7vw, 104px);
  padding: 24px 0 56px;
  border-top: 1.5px solid var(--ink);
  font-size: 0.8125rem;
  color: var(--ink-2);
}

/* ── появление при прокрутке ───────────────────────────────────── */

/* По умолчанию всё видно. Прятать начинаем только когда есть JS, который
   гарантированно покажет обратно: иначе печать, полностраничная съёмка и
   браузеры без поддержки отдают пустую бумагу вместо работ. */
@media (prefers-reduced-motion: no-preference) {
  [data-js] .reveal {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 500ms var(--ease-out), transform 500ms var(--ease-out);
  }
  [data-js] .reveal.is-in { opacity: 1; transform: none; }
}

@media print {
  .reveal { opacity: 1 !important; transform: none !important; }
  .toggle { display: none; }
}

/* ── переход между страницами ──────────────────────────────────── */

@media (prefers-reduced-motion: no-preference) {
  ::view-transition-group(*) {
    animation-duration: 460ms;
    animation-timing-function: var(--ease-in-out);
  }
  ::view-transition-old(root) { animation: fade 180ms var(--ease-out) both reverse; }
  ::view-transition-new(root) { animation: fade 260ms var(--ease-out) 60ms both; }
  @keyframes fade { from { opacity: 0; } to { opacity: 1; } }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) { animation: none !important; }
}
