/* ===== локально скачанные шрифты Rubik ===== */
@font-face {
    font-family: 'Rubik';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('../assets/fonts/rubik-cyrillic-400.woff2') format('woff2');
    unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
    font-family: 'Rubik';
    font-style: normal;
    font-weight: 400;
    font-display: swap;
    src: url('../assets/fonts/rubik-latin-400.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-face {
    font-family: 'Rubik';
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url('../assets/fonts/rubik-cyrillic-500.woff2') format('woff2');
    unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
    font-family: 'Rubik';
    font-style: normal;
    font-weight: 500;
    font-display: swap;
    src: url('../assets/fonts/rubik-latin-500.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-face {
    font-family: 'Rubik';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url('../assets/fonts/rubik-cyrillic-700.woff2') format('woff2');
    unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116;
}
@font-face {
    font-family: 'Rubik';
    font-style: normal;
    font-weight: 700;
    font-display: swap;
    src: url('../assets/fonts/rubik-latin-700.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;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --accent: #ffcd4a;
    --accent-dark: #5a3a00;
    --accent-soft: #d6a72a;
    --bg: #0b0b0b;
    --panel: #1a1a1a;
    --panel-2: #222;
    --border: #333;
    --text: #eee;
    --text-soft: #bbb;
    --text-muted: #888;
    --danger: #ff6a6a;
    --ok: #5aff8c;
    --font-body: 'Rubik', 'Segoe UI', system-ui, -apple-system, 'Helvetica Neue', Arial, sans-serif;
    --font-logo: 'Courier New', Courier, monospace;
}

html { background: var(--bg); }
html, body {
    height: 100%; width: 100%;
    color: var(--text);
    font-family: var(--font-body);
    overflow: hidden;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    font-size: 16px;
    line-height: 1.5;
}
body {
    background: transparent;
    /* по-умолчанию выделение текста разрешено — на кнопках/контроллере оно перекрыто */
    user-select: text;
    -webkit-user-select: text;
    display: flex;
    flex-direction: column;
}

/* всё что кликабельное / интерактивное — текст не выделяем */
button, summary, .seg, .dpad-area, .controller,
.lobby-row, .pal-btn, .palette, .ab-pick-btn,
.refresh-btn, .layout-toggle, .ss-dot,
.bonus-table td.bi {
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}
#screen-host-game, #screen-player-game,
#screen-host-game *, #screen-player-game * {
    user-select: none;
    -webkit-user-select: none;
}

input, textarea {
    user-select: text !important;
    -webkit-user-select: text !important;
    -webkit-touch-callout: default !important;
    -webkit-tap-highlight-color: rgba(255,205,74,.3);
    touch-action: auto;
}

/* фоновый canvas с танковой анимацией — fixed, не двигается при скролле */
.bg-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 0;
    opacity: 0.45;
    pointer-events: none;
    image-rendering: pixelated;
}
/* мягкая виньетка поверх анимации, ниже UI — улучшает читаемость текста */
body::after {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 0;
    background: radial-gradient(ellipse 120% 100% at center, rgba(0,0,0,0) 0%, rgba(0,0,0,0.25) 75%, rgba(0,0,0,0.6) 100%);
    pointer-events: none;
}

.screen {
    display: none;
    position: relative;
    z-index: 1;
    flex: 1;
    padding: 20px;
    flex-direction: column;
    align-items: stretch;
    gap: 16px;
    overflow: auto;
}
.screen.active { display: flex; }

/* ограничение ширины — только в меню/лобби, не на игровых экранах.
   max-width реализован через горизонтальный padding (а не width+margin),
   чтобы .screen оставался во всю ширину и скроллбар был у края экрана,
   а не «внутри блока». */
#screen-home, #screen-setup, #screen-join,
#screen-host-lobby, #screen-player-lobby, #screen-end {
    padding: 24px max(22px, calc((100% - 760px) / 2)) 32px;
}

.home-inner {
    display: flex;
    flex-direction: column;
    gap: 18px;
    width: 100%;
    margin: auto 0;
}

.logo {
    font-family: var(--font-logo);
    font-size: clamp(48px, 10vw, 92px);
    font-weight: bold;
    letter-spacing: 0.2em;
    text-align: center;
    margin: 0 0 2vh;
    color: var(--accent);
    text-shadow: 5px 5px 0 var(--accent-dark);
    line-height: 1;
    animation: logo-glow 3.6s ease-in-out infinite;
}
@keyframes logo-glow {
    0%, 100% { text-shadow: 5px 5px 0 var(--accent-dark), 0 0 14px rgba(255,205,74,0.0); }
    50%      { text-shadow: 5px 5px 0 var(--accent-dark), 0 0 28px rgba(255,205,74,0.35); }
}

.home-buttons { display: flex; flex-direction: column; gap: 12px; max-width: 460px; margin: 0 auto; width: 100%; }

.big-btn {
    background: linear-gradient(180deg, #ffd96a 0%, #ffcd4a 50%, #e6b03a 100%);
    color: #1a1a1a;
    border: 3px solid var(--accent-dark);
    border-radius: 4px;
    padding: 16px 22px;
    font-family: var(--font-body);
    font-size: 18px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    cursor: pointer;
    box-shadow: 4px 4px 0 #000, inset 0 1px 0 rgba(255,255,255,0.5);
    transition: transform 0.06s, box-shadow 0.06s, filter 0.06s;
}
.big-btn:hover { filter: brightness(1.07); }
.big-btn:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 #000, inset 0 1px 0 rgba(255,255,255,0.5); }

.ghost-btn {
    background: rgba(20,20,20,0.7);
    color: #ddd;
    border: 2px solid #666;
    border-radius: 4px;
    padding: 13px 18px;
    font-family: var(--font-body);
    font-size: 16px;
    font-weight: 500;
    letter-spacing: 0.04em;
    cursor: pointer;
    transition: background 0.1s, border-color 0.1s;
}
.ghost-btn:hover { border-color: #aaa; }
.ghost-btn:active { background: #2a2a2a; }

.footer-hint, .hint {
    color: var(--text-muted);
    text-align: center;
    font-size: 14px;
    margin-top: 10px;
    line-height: 1.6;
}
.hint.ability-hint { text-align: left; margin-top: 6px; color: var(--accent); font-size: 13px; }
.muted { color: var(--text-muted); font-size: 13px; font-weight: 400; }

/* статус сервера — большой и видимый на главной */
.server-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    background: rgba(20,20,20,0.78);
    border: 2px solid var(--border);
    border-radius: 6px;
    padding: 10px 18px;
    max-width: 460px;
    margin: 6px auto 0;
    width: 100%;
    font-size: 14px;
    color: var(--text-soft);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}
.server-status .ss-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-muted);
    box-shadow: 0 0 8px currentColor;
    flex-shrink: 0;
}
.server-status .ss-text { flex: 1; text-align: left; letter-spacing: 0.02em; }
.server-status .ss-ping {
    font-family: var(--font-logo);
    font-size: 12px;
    color: var(--text-muted);
    min-width: 56px;
    text-align: right;
}
.server-status[data-state="ok"]      { border-color: rgba(90,255,140,0.35); }
.server-status[data-state="ok"]      .ss-dot { background: var(--ok); color: var(--ok); }
.server-status[data-state="ok"]      .ss-text { color: #cfe; }
.server-status[data-state="err"]     { border-color: rgba(255,90,90,0.4); }
.server-status[data-state="err"]     .ss-dot { background: var(--danger); color: var(--danger); }
.server-status[data-state="err"]     .ss-text { color: #fcc; }
.server-status[data-state="pending"] .ss-dot { background: var(--accent); color: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.server-status[data-state="pending"] .ss-text { color: #fed; }
@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.3; transform: scale(0.7); } }

/* кнопка полного экрана — top-right, всегда поверх всего */
.fs-btn {
    position: fixed;
    top: 8px;
    right: 8px;
    z-index: 1000;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 2px solid var(--border);
    border-radius: 6px;
    background: rgba(20, 20, 20, 0.72);
    color: var(--accent);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    transition: background 0.1s, border-color 0.1s, transform 0.05s;
}
.fs-btn:hover  { border-color: var(--accent); }
.fs-btn:active { transform: scale(0.92); background: rgba(255, 205, 74, 0.18); }
.fs-btn .fs-ic-exit  { display: none; }
.fs-btn.is-full .fs-ic-enter { display: none; }
.fs-btn.is-full .fs-ic-exit  { display: block; }
.fs-btn[hidden] { display: none !important; }
/* на игровых экранах HUD получает правый отступ под кнопку */
#screen-host-game .host-hud,
#screen-player-game .player-hud { padding-right: 54px; }

h1, h2, h3 { font-family: var(--font-body); font-weight: 700; letter-spacing: 0.06em; color: var(--accent); }
h1 { font-size: 44px; }
h2 { font-size: 24px; }
h3 { font-size: 18px; margin-top: 10px; text-transform: uppercase; letter-spacing: 0.12em; }

.form-row { display: flex; flex-direction: column; gap: 8px; }
.form-row label { font-size: 13px; color: var(--text-soft); text-transform: uppercase; letter-spacing: 0.12em; font-weight: 500; }
.form-row input {
    background: rgba(20,20,20,0.85);
    border: 2px solid #555;
    border-radius: 4px;
    color: #fff;
    padding: 12px 14px;
    font-family: var(--font-body);
    font-size: 18px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    transition: border-color 0.1s, box-shadow 0.1s;
}
.form-row input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,205,74,0.18); }

.seg { display: flex; gap: 4px; flex-wrap: wrap; }
.seg.compact { flex: 1; min-width: 0; }
.seg button {
    flex: 1;
    min-width: 64px;
    background: rgba(20,20,20,0.85);
    color: var(--text-soft);
    border: 2px solid #444;
    border-radius: 4px;
    padding: 10px 10px;
    font-family: var(--font-body);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: border-color 0.1s, background 0.1s;
}
.seg button:hover { border-color: #666; }
.seg button.on { background: var(--accent); color: #1a1a1a; border-color: var(--accent-dark); font-weight: 700; }

.num-row { display: flex; gap: 8px; align-items: stretch; }
.num-row .num-input {
    width: 100px;
    text-align: center;
    font-size: 20px;
    text-transform: none;
    padding: 6px 8px;
}

.ability-seg button { padding: 12px 6px; font-size: 15px; }

.form-actions { display: flex; gap: 10px; margin-top: 10px; }
.form-actions .big-btn { flex: 2; }
.form-actions .ghost-btn { flex: 1; }
.err { color: #f66; font-size: 16px; min-height: 1em; }

/* лобби хост */
.lobby-head { display: flex; gap: 14px; align-items: stretch; }
.lobby-code-block {
    flex: 1;
    background: rgba(20,20,20,0.85);
    border: 3px solid var(--border);
    border-radius: 6px;
    padding: 14px 18px;
    text-align: center;
}
.lobby-code-label { font-size: 11px; color: var(--text-soft); text-transform: uppercase; letter-spacing: 0.2em; }
.lobby-code {
    font-family: var(--font-logo);
    font-size: clamp(36px, 7vw, 64px);
    color: var(--accent);
    letter-spacing: 0.2em;
    font-weight: bold;
    margin-top: 4px;
    line-height: 1.05;
    text-shadow: 3px 3px 0 var(--accent-dark);
}
.lobby-list-block {
    background: rgba(20,20,20,0.85);
    border: 2px solid var(--border);
    border-radius: 6px;
    padding: 10px 12px;
}
.ll-head {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 8px;
}
.ll-title {
    color: #ffcd4a; font-size: 14px;
    text-transform: uppercase; letter-spacing: 0.15em;
}
.refresh-btn {
    background: #2a2a2a; color: #ffcd4a;
    border: 2px solid #555; padding: 4px 14px;
    font-family: inherit; font-size: 18px; cursor: pointer;
    line-height: 1; border-radius: 4px;
}
.refresh-btn:active { background: #ffcd4a; color: #1a1a1a; }

.lobby-list { display: flex; flex-direction: column; gap: 6px; }
.lobby-row {
    display: flex; align-items: center; gap: 14px;
    background: #2a2a2a; padding: 10px 14px;
    border: 2px solid #444;
    cursor: pointer;
    transition: border-color 0.1s, background 0.1s;
    flex-wrap: wrap;
}
.lobby-row:hover { border-color: #ffcd4a; }
.lobby-row:active { background: #333; }
.lobby-row.selected { border-color: #ffcd4a; background: #2a2010; }
.lobby-row .ll-code {
    font-size: 22px; color: #ffcd4a; font-weight: bold;
    letter-spacing: 0.15em; min-width: 80px;
}
.lobby-row .ll-meta {
    flex: 1; font-size: 13px; color: #ccc;
    display: flex; flex-wrap: wrap; gap: 10px;
}
.lobby-row .ll-players {
    color: #4aff5a; font-weight: bold; font-size: 15px;
}

.lobby-settings {
    background: rgba(20,20,20,0.85);
    border: 2px solid var(--border);
    border-radius: 6px;
    padding: 12px 14px;
    font-size: 14px;
    color: var(--text-soft);
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    line-height: 1.6;
}

/* свёртываемая панель настроек на host-lobby */
.settings-panel, .bonus-help {
    background: rgba(20,20,20,0.85);
    border: 2px solid var(--border);
    border-radius: 6px;
    padding: 8px 12px;
}
.settings-panel summary, .bonus-help summary {
    cursor: pointer;
    font-size: 16px;
    color: #ffcd4a;
    padding: 4px 0;
    list-style: none;
    user-select: none;
}
.settings-panel summary::-webkit-details-marker,
.bonus-help summary::-webkit-details-marker { display: none; }
.settings-panel[open] summary, .bonus-help[open] summary { margin-bottom: 8px; }
.settings-panel .settings-form {
    display: flex; flex-direction: column; gap: 10px;
    border-top: 1px dashed #444;
    padding-top: 10px;
}

.bonus-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 4px;
    font-size: 14px;
    color: #ddd;
}
.bonus-table th, .bonus-table td {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid #2a2a2a;
}
.bonus-table th {
    color: #888;
    font-weight: normal;
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 0.1em;
}
.bonus-table td.bi {
    width: 36px;
    text-align: center;
    font-weight: bold;
    color: #1a1a1a;
    background: #ffcd4a;
    border: 1px solid #5a3a00;
}
.bonus-table td.bi.tank    { background: #b0e0ff; }
.bonus-table td.bi.helmet  { background: #ccffcc; }
.bonus-table td.bi.shovel  { background: #ddcc99; }
.bonus-table td.bi.clock   { background: #ffcccc; }
.bonus-table td.bi.grenade { background: #555; color: #fff; }
.bonus-table td.bi.pistol  { background: #fff; }
.bonus-table td.bi.speed   { background: #ffe879; }

.players-list { display: flex; flex-direction: column; gap: 8px; }
.player-card {
    display: flex;
    align-items: center;
    gap: 14px;
    background: rgba(20,20,20,0.85);
    border: 2px solid var(--border);
    border-radius: 6px;
    padding: 12px 14px;
    flex-wrap: wrap;
}
.player-card .swatch {
    width: 32px; height: 32px;
    border: 2px solid #000;
    box-shadow: inset 0 0 0 2px rgba(255,255,255,.15);
}
.player-card .pname { font-size: 19px; }
.player-card .ptag { font-size: 13px; color: #888; margin-left: auto; }

.palette { display: flex; gap: 4px; flex-wrap: wrap; width: 100%; margin-top: 6px; }
.pal-btn {
    width: 28px; height: 28px;
    border: 2px solid #000;
    box-shadow: inset 0 0 0 2px rgba(255,255,255,.1);
    cursor: pointer;
    padding: 0;
    transition: transform 0.05s;
}
.pal-btn:active { transform: scale(0.9); }
.pal-btn.on { outline: 3px solid #ffcd4a; outline-offset: 2px; }

.my-color {
    width: 100px; height: 100px;
    margin: 20px auto 12px;
    border: 4px solid #000;
    box-shadow: 0 0 0 4px #ffcd4a, 0 0 0 6px #000;
}
.my-ability {
    text-align: center;
    font-size: 18px;
    color: #ccc;
    margin-bottom: 8px;
}
.my-ability-label { color: #888; margin-right: 8px; }
.my-ability-value { color: #4aaaff; font-weight: bold; font-size: 22px; letter-spacing: 0.05em; }

.ab-picker { display: flex; flex-wrap: wrap; gap: 4px; width: 100%; margin-top: 6px; }
.ab-pick-btn {
    flex: 1;
    min-width: 60px;
    background: #1a1a1a;
    color: #aaa;
    border: 2px solid #333;
    padding: 6px 4px;
    font-family: inherit;
    font-size: 13px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    transition: background 0.05s, border-color 0.05s, color 0.05s;
}
.ab-pick-btn .ico { font-size: 18px; }
.ab-pick-btn.on { background: #2a82d6; color: #fff; border-color: #1a4a82; }
.ab-pick-btn:active { transform: translateY(1px); }

/* хост игровой */
#screen-host-game { padding: 0; gap: 0; background: #000; position: relative; z-index: 2; }
.host-hud {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    padding: 8px 14px;
    background: #111;
    border-bottom: 2px solid #333;
    font-size: 16px;
    color: #ddd;
}
.host-hud .h-code { color: #ffcd4a; font-weight: bold; }
.host-hud .h-player { display: inline-flex; align-items: center; gap: 6px; }
.host-hud .h-player .sw { width: 16px; height: 16px; display: inline-block; border: 1px solid #000; }
.host-hud .h-dead { opacity: 0.4; text-decoration: line-through; }
.host-stage {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: repeating-linear-gradient(45deg, #050505 0 8px, #0a0a0a 8px 16px);
    overflow: hidden;
}
#board {
    image-rendering: pixelated;
    background: #000;
    border: 2px solid #222;
    max-width: 100%;
    max-height: 100%;
}

/* игрок контроллер */
#screen-player-game {
    padding: 0;
    gap: 0;
    background: #1a1a1a;
    overflow: hidden;
    position: relative;
    z-index: 2;
}
#screen-player-game.active { display: flex; }

.player-hud {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: #0a0a0a;
    border-bottom: 2px solid #333;
    font-size: 16px;
    gap: 10px;
    flex-wrap: wrap;
}
.player-hud .hud-mid { display: flex; gap: 14px; }
.hud-color {
    width: 24px; height: 24px;
    border: 2px solid #000;
    display: inline-block;
    vertical-align: middle;
    margin-right: 8px;
}
.hud-name  { font-size: 18px; vertical-align: middle; }
.hud-lives {
    color: #ff7878; font-weight: bold; font-size: 18px;
    background: #181818; border: 1px solid #5a0a0a;
    padding: 3px 9px;
}
.hud-power {
    color: #ffcd4a; font-size: 18px; font-weight: bold;
    background: #181818; border: 1px solid #5a3a00;
    padding: 3px 9px;
    letter-spacing: 0.05em;
}
.hud-ai-left { color: #ccc; font-size: 16px; }
.hud-ping { color: #888; font-size: 14px; }
.hud-right { display: inline-flex; align-items: center; gap: 8px; }

.layout-toggle {
    background: #2a2a2a;
    color: #ffcd4a;
    border: 2px solid #555;
    padding: 4px 10px;
    font-family: inherit;
    font-size: 16px;
    cursor: pointer;
    border-radius: 4px;
    line-height: 1;
}
.layout-toggle:active { background: #ffcd4a; color: #1a1a1a; }

.status-line {
    text-align: center;
    color: #ffcd4a;
    font-size: 17px;
    padding: 6px;
    min-height: 28px;
    font-weight: bold;
}

/* контроллер: d-pad слева, действия справа — оба на всю доступную высоту/ширину */
.controller {
    flex: 1 1 0;
    display: grid;
    grid-template-columns: 1.15fr 1fr;
    grid-template-rows: 1fr;
    gap: clamp(6px, 1.5vw, 14px);
    padding: clamp(6px, 2vw, 16px);
    align-items: stretch;
    justify-self: center;
    min-height: 0;
    width: 100%;
    max-width: 880px;
    max-height: 720px;
    margin: 0 auto;
}

.dpad-area {
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    grid-template-rows: 1fr 1fr 1fr;
    gap: clamp(4px, 1vw, 10px);
    width: 100%;
    height: 100%;
    min-height: 0;
    min-width: 0;
}
.dpad-area .dpad {
    background: linear-gradient(180deg, #3a3a3a, #1f1f1f);
    color: #fff;
    border: 3px solid #555;
    border-radius: clamp(8px, 2vw, 18px);
    font-size: clamp(28px, 9vmin, 64px);
    font-family: inherit;
    cursor: pointer;
    box-shadow: 0 5px 0 #0a0a0a, inset 0 2px 0 rgba(255,255,255,.1);
    transition: transform 0.05s, box-shadow 0.05s, background 0.05s, color 0.05s;
    display: flex; align-items: center; justify-content: center;
    width: 100%; height: 100%;
    line-height: 1;
    min-width: 0; min-height: 0;
    padding: 0;
}
.dpad-area .dpad.up    { grid-column: 2; grid-row: 1; }
.dpad-area .dpad.left  { grid-column: 1; grid-row: 2; }
.dpad-area .dpad.right { grid-column: 3; grid-row: 2; }
.dpad-area .dpad.down  { grid-column: 2; grid-row: 3; }
.dpad-area .dpad-hub {
    grid-column: 2; grid-row: 2;
    background: radial-gradient(circle, #444 0%, #222 70%);
    border-radius: 50%;
    box-shadow: inset 0 0 8px rgba(0,0,0,0.6), 0 0 0 3px #111;
    width: 100%; height: 100%;
    align-self: stretch; justify-self: stretch;
}
.dpad:active, .dpad.pressed {
    background: linear-gradient(180deg, #ffcd4a, #d6a72a);
    color: #1a1a1a;
    transform: translateY(3px);
    box-shadow: 0 2px 0 #0a0a0a;
}

.action-area {
    display: flex;
    flex-direction: column;
    gap: clamp(6px, 1.5vw, 14px);
    min-height: 0;
    min-width: 0;
    justify-content: stretch;
    height: 100%;
}
.fire-btn, .ability-btn {
    flex: 1 1 0;
    width: 100%;
    border: 4px solid #2a1500;
    color: #1a1a1a;
    font-family: inherit;
    font-weight: bold;
    text-transform: uppercase;
    border-radius: clamp(16px, 4vw, 32px);
    cursor: pointer;
    box-shadow: 0 6px 0 rgba(0,0,0,0.7), inset 0 3px 0 rgba(255,255,255,.25), inset 0 -3px 0 rgba(0,0,0,.2);
    transition: transform 0.05s, box-shadow 0.05s, filter 0.05s;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: clamp(2px, 1vh, 6px);
    min-height: 0;
    min-width: 0;
    overflow: hidden;
    letter-spacing: 0.05em;
    padding: clamp(4px, 1vh, 12px);
}
.fire-btn  { background: radial-gradient(circle at 50% 30%, #ff7575 0%, #d33030 70%, #8a1a1a 100%); }
.ability-btn { background: radial-gradient(circle at 50% 30%, #7accff 0%, #2a82d6 70%, #1a4a82 100%); border-color: #0a2a4a; }

.fire-btn  .act-label { font-size: clamp(18px, 4vmin, 36px); color: #fff; text-shadow: 2px 2px 0 #5a0a0a; line-height: 1.1; }
.fire-btn  .act-icon  { font-size: clamp(28px, 7vmin, 56px); color: #fff; line-height: 1; opacity: .9; text-shadow: 2px 2px 0 #5a0a0a; }
.ability-btn .act-label { font-size: clamp(16px, 3.5vmin, 30px); color: #fff; text-shadow: 2px 2px 0 #0a2a4a; line-height: 1.1; }
.ability-btn .act-icon  { font-size: clamp(28px, 7vmin, 56px); color: #fff; line-height: 1; opacity: .9; text-shadow: 2px 2px 0 #0a2a4a; }

.fire-btn:active, .fire-btn.pressed,
.ability-btn:active, .ability-btn.pressed {
    transform: translateY(4px);
    box-shadow: 0 2px 0 rgba(0,0,0,0.7), inset 0 3px 0 rgba(255,255,255,.15);
    filter: brightness(0.92);
}
.ability-btn.cooling {
    background: radial-gradient(circle, #4a4a4a, #2a2a2a);
    border-color: #111;
    box-shadow: 0 4px 0 rgba(0,0,0,.5);
}
.ability-btn.cooling .act-label,
.ability-btn.cooling .act-icon { color: #aaa; text-shadow: none; }
.ab-cd {
    position: absolute;
    bottom: clamp(4px, 1.2vh, 10px);
    left: 0; right: 0;
    font-size: clamp(12px, 2vh, 18px);
    color: #fff;
    text-shadow: 1px 1px 0 #000;
    text-align: center;
}

/* очень узкие экраны — символы поменьше но кнопки всё равно во всю площадь */
@media (max-width: 360px) {
    .controller { gap: 6px; padding: 6px; }
    .dpad-area  { gap: 4px; }
}

/* ландшейп — равные колонки, шрифты по vmin */
@media (orientation: landscape) {
    .controller.layout-1 { grid-template-columns: 1fr 1fr; padding: 10px; gap: 10px; }
    .dpad-area  { gap: 6px; }
    .dpad-area .dpad { font-size: clamp(22px, 7vmin, 64px); }
    .fire-btn .act-icon, .ability-btn .act-icon { font-size: clamp(24px, 6vmin, 56px); }
    .fire-btn .act-label, .ability-btn .act-label { font-size: clamp(14px, 3vmin, 30px); }
}

/* ============================================================
   РАСКЛАДКА 2: огонь+способность в центре, стрелки вокруг
   .   ▲   .
   ◀  FIRE ▶
   ◀  ABIL ▶
   .   ▼   .
   ============================================================ */
.controller.layout-2 {
    grid-template-columns: 1fr 1.35fr 1fr;
    grid-template-rows: 1fr 1.1fr 1.1fr 1fr;
    max-width: 640px;
    max-height: 720px;
}
.controller.layout-2 .dpad-area,
.controller.layout-2 .action-area {
    display: contents;
}
.controller.layout-2 .dpad-hub { display: none; }
.controller.layout-2 .dpad.up    { grid-column: 2; grid-row: 1; }
.controller.layout-2 .dpad.down  { grid-column: 2; grid-row: 4; }
.controller.layout-2 .dpad.left  { grid-column: 1; grid-row: 2 / span 2; }
.controller.layout-2 .dpad.right { grid-column: 3; grid-row: 2 / span 2; }
.controller.layout-2 .fire-btn   { grid-column: 2; grid-row: 2; max-width: none; }
.controller.layout-2 .ability-btn{ grid-column: 2; grid-row: 3; max-width: none; }

@media (orientation: landscape) {
    .controller.layout-2 { max-width: 720px; }
}

/* окончание */
#end-title {
    font-family: var(--font-logo);
    font-weight: bold;
    text-align: center;
    font-size: clamp(44px, 9vw, 72px);
    margin-top: 10vh;
    line-height: 1.1;
    letter-spacing: 0.1em;
}
#end-title.win  { color: var(--ok);     text-shadow: 4px 4px 0 #0a3a14, 0 0 26px rgba(90,255,140,0.35); }
#end-title.lose { color: var(--danger); text-shadow: 4px 4px 0 #3a0a0a, 0 0 26px rgba(255,90,90,0.35); }
.end-stats { text-align: center; font-size: 18px; color: #ddd; margin: 20px 0; line-height: 1.7; }

.toast {
    position: fixed;
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(180deg, #ffd96a, #e6b03a);
    color: #1a1a1a;
    font-family: var(--font-body);
    font-weight: 700;
    padding: 10px 18px;
    font-size: 15px;
    border: 2px solid var(--accent-dark);
    border-radius: 4px;
    box-shadow: 0 6px 16px rgba(0,0,0,0.5);
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
    z-index: 1000;
}
.toast.show { opacity: 1; }
