/* Площадь: картина города — это и есть меню сайта. */

.town {
  /* Полоса неба над картиной появляется, только если экран выше картины: название
     лежит на небе самой картины (там художник оставил место), и на телефоне город
     целиком встаёт в первый экран — плашка магазина и указатель языков не уходят
     под панель браузера. */
  --sky: 0px;
  min-height: 100vh;
  min-height: 100svh;
  overflow-x: hidden;
  background: #1b1233;
  color: #fff;
}

/* Размытая картина вокруг сцены — как в игре на планшете. */
.backdrop {
  position: fixed;
  inset: -6%;
  z-index: 0;
  background: #241844 url("../assets/town/town-blur.webp") center / cover no-repeat;
  filter: saturate(1.25) brightness(0.74);
  pointer-events: none;
}
.backdrop::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 45%, rgba(27, 18, 51, 0.08) 30%, rgba(20, 12, 40, 0.74) 100%);
}

.layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: center;
  min-height: 100vh;
  min-height: 100svh;
}

/* ── Сцена ── */
.stage-wrap {
  position: relative;
  grid-area: 1 / 1;
  display: flex;
  flex-direction: column;
  width: min(100vw, 560px);
  min-height: 100vh;
  min-height: 100svh;
  overflow: hidden;
  overflow: clip;
}

/* Тень под названием: одинаково ложится и на полосу неба, и на небо картины. */
.stage-wrap::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  z-index: 2;
  height: 124px;
  background: linear-gradient(to bottom, rgba(34, 22, 84, 0.86) 0, rgba(34, 22, 84, 0.6) 46%, rgba(34, 22, 84, 0) 100%);
  pointer-events: none;
}

/* Небо над картиной: у стыка — её же верхняя полоска, перевёрнутая (шва нет),
   выше оно темнеет к ночи; по нему плывут облака. */
.sky {
  position: relative;
  flex: 3 0 var(--sky);
  overflow: hidden;
  background: linear-gradient(to bottom, #2b1f69 0, #4a3a8f 38%, #8f72b8 74%, #cf9fc1 100%);
}
.sky::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  aspect-ratio: 941 / 110;
  background: url("../assets/town/sky.webp") center bottom / 100% 100% no-repeat;
  -webkit-mask-image: linear-gradient(to top, #000 35%, transparent);
  mask-image: linear-gradient(to top, #000 35%, transparent);
}
.cloud {
  position: absolute;
  z-index: 1;
  left: 0;
  top: 22%;
  width: 190px;
  height: 46px;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 226, 236, 0.55), rgba(255, 214, 230, 0.22) 60%, rgba(255, 214, 230, 0));
  filter: blur(3px);
  transform: translate3d(-220px, 0, 0);
  animation: drift 95s linear infinite;
}
.cloud:nth-child(2) {
  top: 52%;
  width: 260px;
  height: 54px;
  opacity: 0.8;
  animation-duration: 140s;
  animation-delay: -60s;
}
.cloud:nth-child(3) {
  top: 4%;
  width: 150px;
  height: 34px;
  opacity: 0.65;
  animation-duration: 118s;
  animation-delay: -30s;
}
@keyframes drift {
  to {
    transform: translate3d(calc(min(100vw, 560px) + 60px), 0, 0);
  }
}

.ground {
  flex: 1 0 0;
  background: linear-gradient(to bottom, #af8f8a, #5a4658 60%, #2a1d44);
}

.stage {
  position: relative;
  flex: none;
  width: 100%;
  aspect-ratio: 941 / 1672;
  overflow: hidden;
  overflow: clip;
  background: #8d7773;
  isolation: isolate;
  transform-origin: 50% 50%;
  transition: transform 0.5s var(--ease), filter 0.5s var(--ease);
}
/* Старые браузеры без aspect-ratio: высота сцены — отступом. */
@supports not (aspect-ratio: 1) {
  .stage {
    height: 0;
    padding-top: 177.683%;
  }
}
.stage-art {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  user-select: none;
  -webkit-user-drag: none;
}

/* Вход в здание: сцена наезжает на дверь и гаснет. */
.stage.zoom {
  transform: scale(2.3);
  filter: brightness(0.25);
}
.stage.zoom-out {
  transition: none;
  transform: scale(2.3);
  filter: brightness(0.25);
}

/* ── Жизнь сцены: фонари, дым, искры в воздухе ── */
.fx {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}
.fx i {
  position: absolute;
  display: block;
}
.lamp {
  left: calc(var(--x) / 941 * 100%);
  top: calc(var(--y) / 1672 * 100%);
  width: 9%;
  aspect-ratio: 1;
  margin: -4.5% 0 0 -4.5%;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(170, 215, 255, 0.75), rgba(120, 170, 255, 0.28) 45%, rgba(120, 170, 255, 0));
  mix-blend-mode: screen;
  animation: flicker 3.4s ease-in-out infinite;
  animation-delay: var(--d, 0s);
}
.lamp.warm {
  width: 11%;
  margin: -5.5% 0 0 -5.5%;
  background: radial-gradient(closest-side, rgba(255, 220, 140, 0.8), rgba(255, 170, 70, 0.3) 45%, rgba(255, 170, 70, 0));
  animation-duration: 2.6s;
}
@keyframes flicker {
  0%,
  100% {
    opacity: 0.55;
    transform: scale(0.94);
  }
  18% {
    opacity: 0.95;
    transform: scale(1.04);
  }
  33% {
    opacity: 0.6;
    transform: scale(0.98);
  }
  52% {
    opacity: 1;
    transform: scale(1.08);
  }
  74% {
    opacity: 0.7;
    transform: scale(1);
  }
}
.smoke {
  left: calc(var(--x) / 941 * 100%);
  top: calc(var(--y) / 1672 * 100%);
  width: 5%;
  aspect-ratio: 1;
  margin: -2.5% 0 0 -2.5%;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(245, 240, 250, 0.75), rgba(245, 240, 250, 0));
  opacity: 0;
  animation: puff 5.2s linear infinite;
  animation-delay: var(--d, 0s);
}
.smoke.green {
  background: radial-gradient(closest-side, rgba(150, 255, 150, 0.8), rgba(150, 255, 150, 0));
}
@keyframes puff {
  0% {
    opacity: 0;
    transform: translate3d(0, 0, 0) scale(0.5);
  }
  14% {
    opacity: 0.75;
  }
  100% {
    opacity: 0;
    transform: translate3d(70%, -420%, 0) scale(2.6);
  }
}
.mote {
  left: var(--x);
  top: var(--y);
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: #ffe9a8;
  box-shadow: 0 0 6px 2px rgba(255, 214, 120, 0.7);
  opacity: 0;
  animation: mote var(--t, 9s) ease-in-out infinite;
  animation-delay: var(--d, 0s);
}
@keyframes mote {
  0% {
    opacity: 0;
    transform: translate3d(0, 0, 0) scale(0.6);
  }
  20% {
    opacity: 0.9;
  }
  60% {
    opacity: 0.7;
  }
  100% {
    opacity: 0;
    transform: translate3d(var(--mx, 20px), var(--my, -70px), 0) scale(1.1);
  }
}

/* Пятно света экскурсии: всё, кроме здания, чуть темнеет. */
.spot {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: radial-gradient(circle at var(--sx, 50%) var(--sy, 50%), rgba(24, 12, 48, 0) 0, rgba(24, 12, 48, 0) 17%, rgba(24, 12, 48, 0.62) 40%);
  opacity: 0;
  transition: opacity 0.45s var(--ease);
}
.touring .spot {
  opacity: 1;
}
/* Небо над сценой темнеет вместе с ней. */
.sky::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  background: rgba(24, 12, 48, 0.62);
  opacity: 0;
  transition: opacity 0.45s var(--ease);
  pointer-events: none;
}
.touring-wrap .sky::after {
  opacity: 1;
}

/* ── Здания: ссылки на разделы ── */
.buildings ul {
  margin: 0;
  padding: 0;
  list-style: none;
}
.bld {
  position: absolute;
  left: calc(var(--l) / 941 * 100%);
  top: calc(var(--t) / 1672 * 100%);
  width: calc(var(--w) / 941 * 100%);
  height: calc(var(--h) / 1672 * 100%);
  color: inherit;
  text-decoration: none;
  pointer-events: none;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}
.bld-hit {
  position: absolute;
  inset: 0;
  z-index: 3;
  border-radius: 18%;
  pointer-events: auto;
  cursor: pointer;
}
/* Плашки держат пропорцию к картине: на узком телефоне они меньше и не налезают друг на друга,
   на широком экране — крупнее. Первая строка — для браузеров без единиц cqw. */
.buildings .plaque {
  font-size: 13px;
  font-size: clamp(10.5px, 3.34vw, 13px); /* старые браузеры без cqw: на телефоне картина — во всю ширину */
  font-size: clamp(10.5px, 3.34cqw, 16px);
}
.bld .plaque {
  position: absolute;
  /* Ширина — ровно по содержимому: Safari иначе сжимает плашку у края здания, и текст вылезает. */
  width: -webkit-max-content;
  width: max-content;
  left: calc(var(--px) * 1%);
  top: calc(var(--py) * 1%);
  z-index: 5;
  transform: translate(-50%, 0);
  pointer-events: auto;
  cursor: pointer;
  transition: transform 0.25s var(--pop), filter 0.25s;
}
.bld:hover .plaque,
.bld:focus-visible .plaque,
.bld.lit .plaque {
  transform: translate(-50%, -3px) scale(1.08);
  filter: drop-shadow(0 0 8px rgba(255, 214, 120, 0.9)) drop-shadow(0 3px 4px rgba(20, 8, 30, 0.55));
}
.bld:focus-visible .plaque {
  outline: 3px solid #fff;
  outline-offset: 3px;
  border-radius: 8px;
}

/* Свет в окнах: тёплые пятна в точках, которые замерил художник. */
.glow {
  position: absolute;
  inset: 0;
  z-index: 2;
  mix-blend-mode: screen;
  opacity: 0;
  transition: opacity 0.35s var(--ease);
  pointer-events: none;
}
.glow i {
  position: absolute;
  left: calc(var(--x) * 1%);
  top: calc(var(--y) * 1%);
  width: calc(var(--gw) * 1%);
  height: calc(var(--gh) * 1%);
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(255, 232, 150, 0.98), rgba(255, 176, 64, 0.62) 46%, rgba(255, 150, 40, 0));
}
.glow i.green {
  background: radial-gradient(closest-side, rgba(190, 255, 170, 0.95), rgba(90, 230, 120, 0.55) 46%, rgba(90, 230, 120, 0));
}
.glow i.fire {
  background: radial-gradient(closest-side, rgba(255, 240, 170, 1), rgba(255, 120, 30, 0.7) 46%, rgba(255, 90, 20, 0));
}
.glow i.blue {
  background: radial-gradient(closest-side, rgba(200, 235, 255, 0.98), rgba(90, 160, 255, 0.6) 46%, rgba(90, 160, 255, 0));
}
.bld:hover .glow,
.bld:focus-visible .glow,
.bld.lit .glow {
  opacity: 1;
  animation: breathe 1.8s ease-in-out infinite;
}
@keyframes breathe {
  50% {
    opacity: 0.72;
  }
}

/* Искры над крышей. */
.sparks {
  position: absolute;
  left: 50%;
  top: 2%;
  z-index: 2;
  width: 0;
  height: 0;
  pointer-events: none;
}
.sparks i {
  position: absolute;
  left: 0;
  top: 0;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #fff3c4;
  box-shadow: 0 0 7px 2px rgba(255, 200, 90, 0.9);
  opacity: 0;
}
.bld:hover .sparks i,
.bld:focus-visible .sparks i,
.bld.lit .sparks i {
  animation: spark 1.5s ease-out infinite;
  animation-delay: calc(var(--i) * 0.27s);
}
@keyframes spark {
  0% {
    opacity: 0;
    transform: translate3d(calc(var(--sx0) * 1px), 6px, 0) scale(0.5);
  }
  15% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    transform: translate3d(calc(var(--sx1) * 1px), -46px, 0) scale(1.1);
  }
}

/* ── Выбор языка — справа наверху: на телефоне под названием, на широком экране в углу окна ── */
.town > .langs {
  position: absolute;
  z-index: 8;
  top: calc(env(safe-area-inset-top, 0px) + 58px);
  right: max(12px, env(safe-area-inset-right, 0px));
}
@media (min-width: 1000px) and (min-height: 560px) {
  .town > .langs {
    top: 20px;
    right: 24px;
  }
}

/* ── Плашка магазина — внизу картины, на брусчатке ── */
.stage .store {
  position: absolute;
  left: 3.2%;
  bottom: 2.2%;
  z-index: 6;
  min-height: 44px;
  padding: 5px 13px 5px 8px;
  border-radius: 12px;
}
.stage .store img {
  width: 30px;
  height: 30px;
  border-radius: 8px;
}
.stage .store small {
  font-size: 9.5px;
}
.stage .store b {
  font-size: 12px;
}

/* ── Название: на телефоне — по небу над картиной ── */
.brand {
  position: relative;
  z-index: 3;
  grid-area: 1 / 1;
  align-self: start;
  width: min(100vw, 560px);
  min-height: var(--sky);
  padding: max(8px, env(safe-area-inset-top)) 14px 0;
  text-align: center;
  pointer-events: none;
}
.brand-name {
  margin: 0;
  font: 800 clamp(21px, 6.4vw, 30px) / 1.05 var(--display);
  letter-spacing: -0.01em;
  color: #fff;
  text-shadow: 0 2px 0 #2a1650, 0 0 14px rgba(42, 22, 80, 0.75);
}
.brand-sub {
  margin: 3px 0 0;
  font: 800 clamp(10.5px, 3vw, 13px) / 1.1 var(--display);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  text-shadow: 0 1px 0 #2a1650, 0 0 10px rgba(42, 22, 80, 0.8);
}
.brand-kicker,
.brand-pitch,
.brand-hint,
.side-hero {
  display: none;
}

/* ── Бульк и его пузырь ── */
.guide {
  position: absolute;
  left: calc(var(--gx, 470) / 941 * 100%);
  top: calc(var(--gy, 1010) / 1672 * 100%);
  z-index: 7;
  width: 0;
  height: 0;
  transition: left 0.7s var(--ease), top 0.7s var(--ease);
}
.blub {
  position: absolute;
  left: 0;
  bottom: 0;
  width: clamp(64px, 19%, 104px);
  width: clamp(64px, 19cqw, 104px);
  padding: 0;
  border: 0;
  background: none;
  transform: translateX(-50%);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.stage {
  container-type: inline-size;
}
.blub::before {
  content: "";
  position: absolute;
  left: 18%;
  right: 18%;
  bottom: -5%;
  height: 16%;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(26, 16, 48, 0.5), rgba(26, 16, 48, 0));
}
.blub img {
  position: relative;
  display: block;
  width: 100%;
  height: auto;
  transform-origin: 50% 100%;
  animation: bob 3.2s ease-in-out infinite;
  filter: drop-shadow(0 2px 3px rgba(20, 8, 40, 0.45));
}
.guide.hop .blub img {
  animation: hop 0.7s var(--ease);
}
@keyframes bob {
  50% {
    transform: translateY(-4%) scale(1.02, 0.98);
  }
}
@keyframes hop {
  0% {
    transform: translateY(0) scale(1.08, 0.9);
  }
  45% {
    transform: translateY(-42%) scale(0.95, 1.06);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

.bubble {
  position: absolute;
  left: 50%;
  z-index: 8;
  width: min(92%, 350px);
  transform: translate(-50%, 8px) scale(0.96);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s var(--ease), transform 0.3s var(--pop), visibility 0s 0.3s;
}
.bubble.open {
  transform: translate(-50%, 0) scale(1);
  opacity: 1;
  visibility: visible;
  transition: opacity 0.25s var(--ease), transform 0.3s var(--pop), visibility 0s;
}
.bubble.above {
  bottom: calc(100% - var(--by) * 1%);
}
.bubble.below {
  top: calc(var(--by) * 1%);
}
.bubble .say {
  padding-bottom: 12px;
}
.bubble .say::after {
  content: "";
  position: absolute;
  left: calc(var(--tail, 50) * 1%);
  width: 16px;
  height: 16px;
  margin-left: -8px;
  border: 2px solid var(--ink);
  background: var(--white);
  transform: rotate(45deg);
}
.bubble.above .say::after {
  bottom: -9px;
  border-width: 0 2px 2px 0;
  box-shadow: 3px 3px 0 rgba(30, 21, 17, 0.9);
}
.bubble.below .say::after {
  top: -9px;
  border-width: 2px 0 0 2px;
}
.bubble-text {
  min-height: 2.9em;
}
.bubble-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
.bubble-row .dots {
  display: flex;
  gap: 4px;
  margin-right: auto;
}
.bubble-row .dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #d8c8b4;
}
.bubble-row .dots i.on {
  background: var(--tomato);
}
.bubble-close {
  position: absolute;
  right: 0;
  top: 0;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--note);
  font: 700 20px/1 var(--text);
  cursor: pointer;
}
.bubble-close:hover {
  color: var(--ink);
}
.bubble .say-name {
  padding-right: 34px;
}
[hidden] {
  display: none !important;
}

/* Без скриптов: список разделов под картиной — на случай, если что-то не так. */
.plain {
  position: relative;
  z-index: 1;
  width: min(100vw, 560px);
  margin: 0 auto;
  padding: 18px 18px 28px;
  background: var(--paper);
  color: var(--ink);
}
.plain h2 {
  margin: 0 0 8px;
  font: 800 18px/1.2 var(--display);
}
.plain ul {
  margin: 0;
  padding-left: 20px;
}
.plain li {
  margin: 6px 0;
}

/* ── Планшет: сцена посередине, по бокам — размытая картина ── */
@media (min-width: 561px) {
  .stage-wrap {
    box-shadow: 0 0 0 1px rgba(255, 210, 122, 0.35), 0 30px 80px rgba(8, 4, 24, 0.7);
  }
}

/* ── Широкий экран: сцена — высокое «окно» посередине, слева — слово об игре, справа — герой ── */
@media (min-width: 1000px) and (min-height: 560px) {
  .town {
    --sky: 0px;
    --stage-h: min(100vh - 36px, 1180px);
    --stage-w: calc(var(--stage-h) * 941 / 1672);
  }
  .layout {
    grid-template-columns: minmax(0, 1fr) var(--stage-w) minmax(0, 1fr);
    align-items: center;
    height: 100vh;
    min-height: 0;
    overflow: hidden;
  }
  .stage-wrap {
    grid-area: 1 / 2;
    width: var(--stage-w);
    height: var(--stage-h);
    min-height: 0;
    border: 3px solid #e8b860;
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 0 0 2px #2b1408, 0 0 0 5px rgba(255, 210, 122, 0.25), 0 30px 90px rgba(8, 4, 24, 0.8);
  }
  .sky,
  .ground,
  .stage-wrap::before {
    display: none;
  }
  .brand {
    grid-area: 1 / 1;
    align-self: center;
    justify-self: end;
    width: auto;
    max-width: 400px;
    min-height: 0;
    padding: 0 clamp(20px, 3.2vw, 56px) 4vh 20px;
    text-align: left;
    pointer-events: auto;
  }
  .brand-kicker {
    display: block;
    margin: 0 0 14px;
    font: 700 12px/1.2 var(--text);
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: #d9cdf5;
  }
  .brand-name {
    font-size: clamp(30px, 3.5vw, 50px);
    line-height: 1;
    /* Название из двух слов встаёт в две строки при любой ширине колонки: пробел шире строки. */
    word-spacing: 100vw;
    text-shadow: 0 3px 0 #2a1650, 0 0 24px rgba(42, 22, 80, 0.75);
  }
  .brand-sub {
    margin-top: 12px;
    font-size: clamp(13px, 1.2vw, 16px);
  }
  .brand-pitch {
    display: block;
    margin: 26px 0 0;
    font: 400 clamp(16px, 1.3vw, 19px) / 1.5 var(--text);
    color: #f3ecff;
    text-shadow: 0 1px 8px rgba(20, 10, 40, 0.8);
  }
  .brand-hint {
    display: flex;
    gap: 10px;
    align-items: center;
    margin: 22px 0 0;
    font: 700 14.5px/1.35 var(--text);
    color: var(--gold);
  }
  .brand-hint img {
    flex: none;
    width: 34px;
    height: 34px;
  }
  .side-hero {
    position: relative;
    grid-area: 1 / 3;
    align-self: end;
    justify-self: start;
    display: grid;
    justify-items: center;
    margin: 0 0 max(18px, 5vh) clamp(8px, 3vw, 64px);
    color: #fff;
    text-decoration: none;
  }
  .side-hero::before {
    content: "";
    position: absolute;
    left: 6%;
    right: 12%;
    bottom: 44px;
    height: 46px;
    border-radius: 50%;
    background: radial-gradient(closest-side, rgba(120, 190, 255, 0.5), rgba(120, 190, 255, 0));
  }
  .side-hero .sprite {
    filter: drop-shadow(0 12px 18px rgba(8, 4, 24, 0.6));
  }
  .side-hero .sprite img {
    height: min(60vh, 540px);
  }
  .side-hero .plaque {
    position: relative;
    margin-top: 8px;
    font-size: 14.5px;
  }
  .side-hero:hover .plaque,
  .side-hero:focus-visible .plaque {
    filter: drop-shadow(0 0 8px rgba(255, 214, 120, 0.9));
  }
  .plain {
    display: none;
  }
  /* Лёгкий параллакс от указателя: фон и герой чуть смещаются. */
  .backdrop {
    transform: translate3d(calc(var(--px, 0) * -14px), calc(var(--py, 0) * -10px), 0);
    transition: transform 0.6s var(--ease);
  }
  .side-hero .sprite {
    transform: translate3d(calc(var(--px, 0) * 8px), calc(var(--py, 0) * 4px), 0);
    transition: transform 0.6s var(--ease);
  }
}

@media (prefers-reduced-motion: reduce) {
  .backdrop,
  .side-hero .sprite {
    transform: none !important;
  }
  .fx,
  .cloud {
    display: none;
  }
  .stage.zoom,
  .stage.zoom-out {
    transform: none;
    filter: none;
  }
  .glow {
    animation: none !important;
  }
}
