/* chemeris.co — экран пополам: слева типографика, справа бенто */

:root.is-dark {
  --bg: #000;
  --text: #f2f2f0;
  --muted: #8d8d88;
  --tile-bg: #1a1a1a;
  --tile-bg-hover: #1a1a1a;
}

:root {
  --gap: 10px;
  --tile: 190px;
  --bg: #ffffff;
  --tile-bg: #ededeb;
  --text: #121212;
  --muted: #8a8a8a;
  --accent: #ff6a1f;
  --ink: #0e0e0e;
  --ink-text: #f2f2f0;
  --ink-muted: #8d8d88;
  --radius: 24px;
  --tile-bg-hover: #e4e4e1;
  --ease: cubic-bezier(.22, 1, .36, 1);
  --ease-slow: cubic-bezier(.16, 1, .3, 1);
}

html {
  overflow-x: clip;
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
  transition: background-color .55s var(--ease), color .55s var(--ease);
}

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

::selection { background: var(--accent); color: #fff; }

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

.page {
  display: grid;
  grid-template-columns: 50% 50%;
  height: 100dvh;
  overflow: hidden;
}

/* --- Слева --- */
.intro {
  transition: transform .8s var(--ease-slow), opacity .6s var(--ease);
}
:root.is-sheet .intro {
  transform: translateX(-104%);
  opacity: 0;
}

/* аватар + вращающийся знак: знак начинается в 64px от левого края аватара,
   то есть лежит на нём внахлёст на 16px */
.portrait {
  position: relative;
  width: 144px;                     /* 64 + 80 */
  height: 80px;
  margin-bottom: clamp(20px, 2.4vw, 32px);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .7s var(--ease), transform .7s var(--ease);
}
.is-ready .portrait { opacity: 1; transform: none; }

.badge {
  position: absolute;
  top: 0;
  left: 64px;
  width: 80px;
  height: 80px;
  transform: rotate(var(--spin, 0deg));
  will-change: transform;
}

.avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
}

.intro {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: clamp(28px, 4.5vw, 72px);
}

.intro h1 {
  margin: 0;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .7s var(--ease) 120ms, transform .7s var(--ease) 120ms, color .3s var(--ease);
}
.is-ready .intro h1 { opacity: 1; transform: none; }

.intro h1 {
  max-width: 19ch;
  font-size: clamp(26px, 3vw, 48px);
  font-weight: 500;
  line-height: 1.16;
  letter-spacing: -.03em;
}

.links {
  display: flex;
  flex-wrap: wrap;
  column-gap: clamp(14px, 1.4vw, 24px);
  margin-top: auto;
  padding-top: clamp(24px, 3vw, 48px);
  font-size: clamp(13px, .95vw, 16px);
  font-weight: 400;
  letter-spacing: -.005em;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .7s var(--ease) 220ms, transform .7s var(--ease) 220ms;
}
.is-ready .links { opacity: 1; transform: none; }
.links a {
  color: var(--muted);
  background-image: linear-gradient(currentColor, currentColor);
  background-repeat: no-repeat;
  background-position: 0 100%;
  background-size: 0 1px;
  transition: color .2s var(--ease), background-size .3s var(--ease);
}
.links a:hover, .links a:focus-visible { color: var(--text); background-size: 100% 1px; }

/* стрелка наружу у внешних ссылок */
.arr {
  width: .9em;
  height: .9em;
  margin-left: .28em;
  vertical-align: -.08em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: transform .2s var(--ease);
}
.links a:hover .arr, .links a:focus-visible .arr { transform: translate(2px, -2px); }

/* --- Справа: бенто от середины до края, свой скролл --- */
.bento {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-auto-rows: var(--tile);
  grid-auto-flow: dense;
  align-content: start;
  gap: var(--gap);
  padding: var(--gap) var(--gap) var(--gap) 0;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #dcdcda transparent;
  transition: opacity .45s var(--ease);
}
:root.is-sheet .bento {
  pointer-events: none;
}

.tile {
  position: relative;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  background: var(--tile-bg);
  overflow: hidden;
  cursor: pointer;
  opacity: 0;
  transform: translateX(44px);
  transition:
    background-color .25s var(--ease),
    opacity .85s var(--ease),
    transform 1.1s var(--ease);
}
.tile.is-in { opacity: 1; transform: none; }

/* раскрывающийся блок расталкивает соседей: направление и сила считаются в JS */
:root.is-sheet .tile {
  opacity: 0;
  transform: translate(var(--push-x, 0px), var(--push-y, 0px));
  transition: transform .75s var(--ease-slow), opacity .4s var(--ease);
}
:root.is-closing .tile {
  transition: transform .6s var(--ease-slow) 40ms, opacity .45s var(--ease) 40ms;
}

.tile__img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .6s var(--ease);
}

@media (hover: hover) and (pointer: fine) {
  .tile:hover { background: var(--tile-bg-hover); }
  .tile:hover .tile__toggle { transform: scale(1.1); }
  .tile:hover .tile__img { transform: scale(1.035); }
}
.tile:active { transform: scale(.995); transition-duration: .1s; }
.tile:active .tile__toggle { transform: scale(.92); }

.tile--w2 { grid-column: span 2; }
.tile--h2 { grid-row: span 2; }

/* плитка-источник прячет свой кружок, пока открыт фуллскрин */
.tile.is-open .tile__toggle { opacity: 0; }

/* на закрытии цвет возвращается быстрее, чем едет блок */
:root.is-closing body { transition-duration: .28s; }

/* левая часть возвращается в темпе схлопывания блока, а не быстрее него */
:root.is-closing .intro {
  transition-duration: .78s;
  transition-delay: 60ms;
  transition-timing-function: cubic-bezier(.45, 0, .15, 1);
}
:root.is-closing .bento {
  transition-duration: .6s;
  transition-delay: 90ms;
}

/* фуллскрин-слой */
.sheet {
  position: fixed;
  z-index: 20;
  background: var(--ink);
  color: var(--ink-text);
  border-radius: var(--radius);
  overflow: hidden;
  will-change: top, left, width, height;
}

/* содержимое проекта скроллится внутри слоя */
.sheet__scroll {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #2e2e2e transparent;
}

.sheet__hero {
  height: 100%;
  margin: 0;
}

.sheet__img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* текстовая часть */
.sheet__body {
  padding: clamp(48px, 7vw, 120px) clamp(20px, 5vw, 80px) clamp(64px, 9vw, 160px);
  opacity: 0;
  transform: translateY(14px);
  transition: opacity .5s var(--ease) .18s, transform .5s var(--ease) .18s;
}
.sheet.is-open .sheet__body { opacity: 1; transform: none; }

.sheet__meta {
  margin: 0 0 clamp(16px, 2vw, 28px);
  max-width: 62ch;
  font-size: clamp(13px, .95vw, 16px);
  color: var(--ink-muted);
}

.sheet__title {
  margin: 0 0 clamp(20px, 2.4vw, 32px);
  max-width: 18ch;
  font-size: clamp(32px, 4.4vw, 68px);
  font-weight: 500;
  line-height: 1.06;
  letter-spacing: -.03em;
}

.sheet__intro {
  margin: 0;
  max-width: 34ch;
  font-size: clamp(18px, 1.7vw, 28px);
  font-weight: 500;
  line-height: 1.3;
  letter-spacing: -.02em;
}

.sheet__section {
  margin-top: clamp(48px, 7vw, 112px);
  max-width: 52ch;
}
.sheet__section h3 {
  margin: 0 0 12px;
  font-size: clamp(13px, .95vw, 16px);
  font-weight: 400;
  color: var(--ink-muted);
}
.sheet__section p {
  margin: 0;
  font-size: clamp(16px, 1.3vw, 21px);
  line-height: 1.45;
  letter-spacing: -.015em;
}

.sheet__figure {
  margin: clamp(40px, 6vw, 96px) 0 0;
}
.sheet__figure img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: clamp(12px, 1.4vw, 20px);
}
.sheet[hidden] { display: none; }

.sheet__close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  z-index: 2;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  transition: transform .25s var(--ease), background-color .2s ease;
}
@media (hover: hover) and (pointer: fine) {
  .sheet__close:hover { background: #ff7d3a; }
}
.sheet__close:active { transform: scale(.92); }

/* запас до 44px по площади нажатия */
.sheet__close::after {
  content: '';
  position: absolute;
  inset: -7px;
  border-radius: 50%;
}
.sheet.is-open .sheet__close .tile__icon { transform: rotate(45deg); }

/* кружок с плюсом */
.tile__toggle {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--accent);
  transform-origin: center;
  transition: transform .25s var(--ease);
}

.tile__icon {
  display: grid;
  place-items: center;
  transition: transform .42s var(--ease);
}

.tile__icon svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
}

/* --- Адаптив --- */
@media (max-width: 860px) {
  .page { grid-template-columns: 1fr; }

  /* сетка проявляется снизу вверх, а раскрытый блок выталкивает шапку наверх */
  .tile { transform: translateY(44px); }
  :root.is-sheet .intro { transform: translateY(-104%); }

  /* кружок уходит вниз — под большой палец, и крупнее для тапа */
  .tile__toggle,
  .sheet__close {
    top: auto;
    width: 40px;
    height: 40px;
  }
  .tile__toggle { bottom: 12px; }
  .sheet__close { bottom: 12px; }   /* ровно как у плитки, иначе кружок дёргается на стыке */
  .tile__icon svg { width: 18px; height: 18px; }
  .page { height: auto; overflow: visible; }
  .intro { height: auto; min-height: 72svh; }   /* svh не меняется при скролле — иначе низ прыгает */
  .bento { height: auto; overflow: visible; padding: var(--gap); }
}

@media (max-width: 520px) {
  :root { --tile: 150px; }
  .bento { grid-template-columns: repeat(2, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
  }
  .tile, .intro h1, .links, .portrait { opacity: 1 !important; transform: none !important; }
}
