@font-face {
    font-family: Archivo Black;
    src: url(/js/gta-chess/archivo-black.ttf) format('truetype');
    font-display: swap;
}
:root {
    color-scheme: dark;
    font-family: Arial, Helvetica, sans-serif;
    color: #fff5e4;
    background: #312437;
}
* {
    box-sizing: border-box;
}
body {
    margin: 0;
}
[hidden] {
    display: none !important;
}
#arcade {
    position: relative;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    isolation: isolate;
    background: linear-gradient(#673d67, #ed926c 60%, #423441);
}
#world,
.shade {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}
.shade {
    background:
        linear-gradient(90deg, rgba(20, 19, 32, 0.93), rgba(27, 25, 37, 0.78) 28%, transparent 64%),
        linear-gradient(0deg, rgba(19, 19, 32, 0.77), transparent 23%);
    transition: opacity 0.4s;
}
#arcade:not([data-screen='garage']) .shade {
    opacity: 0;
}
button,
a,
input {
    font: inherit;
}
button,
a {
    touch-action: manipulation;
}
button {
    cursor: pointer;
}
button:focus-visible,
a:focus-visible,
input:focus-visible + span {
    outline: 3px solid #fff;
    outline-offset: 4px;
}
.topbar {
    position: absolute;
    top: max(22px, env(safe-area-inset-top));
    left: 4.5%;
    right: 4.5%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 6;
    pointer-events: none;
}
.bar-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}
.bar-group:last-child {
    justify-content: flex-end;
}
.bar-group > * {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    width: 118px;
    height: 33px;
    white-space: nowrap;
    line-height: 1;
    pointer-events: auto;
    cursor: pointer;
    font-family: inherit;
    border: 1px solid #fff5e45c;
    border-radius: 4px;
    color: #fff5e4;
    background: #201c29b8;
    text-decoration: none;
    padding: 0;
    font-size: 13px;
    font-weight: 700;
}
/* Кнопка «Пройти уровень» — только в локальной версии. */
.bar-group .dev {
    border-style: dashed;
    color: #9ff0d6;
}
#garage {
    position: absolute;
    top: 50%;
    left: 7%;
    transform: translateY(-46%);
    width: min(410px, 42%);
    text-shadow: 0 1px 2px #281c2c66;
}
.edition,
legend,
#level-index {
    font-size: 11px;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    font-weight: 800;
}
.edition {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #f7c679;
}
.flag {
    display: inline-block;
    width: 25px;
    height: 12px;
    background: repeating-conic-gradient(#f7c679 0 25%, transparent 0 50%) 50%/8px 8px;
    transform: skewX(-12deg);
}
h1 {
    font:
        clamp(64px, min(8.1vw, 11.5vh), 138px) / 0.79 'Archivo Black',
        Impact,
        sans-serif;
    letter-spacing: -0.09em;
    margin: 0.24em 0 0.25em;
    transform: skewY(-3deg);
    transform-origin: left;
    color: #fff2d8;
    paint-order: stroke fill;
    -webkit-text-stroke: 4px #201723;
    text-shadow:
        1px 4px #201723,
        2px 7px #201723,
        3px 9px #dc7654;
}
h1 span {
    display: block;
}
.rules {
    font-size: clamp(14px, 1.15vw, 18px);
    line-height: 1.5;
    max-width: 390px;
    margin: 23px 0 18px;
    color: #fff2e2;
}
fieldset {
    padding: 0;
    margin: 0 0 18px;
    border: 0;
}
legend {
    color: #edcda4;
    margin-bottom: 8px;
    letter-spacing: 0.08em;
}
#cars label {
    display: inline-block;
    position: relative;
    cursor: pointer;
    margin: 0 2px 4px 0;
}
#cars input {
    position: absolute;
    opacity: 0;
}
#cars span {
    display: inline-block;
    padding: 8px 13px;
    border: 1px solid #bfb8ae9e;
    border-radius: 4px;
    font-size: 14px;
    background: #281e2cd0;
}
#cars input:checked + span {
    background: #fff1da;
    border-color: #fff1da;
    color: #241c29;
    font-weight: bold;
}
.primary {
    display: inline-block;
    border: 0;
    border-radius: 4px;
    background: #ffc669;
    color: #241b25;
    text-decoration: none;
    font-size: 17px;
    font-weight: 800;
    padding: 12px 25px;
    box-shadow: 0 3px 0 #926344;
}
.primary:hover {
    background: #ffdb9e;
}
.primary:disabled {
    cursor: wait;
    opacity: 0.72;
}
.status {
    font-size: 13px;
    margin: 9px 0 0;
}
.status:empty {
    display: none;
}
.controls-legend {
    display: flex;
    align-items: center;
    gap: 21px;
    position: absolute;
    bottom: 66px;
    left: 7%;
    font-size: 12px;
    color: #ffefdf;
}
/* Ссылка на портал в самом низу стартового экрана. */
.site-link {
    position: absolute;
    left: 7%;
    bottom: max(30px, env(safe-area-inset-bottom));
    margin: 0;
    font-size: 16px;
    color: #d9c9b6;
    pointer-events: auto;
}
.site-link a {
    color: #ffd18a;
    font-weight: bold;
    text-decoration: none;
    border-bottom: 1px solid #ffd18a66;
}
.site-link a:hover,
.site-link a:focus-visible {
    color: #fff1d4;
    border-bottom-color: currentColor;
}
.controls-legend span {
    white-space: nowrap;
}
kbd {
    display: inline-block;
    border: 1px solid #d1c4b291;
    border-bottom-width: 2px;
    padding: 3px 5px;
    margin-right: 2px;
    border-radius: 4px;
    background: #201c28bd;
    color: #fff;
    font: 700 11px Arial;
}
#hud,
#result {
    position: absolute;
    inset: 0;
    pointer-events: none;
}
.mission {
    position: absolute;
    right: 4.5%;
    top: 76px;
    text-align: right;
    color: #fff6de;
    text-shadow: 1px 2px 3px #15121b;
}
#level-index {
    color: #ffdb99;
}
#goal {
    display: block;
    font-size: clamp(17px, 2vw, 28px);
    margin-top: 4px;
}
#clock {
    margin-top: 6px;
    font: 700 clamp(15px, 1.6vw, 22px) / 1 'Courier New', monospace;
    color: #9ff0d6;
    letter-spacing: 0.04em;
}
#radar {
    width: clamp(86px, 10vw, 140px);
    height: auto;
    position: absolute;
    bottom: 4%;
    left: 3%;
}
#field,
#message {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    width: max-content;
    max-width: 82vw;
    text-shadow: 0 2px 4px #231d27;
}
#field {
    bottom: 5%;
    border-radius: 4px;
    background: #1f1c29d9;
    padding: 7px 15px;
    font-size: 14px;
}
#message {
    bottom: 13%;
    font-weight: bold;
}
#level-name {
    position: absolute;
    bottom: 9%;
    right: 4%;
    font:
        bold italic clamp(21px, 3vw, 49px) Georgia,
        serif;
    color: #ffd389;
    text-shadow: 2px 3px #281d29;
    transition: opacity 0.5s;
}
#result {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 22px;
    background: #100b172c;
}
#result h2 {
    margin: 0;
    text-align: center;
    font:
        900 clamp(36px, 8vw, 110px) / 1.05 Impact,
        'Arial Black',
        sans-serif;
    letter-spacing: -0.045em;
    color: #ffd084;
    text-shadow:
        2px 4px 0 #19121a,
        0 5px 12px #000b;
}
#result button,
#result a {
    pointer-events: auto;
}
#result-time {
    margin: -8px 0 0;
    font: 700 clamp(20px, 3vw, 32px) / 1 'Courier New', monospace;
    color: #9ff0d6;
    text-shadow: 0 2px 4px #15121b;
}
.share {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
}
.share a,
.share button {
    border: 1px solid #fff5e47a;
    border-radius: 6px;
    background: #201c29d9;
    color: #fff5e4;
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    padding: 11px 16px;
    text-decoration: none;
    cursor: pointer;
}
.share .share-vk {
    background: #0077ff;
    border-color: #0077ff;
    color: #fff;
}
[data-screen='wasted'] #world {
    filter: grayscale(1) brightness(0.58);
}
[data-screen='wasted'] #result h2 {
    color: #b83d41;
    text-shadow:
        2px 4px #191015,
        0 7px 9px #190d12;
}
#touch {
    --pad: max(14px, env(safe-area-inset-bottom));
    --radar: clamp(86px, 10vw, 140px);
    --stick: clamp(118px, 30vmin, 150px);
    --grab: 74px;
    position: absolute;
    inset: 0;
    display: none;
    pointer-events: none;
}
#touch .grab,
#touch .stick {
    position: absolute;
    pointer-events: auto;
    touch-action: none;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}
/* Захват — слева, рядом с радаром и по центру его высоты. */
#touch .grab {
    left: calc(3% + var(--radar) + 14px);
    bottom: calc(var(--pad) + (var(--radar) - var(--grab)) / 2);
    width: var(--grab);
    height: var(--grab);
    border-radius: 50%;
    border: 2px solid #ffd18a;
    background: #282333e6;
    color: #ffe6b8;
    font-weight: bold;
    font-size: 13px;
    box-shadow: 0 3px 10px #0008;
}
#touch .grab:active {
    background: #ffbd57;
    color: #241c34;
}
/* Джойстик — справа, на уровне радара. */
#touch .stick {
    right: 3%;
    /* Джойстик выше радара: центры совпадают, но не ниже края экрана. */
    bottom: max(var(--pad), calc(var(--pad) + (var(--radar) - var(--stick)) / 2));
    width: var(--stick);
    height: var(--stick);
    border-radius: 50%;
    border: 2px solid #fff6;
    background: radial-gradient(circle, #ffffff14 0 40%, #1a1622b3 41%);
    box-shadow: 0 3px 12px #0007;
}
#touch .knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 46%;
    height: 46%;
    margin: -23% 0 0 -23%;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #fff1d4, #e9a94f 70%);
    border: 2px solid #fff8;
    box-shadow: 0 3px 8px #0009;
    pointer-events: none;
}
@media (any-pointer: coarse) {
    #arcade {
        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
    }
    #touch {
        display: block;
    }
    #radar {
        bottom: max(14px, env(safe-area-inset-bottom));
    }
    #field {
        bottom: calc(max(14px, env(safe-area-inset-bottom)) + clamp(118px, 30vmin, 150px) + 12px);
    }
    #message {
        bottom: calc(max(14px, env(safe-area-inset-bottom)) + clamp(118px, 30vmin, 150px) + 54px);
    }
    #level-name {
        bottom: calc(max(14px, env(safe-area-inset-bottom)) + clamp(118px, 30vmin, 150px) + 96px);
    }
}
@media (max-width: 700px) {
    /* Узкий экран: на кнопках остаются значки и состояние. */
    .topbar .long {
        display: none;
    }
    .bar-group {
        gap: 6px;
    }
    .bar-group > * {
        width: min(59px, calc((91vw - 24px) / 5));
        gap: 2px;
        font-size: 12px;
    }
}
@media (max-width: 700px) and (orientation: portrait) {
    .shade {
        background: linear-gradient(0deg, #211d2a 4%, #232030f2 41%, #2a22303b 76%, transparent);
    }
    #garage {
        width: 88%;
        top: auto;
        bottom: 112px;
        transform: none;
        left: 6%;
    }
    h1 {
        font-size: clamp(50px, 12vw, 75px);
        margin: 0.18em 0;
    }
    h1 span {
        display: inline;
    }
    h1 span + span {
        margin-left: 0.12em;
    }
    .rules {
        margin: 14px 0;
        font-size: 14px;
    }
    .controls-legend {
        left: 6%;
        gap: 7px;
        font-size: 10px;
        bottom: 62px;
        flex-wrap: wrap;
    }
    .site-link {
        left: 6%;
        font-size: 15px;
    }
    .topbar {
        top: 14px;
    }
    .mission {
        top: 62px;
    }
    #level-name {
        bottom: 27%;
    }
}
@media (max-height: 580px) and (orientation: landscape) {
    #garage {
        top: 54%;
        width: 58%;
    }
    h1 {
        font-size: clamp(43px, 12vh, 70px);
    }
    h1 span {
        display: inline;
    }
    h1 span + span {
        margin-left: 0.12em;
    }
    .rules {
        margin: 10px 0;
        font-size: 13px;
    }
    .topbar {
        top: 8px;
    }
    .controls-legend {
        bottom: 58px;
    }
    fieldset {
        margin-bottom: 8px;
    }
    .edition {
        font-size: 9px;
    }
}
/* Телефон боком: середина низа свободна, подсказки опускаются между кнопками. */
@media (any-pointer: coarse) and (orientation: landscape) {
    #field {
        bottom: max(14px, env(safe-area-inset-bottom));
    }
    #message {
        bottom: calc(max(14px, env(safe-area-inset-bottom)) + 44px);
    }
}
