@font-face {
  font-family: 'PS2P';
  src: url('/fonts/press-start-2p/files/press-start-2p-cyrillic-400-normal.woff2') format('woff2');
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
  font-display: swap;
}
@font-face {
  font-family: 'PS2P';
  src: url('/fonts/press-start-2p/files/press-start-2p-latin-400-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
  font-display: swap;
}

/* палитра ENDESGA 32 */
:root {
  --night: #181425; --navyD: #262b44; --navy: #3a4466; --grey3: #5a6988; --grey2: #8b9bb4; --grey1: #c0cbdc; --white: #ffffff;
  --amber: #feae34; --yellow: #fee761; --orange: #f77622; --rust: #be4a2f; --red: #e43b44; --redD: #a22633;
  --green: #63c74d; --greenM: #3e8948; --greenD: #265c42; --cyan: #2ce8f5; --blue: #0099db; --purple: #68386c; --pink: #b55088; --sand: #ead4aa;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--night); color: var(--white);
  font-family: 'PS2P', monospace; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  touch-action: manipulation; overscroll-behavior: none; -webkit-text-size-adjust: 100%;
}
/* The page canvas fills Safari's edges; the menu uses a stable layout height. */
html {
  background: #202035 linear-gradient(to bottom, #202035 0% 20%, #292e49 66%, #202035 95%) no-repeat;
}
body { background: transparent; position: fixed; inset: 0; }
#app { position: absolute; inset: 0; }
#s-join {
  bottom: auto;
  height: 100%;
  height: 100svh;
  justify-content: flex-start;
  overflow-y: auto;
}
#s-join > * { flex: none; }
#s-join > :first-child { margin-top: auto; }
#join-form { margin-bottom: auto; }
canvas { image-rendering: pixelated; image-rendering: crisp-edges; }

.screen {
  position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom)); text-align: center; gap: 16px;
}
.screen.on { display: flex; }

h1 { font-size: 26px; line-height: 1.45; color: var(--yellow); margin: 0 0 8px; text-shadow: 3px 3px 0 var(--rust), 6px 6px 0 var(--night); letter-spacing: 1px; }
.sub { font-size: 13px; line-height: 1.7; color: var(--grey1); margin: 0; }
.hint { font-size: 12px; line-height: 1.7; color: var(--grey1); margin: 0; }
.kicker { font-size: 18px; color: var(--amber); margin: 0; text-shadow: 3px 3px 0 var(--night); }
.top-deco { width: 120px; height: 12px; background: repeating-linear-gradient(45deg, var(--amber) 0 8px, var(--night) 8px 16px); border: 3px solid var(--night); }

form { display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 320px; }
input {
  font-family: inherit; font-size: 18px; padding: 16px 14px; width: 100%; color: var(--white); background: var(--navyD);
  border: 4px solid var(--grey3); outline: none; border-radius: 0; text-align: center; -webkit-user-select: text; user-select: text;
  box-shadow: inset 0 4px 0 var(--night);
}
input:focus { border-color: var(--amber); }
input::placeholder { color: var(--grey3); }

.btn {
  font-family: inherit; font-size: 14px; color: var(--night); background: var(--amber); border: 0; padding: 16px 18px; cursor: pointer;
  box-shadow: 0 0 0 4px var(--night), inset -4px -4px 0 var(--orange), inset 4px 4px 0 var(--yellow); position: relative; top: 0;
  transition: top .05s, box-shadow .05s; border-radius: 0; touch-action: manipulation;
}
.btn:active { top: 4px; box-shadow: 0 0 0 4px var(--night), inset 4px 4px 0 var(--orange); }
.btn.big { font-size: 16px; padding: 20px; }
.btn:disabled { background: var(--grey3); box-shadow: 0 0 0 4px var(--night); color: var(--navyD); }

#me-big { width: 156px; height: 168px; animation: bob 1.2s steps(2) infinite; }
#me-big.fx1 { filter: drop-shadow(0 0 14px #feae34); }
#me-big.fx2 { filter: drop-shadow(0 0 14px #2ce8f5); }
#me-big.fx3 { filter: drop-shadow(0 0 14px #ff2e93); }
#me-big.fx4 { filter: drop-shadow(0 0 14px #fee761); animation: bob 1.2s steps(2) infinite, rainbow 1.4s linear infinite; }
@keyframes rainbow { to { filter: drop-shadow(0 0 14px #fee761) hue-rotate(360deg); } }
@keyframes bob { 50% { transform: translateY(-6px); } }
.myname { font-size: 16px; color: var(--white); margin: 0; word-break: break-word; }
.wait { font-size: 12px; color: var(--grey2); margin-top: 6px; }
.dots::after { content: ''; animation: dots 1.4s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

.count { font-size: 120px; color: var(--yellow); margin: 0; text-shadow: 8px 8px 0 var(--rust), 14px 14px 0 var(--night); }
.count.pop { animation: pop .4s ease-out; }
@keyframes pop { 0% { transform: scale(2.2) rotate(-10deg); } 100% { transform: scale(1); } }

/* раунд */
.round { padding: 0; gap: 0; justify-content: flex-start; }
.bar {
  width: 100%; display: flex; justify-content: space-between; align-items: center; padding: max(14px, env(safe-area-inset-top)) 16px 12px 64px;
  background: var(--night); border-bottom: 4px solid var(--navy); font-size: 14px; position: relative; z-index: 2;
}
#timer { color: var(--yellow); font-size: 18px; }
#timer.hot { color: var(--red); animation: blink .5s steps(2) infinite; }
@keyframes blink { 50% { opacity: .4; } }
.bar-score { color: var(--grey1); font-size: 12px; }
.bar-score b { color: var(--white); font-size: 18px; display: inline-block; font-weight: normal; }
.bar-score b.bump { animation: bump .12s ease-out; }
@keyframes bump { 0% { transform: translateY(-5px) scale(1.25); color: var(--yellow); } }

.hammer {
  flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden;
  background: repeating-linear-gradient(135deg, rgba(254,174,52,.06) 0 22px, transparent 22px 44px);
  touch-action: none;
}
.hammer-inner {
  width: min(76vw, 52vh); height: min(76vw, 52vh); background: var(--amber); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  box-shadow: 0 0 0 6px var(--night), inset -10px -10px 0 var(--orange), inset 10px 10px 0 var(--yellow), 0 14px 0 6px var(--rust), 0 14px 0 12px var(--night);
  transition: transform .04s; pointer-events: none;
}
.hammer.down .hammer-inner { transform: translateY(10px) scale(.96); box-shadow: 0 0 0 6px var(--night), inset 10px 10px 0 var(--orange), 0 4px 0 6px var(--rust), 0 4px 0 12px var(--night); }
#hammer-ico { width: 160px; height: 160px; transform-origin: 22% 80%; transform: rotate(-12deg); transition: transform .06s ease-out; }
.hammer.down #hammer-ico { transform: rotate(22deg) translate(4px, 4px); transition-duration: .03s; }
.hammer-label { font-size: 26px; color: var(--night); text-shadow: 3px 3px 0 var(--yellow); }
.hammer.rush .hammer-inner { background: var(--orange); box-shadow: 0 0 0 6px var(--night), inset -10px -10px 0 var(--rust), inset 10px 10px 0 var(--amber), 0 14px 0 6px var(--redD), 0 14px 0 12px var(--night), 0 0 60px 20px rgba(247,118,34,.5); }
.flash { position: absolute; width: 90px; height: 90px; margin: -45px 0 0 -45px; pointer-events: none; border: 6px solid var(--yellow); animation: flash .3s ease-out forwards; }
@keyframes flash { 0% { transform: scale(.3); opacity: 1; } 100% { transform: scale(1.4); opacity: 0; } }
.plus { position: absolute; pointer-events: none; color: var(--yellow); font-size: 14px; text-shadow: 2px 2px 0 var(--night); animation: plus .55s ease-out forwards; }
@keyframes plus { to { transform: translateY(-60px); opacity: 0; } }
.rush-tag { display: none; position: absolute; top: 76px; left: 50%; transform: translateX(-50%); background: var(--red); color: var(--white); font-size: 14px; padding: 8px 12px; box-shadow: 0 0 0 4px var(--night); animation: blink .4s steps(2) infinite; z-index: 3; }
.rush-tag.on { display: block; width: max-content; max-width: calc(100% - 32px); line-height: 1.45; animation: none; text-align: center; }

/* финал */
.place { font-size: 72px; color: var(--yellow); margin: 0; text-shadow: 6px 6px 0 var(--rust), 10px 10px 0 var(--night); }
.stage { background: radial-gradient(circle at 50% 40%, var(--purple), var(--night) 75%); }
.stage-cta { font-size: 24px; line-height: 1.5; color: var(--white); margin: 0; text-shadow: 4px 4px 0 var(--red); animation: pulse .8s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.08); } }
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -10px; width: 8px; height: 4px; animation: fall linear infinite; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* оверлеи */
.overlay { position: absolute; inset: 0; display: none; flex-direction: column; align-items: center; justify-content: center; gap: 18px; z-index: 20; text-align: center; padding: 20px; }
.overlay.on { display: flex; }
.inspect { background: var(--red); animation: none; }
.inspect .big-txt, .fined .big-txt { font-size: 44px; line-height: 1.3; color: var(--white); margin: 0; text-shadow: 5px 5px 0 var(--redD), 9px 9px 0 var(--night); }
.inspect .sub { color: var(--white); }
.freeze-count { font-size: 96px; color: var(--yellow); margin: 0; text-shadow: 6px 6px 0 var(--redD), 10px 10px 0 var(--night); }
.freeze-count.pop { animation: pop .35s ease-out; }
.fined { background: rgba(24,20,37,.85); pointer-events: none; }
.goat { background: radial-gradient(circle at 50% 60%, #3e2731, var(--night) 80%); justify-content: flex-start; padding-top: max(28px, env(safe-area-inset-top)); gap: 12px; }
.goat-title { font-size: 28px; line-height: 1.35; color: var(--yellow); margin: 0; text-shadow: 4px 4px 0 var(--red), 7px 7px 0 var(--night); animation: shake .3s infinite; }
.goat-sub { font-size: 13px; line-height: 1.8; color: var(--white); margin: 0; }
.goat-sub b { color: var(--green); font-weight: normal; }
@keyframes shake { 25% { transform: rotate(-2deg); } 75% { transform: rotate(2deg); } }
.goat-field { position: relative; flex: 1; width: 100%; border: 4px dashed rgba(254,174,52,.35); touch-action: none; }
.goat-cv { position: absolute; left: 0; top: 0; width: 130px; height: 110px; transition: left .32s cubic-bezier(.3,1.6,.6,1), top .32s cubic-bezier(.3,1.6,.6,1);
  filter: drop-shadow(0 0 14px rgba(247,118,34,.8)); cursor: pointer; touch-action: none; }
.goat-cv.flip { transform: scaleX(-1); }
.goat-cv.caught { animation: caught .5s ease-in forwards; }
@keyframes caught { to { transform: translateY(-120vh) rotate(540deg); opacity: 0; } }
.goat-bar { width: min(86vw, 360px); height: 16px; background: var(--night); border: 3px solid var(--night); margin-bottom: max(16px, env(safe-area-inset-bottom)); flex: none; }
.goat-bar i { display: block; height: 100%; background: var(--amber); width: 100%; transition: width .1s linear; }

.toast { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); z-index: 30; background: var(--green); color: var(--night); font-size: 16px; line-height: 1.6; padding: 16px 18px; box-shadow: 0 0 0 4px var(--night); display: none; text-align: center; width: max-content; max-width: 90vw; }
.toast.on { display: block; animation: pop .35s ease-out; }

#me-mini { position: absolute; left: 10px; top: max(8px, env(safe-area-inset-top)); width: 39px; height: 42px; z-index: 25; display: none; pointer-events: none; }
#me-mini.on { display: block; }

.offline { position: absolute; left: 0; right: 0; bottom: 0; background: var(--red); color: var(--white); font-size: 10px; padding: 10px; text-align: center; z-index: 40; display: none; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
.offline.on { display: block; }

.rotate { display: none; position: fixed; inset: 0; background: var(--night); color: var(--amber); z-index: 100; align-items: center; justify-content: center; text-align: center; font-size: 16px; line-height: 1.8; }
@media (orientation: landscape) and (max-height: 500px) { .rotate { display: flex; } }

/* сообщения на экран */
.chat { position: absolute; left: 12px; right: 12px; bottom: max(14px, env(safe-area-inset-bottom)); display: none; flex-direction: row; align-items: stretch; gap: 10px; z-index: 15;
  max-width: 420px; width: auto; margin: 0 auto; }
.chat.on { display: flex; }
.chat input { flex: 1; min-width: 0; font-size: 16px; padding: 13px 12px; text-align: left; }
.chat .btn { font-size: 16px; padding: 0 18px; flex: none; }

/* выбор: парень / девушка */
.gender { display: flex; gap: 12px; }
.g-opt { flex: 1; font-family: inherit; font-size: 12px; color: var(--grey1); background: var(--navyD); border: 4px solid var(--grey3); border-radius: 0; padding: 10px 4px 12px;
  display: flex; flex-direction: column; align-items: center; gap: 8px; cursor: pointer; touch-action: manipulation; }
.g-opt canvas { width: 78px; height: 84px; }
.g-opt.on { border-color: var(--amber); color: var(--yellow); background: var(--navy); box-shadow: 0 0 0 3px var(--night), 0 0 18px rgba(254,174,52,.45); }
.gender.need .g-opt { animation: shake .3s 2; border-color: var(--red); }
.row-btns { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.btn.alt { background: var(--cyan); box-shadow: 0 0 0 4px var(--night), inset -4px -4px 0 var(--blue), inset 4px 4px 0 var(--white); }

/* плашки событий в раунде */
.ev-tag { display: none; position: absolute; top: 76px; left: 50%; transform: translateX(-50%); width: max-content; max-width: 92vw; text-align: center; color: var(--night); font-size: 13px; line-height: 1.6; padding: 8px 12px; box-shadow: 0 0 0 4px var(--night); z-index: 3; }
.ev-tag.on { display: block; animation: evpop .3s ease-out; }
@keyframes evpop { 0% { transform: translateX(-50%) scale(1.35); } 100% { transform: translateX(-50%) scale(1); } }
.ev-tag.garland { background: var(--cyan); }
.ev-tag.blizzard { background: var(--grey1); }
.ev-tag.slow { background: var(--amber); }
.inspect.warn { background: var(--orange, #f77622); }
.inspect.warn .freeze-count { color: var(--white); }
.haptic { position: fixed; left: -100px; top: -100px; width: 1px; height: 1px; opacity: 0; pointer-events: none; overflow: hidden; }

/* невидимый свитч для отдачи на iPhone: родной вид обязателен (иначе iOS не даёт отдачу), поэтому только opacity:0 */
.haptic-switch { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; z-index: 2; -webkit-tap-highlight-color: transparent; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; cursor: pointer; }

/* раунд 2: наряди ёлку */
.deco { flex: 1; width: 100%; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; overflow: hidden; touch-action: none; }
#deco-cv { width: min(88vw, 56vh * 0.8); height: auto; aspect-ratio: 120 / 150; }
.deco-hint { font-size: 11px; line-height: 1.7; color: var(--grey1); text-align: center; margin-top: 8px; }
.deco-pop { position: absolute; top: 18%; left: 50%; transform: translateX(-50%); font-size: 22px; color: var(--yellow); text-shadow: 3px 3px 0 var(--night); opacity: 0; pointer-events: none; white-space: nowrap; }
.deco-pop.on { animation: decopop .8s ease-out forwards; }
@keyframes decopop { 0% { opacity: 1; transform: translateX(-50%) scale(1.6); } 30% { transform: translateX(-50%) scale(1); } 100% { opacity: 0; transform: translateX(-50%) translateY(-30px); } }
.res-lines { font-size: 12px; line-height: 1.9; color: var(--grey1); margin: 0; }
.res-lines b { color: var(--amber); font-weight: normal; }

#name-error { margin: 0; color: var(--yellow); font: 20px/1.2 monospace; }
#name-error:empty { display: none; }

/* Match the visible edges to the page canvas around Safari's controls. */
:root { --page-edge: #202035; }
.stage { background: transparent; }
html:has(.stage.on) {
  background-color: var(--page-edge);
  background-image: linear-gradient(to bottom, var(--page-edge) 0%, transparent 15% 85%, var(--page-edge) 100%),
    radial-gradient(ellipse at 50% 42%, var(--purple), var(--page-edge) 75%);
}
.round .bar { background-color: var(--page-edge); }
.hammer { background-image: linear-gradient(to top, var(--page-edge), transparent 12%), repeating-linear-gradient(135deg, rgba(254,174,52,.06) 0 22px, transparent 22px 44px); }
.overlay.on {
  background-image: linear-gradient(to bottom, var(--page-edge), transparent 12% 88%, var(--page-edge));
}
.goat.on {
  background-image: linear-gradient(to bottom, var(--page-edge), transparent 12% 88%, var(--page-edge)),
    radial-gradient(circle at 50% 60%, #3e2731, var(--night) 80%);
}

.goat-cv { width: min(22vw, 80px); height: auto; aspect-ratio: 26 / 22; transition: none; }
#light-window { position:absolute; z-index:5; top:clamp(82px, 17%, 150px); left:50%; transform:translateX(-50%); width:min(70%,265px); background:#262b44; color:#fff; line-height:1.6; }
#light-window:not([hidden]) { display:grid; justify-items:center; gap:12px; }
#light-window i { width:36px; height:40px; border:4px solid #8b9bb4; background:linear-gradient(90deg, transparent 45%,#8b9bb4 45% 55%,transparent 55%),linear-gradient(transparent 45%,#8b9bb4 45% 55%,transparent 55%),#3a4466; }
#light-window.illuminated i { background-color:#fee761; box-shadow:0 0 14px #feae34; }
#light-count { font-size:11px; color:#ead4aa; }
