@font-face {
  font-family: PS2P;
  src: url(assets/ps2p-cyr.woff2) format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
  font-display: block;
}
@font-face {
  font-family: PS2P;
  src: url(assets/ps2p-lat.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
  font-display: block;
}

:root {
  --bg: #14121c;
  --panel: #101010;
  --ink: #fcfcfc;
  --muted: #a8a8c8;
  --gold: #f8b800;
  --red: #d82800;
  --shell: #2a2838;
  --shell-hi: #3a3850;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: PS2P, monospace;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}
body {
  background:
    radial-gradient(circle at 1px 1px, #ffffff0d 1px, transparent 0) 0 0 / 8px 8px,
    var(--bg);
}
button { font-family: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

#app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px;
  padding: max(12px, env(safe-area-inset-top)) 16px max(12px, env(safe-area-inset-bottom));
}

#screen {
  position: relative;
  width: min(100%, calc((100dvh - 110px) * 1.6));
  aspect-ratio: 16 / 10;
  background: #000;
  border: 4px solid #000;
  box-shadow: 0 0 0 4px var(--shell-hi), 0 0 0 8px #000, 0 18px 50px #0009;
}
#game {
  display: block; width: 100%; height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

#hints {
  display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px;
  font-size: 10px; color: var(--muted); line-height: 1.6;
  max-width: 900px; text-align: center;
}
#hints b { color: var(--ink); font-weight: normal; }

/* кнопка музыки */
.mute {
  position: absolute; bottom: 6px; right: 6px; z-index: 2;
  width: 34px; height: 34px; padding: 0;
  background: #000a; border: 2px solid #fff6;
  display: grid; place-items: center;
}
.mute span {
  width: 16px; height: 16px;
  background: var(--ink);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8' shape-rendering='crispEdges'%3E%3Cpath d='M3 0h5v6h-1v1h-2v-1h-1v-1h3v-3h-3v4h-1v1h-2v-1h-1v-1h3z'/%3E%3C/svg%3E") center / contain no-repeat;
          mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8' shape-rendering='crispEdges'%3E%3Cpath d='M3 0h5v6h-1v1h-2v-1h-1v-1h3v-3h-3v4h-1v1h-2v-1h-1v-1h3z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.mute.off span { background: #777; }
.mute.off::after {
  content: ''; position: absolute; width: 26px; height: 3px; background: var(--red); transform: rotate(-45deg);
}
/* на титульнике канва рисует свою кнопку не мешая — значок не прячем */

/* ---------- тач-пульт */
#pad { display: none; }

@media (pointer: coarse) {
  #hints { display: none; }
  #pad {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    width: 100%;
    touch-action: none;
  }
  #dpad {
    position: relative; justify-self: start;
    width: 150px; height: 150px;
    touch-action: none;
  }
  #dpad i { position: absolute; background: #1c1b26; box-shadow: inset 0 -4px 0 #000, 0 3px 0 #000; }
  #dpad .u, #dpad .d { left: 50px; width: 50px; height: 52px; }
  #dpad .l, #dpad .r { top: 50px; width: 52px; height: 50px; }
  #dpad .u { top: 0; border-radius: 6px 6px 0 0; }
  #dpad .d { bottom: 0; border-radius: 0 0 6px 6px; }
  #dpad .l { left: 0; border-radius: 6px 0 0 6px; }
  #dpad .r { right: 0; border-radius: 0 6px 6px 0; }
  #dpad .c { left: 48px; top: 48px; width: 54px; height: 54px; box-shadow: none; }
  #dpad .u::after, #dpad .d::after, #dpad .l::after, #dpad .r::after {
    content: ''; position: absolute; inset: 0; margin: auto; width: 0; height: 0;
    border: 8px solid transparent;
  }
  #dpad .u::after { border-bottom-color: #555; top: -8px; }
  #dpad .d::after { border-top-color: #555; bottom: -8px; }
  #dpad .l::after { border-right-color: #555; left: -8px; }
  #dpad .r::after { border-left-color: #555; right: -8px; }
  #dpad[data-dir~="up"] .u, #dpad[data-dir~="down"] .d,
  #dpad[data-dir~="left"] .l, #dpad[data-dir~="right"] .r { background: #34324a; }

  .mid { display: flex; flex-direction: column; gap: 14px; align-items: center; }
  .pill {
    font-size: 8px; padding: 7px 10px; border-radius: 12px;
    background: #4a4860; border: 0; box-shadow: 0 3px 0 #000; color: #ddd;
  }
  .ab { justify-self: end; display: flex; gap: 14px; transform: rotate(-20deg); }
  .round {
    width: 66px; height: 66px; border-radius: 50%;
    background: var(--red); border: 0; color: #fff; font-size: 16px;
    box-shadow: inset 0 -5px 0 #8c1800, 0 4px 0 #000;
  }
  .round.on, .pill.on { transform: translateY(3px); box-shadow: inset 0 -2px 0 #8c1800, 0 1px 0 #000; }
  .ab .round:first-child { margin-top: 30px; }
}

/* телефон вертикально: «приставка» — экран сверху, пульт снизу */
@media (pointer: coarse) and (orientation: portrait) {
  #app {
    justify-content: flex-start; gap: 0;
    padding: 0 0 env(safe-area-inset-bottom);
    background: linear-gradient(var(--shell), #201e2c);
  }
  #screen {
    width: 100%;
    height: min(100vw, calc(100dvh - 250px - env(safe-area-inset-bottom)));
    aspect-ratio: auto;
    border: 0; border-bottom: 4px solid #000;
    box-shadow: none;
    margin-top: env(safe-area-inset-top);
  }
  #pad { flex: 1; padding: 10px 22px 18px; max-width: 520px; }
}

/* телефон горизонтально: экран на весь дисплей, пульт поверх полупрозрачный */
@media (pointer: coarse) and (orientation: landscape) {
  #app { padding: 0; }
  #screen { width: 100vw; height: 100dvh; aspect-ratio: auto; border: 0; box-shadow: none; }
  #pad {
    position: fixed; left: 0; right: 0; bottom: 0;
    padding: 0 max(18px, env(safe-area-inset-right)) 14px max(18px, env(safe-area-inset-left));
    pointer-events: none;
  }
  #pad > * { pointer-events: auto; opacity: .55; }
  #dpad { transform: scale(.8); transform-origin: left bottom; }
  .ab { transform: rotate(-20deg) scale(.85); transform-origin: right bottom; }
  .mid { visibility: hidden; }
}

/* ---------- окна */
.overlay {
  position: fixed; inset: 0; z-index: 10;
  display: grid; place-items: center;
  background: #000c;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
  animation: fade .15s steps(3);
}
.overlay.see-through { background: #0006; }
.hidden { display: none !important; }
@keyframes fade { from { opacity: 0; } }

.panel {
  background: var(--panel);
  border: 4px solid var(--ink);
  outline: 4px solid #000;
  box-shadow: 0 0 0 8px #0006;
  display: flex; flex-direction: column;
  gap: 12px;
  padding: 16px;
  max-height: 100%;
  animation: pop .2s steps(4);
}
@keyframes pop { from { transform: scale(.85); } }
.panel header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.h1 { font-size: clamp(14px, 3.4vmin, 26px); line-height: 1.3; color: var(--gold); text-shadow: 3px 3px 0 #881400; }
.sub { font-size: clamp(9px, 1.8vmin, 13px); color: var(--muted); margin-top: 8px; line-height: 1.5; }
#cityText:empty { display: none; }
.text { font-size: clamp(10px, 2vmin, 14px); line-height: 1.8; margin: 0; min-height: 3.6em; user-select: text; }
.x {
  flex: none; width: 40px; height: 40px; font-size: 14px;
  background: var(--ink); color: #000; border: 0;
  box-shadow: inset -4px -4px 0 #adafbc;
}
.x:active, .btn:active { box-shadow: inset 4px 4px 0 #adafbc; }
.btn {
  font-size: clamp(10px, 1.8vmin, 14px); padding: 14px 18px;
  background: var(--ink); color: #000; border: 0;
  box-shadow: inset -4px -4px 0 #adafbc;
  align-self: flex-start;
}

.city-panel { width: min(100%, 1100px); height: min(100%, 920px); }
.photo-box {
  position: relative; flex: 1 1 auto; min-height: 140px;
  background: #000; border: 2px solid #333;
  touch-action: pan-y;
}
#photo {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; image-rendering: pixelated;
}
.nav {
  position: absolute; top: 0; bottom: 0; width: 18%; border: 0; background: transparent;
}
.nav::after {
  content: ''; position: absolute; top: 50%; margin-top: -14px;
  border: 14px solid transparent;
  filter: drop-shadow(2px 2px 0 #000);
}
.nav.prev { left: 0; } .nav.prev::after { left: 6px; border-right-color: var(--ink); border-left-width: 0; }
.nav.next { right: 0; } .nav.next::after { right: 6px; border-left-color: var(--ink); border-right-width: 0; }
.nav[hidden] { display: none; }
.greet { font-size: clamp(11px, 2.2vmin, 16px); color: var(--gold); line-height: 1.6; text-shadow: 2px 2px 0 #881400; }
.greet:empty { display: none; }
.caption { font-size: clamp(9px, 1.7vmin, 12px); color: var(--gold); line-height: 1.6; min-height: 0; }
.caption:empty { display: none; }
.panel footer {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  font-size: clamp(8px, 1.5vmin, 11px); color: var(--muted);
}
@media (pointer: coarse) { .hint-keys { display: none; } }

.stamp {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  background: var(--gold); color: #000; padding: 10px 14px;
  font-size: clamp(10px, 2vmin, 15px);
  border: 3px solid #000; box-shadow: 4px 4px 0 #000;
  white-space: nowrap; pointer-events: none;
}
.stamp.pop { animation: stamp 2.6s steps(12) forwards; }
@keyframes stamp {
  0% { transform: translate(-50%, -30px) scale(1.6); opacity: 0; }
  12% { transform: translate(-50%, 0) scale(1); opacity: 1; }
  80% { opacity: 1; }
  100% { opacity: 0; }
}

/* пиксельные иконки */
.star, .heart, .homeic {
  display: inline-block; width: 14px; height: 14px; vertical-align: -2px;
  background: currentColor;
  -webkit-mask: var(--m) center / contain no-repeat; mask: var(--m) center / contain no-repeat;
}
.star { color: var(--gold); --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 7' shape-rendering='crispEdges'%3E%3Cpath d='M3 0h1v2h3v1h-1v1h-1v1h1v2h-1v-1h-1v-1h-1v1h-1v1h-1v-2h1v-1h-1v-1h-1v-1h3z'/%3E%3C/svg%3E"); }
.stamp .star { color: #000; }
.heart { color: var(--red); --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 6' shape-rendering='crispEdges'%3E%3Cpath d='M1 0h2v1h1v-1h2v1h1v2h-1v1h-1v1h-1v1h-1v-1h-1v-1h-1v-1h-1v-2h1z'/%3E%3C/svg%3E"); }
.homeic { color: #fca044; --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 7' shape-rendering='crispEdges'%3E%3Cpath d='M3 0h1v1h1v1h1v1h1v1h-1v3h-2v-2h-1v2h-2v-3h-1v-1h1v-1h1v-1h1z'/%3E%3C/svg%3E"); }
.wine { display: inline-block; width: 14px; height: 14px; vertical-align: -2px; background: #e0306c;
  -webkit-mask: var(--m) center / contain no-repeat; mask: var(--m) center / contain no-repeat;
  --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 7 7' shape-rendering='crispEdges'%3E%3Cpath d='M1 0h5v2h-1v1h-1v2h1v1h1v1h-5v-1h1v-1h1v-2h-1v-1h-1z'/%3E%3C/svg%3E"); }
.meat { display: inline-block; width: 16px; height: 14px; vertical-align: -2px; background: #a0582c;
  -webkit-mask: var(--m) center / contain no-repeat; mask: var(--m) center / contain no-repeat;
  --m: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 9 7' shape-rendering='crispEdges'%3E%3Cpath d='M0 3h9v1h-9zM1 1h2v5h-2zM4 1h2v5h-2zM7 2h1v3h-1z'/%3E%3C/svg%3E"); }

/* посиделки в Патрушах */
.feast { display: flex; flex-direction: column; gap: 10px; }
.meter { display: flex; align-items: center; gap: 10px; font-size: clamp(9px, 1.7vmin, 12px); color: var(--muted); }
.meter .bar { flex: 1; height: 14px; background: #3a3a4a; border: 2px solid #000; outline: 2px solid var(--ink); }
.meter .bar i { display: block; height: 100%; background: #58d854; transition: width .4s steps(8); box-shadow: inset 0 3px 0 #ffffff55; }
.meter .bar i[data-lvl="mid"] { background: var(--gold); }
.meter .bar i[data-lvl="low"] { background: #f83800; }
.meter b { font-weight: normal; color: var(--ink); min-width: 4ch; text-align: right; font-variant-numeric: tabular-nums; }
.feast-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.feast-row .btn { align-self: auto; display: inline-flex; align-items: center; gap: 8px; }
.feast-say { font-size: clamp(9px, 1.8vmin, 13px); color: var(--gold); line-height: 1.5; min-width: 0; }
.feast-say.pop { animation: say .5s steps(5); }
@keyframes say { from { transform: translateY(-6px) scale(1.15); } }
.q {
  display: inline-grid; place-items: center; width: 16px; height: 16px;
  background: var(--gold); color: #000; font-style: normal; font-size: 9px;
  box-shadow: inset -2px -2px 0 #c84c0c;
}

/* телепорт */
.rules-panel { width: min(100%, 760px); max-height: calc(100dvh - 24px); }
.rules-list { margin: 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: 12px;
  font-size: clamp(10px, 1.9vmin, 14px); line-height: 1.7; }
.rules-list b { font-weight: normal; color: var(--gold); }
/* прокручивается только текст правил, кнопка всегда видна под ним */
.rules-scroll { min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
#rulesGo { flex: none; }
.warp-panel { width: min(100%, 520px); max-height: calc(100dvh - 24px); }
#warpList { min-height: 0; }
#warpList { list-style: none; margin: 0; padding: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
#warpList li {
  display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 10px;
  padding: 12px 10px 12px 26px; position: relative; cursor: pointer;
  font-size: clamp(11px, 2vmin, 14px);
}
#warpList li .sub { margin: 0; }
#warpList li.sel { background: #24223a; }
#warpList li.sel::before {
  content: ''; position: absolute; left: 8px; top: 50%; margin-top: -6px;
  border: 6px solid transparent; border-left-color: var(--ink); border-right-width: 0;
  animation: blink .6s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* финал */
.fin-panel { max-height: calc(100dvh - 24px); width: min(100%, 980px); flex-direction: row; align-items: stretch; gap: 22px; }
.fin-photo { flex: 0 0 40%; position: relative; min-height: 260px; background: #000; border: 2px solid #333; }
#portrait { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.fin-body { min-height: 0; flex: 1; display: flex; flex-direction: column; gap: 16px; justify-content: flex-start; overflow-y: auto; }
.fin-body > * { flex-shrink: 0; }
.credits-h { font-size: clamp(10px, 1.8vmin, 13px); color: var(--gold); }
.credits { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px;
  font-size: clamp(9px, 1.6vmin, 12px); line-height: 1.6; }
.credits li { animation: credit .4s steps(4) backwards; }
.credits b { font-weight: normal; color: #b8f818; }
.credits .who { color: var(--muted); }
@keyframes credit { from { transform: translateX(-12px); color: var(--gold); } }
.rainbow { animation: rainbow 1.2s steps(1) infinite; }
@keyframes rainbow {
  0% { color: #f8b800; } 25% { color: #f83800; } 50% { color: #3cbcfc; } 75% { color: #b8f818; }
}
@media (max-width: 700px), (orientation: portrait) {
  .fin-panel { flex-direction: column; height: 100%; }
  .fin-photo { flex: 1 1 40%; min-height: 180px; }
  .fin-body { flex: 0 1 auto; justify-content: flex-start; }
  .city-panel { height: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  .rainbow, .stamp.pop, .panel, .overlay { animation: none; }
}
