#game-wrap {
    position: relative; width: 100%; max-width: 100%; aspect-ratio: 1600 / 320; height: auto; margin: 0 auto; overflow: hidden;
    background: #000 linear-gradient(180deg, #1c1c22 0%, #050505 28%, #050505 72%, #1c1c22 100%);
    font-family: 'Courier New', Courier, monospace;
    user-select: none; touch-action: none; border: none; box-shadow: 0 15px 40px rgba(0,0,0,0.6);
}
#game-wrap:fullscreen { aspect-ratio: auto; width: 100vw; height: 100vh; min-height: 0; }
#game-canvas { display: block; width: 100%; height: 100%; cursor: pointer; object-fit: contain; }

#game-ui { position: absolute; top: 10px; left: 10px; z-index: 5; display: flex; gap: 10px; }
.ui-tile {
    background: rgba(30, 30, 30, 0.9); border: none; border-radius: 4px; padding: 10px;
    color: #aaa; font-size: 10px; box-shadow: 0 4px 10px rgba(0,0,0,0.5); display: flex; align-items: center;
}
.ui-tile span { color: #F59500; margin-left: 6px; font-weight: bold; font-size: 13px; }
#btn-fullscreen:hover { background: #555 !important; }

.ui-tile-lb {
    font-size: 12px; min-width: 160px; pointer-events: auto;
    background: rgba(30, 30, 30, 0.4); border-radius: 4px; backdrop-filter: blur(4px); padding: 10px;
}
.lb-title { text-align: center; margin-bottom: 10px; font-size: 14px; border-bottom: 1px solid rgba(245, 149, 0, 0.5); padding-bottom: 5px; color: #fff;}

/* Общие стили для всех таблиц рекордов (десктоп-панель, меню, экран проигрыша) */
.lb-list { margin: 0; padding: 0; list-style: none; counter-reset: rank; }
.lb-list li {
    counter-increment: rank;
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 4px; text-transform: uppercase; color: #fff;
}
.lb-list li::before {
    content: counter(rank); flex-shrink: 0;
    width: 18px; height: 18px; line-height: 18px; text-align: center;
    font-size: 11px; font-weight: bold; border-radius: 3px;
    background: rgba(255,255,255,0.12); color: #ccc;
}
.lb-list li:nth-child(1)::before { background: #ffd700; color: #000; }
.lb-list li:nth-child(2)::before { background: #c0c0c0; color: #000; }
.lb-list li:nth-child(3)::before { background: #cd7f32; color: #000; }
.lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { color: #F59500; font-weight: bold; }
.lb-list li.lb-empty { display: block; color: #888; font-size: 11px; text-transform: none; text-align: center; }
.lb-list li.lb-empty::before { display: none; }

/* Блоки рекордов для мобильных (в меню и на экране проигрыша) — на десктопе скрыты */
.lb-mobile { display: none; }

#game-rules, #game-modal {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85); display: flex; align-items: center; justify-content: center;
    z-index: 20; backdrop-filter: blur(5px);
}
#game-modal { z-index: 10; display: none; }

.rules-box {
    background: #222; border: 2px solid #F59500; padding: 10px 20px; border-radius: 4px;
    width: 90%; max-width: 900px; display: flex; flex-direction: column; gap: 6px; box-sizing: border-box;
}
.rules-box .gh2 { font-size: 22px; margin: 0; }
.rules-box .gh3 { margin: 0; color: #F59500; text-align: center; font-size: 16px; font-weight: 900; letter-spacing: 2px; }

.rules-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 7px; margin-top: 3px; }
.rule-tile {
    background: #111; padding: 7px 9px; border-radius: 4px; border: 1px solid #444; margin: 0;
    color: #ccc; font-size: 11px; box-sizing: border-box;
    display: flex; gap: 8px; align-items: center; line-height: 1.3;
}
.rule-tile span { font-size: 20px; flex-shrink: 0; }
.rule-tile b { color: #fff; }

#btn-start-game {
    background: #F59500; color: #000; border: none; padding: 10px; border-radius: 4px;
    font-weight: bold; cursor: pointer; font-size: 18px; width: 100%; transition: 0.2s;
    font-family: inherit; letter-spacing: 2px; margin-top: 5px;
}
#btn-start-game:hover { background: #fff; }

.modal-box {
    display: flex; flex-direction: row; align-items: stretch; justify-content: center;
    width: 600px; max-width: 100%; gap: 10px; padding: 10px; box-sizing: border-box;
}
.modal-tile { background: #222; border: 2px solid #F59500; padding: 20px; display: flex; flex-direction: column; justify-content: center; border-radius: 4px;}
.stats-tile { flex: 1; text-align: left; border-color: #c13d3d; }
.action-tile { flex: 1; gap: 10px; }

.modal-box .gh3 { margin: 0 0 10px 0; color: #c13d3d; font-size: 24px; font-weight: 900; letter-spacing: 2px; text-align: center;}
.stats-grid { display: flex; gap: 10px; }
.stat-item { background: #111; padding: 10px; border: 1px solid #444; flex: 1; display: flex; flex-direction: column; align-items: center; border-radius: 4px;}
.stat-item span { color: #aaa; font-size: 12px; letter-spacing: 1px; margin-bottom: 5px;}
.stat-item b { color: #F59500; font-size: 24px; font-weight: bold; }

.modal-box input {
    width: 100%; box-sizing: border-box; padding: 10px; border-radius: 4px;
    background: #111; border: 2px solid #F59500; color: #F59500; font-family: inherit;
    text-align: center; outline: none; font-size: 16px; font-weight: bold; text-transform: uppercase;
}
.modal-box input:focus { background: #000; box-shadow: inset 0 0 10px rgba(245, 149, 0, 0.3); }
.modal-btns { display: flex; gap: 10px; }
.modal-btns button {
    background: #333; color: #fff; border: 2px solid #555; padding: 10px; border-radius: 4px;
    cursor: pointer; font-family: inherit; transition: 0.2s; flex: 1; font-weight: bold; font-size: 14px;
}
#btn-save { background: #F59500; color: #000; border-color: #F59500; }
#btn-save:hover:not(:disabled) { background: #fff; border-color: #fff; }
#btn-save:disabled { opacity: 0.5; cursor: not-allowed; }
#btn-skip:hover { background: #555; }

@media (max-width: 768px) {
    #game-wrap { min-height: 230px; }
    /* Экран проигрыша: 3 блока В РЯД (итог+рестарт · ввод имени · топ рекордов),
       т.к. друг под другом они не помещались в невысокое поле игры */
    .modal-box { flex-direction: row; align-items: stretch; width: 97%; max-width: 600px; padding: 5px; gap: 5px; max-height: 100%; overflow-y: auto; }
    #game-leaderboard { display: none; } /* боковая панель — её заменяют блоки .lb-mobile */
    .modal-tile { flex: 1; min-width: 0; padding: 8px 6px; border-width: 1px; }
    .modal-box .gh3 { font-size: 15px; margin-bottom: 6px; }

    .stats-grid { flex-direction: column; gap: 5px; }
    .stat-item { padding: 5px; }
    .stat-item span { font-size: 10px; margin-bottom: 2px; }
    .stat-item b { font-size: 18px; }

    #record-msg { font-size: 13px; margin: 0 0 6px 0; }
    #no-record-msg { font-size: 11px; margin: 0 0 6px 0; }
    .modal-box input { font-size: 14px; padding: 8px 4px; margin-bottom: 6px; }
    .modal-btns { flex-direction: column; gap: 6px; }
    .modal-btns button { padding: 10px 6px; font-size: 13px; }

    #game-ui { flex-direction: row; gap: 5px; flex-wrap: wrap; }
    .ui-tile { padding: 7px 8px; font-size: 9px; }
    .ui-tile span { font-size: 12px; }
    #btn-fullscreen { font-size: 9px; padding: 8px; }

    .rules-content { display: none; }
    .mobile-only-text { display: block !important; font-size: 10px; line-height: 1.15; margin-bottom: 0; }

    .rules-box { padding: 8px 10px; width: 92%; max-width: 340px; gap: 4px; justify-content: center; border-width: 1px; max-height: 100%; overflow-y: auto; }
    .rules-box .gh2 { font-size: 15px; letter-spacing: 1px; }
    #btn-start-game { font-size: 13px; padding: 8px; margin-top: 0; }

    /* Таблица рекордов внутри меню и на экране проигрыша */
    .lb-mobile { display: block; width: 100%; box-sizing: border-box; }
    .lb-mobile .lb-title { font-size: 12px; margin-bottom: 4px; padding-bottom: 3px; }
    .lb-mobile .lb-list { font-size: 13px; }
    .lb-mobile .lb-list li { margin-bottom: 2px; }
    /* по умолчанию показываем топ-5 (экран проигрыша — там 3 колонки, место есть) */
    .lb-mobile .lb-list li:nth-child(n+6) { display: none; }
    /* В меню блок рекордов — на всю ширину; топ-3 и максимально компактно,
       чтобы стартовый экран влезал без прокрутки в невысокое поле игры */
    #game-rules .lb-mobile { width: 100%; }
    #game-rules .lb-mobile .lb-title { font-size: 11px; margin-bottom: 2px; padding-bottom: 2px; }
    #game-rules .lb-mobile .lb-list { font-size: 11px; }
    #game-rules .lb-mobile .lb-list li { margin-bottom: 1px; gap: 5px; }
    #game-rules .lb-mobile .lb-list li::before { width: 14px; height: 14px; line-height: 14px; font-size: 9px; }
    #game-rules .lb-mobile .lb-list li:nth-child(n+4) { display: none; }
    .lb-modal { display: flex; flex-direction: column; }
    .lb-modal .lb-list { font-size: 11px; }
    .lb-modal .lb-list li { gap: 5px; }
    .lb-modal .lb-list li::before { width: 15px; height: 15px; line-height: 15px; font-size: 9px; }
}