*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #fff9e6;
  --block-bg: #fff;
  --block-border: #000;
  --text: #000;
  --text-muted: #333;
  --accent: #f5d547;
  --accent-red: #e85d5d;
  --accent-blue: #4a90d9;
  --shadow: 6px 6px 0 #000;
  --shadow-sm: 4px 4px 0 #000;
  --btn-bg: #000;
  --btn-text: #fff;
}

/* Hide native scrollbar, use custom one */
html {
  scrollbar-width: none;
}

html::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

/* Custom scrollbar: thick track (yellow), rectangular thumb (red), block-style border, levitating */
.custom-scrollbar {
  position: fixed;
  top: 20px;
  right: 20px;
  bottom: 20px;
  width: 28px;
  z-index: 100;
  pointer-events: none;
}

.custom-scrollbar-track {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  background: var(--accent);
  border: 5px solid var(--block-border);
  border-radius: 0;
  pointer-events: auto;
}

.custom-scrollbar-thumb {
  position: absolute;
  left: 0;
  width: 100%;
  min-height: 42px;
  background: var(--accent-red);
  border: none;
  border-top: 5px solid var(--block-border);
  border-bottom: 5px solid var(--block-border);
  border-radius: 0;
  box-sizing: border-box;
  pointer-events: auto;
  cursor: grab;
  opacity: 1;
  transition: opacity 0.9s ease-in-out;
}

.custom-scrollbar-thumb:active {
  cursor: grabbing;
}

/* плавная синхронизация с разворотом/сворачиванием списка треков */
.custom-scrollbar-thumb.syncing {
  transition: height 0.9s ease-in-out, top 0.9s ease-in-out;
}

.scroll-locked .custom-scrollbar-track,
.scroll-locked .custom-scrollbar-thumb {
  pointer-events: none;
}

.scroll-locked .custom-scrollbar-thumb {
  opacity: 0;
}

body {
  font-family: 'Manrope', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.2;
}

/* Белый шум поверх всего */
.noise-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 99999;
  background: transparent;
}

#page-flash-overlay {
  position: fixed;
  inset: 0;
  background-color: transparent;
  opacity: 0;
  pointer-events: none;
  z-index: 150;
  transition: background-color 0.9s ease-in-out, opacity 0.9s ease-in-out;
}

#page-flash-overlay.is-active {
  opacity: 1;
}

.page-flash-source {
  position: relative;
  z-index: 200;
}

.page-flash-active .page-flash-source {
  box-shadow: none !important;
  transition: box-shadow 0.9s ease-in-out;
}

/* Во время флеша убираем transform у тайлов, чтобы их стек не перекрывался оверлеем */
.page-flash-active .tile,
.page-flash-active .tile:hover {
  transform: none;
  box-shadow: var(--shadow);
}

.main-layout {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 32px;
  padding: 20px;
  max-width: 1600px;
  margin: 0 auto;
  min-height: 100vh;
}

.masonry-left {
  column-gap: 24px;
  column-count: 2;
  column-width: 260px; /* одинаковая ширина колонок */
  max-width: calc(2 * 260px + 24px);
}

.masonry-right {
  display: flex;
  gap: 24px;
  max-width: calc(2 * 260px + 24px);
}

.right-col {
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: 260px;
}

/* В правой колонке вертикальные отступы даёт gap,
   поэтому убираем дополнительный margin-bottom у фиксированных плиток */
.masonry-right > .right-col > .tile {
  margin-bottom: 0;
}

/* У блока треков (внутри #spotify-section) тоже убираем margin-bottom,
   иначе отступ до следующего блока получается двойным */
#spotify-section .tile:last-child {
  margin-bottom: 0;
}

/* masonry через многоколоночный layout (левая часть) */

.tile {
  background: var(--block-bg);
  border: 5px solid var(--block-border);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  min-height: 64px;
  border-radius: 0;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  break-inside: avoid;
  margin-bottom: 24px;
}

.tile:hover {
  transform: translate(2px, 2px);
  box-shadow: 4px 4px 0 #000;
}

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

.tile .btn-steam,
.tile .btn-discord,
.tile .btn-telegram,
.tile .btn-spotify,
.tile .btn-statsfm {
  color: #fff;
}

.tile .btn-letterboxd {
  color: #fff;
}

/* Hero — крупный блок, neubrutalist акцент */
.tile-hero {
  background: var(--accent);
  column-span: all;
  width: 100%;
  aspect-ratio: 1 / 1;
}

.avatar,
.avatar-placeholder {
  width: 180px;
  height: 180px;
  object-fit: cover;
  border: 5px solid var(--block-border);
  box-shadow: var(--shadow-sm);
  border-radius: 0;
}

.avatar-placeholder {
  background: var(--accent);
}

.tile-hero h1 {
  font-family: 'Oswald', sans-serif;
  font-size: 80px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-top: 16px;
  text-transform: uppercase;
  line-height: 0.9;
  color: #4a90d9;
  position: relative;
  z-index: 1;
}

.tile-hero h1::before {
  content: attr(data-text);
  position: absolute;
  left: 0;
  top: 0;
  transform: translate(4px, -4px); /* слегка выше и правее */
  color: transparent;
  -webkit-text-stroke: 3px #000;
  text-stroke: 3px #000;
  z-index: 0;
  pointer-events: none;
}

.tagline {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
}

/* Links */
.tile-links {
  justify-content: center;
  gap: 8px;
  padding: 16px;
}

.tile-links .btn {
  width: 100%;
  min-height: 56px;
}

.btn {
  background: var(--btn-bg);
  color: var(--btn-text);
  border: 4px solid #000;
  border-radius: 0;
  padding: 0;
  font-family: 'Oswald', sans-serif;
  font-size: 18px;
  font-weight: 700;
  text-decoration: none;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  box-shadow: var(--shadow-sm);
  transition: transform 0.1s ease, box-shadow 0.1s ease;
  display: flex;
  align-items: center;
  gap: 0;
}

.btn-steam { background: #1b2838; border-color: #000; color: #fff; }
.btn-steam .btn-icon { background: rgba(0,0,0,0.3); border-color: #000; }

.btn-discord { background: #5865F2; border-color: #000; color: #fff; }
.btn-discord .btn-icon { background: rgba(0,0,0,0.2); border-color: #000; }

.btn-telegram { background: #0088cc; border-color: #000; color: #fff; }
.btn-telegram .btn-icon { background: rgba(0,0,0,0.2); border-color: #000; }

.btn-spotify,
.btn-statsfm { background: #1DB954; border-color: #000; color: #fff; }
.btn-spotify .btn-icon,
.btn-statsfm .btn-icon { background: rgba(0,0,0,0.2); border-color: #000; }

.btn-letterboxd { background: #272e36; border-color: #000; color: #fff; }
.btn-letterboxd .btn-icon { background: rgba(0,0,0,0.25); border-color: #000; }
.btn-letterboxd .btn-icon img { filter: none; }

.btn-icon {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-right: 4px solid #000;
}

.btn-icon img {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.btn-icon svg {
  width: 24px;
  height: 24px;
  display: block;
}

.btn-large .btn-icon {
  width: 64px;
  height: 64px;
}

.btn-large .btn-icon img {
  width: 28px;
  height: 28px;
}

.btn-text {
  flex: 1;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-large .btn-text {
  padding: 0 32px;
}

.btn:hover {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 #000;
}

.btn-large {
  font-size: 28px;
  letter-spacing: 0.15em;
  min-height: 64px;
}

.tile-spotify {
  background: var(--accent-blue);
}

.tile-now-playing {
  align-items: stretch;
  justify-content: flex-start;
  padding: 0;
  /* как и у блока треков: убираем внешнюю рамку плитки, оставляем только общую тень */
  border: none;
  box-shadow: var(--shadow);
}

.now-playing-link {
  display: block;
  width: 100%;
  height: 100%;
  text-decoration: none;
  color: inherit;
}

.tile-now-playing .now-playing-title {
  font-size: 14px;
  color: var(--text);
}

.now-playing-link:hover .now-playing-body {
  background-color: var(--now-playing-hover-bg, var(--accent));
}

.now-playing-heading {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 16px;
  border-bottom: 4px solid #000;
}

.now-playing-main {
  font-family: 'Oswald', sans-serif;
  font-size: 18px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.18em;
}

.now-playing-accent {
  position: absolute;
  left: 50%;
  bottom: 6px;
  transform: translateX(20px);
  font-family: 'Source Code Pro', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
  font-size: 11px;
  font-style: normal;
  text-transform: lowercase;
  letter-spacing: 0.12em;
  color: var(--accent-blue);
}

.now-playing-body {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px 14px;
  border: 5px solid #000; /* полноценная рамка со всех сторон, как у остальных тайлов */
  background: var(--block-bg);
  overflow: hidden; /* не даём тексту вылезать за рамку */
  transition: background-color 0.9s ease-in-out;
}

.now-playing-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px; /* строгий квадрат */
  flex: 0 0 48px; /* не даём тексту сжимать квадрат */
  padding: 0;
  border: 3px solid #000; /* как было раньше */
  background: #1DB954; /* насыщенный зеленый, как Spotify */
  font-family: 'Oswald', sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  position: relative; /* якорь для псевдо-элемента треугольника */
}

.now-playing-tag::before {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 0;
  height: 0;
  border-left: 14px solid #000;
  border-top: 9px solid transparent;
  border-bottom: 9px solid transparent;
}

.now-playing-track {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  flex: 1 1 auto;
  min-width: 0; /* важно для ellipsis */
  gap: 4px;
  text-align: left;
}

.now-playing-title {
  font-family: 'Oswald', sans-serif;
  font-size: 15px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  display: block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis; /* не даём вылезать за рамку */
}

.now-playing-artist {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis; /* как .artists в списке треков */
}

/* Tracks — 5 по умолчанию, разворот по hover, наплывающий список */
.tile-tracks {
  align-items: stretch;
  justify-content: flex-start;
  min-height: 0;
  position: relative;
  overflow: visible;
  /* убираем только рамку тайла, чтобы не утолщать границы вокруг отдельных треков,
     но сохраняем общую тень блока как у остальных плиток */
  border: none;
  box-shadow: var(--shadow);
  padding: 0;
}

.tile h2 {
  font-family: 'Oswald', sans-serif;
  font-size: 18px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: #000;
  padding: 16px;
  border-bottom: 5px solid #000;
}

/* Tracks heading: жирный гротеск + маленький акцент "latest" */
.tile-tracks .tracks-heading {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 5px solid #000; /* та же толщина, что у .tile и .track-item */
  border-bottom: none; /* снизу рамку даёт первый трек */
  margin: 0;
  padding: 16px;
}

.tracks-heading-main {
  font-family: 'Oswald', sans-serif;
  font-size: 18px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.18em;
}

.tracks-heading-accent {
  position: absolute;
  /* рисуем «поверх» основного слова, чуть смещая вниз‑вправо */
  left: 50%;
  bottom: 6px;
  transform: translateX(18px);
  font-family: 'Source Code Pro', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;
  font-size: 11px;
  font-style: normal;
  text-transform: lowercase;
  letter-spacing: 0.12em;
  color: var(--accent-red);
}

.tracks-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  flex: 1 1 auto;
  min-height: 0;
  max-height: 470px; /* подгон: видны 5 треков и их нижняя рамка, но скрыт следующий элемент */
  overflow: hidden;
  transition: max-height 0.9s ease-in-out;
}

.tile-tracks:hover .tracks-list {
  max-height: 1200px; /* плавно раскрываемся вниз */
  overflow: hidden; /* без полосы прокрутки, контент раскрывается вместе с блоком */
}


.track-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  border: 5px solid #000;    /* как у остальных плиток */
  margin-top: -5px;          /* перекрываем верхнюю границу предыдущего/заголовка */
  text-decoration: none;
  color: var(--text);
  background-color: var(--block-bg);
  transition: background-color 0.9s ease-in-out;
}

.tracks-list .track-item:first-child {
  margin-top: 0;             /* у первого трека своя верхняя граница */
}

.track-item img {
  width: 56px;
  height: 56px;
  flex-shrink: 0;
  object-fit: contain;
  border: 4px solid #000;
  border-radius: 0;
}

.track-item .track-text {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.track-item .track-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.track-item:hover {
  background-color: var(--track-hover-bg, var(--accent));
}

.track-item .artists {
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#games-inject {
  display: none;
}

/* Game tile — строка 1: иконка + плашка времени, строка 2: название с переносами */
.tile-game {
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  padding: 0;
  text-align: left;
  text-decoration: none;
}

.tile-game .game-top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 12px 8px;
}

.tile-game .game-img-wrap {
  flex: 0 0 auto;
  background: transparent;
  overflow: hidden;
}

.tile-game .game-img-wrap.game-img-missing {
  display: none;
}

.tile-game .game-img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  border: 2px solid #000;
  border-radius: 0;
  flex-shrink: 0;
  display: block;
}

.tile-game .game-playtime {
  flex-shrink: 0;
  height: 32px;
  display: flex;
  align-items: center;
  padding: 0 8px;
  border: 2px solid #000;
  background: var(--accent);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #000;
}

.tile-game .game-name {
  font-family: 'Oswald', sans-serif;
  font-size: 16px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  line-height: 1.3;
  color: #000;
  padding: 0 12px 12px;
  word-wrap: break-word;
  white-space: normal;
}

/* Film tile — вертикальные постеры 2:3, без обрезки и без пробелов */
.tile-film {
  align-self: start;
  background: var(--color, var(--accent));
  font-family: 'Oswald', sans-serif;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  padding: 0;
  flex-direction: column;
  align-items: stretch;
  justify-content: flex-start;
  color: #fff;
  overflow: hidden;
  text-decoration: none;
}

.tile-film-img {
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  flex-shrink: 0;
  overflow: hidden;
}

.tile-film-img img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  vertical-align: top;
}

.tile-film-title {
  padding: 12px 16px;
  background: #000;
  flex-shrink: 0;
  color: #fff;
  font-weight: 700;
}

.tile-film:hover .tile-film-img img {
  transform: none;
}

/* Screenshot tile — изображение + плашка игры */
.tile-screenshot {
  position: relative;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  min-height: 64px;
  background: var(--color, var(--block-bg));
}

.tile-screenshot img {
  width: 100%;
  height: auto;
  display: block;
  vertical-align: top;
}

.tile-screenshot .screenshot-plaque {
  position: absolute;
  right: 12px;
  bottom: 12px;
  padding: 6px 12px;
  background: var(--accent);
  border: 3px solid var(--block-border);
  font-family: 'Oswald', sans-serif;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #000;
  z-index: 2;
}

/* Скрываем исходную карточку при развороте/сворачивании */
.tile-screenshot.screenshot-source-hidden {
  visibility: hidden;
}

/* Overlay для раскрытого скриншота */
.screenshot-overlay {
  position: fixed;
  inset: 0;
  z-index: 140;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.9s ease-in-out;
}

.screenshot-overlay.is-active {
  opacity: 1;
}

.scroll-locked .screenshot-overlay {
  pointer-events: auto;
}

.screenshot-expanded {
  position: fixed;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 5px solid var(--block-border);
  background: var(--block-bg);
  overflow: visible;
  cursor: pointer;
  z-index: 141;
  box-shadow: var(--shadow);
  transition: top 0.9s ease-in-out, left 0.9s ease-in-out, width 0.9s ease-in-out, height 0.9s ease-in-out, box-shadow 0.9s ease-in-out;
}

.screenshot-expanded img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.screenshot-expanded .screenshot-plaque {
  position: absolute;
  right: 12px;
  bottom: 12px;
  padding: 6px 12px;
  background: var(--accent);
  border: 3px solid var(--block-border);
  font-family: 'Oswald', sans-serif;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #000;
}

.tile-screenshot:nth-of-type(1),
.tile-screenshot:nth-of-type(2),
.tile-screenshot:nth-of-type(3),
.tile-screenshot:nth-of-type(4),
.tile-screenshot:nth-of-type(5),
.tile-screenshot:nth-of-type(6) {
  /* в masonry через columns эти правила не нужны, оставим только min-height */
}

.empty-state {
  color: var(--text-muted);
  font-size: 14px;
  padding: 20px;
}

/* 404 page */
.page-404 {
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 20px;
}

.tile-404-card {
  column-span: unset;
  width: 100%;
  max-width: 400px;
  aspect-ratio: 1 / 1;
  text-decoration: none;
  color: inherit;
}

.tile-404-card h1 {
  margin-top: 0;
  color: var(--accent-red);
}

.btn-404-home {
  min-width: 200px;
  min-height: 72px;
  justify-content: center;
  padding: 16px 24px;
  background: var(--accent-blue);
  color: #000;
  border: 4px solid var(--block-border);
}

@media (max-width: 1299px) {
  .main-layout {
    flex-direction: column;
    align-items: stretch;
    max-width: 100%;
    padding: 16px;
    gap: 16px;
  }

  .masonry-left {
    column-count: 1;
    column-width: auto;
    max-width: 100%;
  }

  .masonry-right {
    display: flex;
    flex-direction: column;
    max-width: 100%;
    gap: 16px;
  }

  .right-col {
    width: 100%;
  }

  .tile {
    width: 100%;
  }

  .custom-scrollbar {
    display: none;
  }

  /* iOS Safari: полная заливка оверлеев при переходах и развороте скриншотов */
  /* env(safe-area-inset-*) часто 0 в portrait — псевдоэлемент расширяет оверлей в полосы за челкой и панелью */
  html.overlay-fill-active,
  html.overlay-fill-active body {
    background: var(--overlay-bg) !important;
    background-attachment: fixed !important;
    min-height: 100vh !important;
    min-height: 100dvh !important;
  }

  /* Псевдоэлемент расширяет заливку в safe area (челка ~47px, home indicator ~34px) */
  #page-flash-overlay.is-active::before,
  .screenshot-overlay.is-active::before {
    content: '';
    position: absolute;
    top: -60px;
    left: -20px;
    right: -20px;
    bottom: -60px;
    background: var(--overlay-bg);
    z-index: -1;
  }

  #page-flash-overlay,
  .screenshot-overlay {
    top: calc(-1 * env(safe-area-inset-top, 0px));
    left: calc(-1 * env(safe-area-inset-left, 0px));
    right: calc(-1 * env(safe-area-inset-right, 0px));
    bottom: calc(-1 * env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 900px) {
  .masonry {
    column-count: 2;
  }

  .tile-hero {
  }
  .tile-hero h1 {
    font-size: 40px;
  }
  .tile-hero h1::before {
    transform: translate(2px, -2px);
    -webkit-text-stroke: 2px #000;
    text-stroke: 2px #000;
  }

  .avatar,
  .avatar-placeholder {
    width: 120px;
    height: 120px;
  }

  .tile-links {
  }

  .tile-spotify,
  .tile-now-playing {
  }

  .tile-tracks {
  }

  .tile-game {
  }

  .tile-film,
  .tile-film:nth-child(odd),
  .tile-film:nth-child(3n) {
  }

  .tile-screenshot:nth-of-type(1),
  .tile-screenshot:nth-of-type(2),
  .tile-screenshot:nth-of-type(3),
  .tile-screenshot:nth-of-type(4),
  .tile-screenshot:nth-of-type(5),
  .tile-screenshot:nth-of-type(6) {
  }
}
