/* ============================================================
   «Крокодил» — стили (полный редизайн)
   ============================================================ */

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { min-height: 100%; max-width: 100%; }
html {
    background:
        radial-gradient(ellipse at top, #1a2333 0%, #0d1117 60%, #06080c 100%) fixed;
    background-color: #0d1117;
    color-scheme: dark;
    overflow-x: hidden;
}

:root {
    --bg: #0d1117;
    --bg-2: #161b22;
    --panel: rgba(22, 27, 34, .72);
    --panel-solid: #161b22;
    --line: rgba(255, 255, 255, .08);
    --line-2: rgba(255, 255, 255, .14);
    --text: #e6edf3;
    --muted: #8b96a8;
    --accent: #5fe6a4;
    --accent-2: #9c5fe0;
    --accent-3: #f0b033;
    --danger: #ff5d6c;
    --info: #6aa6ff;

    --radius: 14px;
    --radius-sm: 10px;
    --shadow-card: 0 10px 30px rgba(0, 0, 0, .35), 0 2px 8px rgba(0, 0, 0, .25);
    --shadow-glow: 0 0 24px rgba(95, 230, 164, .25);
    --transition: 220ms cubic-bezier(.4, .0, .2, 1);

    --grad-primary: linear-gradient(135deg, #5fe6a4, #2a9c5a);
    --grad-rainbow: linear-gradient(90deg, #5fe6a4 0%, #9c5fe0 25%, #f0b033 50%, #9c5fe0 75%, #5fe6a4 100%);
}

body {
    margin: 0;
    background: transparent;
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    overflow-x: hidden;
    position: relative;
    z-index: 0;
    min-width: 0;
    max-width: 100%;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.2); }
::selection { background: var(--accent); color: #0d1117; }

/* select option меню в нативном dropdown должно быть тёмным */
select { color-scheme: dark; }
select option {
    background-color: #161b22;
    color: #e6edf3;
}

/* ============================================================
   ФОН
   ============================================================ */
#bg-canvas {
    position: fixed; inset: 0;
    width: 100vw; height: 100vh;
    z-index: -2;
    pointer-events: none;
    opacity: .55;
}
.bg-vignette {
    position: fixed; inset: 0; z-index: -1; pointer-events: none;
    background:
        radial-gradient(ellipse at 50% 0%, transparent 0%, rgba(13, 17, 23, .4) 100%),
        radial-gradient(ellipse at 50% 100%, transparent 50%, rgba(13, 17, 23, .8) 100%);
}

.screen, .preloader, .topbar { position: relative; z-index: 1; }

/* ============================================================
   КНОПКА «БРАУЗЕР НА ВЕСЬ ЭКРАН» — фиксирована сверху справа, только моб
   ============================================================ */
.page-fs-btn {
    display: none;
    position: fixed;
    top: 8px; right: 8px;
    z-index: 250;
    width: 34px; height: 34px;
    border-radius: 50%;
    background: rgba(13, 17, 23, .82);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--line);
    color: var(--text);
    align-items: center; justify-content: center;
    cursor: pointer;
    transition: color var(--transition), border-color var(--transition), background var(--transition), transform var(--transition);
}
.page-fs-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: rgba(95, 230, 164, .12);
}
.page-fs-btn:active { transform: scale(.92); }
.page-fs-btn .fs-icon-collapse { display: none; }
body.page-fs .page-fs-btn .fs-icon-expand { display: none; }
body.page-fs .page-fs-btn .fs-icon-collapse { display: inline; }

@media (max-width: 900px) {
    .page-fs-btn { display: inline-flex; }
    /* Чтобы кнопка не наезжала на содержимое топбара (Выйти и т.п.) */
    .topbar { padding-right: 52px; }
}

/* ============================================================
   ОБЩЕЕ
   ============================================================ */
.screen {
    display: flex; flex-direction: column;
    min-height: 100vh;
    animation: screen-in .35s ease;
}
@keyframes screen-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.hidden { display: none !important; }
.muted { color: var(--muted); }

.glass {
    background: var(--panel);
    backdrop-filter: blur(14px) saturate(140%);
    -webkit-backdrop-filter: blur(14px) saturate(140%);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-card);
}
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    position: relative;
}
.card-title { margin: 0 0 12px; font-size: 16px; letter-spacing: .3px; color: #fff; }

.btn-primary {
    --bg: var(--grad-primary);
    position: relative;
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    background: var(--bg);
    color: #0a1812;
    border: 0;
    padding: 11px 18px;
    border-radius: var(--radius-sm);
    font-weight: 700;
    letter-spacing: .2px;
    transition: transform var(--transition), box-shadow var(--transition), filter var(--transition);
    box-shadow: 0 6px 18px rgba(95, 230, 164, .35);
    overflow: hidden;
}
.btn-primary::before {
    content: ""; position: absolute; inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,.3), transparent 40%);
    opacity: 0; transition: opacity var(--transition);
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 10px 26px rgba(95, 230, 164, .45); }
.btn-primary:hover::before { opacity: 1; }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { background: #2a3140; color: #586172; cursor: not-allowed; box-shadow: none; transform: none; }
.btn-primary:disabled::before { display: none; }
.btn-primary.big { width: 100%; padding: 14px 20px; font-size: 16px; }
.btn-arrow { width: 16px; height: 16px; transition: transform var(--transition); }
.btn-primary:hover .btn-arrow { transform: translateX(3px); }

.btn-ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--line-2);
    padding: 9px 14px;
    border-radius: var(--radius-sm);
    transition: background var(--transition), border-color var(--transition), transform var(--transition);
}
.btn-ghost:hover { background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.3); transform: translateY(-1px); }
.btn-ghost:active { transform: translateY(0); }

.hint { font-size: 12px; color: var(--muted); margin: 10px 0 0; }

/* ============================================================
   ПРЕЛОАДЕР
   ============================================================ */
.preloader {
    position: fixed; inset: 0; z-index: 200;
    display: flex; align-items: center; justify-content: center;
    background: radial-gradient(circle at 50% 50%, #18222d 0%, #0d1117 100%);
    transition: opacity .5s ease, visibility 0s linear .5s;
}
.preloader.hidden { opacity: 0; visibility: hidden; pointer-events: none; display: flex !important; }

.loader-card { text-align: center; padding: 32px; }
.croc-loader { width: 220px; height: 180px; overflow: visible; display: block; margin: 0 auto; }
.cl-upper { transform-origin: 18px 70px; animation: cl-jaw 1.6s ease-in-out infinite; }
@keyframes cl-jaw {
    0%, 100% { transform: rotate(0deg); }
    40%      { transform: rotate(-22deg); }
}
.cl-pupil { animation: cl-blink 3s infinite; transform-origin: 60px 34px; }
@keyframes cl-blink {
    0%, 93%, 100% { transform: scaleY(1); }
    96% { transform: scaleY(.1); }
}
.loader-bar {
    width: 220px; height: 4px;
    margin: 18px auto 12px;
    background: rgba(255,255,255,.06);
    border-radius: 2px; overflow: hidden;
}
.loader-bar-inner {
    height: 100%;
    background: var(--grad-rainbow);
    background-size: 200% 100%;
    animation: lb-slide 1.4s linear infinite;
}
@keyframes lb-slide {
    0% { background-position: 0% 0%; transform: translateX(-100%); }
    100% { background-position: 200% 0%; transform: translateX(100%); }
}
.loader-text { color: var(--muted); font-size: 13px; }

/* ============================================================
   HERO
   ============================================================ */
.hero {
    text-align: center;
    padding: 56px 16px 24px;
}
.title-svg {
    width: min(720px, 88vw);
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto 6px;
    filter: drop-shadow(0 8px 30px rgba(95, 230, 164, .25));
    animation: title-float 6s ease-in-out infinite;
}
@keyframes title-float {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-6px); }
}
.t-letter {
    opacity: 0;
    transform-origin: center 90px;
    animation:
        letter-in .7s cubic-bezier(.34,1.56,.64,1) forwards calc(var(--i) * .08s + .2s),
        letter-bounce 3.8s ease-in-out infinite calc(var(--i) * .12s + 1.5s);
}
@keyframes letter-in {
    from { opacity: 0; transform: translateY(-30px) rotate(-12deg) scale(.6); }
    to   { opacity: 1; transform: none; }
}
@keyframes letter-bounce {
    0%, 100% { transform: translateY(0) rotate(0); }
    50%      { transform: translateY(-4px) rotate(-1.5deg); }
}
.title-underline {
    stroke-dasharray: 800;
    stroke-dashoffset: 800;
    animation: ul-draw 1.4s ease-out forwards 1.1s;
}
@keyframes ul-draw { to { stroke-dashoffset: 0; } }

.subtitle {
    margin: 4px 0 0;
    font-size: 16px;
    color: var(--muted);
    display: flex; gap: 12px; justify-content: center; align-items: center;
    letter-spacing: .8px;
    opacity: 0;
    animation: sub-in .6s ease forwards 1.6s;
}
.subtitle b { color: var(--accent); font-weight: 900; }
@keyframes sub-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

@media (max-width: 540px) {
    .hero { padding: 36px 12px 16px; }
    .subtitle { font-size: 13px; gap: 8px; }
}

/* ============================================================
   HERO-STATUS (под заголовком)
   ============================================================ */
.hero-status {
    display: inline-flex; align-items: center; gap: 10px;
    margin: 14px auto 0;
    padding: 8px 16px;
    background: rgba(13, 17, 23, .55);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 13px;
    color: var(--muted);
    opacity: 0;
    animation: hs-in .6s ease forwards 1.9s;
    transition: border-color var(--transition), background var(--transition), color var(--transition);
}
@keyframes hs-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.hs-spinner {
    width: 14px; height: 14px;
    border-radius: 50%;
    border: 2px solid transparent;
    border-top-color: var(--accent-3);
    border-right-color: var(--accent-3);
    animation: hs-spin .8s linear infinite;
}
@keyframes hs-spin { to { transform: rotate(360deg); } }

.hs-label { font-weight: 600; color: var(--text); letter-spacing: .2px; }
.hs-sep { color: var(--muted); opacity: .6; }
.hs-ping { font-variant-numeric: tabular-nums; min-width: 56px; text-align: left; }
.hs-retry {
    display: none;
    background: transparent; border: 0; color: var(--text);
    padding: 0 4px; font-size: 14px;
}
.hero-status[data-state="disconnected"] .hs-retry { display: inline-flex; }
.hs-retry:hover { color: var(--accent); }

.hero-status[data-state="connected"] {
    border-color: rgba(95, 230, 164, .4);
    background: rgba(95, 230, 164, .08);
    color: var(--text);
}
.hero-status[data-state="connected"] .hs-spinner {
    border: 2px solid var(--accent);
    animation: hs-pulse 1.8s ease-in-out infinite;
}
@keyframes hs-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(95, 230, 164, .5); }
    50%      { box-shadow: 0 0 0 6px rgba(95, 230, 164, 0); }
}
.hero-status[data-state="connected"] .hs-ping { color: var(--accent); }

.hero-status[data-state="disconnected"] {
    border-color: rgba(255, 93, 108, .5);
    background: rgba(255, 93, 108, .08);
    color: var(--danger);
}
.hero-status[data-state="disconnected"] .hs-spinner {
    border: 2px solid var(--danger);
    animation: none;
}
.hero-status[data-state="disconnected"] .hs-ping { color: var(--danger); }

@media (max-width: 540px) {
    .hero-status { font-size: 12px; gap: 8px; padding: 6px 12px; flex-wrap: wrap; justify-content: center; max-width: 92vw; }
    .hs-ping { min-width: 48px; }
}

/* ============================================================
   ВХОД (форма)
   ============================================================ */
#screen-login {
    align-items: center;
    justify-content: flex-start;
    padding: 0 16px 32px;
}
.login {
    width: min(440px, 100%);
    border-radius: 18px;
    padding: 20px 22px 24px;
    animation: card-in .5s cubic-bezier(.34,1.56,.64,1) .8s backwards;
}
@keyframes card-in { from { opacity: 0; transform: translateY(20px) scale(.96); } to { opacity: 1; transform: none; } }

.tabs {
    position: relative;
    display: flex; gap: 4px;
    margin-bottom: 8px;
    padding: 4px;
    background: rgba(255,255,255,.04);
    border-radius: 12px;
}
.tab {
    flex: 1;
    background: transparent; border: 0;
    padding: 9px 12px;
    color: var(--muted);
    border-radius: 8px;
    font-weight: 600;
    transition: color var(--transition);
    position: relative; z-index: 1;
}
.tab.active { color: #0d1117; }
.tab:not(.active):hover { color: var(--text); }
.tab-glider {
    position: absolute;
    top: 4px; bottom: 4px;
    left: 4px;
    width: calc(50% - 4px);
    background: var(--grad-primary);
    border-radius: 8px;
    transition: transform var(--transition), opacity .3s;
    box-shadow: 0 4px 12px rgba(95, 230, 164, .35);
    pointer-events: none;
}
.tabs .tab:nth-child(1).active ~ .tab-glider { transform: translateX(0); }
.tabs .tab:nth-child(2).active ~ .tab-glider { transform: translateX(100%); }

.tab-panel { display: flex; flex-direction: column; gap: 12px; padding-top: 14px; }

.field { position: relative; }
.field input {
    width: 100%;
    background: rgba(255,255,255,.04);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 18px 14px 8px;
    color: var(--text);
    transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}
.field input:hover { background: rgba(255,255,255,.06); }
.field input:focus {
    outline: none;
    border-color: var(--accent);
    background: rgba(95, 230, 164, .06);
    box-shadow: 0 0 0 4px rgba(95, 230, 164, .14);
}
.field label {
    position: absolute;
    left: 14px; top: 50%; transform: translateY(-50%);
    color: var(--muted); font-size: 14px;
    pointer-events: none;
    transition: top var(--transition), font-size var(--transition), color var(--transition);
    background: transparent; padding: 0;
}
.field input:focus + label,
.field input:not(:placeholder-shown) + label {
    top: 8px; transform: translateY(0);
    font-size: 11px; color: var(--accent);
    font-weight: 600; letter-spacing: .5px; text-transform: uppercase;
}

.section-label {
    margin: 18px 0 6px;
    display: flex; align-items: center; gap: 10px;
    color: var(--muted); font-size: 12px;
    text-transform: uppercase; letter-spacing: 1px;
}
.section-label::before, .section-label::after {
    content: ""; flex: 1; height: 1px; background: var(--line);
}

/* ----------- Список лобби ----------- */
.lobby-list {
    display: flex; flex-direction: column; gap: 6px;
    max-height: 220px; overflow-y: auto; overflow-x: hidden;
    padding: 2px;
}
.lobby-list .item {
    display: flex; justify-content: space-between; align-items: center; gap: 8px;
    background: rgba(255,255,255,.03);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    cursor: pointer;
    user-select: none;
    transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
    /* фикс: никакого transform, чтобы айтем не выезжал и не клипался */
}
.lobby-list .item:hover {
    border-color: var(--accent);
    background: rgba(95, 230, 164, .07);
    box-shadow: inset 3px 0 0 var(--accent);
}
.lobby-list .item.locked b::after { content: " 🔒"; font-size: 11px; }
.lobby-list .item b { letter-spacing: 2px; color: var(--accent); }
.lobby-list .item .left  { display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1; overflow: hidden; }
.lobby-list .item .left .meta { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lobby-list .item .meta { font-size: 12px; color: var(--muted); }
.lobby-list .item .right { flex-shrink: 0; font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

.status { min-height: 1.2em; margin-top: 14px; font-size: 13px; text-align: center; }
.status.err { color: var(--danger); }
.status.ok  { color: var(--accent); }

/* ============================================================
   TOPBAR
   ============================================================ */
.topbar {
    display: flex; align-items: center; gap: 14px;
    padding: 12px 18px;
    border-radius: 0;
    border-bottom: 1px solid var(--line);
    flex-wrap: wrap; margin: 0;
}
.topbar .brand {
    display: inline-flex; align-items: center; gap: 8px;
    font-weight: 800; font-size: 18px;
    color: var(--text);
    letter-spacing: .3px;
    flex-shrink: 0;
    overflow: visible;
}
.brand-icon {
    width: 36px; height: 28px;
    flex-shrink: 0;
    overflow: visible;
    filter: drop-shadow(0 2px 6px rgba(95,230,164,.4));
    animation: brand-wobble 4s ease-in-out infinite;
    transform-origin: 50% 50%;
}
@keyframes brand-wobble { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-6deg); } }

.code-pill {
    display: inline-flex; gap: 6px; align-items: center;
    padding: 4px 10px;
    background: rgba(255,255,255,.05);
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 13px;
    color: var(--muted);
}
.code-pill b { color: var(--text); letter-spacing: 3px; font-weight: 700; }

.round-info { font-size: 13px; color: var(--muted); }
.round-info b { color: var(--text); }

.timer {
    margin-left: auto;
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    font-size: 22px;
    padding: 4px 12px;
    border-radius: 8px;
    background: rgba(255,255,255,.04);
    border: 1px solid var(--line);
    transition: color var(--transition), border-color var(--transition);
}
.timer.warn { color: var(--accent-3); border-color: rgba(240, 176, 51, .5); animation: t-pulse 1s ease-in-out infinite; }
.timer.danger { color: var(--danger); border-color: rgba(255, 93, 108, .6); animation: t-pulse .6s ease-in-out infinite; }
@keyframes t-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }

/* кнопка fit-to-screen видна только зрителю */
#btn-fit { display: none; }
body.is-spectator #btn-fit { display: inline-flex; }

/* Sound-toggle кнопка */
.btn-icon {
    padding: 6px 10px;
    min-width: 36px;
    display: inline-flex; align-items: center; justify-content: center;
}
#btn-sound .ic-sound-off { display: none; }
body.sounds-off #btn-sound .ic-sound-on { display: none; }
body.sounds-off #btn-sound .ic-sound-off { display: inline-block; }
body.sounds-off #btn-sound { color: var(--muted); }

/* Прячем лидерборд по настройке лобби */
body.hide-leaderboard #g-leaderboard { display: none !important; }

/* ============================================================
   ЛОББИ
   ============================================================ */
.lobby-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
    padding: 20px;
    max-width: 1100px; margin: 0 auto; width: 100%;
}

.players-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.players-list li {
    display: flex; align-items: center; gap: 10px;
    background: rgba(255,255,255,.03);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    transition: border-color var(--transition);
}
.players-list li:hover { border-color: var(--line-2); }
.players-list .name { flex: 1; font-weight: 600; }
.players-list .name.you { color: var(--accent); }
.players-list .role {
    font-size: 11px; padding: 3px 8px; border-radius: 999px;
    background: rgba(255,255,255,.05); color: var(--muted);
    text-transform: uppercase; letter-spacing: .5px; font-weight: 600;
}
.players-list .role.player    { color: var(--accent);   background: rgba(95,230,164,.1); }
.players-list .role.spectator { color: var(--accent-3); background: rgba(240,176,51,.12); }
.players-list .host-badge {
    font-size: 10px; background: var(--accent-2); color: #fff;
    padding: 3px 6px; border-radius: 4px; font-weight: 700; letter-spacing: .5px;
}
.players-list .role-toggle {
    background: transparent; border: 1px solid var(--line-2);
    border-radius: 6px; padding: 4px 8px; font-size: 12px;
    color: var(--muted);
    transition: all var(--transition);
}
.players-list .role-toggle:hover { background: rgba(95,230,164,.1); color: var(--accent); border-color: var(--accent); }

.settings { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.span-2 { grid-column: span 2; }
.field-select { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.field-label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding-left: 2px; }
.field-select input, .field-select select {
    background: rgba(255,255,255,.04);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 9px 11px;
    color: var(--text);
    transition: border-color var(--transition), background var(--transition);
}
.field-select input:hover, .field-select select:hover { background: rgba(255,255,255,.06); }
.field-select input:focus, .field-select select:focus {
    outline: none; border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(95,230,164,.14);
}

/* ----------- chip-group для сложности ----------- */
.chip-group {
    display: flex; gap: 8px; flex-wrap: wrap;
    padding-top: 2px;
}
.chip {
    cursor: pointer; user-select: none;
    display: inline-flex; align-items: center;
    padding: 6px 12px;
    background: rgba(255,255,255,.04);
    border: 1px solid var(--line);
    border-radius: 999px;
    font-size: 13px;
    color: var(--text);
    transition: all var(--transition);
}
.chip input[type="checkbox"] {
    position: absolute !important;
    width: 0 !important;
    height: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    margin: 0 !important;
}
.chip:hover { background: rgba(255,255,255,.07); border-color: var(--line-2); }
.chip:has(input:checked) {
    background: rgba(95, 230, 164, .15);
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
    box-shadow: 0 0 0 1px var(--accent);
}
/* fallback без :has — добавит JS класс .checked */
.chip.checked {
    background: rgba(95, 230, 164, .15);
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
    box-shadow: 0 0 0 1px var(--accent);
}

/* Кастомный switch */
.switch {
    display: flex; align-items: center; gap: 10px;
    grid-column: span 2;
    padding: 8px 4px;
    cursor: pointer; user-select: none;
}
.switch input[type="checkbox"] {
    position: absolute !important;
    width: 0 !important;
    height: 0 !important;
    opacity: 0 !important;
    pointer-events: none !important;
    margin: 0 !important;
}
.switch-slider {
    position: relative;
    width: 38px; height: 22px;
    background: rgba(255,255,255,.08);
    border-radius: 999px;
    transition: background var(--transition);
    flex-shrink: 0;
}
.switch-slider::before {
    content: "";
    position: absolute;
    width: 16px; height: 16px;
    background: #fff;
    border-radius: 50%;
    top: 3px; left: 3px;
    transition: transform var(--transition), background var(--transition);
    box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.switch input:checked + .switch-slider { background: var(--accent); }
.switch input:checked + .switch-slider::before { transform: translateX(16px); }
.switch input:focus-visible + .switch-slider { box-shadow: 0 0 0 3px rgba(95,230,164,.3); }

/* Блокировка настроек у не-хоста: тушим контролы, но не сами скрытые чекбоксы внутри .chip/.switch */
.settings[data-locked="true"] select,
.settings[data-locked="true"] input[type="number"],
.settings[data-locked="true"] input[type="text"],
.settings[data-locked="true"] .switch,
.settings[data-locked="true"] .chip { pointer-events: none; opacity: .6; }

/* ============================================================
   ИГРА
   ============================================================ */
.word-bar {
    display: flex; align-items: center; gap: 14px;
    padding: 12px 20px;
    margin: 10px 18px 0;
    border-radius: var(--radius);
    border: 1px dashed rgba(95,230,164,.5);
    animation: word-glow 2.4s ease-in-out infinite alternate;
}
@keyframes word-glow {
    from { box-shadow: 0 0 8px rgba(95,230,164,.1); }
    to   { box-shadow: 0 0 24px rgba(95,230,164,.35); }
}
.word-bar .muted { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; }
.word-bar b {
    font-size: 26px;
    letter-spacing: 3px;
    background: var(--grad-rainbow);
    background-size: 200% 100%;
    background-clip: text; -webkit-background-clip: text;
    color: transparent;
    animation: word-shimmer 4s linear infinite;
    text-transform: uppercase;
}
@keyframes word-shimmer { from { background-position: 0% 0; } to { background-position: 200% 0; } }

/* Игровая сетка: КАНВАС СЛЕВА, ЧАТ СПРАВА */
.game-grid {
    display: grid;
    grid-template-columns: 1fr 340px;
    grid-template-rows: minmax(0, 1fr);
    gap: 14px;
    padding: 14px 18px 18px;
    flex: 1 1 0;
    min-height: 0;
}
.game-pane { display: flex; flex-direction: column; gap: 14px; min-height: 0; min-width: 0; }
#g-left, #g-right { min-width: 0; min-height: 0; }

/* Десктоп: фиксируем общую высоту, чтобы чат имел чем скроллить */
@media (min-width: 901px) {
    #screen-game { height: 100vh; max-height: 100vh; overflow: hidden; }
}

/* Лидерборд */
.leaderboard-header {
    display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.leaderboard h3 { margin: 0; font-size: 14px; color: var(--text); letter-spacing: .3px; }
.lb-toggle {
    background: transparent; border: 1px solid var(--line); color: var(--muted);
    width: 26px; height: 26px; border-radius: 6px;
    display: inline-flex; align-items: center; justify-content: center;
    transition: all var(--transition);
}
.lb-toggle:hover { color: var(--accent); border-color: var(--accent); background: rgba(95,230,164,.08); }
.lb-toggle svg { transition: transform var(--transition); }
.leaderboard.collapsed .lb-toggle svg { transform: rotate(-90deg); }

/* Отступ — на самом списке, чтобы при сворачивании он анимировался к 0 вместе с max-height */
.leaderboard ol {
    list-style: none; counter-reset: lb; margin: 0; padding: 8px 0 0;
    display: flex; flex-direction: column; gap: 4px;
    max-height: 600px; overflow: hidden;
    transition: max-height .35s cubic-bezier(.4,0,.2,1), opacity .25s, padding .3s;
}
.leaderboard.collapsed ol { max-height: 0; opacity: 0; padding: 0; }
.leaderboard li {
    counter-increment: lb;
    display: flex; justify-content: space-between; gap: 10px; align-items: center;
    padding: 5px 8px;
    border-radius: 6px;
    transition: background var(--transition);
}
.leaderboard li:hover { background: rgba(255,255,255,.04); }
.leaderboard li::before {
    content: counter(lb);
    width: 22px; height: 22px; border-radius: 50%;
    background: rgba(255,255,255,.06); color: var(--muted);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.leaderboard li:nth-child(1)::before { background: linear-gradient(135deg, #f0b033, #d18a0a); color: #0d1117; }
.leaderboard li:nth-child(2)::before { background: linear-gradient(135deg, #c9d0db, #8c95a3); color: #0d1117; }
.leaderboard li:nth-child(3)::before { background: linear-gradient(135deg, #cd7f32, #864e0f); color: #fff; }
.leaderboard li.you { background: rgba(95, 230, 164, .08); color: var(--accent); font-weight: 600; }
.leaderboard li .pts { font-variant-numeric: tabular-nums; font-weight: 700; }

/* CHAT */
.chat {
    display: flex; flex-direction: column;
    min-height: 0;
    flex: 1;
}
.chat-history {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 4px;
    display: flex; flex-direction: column; gap: 6px;
    min-height: 0;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
}
.chat-msg {
    padding: 6px 10px;
    border-radius: 8px;
    background: rgba(255,255,255,.03);
    border: 1px solid var(--line);
    animation: msg-in .25s ease;
    word-wrap: break-word;
}
@keyframes msg-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.chat-msg .from { font-weight: 700; color: var(--info); margin-right: 6px; }
.chat-msg .from.spectator { color: var(--accent-3); }
.chat-msg .from.system { color: var(--muted); font-style: italic; }
.chat-msg.correct {
    background: rgba(95, 230, 164, .12);
    border-color: var(--accent);
    box-shadow: 0 0 14px rgba(95, 230, 164, .25);
    animation: msg-correct .5s ease;
}
@keyframes msg-correct {
    0% { transform: scale(.96); }
    50% { transform: scale(1.02); }
    100% { transform: scale(1); }
}
.chat-msg.system { background: transparent; border: 0; padding: 3px 8px; color: var(--muted); font-style: italic; }
.chat-msg .ts { font-size: 10px; color: var(--muted); margin-left: 6px; opacity: .7; }

.chat-input { display: flex; gap: 6px; margin-top: 10px; }
.chat-input input {
    flex: 1;
    background: rgba(255,255,255,.04);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    color: var(--text);
    transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}
.chat-input input:focus {
    outline: none; border-color: var(--accent);
    background: rgba(95,230,164,.06);
    box-shadow: 0 0 0 3px rgba(95,230,164,.14);
}
.chat-input input:disabled { opacity: .5; }
.chat-input button {
    background: var(--grad-primary); color: #0a1812; border: 0;
    border-radius: var(--radius-sm);
    padding: 0 14px;
    display: inline-flex; align-items: center; justify-content: center;
    transition: transform var(--transition), filter var(--transition);
    box-shadow: 0 4px 12px rgba(95,230,164,.3);
}
.chat-input button:hover:not(:disabled) { transform: translateY(-1px) scale(1.04); filter: brightness(1.05); }
.chat-input button:disabled { background: #2a3140; color: #586172; cursor: not-allowed; box-shadow: none; }

/* CANVAS */
.canvas-wrap {
    position: relative;
    flex: 1 1 0;
    display: flex; flex-direction: column;
    padding: 10px;
    min-height: 280px;
    min-width: 0;
    overflow: hidden;
}
#g-canvas {
    display: block;
    width: 100%; height: auto;
    max-width: 100%; max-height: 100%;
    aspect-ratio: 3 / 2;
    background: #fff;
    border-radius: var(--radius-sm);
    touch-action: none;
    cursor: crosshair;
    box-shadow: inset 0 0 0 1px rgba(0,0,0,.1);
    margin: 0 auto;
}
#g-canvas.readonly { cursor: default; }
#g-canvas.tool-fill { cursor: cell; }

/* Десктоп: канвас вписывается по высоте, чтобы чат-скролл работал */
@media (min-width: 901px) {
    #g-canvas {
        width: auto; height: auto;
        max-width: 100%; max-height: 100%;
    }
}

.canvas-tools {
    display: flex; gap: 8px; margin-top: 10px;
    flex-wrap: wrap; align-items: center;
}
.canvas-tools .tool-group {
    display: flex; gap: 4px; align-items: center;
    padding: 3px; background: rgba(255,255,255,.03);
    border-radius: 999px; border: 1px solid var(--line);
}

.color-tool {
    width: 28px; height: 28px; border-radius: 50%;
    border: 2px solid transparent !important;
    padding: 0;
    transition: transform var(--transition), border-color var(--transition);
}
.color-tool:hover { transform: scale(1.1); }
.color-tool.active { border-color: var(--accent) !important; box-shadow: 0 0 0 2px rgba(95,230,164,.35); }

.size-btn, .mode-btn, .history-btn {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: rgba(255,255,255,.04); color: var(--text);
    border: 1px solid var(--line);
    display: inline-flex; align-items: center; justify-content: center;
    transition: background var(--transition), border-color var(--transition), transform var(--transition), opacity var(--transition);
}
.size-btn svg, .mode-btn svg, .history-btn svg { width: 16px; height: 16px; }
.size-btn:hover, .mode-btn:hover, .history-btn:hover { background: rgba(255,255,255,.08); border-color: var(--line-2); }
.size-btn.active, .mode-btn.active {
    background: var(--grad-primary);
    color: #0d1117; border-color: transparent;
    transform: scale(1.05);
}
.history-btn:disabled {
    opacity: .35;
    cursor: not-allowed;
    transform: none;
}
.history-btn:not(:disabled):active { transform: scale(.92); }

.tool.wide {
    width: auto; padding: 6px 12px;
    border-radius: 999px;
    background: rgba(255,255,255,.04); color: var(--text);
    border: 1px solid var(--line);
    font-size: 13px;
    transition: all var(--transition);
}
.tool.wide:hover { background: rgba(255, 93, 108, .15); color: var(--danger); border-color: rgba(255, 93, 108, .4); }

.round-controls {
    display: flex; gap: 10px; justify-content: center;
    padding: 14px;
    border-top: 1px solid var(--line);
    background: rgba(13, 17, 23, .6);
    backdrop-filter: blur(8px);
}

/* ============================================================
   ИТОГИ
   ============================================================ */
#screen-end { align-items: center; justify-content: center; padding: 16px; }
.end-card {
    width: min(520px, 100%); text-align: center;
    border-radius: 18px; padding: 28px;
    animation: card-in .6s cubic-bezier(.34,1.56,.64,1);
}
.trophy { font-size: 64px; line-height: 1; margin-bottom: 8px; animation: trophy-spin 6s ease-in-out infinite; display: inline-block; }
@keyframes trophy-spin { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg); } }
.end-card h1 { margin: 0 0 6px; font-size: 26px; }
.final-list { list-style: none; padding: 0; margin: 16px 0; text-align: left; }
.final-list li {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    display: flex; justify-content: space-between; align-items: center;
    transition: background var(--transition);
}
.final-list li:hover { background: rgba(255,255,255,.03); }
.final-list li:last-child { border: 0; }
.final-list li.winner {
    color: var(--accent-3); font-weight: 700; font-size: 18px;
    background: linear-gradient(90deg, rgba(240, 176, 51, .12), transparent);
    border-radius: 8px;
}
.actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

/* ============================================================
   FIT-TO-SCREEN (зритель: уместить всё в экран)
   ============================================================ */
body.fit-to-screen {
    overflow: hidden;
}
body.fit-to-screen #screen-game { height: 100vh; min-height: 100vh; }
body.fit-to-screen .game-grid {
    flex: 1;
    overflow: hidden;
    padding: 8px 12px 8px;
    min-height: 0;
}
body.fit-to-screen .canvas-wrap { min-height: 0; flex: 1; padding: 6px; }
body.fit-to-screen #g-canvas {
    height: 100%; width: auto;
    max-height: 100%; max-width: 100%;
    aspect-ratio: 3 / 2;
    margin: 0 auto;
    object-fit: contain;
}
body.fit-to-screen .canvas-tools { margin-top: 6px; flex-shrink: 0; }
body.fit-to-screen .chat { min-height: 0; }
body.fit-to-screen .chat-history { min-height: 0; }
body.fit-to-screen .leaderboard ol { max-height: 200px; overflow-y: auto; }
body.fit-to-screen .word-bar { display: none !important; }

/* ============================================================
   АДАПТИВ
   ============================================================ */

@media (max-width: 900px) {
    .lobby-grid { grid-template-columns: 1fr; padding: 14px; gap: 14px; }
    .settings { grid-template-columns: 1fr; }
    .switch { grid-column: span 1; }
    .span-2 { grid-column: span 1; }

    /* На мобиле экран минимум во вьюпорт (dvh учитывает мобильную адресную строку).
       Если канвас+чат влезают в 100dvh — раскладка фиксирована, история скроллится внутри.
       Если не влезают (короткий вьюпорт + большой канвас) — страница начинает скроллиться
       и до чата можно докрутить. Это достигается тем, что у чата есть гарантированный
       минимум (280px) через minmax в grid-row, а game-grid НЕ сжимается ниже контента. */
    #screen-game { min-height: 100dvh; }

    .game-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto minmax(280px, 1fr);
        padding: 12px;
        flex: 1 0 auto;       /* basis auto + shrink 0: не уменьшается ниже своего контента */
        min-height: 0;
    }
    #g-left  { grid-row: 1; position: relative; min-height: 0; }
    #g-right { grid-row: 2; min-height: 0; overflow: hidden; display: flex; flex-direction: column; gap: 14px; }
    body.no-canvas #g-left { display: none !important; }
    /* Если рисунок отключён — даём чату небольшой отступ сверху */
    body.no-canvas #g-right { margin-top: 8px; }

    /* Чат и история без жёстких max-height — заполняют отведённое грид-ом.
       chat-history скроллится внутри если сообщений много. */
    .chat {
        min-height: 0;
        max-height: none;
        flex: 1 1 auto;
    }
    .chat-history {
        min-height: 0;
        max-height: none;
        flex: 1 1 auto;
    }

    /* Канвас: пропорция 3:2, ограничен 45vh чтобы оставить достаточно места чату на
       широких/коротких мобильных экранах. */
    .canvas-wrap {
        min-height: 0;
        max-height: none;
        overflow: visible;
        flex: 0 0 auto;
    }
    #g-canvas {
        flex: 0 0 auto;
        display: block;
        width: 100%;
        height: auto;
        max-width: 100%;
        max-height: 45vh;
        aspect-ratio: 3 / 2;
        margin: 0 auto;
    }

    /* Инструменты по центру и переносятся по строкам, никогда не клипаются */
    .canvas-tools {
        justify-content: center;
        flex-shrink: 0;
        flex-wrap: wrap;
    }

    .word-bar { margin: 8px 12px 0; }

    /* Спектатор на мобиле: убираем лидерборд и инпут чата — только канвас и история */
    body.is-spectator #g-leaderboard { display: none !important; }
    body.is-spectator .chat-input { display: none !important; }
}

/* ============================================================
   КНОПКА «РАЗВЕРНУТЬ ПОЛОТНО» (только мобильная версия)
   ============================================================ */
.canvas-fs-btn {
    display: none;
    position: absolute;
    top: 18px; right: 18px;
    z-index: 5;
    width: 38px; height: 38px;
    border-radius: 50%;
    background: rgba(13, 17, 23, .82);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--line);
    color: var(--text);
    align-items: center; justify-content: center;
    transition: color var(--transition), border-color var(--transition), background var(--transition), transform var(--transition);
}
.canvas-fs-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: rgba(95, 230, 164, .12);
}
.canvas-fs-btn:active { transform: scale(.92); }
.canvas-fs-btn .fs-icon-collapse { display: none; }
body.canvas-fs .canvas-fs-btn .fs-icon-expand { display: none; }
body.canvas-fs .canvas-fs-btn .fs-icon-collapse { display: inline; }

@media (max-width: 900px) {
    .canvas-fs-btn { display: inline-flex; }
}
/* Прячем кнопку у тех, кому канвас не доступен */
body.no-canvas .canvas-fs-btn,
body.is-spectator .canvas-fs-btn { display: none !important; }

/* ============================================================
   КНОПКА «РАЗВЕРНУТЬ ЧАТ» (только мобильная версия)
   ============================================================ */
.chat { position: relative; }
.chat-fs-btn {
    display: none;
    position: absolute;
    top: 10px; right: 10px;
    z-index: 4;
    width: 32px; height: 32px;
    border-radius: 50%;
    background: rgba(13, 17, 23, .82);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--line);
    color: var(--text);
    align-items: center; justify-content: center;
    transition: color var(--transition), border-color var(--transition), background var(--transition), transform var(--transition);
}
.chat-fs-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
    background: rgba(95, 230, 164, .12);
}
.chat-fs-btn:active { transform: scale(.92); }
.chat-fs-btn .fs-icon-collapse { display: none; }
body.chat-fs .chat-fs-btn .fs-icon-expand { display: none; }
body.chat-fs .chat-fs-btn .fs-icon-collapse { display: inline; }

@media (max-width: 900px) {
    .chat-fs-btn { display: inline-flex; }
}
/* Прячем у ведущего — он не пишет и канвас в приоритете */
body.is-leader .chat-fs-btn { display: none !important; }

/* ============================================================
   ПОЛНОЭКРАННЫЙ РЕЖИМ ЧАТА
   ============================================================ */
body.chat-fs { overflow: hidden; }
body.chat-fs #screen-game { height: 100vh; max-height: 100vh; overflow: hidden; }
body.chat-fs .chat {
    position: fixed;
    inset: 0;
    z-index: 200;
    margin: 0;
    padding: 14px;
    background: var(--bg);
    width: 100vw; height: 100vh;
    border-radius: 0;
    border: 0;
    max-height: none;
    min-height: 0;
    display: flex; flex-direction: column;
    gap: 0;
}
body.chat-fs .chat-fs-btn {
    top: 14px; right: 14px;
    width: 38px; height: 38px;
}
body.chat-fs .chat-history {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    padding-right: 6px;
    padding-top: 48px;          /* место под кнопку-крестик */
}
body.chat-fs .chat-input {
    flex: 0 0 auto;
    margin-top: 10px;
}
body.chat-fs .topbar,
body.chat-fs #g-left,
body.chat-fs #g-leaderboard,
body.chat-fs #g-controls,
body.chat-fs .word-bar,
body.chat-fs #g-input-hint {
    display: none !important;
}

/* ============================================================
   ПОЛНОЭКРАННЫЙ РЕЖИМ КАНВАСА
   ============================================================ */
body.canvas-fs { overflow: hidden; }
body.canvas-fs #screen-game { height: 100vh; max-height: 100vh; overflow: hidden; }
body.canvas-fs #g-left {
    position: fixed;
    inset: 0;
    z-index: 200;
    margin: 0;
    padding: 0;
    background: var(--bg);
    width: 100vw; height: 100vh;
    display: flex; flex-direction: column;
    gap: 0;
    grid-row: auto;
}
body.canvas-fs .canvas-wrap {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 14px;
    background: var(--bg);
    overflow: hidden;
    border-radius: 0;
    border: 0;
    max-height: none;
    min-height: 0;
}
body.canvas-fs #g-canvas {
    flex: 0 1 auto;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 3 / 2;
    margin: 0;
    background: #fff;
    border: 1px solid rgba(255, 255, 255, .18);
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, .55);
}
body.canvas-fs .canvas-tools {
    flex: 0 0 auto;
    margin: 0;
    justify-content: center;
    flex-wrap: wrap;
}
body.canvas-fs .canvas-fs-btn {
    top: 14px; right: 14px;
}
body.canvas-fs #g-right,
body.canvas-fs .topbar,
body.canvas-fs #g-controls,
body.canvas-fs #g-canvas-hint {
    display: none !important;
}
/* Слово ведущего — плавающая пилюля сверху по центру */
body.canvas-fs .word-bar:not(.hidden) {
    position: fixed;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 201;
    margin: 0;
    padding: 6px 16px;
    border-radius: 999px;
    max-width: calc(100vw - 100px);
    width: auto;
}
body.canvas-fs .word-bar b { font-size: 18px; letter-spacing: 1.5px; }

@media (max-width: 540px) {
    .topbar { padding: 10px 12px; font-size: 13px; gap: 8px; }
    .topbar .brand { font-size: 16px; }
    .topbar .brand span { display: none; }
    .code-pill { padding: 3px 8px; font-size: 12px; }
    .code-pill b { letter-spacing: 2px; }
    .timer { font-size: 18px; padding: 3px 8px; }
    .round-info { display: none; }
    #btn-fit { padding: 6px 10px; font-size: 12px; }

    .lobby-grid { padding: 10px; gap: 10px; }
    .card { padding: 14px; }

    .word-bar { padding: 10px 12px; gap: 8px; }
    .word-bar b { font-size: 20px; letter-spacing: 2px; }

    .game-grid { padding: 8px; gap: 10px; }
    .canvas-tools { gap: 6px; }
    .color-tool { width: 24px; height: 24px; }
    .size-btn, .mode-btn, .history-btn { width: 28px; height: 28px; }
    .size-btn svg, .mode-btn svg, .history-btn svg { width: 14px; height: 14px; }

    .chat { min-height: 200px; }
    .chat-history { min-height: 160px; }

    .hero { padding: 32px 12px 12px; }
    .title-svg { width: 96vw; }

    .end-card { padding: 22px; }
    .trophy { font-size: 48px; }

    /* Список лобби — поджимаем */
    .lobby-list .item { padding: 8px 10px; }
}

/* Когда у плеера канваса быть не должно */
.no-canvas .canvas-wrap,
.no-canvas #g-left { }
body.no-canvas .game-grid { grid-template-columns: 1fr !important; }
@media (min-width: 901px) {
    body.no-canvas #g-left { display: none !important; }
}

/* Ведущий — не пишет в чат */
body.is-leader .chat-input,
body.is-leader #g-input-hint { display: none !important; }

/* Спектатор — не пишет в чат и не рисует. Инструменты и инпут скрыты. */
body.is-spectator .chat-input,
body.is-spectator #g-input-hint,
body.is-spectator #g-tools,
body.is-spectator #g-canvas-hint { display: none !important; }
body.is-spectator #g-canvas { cursor: default; }

/* ============================================================
   МОДАЛКА ЗАВЕРШЕНИЯ РАУНДА
   ============================================================ */
.modal {
    position: fixed; inset: 0;
    z-index: 150;
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
}
.modal.hidden { display: none !important; }

.modal-backdrop {
    position: absolute; inset: 0;
    background: rgba(0, 0, 0, .65);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    animation: modal-fade .3s ease;
}
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }

.modal-card {
    position: relative;
    max-width: 480px; width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    overflow-x: hidden;     /* фикс: контент мог провоцировать горизонтальный скроллбар внизу */
    padding: 26px 24px 22px;
    border-radius: 18px;
    animation: modal-pop .4s cubic-bezier(.34, 1.56, .64, 1);
}
@keyframes modal-pop {
    from { opacity: 0; transform: translateY(24px) scale(.92); }
    to   { opacity: 1; transform: none; }
}

.modal-icon {
    font-size: 56px; line-height: 1; text-align: center;
    margin-bottom: 6px;
    animation: modal-bounce .6s cubic-bezier(.34, 1.56, .64, 1);
}
@keyframes modal-bounce {
    0%   { transform: scale(.2); opacity: 0; }
    60%  { transform: scale(1.18); opacity: 1; }
    100% { transform: scale(1); }
}

.modal-title { margin: 0 0 4px; text-align: center; font-size: 22px; color: var(--text); }
.modal-subtitle { margin: 0 0 14px; text-align: center; color: var(--muted); font-size: 14px; }

.modal-word {
    display: flex; align-items: center; gap: 12px; justify-content: center;
    padding: 12px 14px;
    background: rgba(95, 230, 164, .08);
    border: 1px dashed rgba(95, 230, 164, .45);
    border-radius: 12px;
    margin: 0 0 16px;
}
.modal-word .muted { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; }
.modal-word b {
    font-size: 22px; letter-spacing: 2px;
    background: var(--grad-rainbow);
    background-size: 200% 100%;
    background-clip: text; -webkit-background-clip: text;
    color: transparent;
    text-transform: uppercase;
    animation: word-shimmer 4s linear infinite;
}

.modal-section {
    margin: 8px 0 6px;
    font-size: 13px;
    color: var(--text);
    letter-spacing: .3px;
}
.modal-leaderboard {
    list-style: none; counter-reset: lb;
    padding: 0; margin: 0 0 18px;
    display: flex; flex-direction: column; gap: 4px;
    max-height: 220px; overflow-y: auto;
}
.modal-leaderboard li {
    counter-increment: lb;
    display: flex; justify-content: space-between; align-items: center; gap: 10px;
    padding: 6px 10px;
    border-radius: 6px;
    background: rgba(255, 255, 255, .03);
    border: 1px solid var(--line);
    transition: background var(--transition);
}
.modal-leaderboard li:hover { background: rgba(255, 255, 255, .06); }
.modal-leaderboard li::before {
    content: counter(lb);
    width: 24px; height: 24px; border-radius: 50%;
    background: rgba(255, 255, 255, .06); color: var(--muted);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.modal-leaderboard li:nth-child(1)::before { background: linear-gradient(135deg, #f0b033, #d18a0a); color: #0d1117; }
.modal-leaderboard li:nth-child(2)::before { background: linear-gradient(135deg, #c9d0db, #8c95a3); color: #0d1117; }
.modal-leaderboard li:nth-child(3)::before { background: linear-gradient(135deg, #cd7f32, #864e0f); color: #fff; }
.modal-leaderboard li.you { background: rgba(95, 230, 164, .1); color: var(--accent); font-weight: 600; }
.modal-leaderboard li .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-leaderboard li .pts { font-variant-numeric: tabular-nums; font-weight: 700; }
.modal-leaderboard li .delta {
    font-size: 11px; color: var(--accent); font-weight: 700;
    background: rgba(95, 230, 164, .12); padding: 1px 6px; border-radius: 999px;
}

.modal-actions {
    display: flex; gap: 10px; justify-content: center; flex-wrap: wrap;
}

@media (max-width: 540px) {
    .modal-card { padding: 22px 18px 18px; max-height: 94vh; }
    .modal-icon { font-size: 44px; }
    .modal-title { font-size: 19px; }
    .modal-word b { font-size: 18px; letter-spacing: 1.5px; }
}

/* ============================================================
   Очень узкие экраны (<= 380px) — мобильный поджим
   ============================================================ */
@media (max-width: 380px) {
    #screen-login { padding: 0 10px 24px; }
    .hero { padding: 26px 8px 12px; }
    .title-svg { width: 94vw; }
    .login { padding: 16px 16px 20px; }
    .field input { padding: 16px 12px 6px; }
    .tabs { padding: 3px; }
    .tab { padding: 8px 10px; font-size: 14px; }

    .hero-status {
        padding: 5px 10px;
        font-size: 11px;
        gap: 6px;
        max-width: 96vw;
    }
    .hs-ping { min-width: 42px; }

    .topbar { padding: 8px 8px; gap: 6px; }
    .code-pill { padding: 2px 7px; font-size: 11px; }
    .timer { font-size: 16px; padding: 2px 6px; }
    #btn-leave2, #btn-leave, #btn-fit { padding: 5px 8px; font-size: 12px; }

    .lobby-grid { padding: 8px; gap: 8px; }
    .card { padding: 12px; }
    .card-title { font-size: 14px; }

    .chip { padding: 5px 10px; font-size: 12px; }
    .chip-group { gap: 6px; }

    .game-grid { padding: 6px; }
    .canvas-tools { gap: 5px; }
    .color-tool { width: 22px; height: 22px; }
    .size-btn, .mode-btn, .history-btn { width: 26px; height: 26px; }
    .tool.wide { padding: 5px 10px; font-size: 12px; }
}

/* ≤ 370px — кнопки в модалке итогов чуть мельче, чтобы не переносились */
@media (max-width: 370px) {
    .modal-actions { gap: 6px; }
    .modal-actions .btn-primary,
    .modal-actions .btn-ghost {
        font-size: 13px;
        padding: 9px 12px;
    }
}
