/* Mini-app «Угадай по скриншоту»: 8-битная тёмная палитра (цвета из палитры NES),
   окна как в играх Dendy, кадр — в корпусе ЭЛТ-телевизора. */

@font-face {
    font-family: 'Press Start 2P';
    src: url('../fonts/PressStart2P-Regular.ttf') format('truetype');
    font-display: swap;
}

:root {
    --night: #0b0a2e;        /* фон; он же setHeaderColor / setBackgroundColor в app.js */
    --night-2: #15135a;
    --window: #1c1a8c;       /* заливка окон */
    --window-deep: #100e5c;
    --chalk: #fcfcfc;        /* рамки и текст */
    --ash: #a8a8d8;          /* второстепенный текст */
    --coin: #f8b800;         /* заголовок, очки */
    --coin-shadow: #a81000;
    --brick: #f83800;        /* ошибка */
    --pipe: #58d854;         /* верно */
    --sky: #3cbcfc;          /* подсказка */
    --pink: #f878f8;         /* салют, баннеры порогов */
    --plastic: #24242c;      /* корпус телевизора */
    --px: 4px;               /* «пиксель» рамок */
    --font: 'Press Start 2P', monospace;

    /* отступы Telegram: safeAreaInset (вырезы экрана) + contentSafeAreaInset (кнопки Telegram в полноэкранном режиме) */
    --safe-top: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
    --safe-right: calc(var(--tg-safe-area-inset-right, 0px) + var(--tg-content-safe-area-inset-right, 0px));
    --safe-bottom: calc(var(--tg-safe-area-inset-bottom, 0px) + var(--tg-content-safe-area-inset-bottom, 0px));
    --safe-left: calc(var(--tg-safe-area-inset-left, 0px) + var(--tg-content-safe-area-inset-left, 0px));
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
    height: 100%;
    margin: 0;
    background: var(--night);
    color: var(--chalk);
    font-family: var(--font);
    font-size: 12px;
    line-height: 1.6;
    -webkit-text-size-adjust: 100%;
}
body { overflow: hidden; }

/* лёгкие ЭЛТ-полосы поверх всего; класс reduced на <html> их выключает */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 50;
    pointer-events: none;
    background: repeating-linear-gradient(to bottom,
        transparent 0, transparent 2px,
        rgba(0, 0, 0, 0.16) 2px, rgba(0, 0, 0, 0.16) 3px);
}
.reduced body::before { display: none; }

h1, h2, p, dl, dd { margin: 0; }
h1, h2 { font-weight: normal; }

.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ── каркас ─────────────────────────────────────────────── */

.app {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 520px;
    margin: 0 auto;
    padding: calc(var(--safe-top) + 12px) calc(var(--safe-right) + 12px)
             calc(var(--safe-bottom) + 12px) calc(var(--safe-left) + 12px);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.screen {
    flex: 1 0 auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* пиксельная рамка у кнопок, окон и сообщений: четыре тени по сторонам дают рамку
   со «срезанными» углами; --edge — её цвет */
.btn, .window { --edge: var(--chalk); }

/* ── кнопки ─────────────────────────────────────────────── */

.btn {
    --fill: var(--window);
    appearance: none;
    position: relative;
    display: block;
    width: calc(100% - 2 * var(--px));
    min-height: 48px;
    margin: var(--px);
    padding: 12px 14px;
    border: 0;
    border-radius: 0;
    background: var(--fill);
    color: var(--chalk);
    font: inherit;
    text-align: left;
    overflow-wrap: anywhere;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    box-shadow:
        0 calc(-1 * var(--px)) 0 0 var(--edge),
        0 var(--px) 0 0 var(--edge),
        calc(-1 * var(--px)) 0 0 0 var(--edge),
        var(--px) 0 0 0 var(--edge),
        inset calc(-1 * var(--px)) calc(-1 * var(--px)) 0 0 rgba(0, 0, 0, 0.35),
        inset var(--px) var(--px) 0 0 rgba(255, 255, 255, 0.16);
}
.btn:active:not(:disabled) {
    transform: translateY(2px);
    box-shadow:
        0 calc(-1 * var(--px)) 0 0 var(--edge),
        0 var(--px) 0 0 var(--edge),
        calc(-1 * var(--px)) 0 0 0 var(--edge),
        var(--px) 0 0 0 var(--edge),
        inset var(--px) var(--px) 0 0 rgba(0, 0, 0, 0.35);
}
.btn:focus-visible, .hud-sound:focus-visible, .back-link:focus-visible {
    outline: 2px dashed var(--coin);
    outline-offset: 6px;
}
.btn:disabled { cursor: default; }
/* пока идёт запрос: кнопки гаснут не сразу, чтобы быстрый ответ не мигал */
.app.busy .btn:disabled:not(.is-right):not(.is-wrong) {
    opacity: 0.55;
    transition: opacity 0.1s 0.15s;
}

.btn-primary { --fill: var(--coin); color: var(--night); text-align: center; }
.btn-quiet { --fill: var(--night-2); text-align: center; }
.btn-small { width: auto; min-height: 40px; padding: 10px 12px; text-align: center; }

/* курсор-треугольник, как в меню игр */
.btn-option, .btn-menu { padding-left: 32px; }
.btn-option::before, .btn-menu::before {
    content: '';
    position: absolute;
    left: 12px;
    top: 50%;
    margin-top: -6px;
    border-left: 8px solid var(--coin);
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    visibility: hidden;
}
.btn-option:active::before, .btn-option:focus-visible::before, .btn-option.is-picked::before,
.btn-menu:active::before, .btn-menu:focus-visible::before { visibility: visible; }
@media (hover: hover) {
    .btn-option:hover:not(:disabled)::before, .btn-menu:hover:not(:disabled)::before { visibility: visible; }
}

.btn-option {
    --fill: var(--window-deep);
    font-size: clamp(10px, 2.9vw, 13px);
    line-height: 1.5;
}
.btn-option.is-right { --fill: var(--pipe); --edge: var(--pipe); color: var(--night); }
.btn-option.is-wrong { --fill: var(--brick); --edge: var(--brick); }
.btn-option.is-right::before { border-left-color: var(--night); }

.btn-hint { --fill: var(--night-2); --edge: var(--sky); color: var(--sky); text-align: center; font-size: 10px; }

/* строки меню внутри окна — без своей рамки */
.btn-menu {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    margin: 0;
    padding-top: 12px;
    padding-bottom: 12px;
    background: transparent;
    box-shadow: none;
}
.btn-menu:active:not(:disabled) { transform: none; box-shadow: none; background: rgba(255, 255, 255, 0.08); }
.menu-note { font-size: 9px; color: var(--ash); }

.back-link {
    appearance: none;
    align-self: flex-start;
    margin: 0 0 8px;
    padding: 8px 4px 8px 18px;
    border: 0;
    background: none;
    color: var(--ash);
    font: inherit;
    font-size: 10px;
    position: relative;
    cursor: pointer;
}
.back-link::before {
    content: '';
    position: absolute;
    left: 2px;
    top: 50%;
    margin-top: -5px;
    border-right: 7px solid currentColor;
    border-top: 5px solid transparent;
    border-bottom: 5px solid transparent;
}

/* ── окна ───────────────────────────────────────────────── */

.window {
    margin: var(--px);
    padding: 16px;
    background: var(--window);
    box-shadow:
        0 calc(-1 * var(--px)) 0 0 var(--edge),
        0 var(--px) 0 0 var(--edge),
        calc(-1 * var(--px)) 0 0 0 var(--edge),
        var(--px) 0 0 0 var(--edge),
        inset 0 0 0 var(--px) var(--window-deep);
}
.window-title { margin-bottom: 10px; color: var(--coin); font-size: 12px; line-height: 1.5; }
.window p + p { margin-top: 12px; }
.menu { display: flex; flex-direction: column; margin: 0 -8px; }

/* ── старт ──────────────────────────────────────────────── */

.logo { margin: 18px 0 10px; text-align: center; }
.logo-title {
    color: var(--coin);
    font-size: clamp(28px, 10vw, 44px);
    line-height: 1.2;
    text-shadow: 4px 4px 0 var(--coin-shadow);
}
.logo-sub { margin-top: 12px; font-size: 11px; }

.rules { padding: 0 4px; color: var(--ash); font-size: 9px; line-height: 1.9; }
.rules p + p { margin-top: 8px; }
.credit { margin-top: auto; padding-top: 8px; text-align: center; color: var(--ash); font-size: 9px; }
.link { color: var(--sky); }

/* ── раунд ──────────────────────────────────────────────── */

.screen-round, .screen-continue { gap: 10px; }

.hud {
    display: flex;
    align-items: center;
    gap: 14px;
    min-height: 40px;
    font-size: 12px;
}
.hud-item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.hud-label { color: var(--ash); font-size: 9px; }
.hud-score .hud-value { color: var(--coin); }
.hud-sound {
    appearance: none;
    margin-left: auto;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 0;
    background: none;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* корпус телевизора и экран; картинку размещает app.js (fitImage), чтобы её рамка была точной */
.tv {
    flex: 1 1 0;
    min-height: 150px;
    display: flex;
    flex-direction: column;
    padding: 10px 10px 4px;
    background: var(--plastic);
    border-radius: 10px;
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.08), inset 0 -3px 0 rgba(0, 0, 0, 0.45);
}
.tv-screen {
    position: relative;
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
    background: #000;
    border-radius: 18px / 14px;
}
.tv-screen::after {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    border-radius: inherit;
    box-shadow: inset 0 0 28px rgba(0, 0, 0, 0.85);
}
.shot {
    position: absolute;
    display: block;
    max-width: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
}
.shot.pixelated, .shot.zooming { image-rendering: pixelated; }
.tv-status {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 12px;
    color: var(--ash);
    font-size: 10px;
    text-align: center;
}
.tv-plate {
    padding-top: 4px;
    color: #6e6e80;
    font-size: 7px;
    letter-spacing: 1px;
    text-align: center;
}

.round-caption { color: var(--ash); font-size: 9px; text-align: center; }
.options { display: flex; flex-direction: column; gap: 4px; }

/* ── CONTINUE, итог, победа ─────────────────────────────── */

.screen-title { margin-top: 8px; font-size: 20px; line-height: 1.3; text-align: center; }
.screen-title.is-bad { color: var(--brick); text-shadow: 3px 3px 0 #000; }
.screen-title.is-win { color: var(--coin); text-shadow: 4px 4px 0 var(--coin-shadow); }
.lead { text-align: center; font-size: 10px; line-height: 1.8; }

.reveal { font-size: 10px; line-height: 1.8; text-align: center; }
.reveal strong { display: block; margin-top: 4px; color: var(--pipe); font-weight: normal; font-size: 12px; }
.continue-offer:empty { display: none; }

/* отсчёт CONTINUE: большие цифры; каждая новая секунда «выпрыгивает», последние три — красные и дрожат.
   app.js ставит новый .continue-digit на каждую секунду — анимация запускается заново; в reduced — без анимации */
.continue-offer { text-align: center; }
.continue-label { color: var(--coin); font-size: 10px; letter-spacing: 1px; }
.continue-count {
    margin-top: 6px;
    color: var(--chalk);
    font-size: clamp(44px, 16vw, 64px);
    line-height: 1.1;
    text-shadow: 4px 4px 0 var(--coin-shadow);
}
.continue-count.is-long { font-size: clamp(28px, 10vw, 40px); } /* открыли снова во время окна оплаты: 4:00 */
.continue-count.is-paused { opacity: 0.5; }
.continue-digit { display: inline-block; animation: count-pop 320ms steps(4) both; }
.continue-digit.is-hot { color: var(--brick); text-shadow: 4px 4px 0 #000; animation: count-shake 420ms steps(1) both; }
@keyframes count-pop {
    0% { transform: scale(1.5); }
    40% { transform: scale(0.9); }
    100% { transform: none; }
}
@keyframes count-shake {
    0% { transform: scale(1.3) translate(-3px, 0); }
    20% { transform: translate(3px, -2px); }
    40% { transform: translate(-2px, 1px); }
    60% { transform: translate(2px, 0); }
    80%, 100% { transform: none; }
}
.reduced .continue-digit { animation: none; }
.continue-status { margin-top: 6px; color: var(--ash); font-size: 10px; line-height: 1.8; }
.continue-status.is-waiting { color: var(--chalk); }
.continue-status.is-waiting::after { /* «Оплата обрабатывается…» с мигающим курсором, как «Загрузка» */
    content: '';
    display: inline-block;
    width: 0.7em;
    height: 1em;
    margin-left: 6px;
    vertical-align: -2px;
    background: currentColor;
    animation: blink 1s steps(1) infinite;
}
.reduced .continue-status.is-waiting::after { animation: none; }

/* окно условий покупки поверх экрана CONTINUE (под эффектами, ЭЛТ-полосами и тостом) */
.modal {
    position: fixed;
    inset: 0;
    z-index: 40;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: calc(var(--safe-top) + 12px) calc(var(--safe-right) + 12px)
             calc(var(--safe-bottom) + 12px) calc(var(--safe-left) + 12px);
    background: rgba(11, 10, 46, 0.97);
}
.modal-body { display: flex; flex-direction: column; gap: 8px; max-width: 496px; min-height: 100%; margin: 0 auto; }
.modal .window p { font-size: 10px; line-height: 1.8; }

.score-big {
    color: var(--coin);
    font-size: clamp(32px, 12vw, 48px);
    line-height: 1.2;
    text-align: center;
    text-shadow: 4px 4px 0 var(--coin-shadow);
}
.score-label { color: var(--ash); font-size: 10px; text-align: center; }
.stats {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px 12px;
    margin-top: 18px;
    font-size: 10px;
}
.stats dt { color: var(--ash); }
.stats dd { text-align: right; }
.window .reveal { margin-top: 18px; }

.actions { display: flex; flex-direction: column; gap: 4px; margin-top: auto; padding-top: 8px; }

/* ── загрузка, сообщения ────────────────────────────────── */

.loading { margin: auto; color: var(--ash); font-size: 12px; }
.loading::after {
    content: '';
    display: inline-block;
    width: 0.7em;
    height: 1em;
    margin-left: 6px;
    vertical-align: -2px;
    background: currentColor;
    animation: blink 1s steps(1) infinite;
}
.reduced .loading::after { animation: none; }
@keyframes blink { 50% { opacity: 0; } }

.toast {
    --edge: var(--brick);
    position: fixed;
    left: 50%;
    bottom: calc(var(--safe-bottom) + 20px);
    z-index: 60;
    width: min(460px, calc(100% - 40px));
    padding: 12px 14px;
    transform: translateX(-50%);
    background: var(--night-2);
    color: var(--chalk);
    font-size: 10px;
    line-height: 1.8;
    box-shadow:
        0 calc(-1 * var(--px)) 0 0 var(--edge),
        0 var(--px) 0 0 var(--edge),
        calc(-1 * var(--px)) 0 0 0 var(--edge),
        var(--px) 0 0 0 var(--edge);
}

/* ── эффекты (effects.js) ───────────────────────────────── */

/* слой поверх экрана: салют, вспышки, баннеры порогов; касания проходят насквозь */
.fx-layer {
    position: fixed;
    inset: 0;
    z-index: 45; /* под ЭЛТ-полосами (50) и тостом (60) */
    overflow: hidden;
    pointer-events: none;
}
.fx-layer * { pointer-events: none; }
.fx-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    image-rendering: pixelated; /* canvas мелкий: «пиксель» салюта = 3 CSS-пикселя */
}

/* вспышка на весь экран: гаснет ступеньками; яркость и длительность задаёт effects.js */
.fx-flash {
    position: absolute;
    inset: 0;
    opacity: 0;
    background: var(--pipe);
}
.fx-flash.is-bad { background: var(--brick); }
.fx-flash.is-gold { background: var(--coin); }
.fx-flash.is-on { animation: fx-flash var(--fx-dur, 300ms) steps(4) both; }
@keyframes fx-flash {
    from { opacity: var(--fx-peak, 0.3); }
    to { opacity: 0; }
}

/* неверный ответ: экран дёргается рывками, как спрайт от удара (SHAKE_MS в effects.js) */
.fx-shake { animation: fx-shake 400ms steps(1) both; }
@keyframes fx-shake {
    0% { transform: translate(-6px, 2px); }
    12% { transform: translate(6px, -2px); }
    24% { transform: translate(-5px, -1px); }
    36% { transform: translate(5px, 2px); }
    50% { transform: translate(-3px, 1px); }
    64% { transform: translate(3px, -1px); }
    80% { transform: translate(-1px, 0); }
    100% { transform: none; }
}

/* баннер порога / победы: --fx-size и --fx-dur задаёт effects.js, каждый следующий порог крупнее */
.fx-banner {
    --edge: var(--coin);
    position: absolute;
    left: 0;
    right: 0;
    top: calc(var(--safe-top) + 16vh);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0 8px;
    text-align: center;
    animation: fx-pop var(--fx-dur, 1600ms) steps(1) both;
}
.fx-banner-title {
    display: block;
    color: var(--coin);
    font-size: var(--fx-size, 36px);
    line-height: 1.15;
    white-space: nowrap;
    /* чёрная пиксельная обводка + тень: надпись читается поверх любого кадра */
    text-shadow:
        3px 0 0 #000, -3px 0 0 #000, 0 3px 0 #000, 0 -3px 0 #000,
        0.12em 0.12em 0 var(--coin-shadow);
}
.fx-banner-sub {
    margin-top: 14px;
    padding: 6px 10px;
    background: var(--night-2);
    color: var(--chalk);
    font-size: 10px;
    line-height: 1.6;
    box-shadow:
        0 -3px 0 0 var(--edge), 0 3px 0 0 var(--edge),
        -3px 0 0 0 var(--edge), 3px 0 0 0 var(--edge);
}
.fx-banner.lvl-50 { --edge: var(--pipe); }
.fx-banner.lvl-50 .fx-banner-title {
    color: var(--pipe);
    text-shadow: 3px 0 0 #000, -3px 0 0 #000, 0 3px 0 #000, 0 -3px 0 #000, 0.12em 0.12em 0 #005800;
}
.fx-banner.lvl-100 { --edge: var(--sky); }
.fx-banner.lvl-100 .fx-banner-title {
    color: var(--sky);
    text-shadow: 3px 0 0 #000, -3px 0 0 #000, 0 3px 0 #000, 0 -3px 0 #000, 0.12em 0.12em 0 #0058f8;
    animation: fx-glow 480ms steps(1) infinite;
}
.fx-banner.lvl-250 { --edge: var(--pink); }
.fx-banner.lvl-250 .fx-banner-title, .fx-banner.lvl-win .fx-banner-title {
    animation: fx-rainbow 360ms steps(1) infinite;
}
.fx-banner.lvl-win { top: calc(var(--safe-top) + 12vh); }
@keyframes fx-pop {
    0% { opacity: 1; transform: scale(0.3); }
    6% { transform: scale(0.7); }
    12% { transform: scale(1.25); }
    18% { transform: scale(0.94); }
    24% { transform: scale(1.04); }
    30% { transform: scale(1); }
    84% { opacity: 1; }
    88% { opacity: 0; }
    92% { opacity: 1; }
    96%, 100% { opacity: 0; transform: scale(1); }
}
@keyframes fx-glow {
    0% { color: var(--sky); }
    50% { color: var(--chalk); }
}
@keyframes fx-rainbow {
    0% { color: var(--coin); }
    25% { color: var(--pink); }
    50% { color: var(--sky); }
    75% { color: var(--pipe); }
}
/* reduced: баннер просто появляется и гаснет, без прыжков и мигания */
.reduced .fx-banner { animation: fx-fade var(--fx-dur, 1600ms) linear both; }
.reduced .fx-banner .fx-banner-title { animation: none; }
@keyframes fx-fade {
    0% { opacity: 0; }
    8%, 85% { opacity: 1; }
    100% { opacity: 0; }
}
/* на экране уже новый кадр: баннер быстро гаснет и не закрывает его (SETTLE_MS в effects.js) */
.fx-banner.is-settling, .reduced .fx-banner.is-settling { animation: fx-settle 150ms linear both; }
@keyframes fx-settle {
    from { opacity: 1; }
    to { opacity: 0; }
}


.noscript { padding: 24px; text-align: center; }

@media (prefers-reduced-motion: reduce) {
    .loading::after { animation: none; }
    .continue-digit, .continue-status.is-waiting::after { animation: none; }
    .btn:active:not(:disabled) { transform: none; }
}
