:root {
    --bg: #1a1a2e; --field-bg: #16213e; --snake-head: #e94560;
    --snake-body: #533483; --food: #f5a623; --food-wildcard: #e94560;
    --ui-bg: #0a0a1a; --gold: #ffd700; --danger: #e94560;
    --success: #2ecc71; --word-ready: #f39c12;
}
* { margin:0; padding:0; box-sizing:border-box; -webkit-tap-highlight-color: transparent; }
html, body { width: 100%; height: 100%; }
body { background: var(--bg); font-family: 'Segoe UI','Courier New',monospace; color: #fff; user-select: none; -webkit-user-select: none; }
.hidden { display: none !important; }
canvas { display: block; }

/* ========== ДЕСКТОП ========== */
body.desktop {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow-y: auto;
}
body.desktop .game-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 16px;
    width: 100%;
    max-width: 750px;
}
body.desktop .mobile-controls,
body.desktop .mobile-hint,
body.desktop .game-logo-bg,
body.desktop .last-word,
body.desktop .controls { display: none; }

body.desktop .top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    flex-shrink: 0;
    gap: 12px;
    padding: 4px 0;
}
body.desktop .top-btn {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 12px;
    color: #ccc;
    padding: 8px 18px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
    font-size: 0.8rem;
}
body.desktop .top-btn:hover { background: rgba(245,166,35,0.2); border-color: #f5a623; }
body.desktop .top-btn.danger { border-color: rgba(233,69,96,0.35); }
body.desktop .top-btn.danger:hover { background: rgba(233,69,96,0.2); }
body.desktop .top-btn-icon { font-size: 1rem; }
body.desktop .top-btn-label { font-size: 0.7rem; letter-spacing: 1px; opacity: 0.85; }

body.desktop .score-header {
    display: flex;
    align-items: center;
    gap: 18px;
    flex-shrink: 0;
}
body.desktop .stat-inline { display: flex; align-items: center; gap: 6px; }
body.desktop .stat-inline .stat-label { color: #888; font-size: 0.65rem; text-transform: uppercase; }
body.desktop .stat-inline .stat-value { color: var(--gold); font-weight: 900; font-size: 1.1rem; }

body.desktop .word-display {
    padding: 14px 28px;
    border-radius: 20px;
    border: 3px solid #555;
    font-size: 1.8rem;
    letter-spacing: 5px;
    min-width: 250px;
}
body.desktop .game-container {
    border: 3px solid #f5a623;
    border-radius: 15px;
    box-shadow: 0 0 30px rgba(233,69,96,0.3), inset 0 0 60px rgba(0,0,0,0.5);
    overflow: hidden;
    position: relative;
    flex-shrink: 0;
    line-height: 0;
    width: fit-content;
    height: fit-content;
    margin: 4px 0;
}
body.desktop .found-word { font-size: 3rem; }
body.desktop .btn-menu { padding: 14px 30px; border-radius: 30px; font-size: 1.1rem; }
body.desktop .btn-play { font-size: 1.3rem; }
/* Новая десктопная панель */
body.desktop .bottom-panel {
    display: flex;
    align-items: center;
    gap: 20px;
    width: 100%;
    margin-top: 4px;
    padding: 14px 20px;
    background: rgba(255,255,255,0.03);
    border-radius: 14px;
    border: 1px solid rgba(255,255,255,0.1);
}

body.desktop .hint-divider {
    width: 1px;
    height: 50px;
    background: rgba(255,255,255,0.15);
    flex-shrink: 0;
}

body.desktop .hint-text-inline { 
    color: #bbb; 
    font-size: 0.85rem; 
    text-align: left; 
    line-height: 1.7;
    margin-right: auto;
}
/* ========== МОБАЙЛ ========== */
body.mobile {
    position: fixed;
    top: 0; left: 0;
    width: 100vw;
    height: 100dvh;
    display: flex;
    justify-content: center;
    align-items: stretch;
    touch-action: manipulation;
}
body.mobile .game-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    height: 100%;
    padding: 6px 8px;
    gap: 6px;
    overflow-y: auto;
}

body.mobile #mainMenu,
body.mobile #recordsScreen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 100%;
}

body.mobile #gameUI {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    height: 100%;
    gap: 4px;
}

body.mobile .desktop-only,
body.mobile .stats,
body.mobile .controls,
body.mobile .speed-slider { display: none !important; }

body.mobile .top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    flex-shrink: 0;
    gap: 4px;
    padding: 2px 0;
}
body.mobile .top-btn {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 10px;
    color: #ccc;
    padding: 5px 10px;
    display: flex;
    align-items: center;
    gap: 3px;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    flex-shrink: 0;
    font-size: 0.7rem;
    min-width: 62px;
    justify-content: center;
}
body.mobile .top-btn:active { background: rgba(245,166,35,0.2); border-color: #f5a623; transform: scale(0.95); }
body.mobile .top-btn.danger { border-color: rgba(233,69,96,0.35); }
body.mobile .top-btn-icon { font-size: 0.9rem; }
body.mobile .top-btn-label { font-size: 0.6rem; letter-spacing: 1px; opacity: 0.85; }

body.mobile .score-header {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
body.mobile .stat-inline { display: flex; align-items: center; gap: 3px; }
body.mobile .stat-inline .stat-label { color: #888; font-size: 0.55rem; text-transform: uppercase; }
body.mobile .stat-inline .stat-value { color: var(--gold); font-weight: 900; font-size: 0.85rem; }

body.mobile .word-display {
    padding: 6px 12px;
    border-radius: 10px;
    border: 2px solid #555;
    font-size: 1rem;
    letter-spacing: 3px;
    width: calc(100% - 8px);
    flex-shrink: 0;
    text-align: center;
}

body.mobile .game-container {
    border: 2px solid #f5a623;
    border-radius: 12px;
    box-shadow: 0 0 20px rgba(233,69,96,0.3);
    overflow: hidden;
    position: relative;
    flex-shrink: 0;
    flex-grow: 0;
    width: fit-content;
    height: fit-content;
    margin: 2px auto;
    line-height: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

body.mobile .game-logo-bg {
    display: block;
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%,-50%);
    font-size: 2.5rem;
    opacity: 0.05;
    pointer-events: none;
    z-index: 1;
}
body.mobile .found-word { font-size: 1.5rem; }
body.mobile .last-word {
    display: block;
    padding: 3px 8px;
    border-radius: 8px;
    border: 1px solid #333;
    font-size: 0.6rem;
    color: #aaa;
    width: calc(100% - 8px);
    text-align: center;
    flex-shrink: 0;
}
/* D-Pad — сразу под игровым полем */
body.mobile .mobile-controls {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    flex-shrink: 0;
    flex-grow: 0;
    width: 100%;
    max-width: 350px;
    padding: 2px 0;
    margin: 0;
}
body.mobile .dpad-grid {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    width: 100%;
    max-width: 300px;
}
body.mobile .dpad-row {
    display: flex;
    gap: 4px;
    justify-content: center;
    width: 100%;
}
body.mobile .dpad-btn {
    background: rgba(255,255,255,0.12);
    border: 2px solid rgba(255,255,255,0.25);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    cursor: pointer;
    color: #fff;
    transition: all 0.1s;
    -webkit-tap-highlight-color: transparent;
    aspect-ratio: 1;
    width: 60px;
    height: 60px;
    flex-shrink: 0;
}
body.mobile .dpad-btn-wide {
    width: 68px;
}
body.mobile .dpad-btn:active {
    background: rgba(245,166,35,0.35);
    border-color: #f5a623;
    transform: scale(0.93);
}
body.mobile .dpad-pause {
    background: rgba(233,69,96,0.4);
    border-color: #e94560;
    font-size: 1.3rem;
    font-weight: 900;
    width: 56px;
    height: 56px;
}
body.mobile .dpad-spacer {
    width: 60px;
    height: 60px;
    background: transparent;
    border: none;
    flex-shrink: 0;
}
body.mobile .dpad-row .dpad-spacer:first-child,
body.mobile .dpad-row .dpad-spacer:last-child {
    width: 60px;
}

/* Мобильное меню */
body.mobile .menu-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 20px 10px;
    overflow-y: auto;
    max-height: 100%;
    width: 100%;
    position: relative;
    z-index: 5;
    text-align: center;
}
body.mobile .menu-logo { font-size: 3.5rem; }
body.mobile .menu-buttons { max-width: 280px; gap: 12px; }
body.mobile .btn-menu { padding: 16px 18px; font-size: 1.1rem; border-radius: 24px; }
body.mobile .btn-play { font-size: 1.2rem; }
body.mobile .title { font-size: 1.8rem; }
body.mobile .subtitle { font-size: 0.8rem; }
body.mobile .records-title { font-size: 1.2rem; }
body.mobile .records-tab { padding: 8px 14px; font-size: 0.7rem; }
body.mobile .records-table { font-size: 0.6rem; }
body.mobile .modal-dialog {
    padding: 16px;
    max-width: 300px;
    border-width: 2px;
    margin: 0 auto;
}
body.mobile .records-container {
    overflow-y: auto;
    max-height: 100%;
    padding: 10px;
    width: 100%;
    text-align: center;
}
/* ========== ОБЩИЕ СТИЛИ ========== */
.word-display {
    background: var(--ui-bg);
    font-weight: 900;
    text-align: center;
    text-transform: uppercase;
    transition: border-color 0.3s;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.word-display.has-match {
    border-color: var(--word-ready);
    cursor: pointer;
    animation: border-pulse 1.5s infinite;
}
.word-display .highlight { color: #fff; background: var(--word-ready); padding: 2px 4px; border-radius: 3px; display: inline-block; }
.word-display .wildcard-highlight {
    color: #fff; background: #e94560; padding: 2px 4px; border-radius: 3px; display: inline-block;
    animation: wildcard-glow 1s infinite;
}
@keyframes wildcard-glow {
    0%,100% { box-shadow: 0 0 8px rgba(233,69,96,0.5); }
    50% { box-shadow: 0 0 16px rgba(233,69,96,0.9); }
}
@keyframes border-pulse {
    0%,100% { border-color: var(--word-ready); }
    50% { border-color: #e67e22; }
}

.pause-overlay {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.55); color: #fff;
    font-size: 36px; font-weight: 900; letter-spacing: 4px;
    display: flex; justify-content: center; align-items: center;
    z-index: 20; pointer-events: none;
}
body.mobile .pause-overlay { font-size: 24px; }

.found-word {
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%,-50%) scale(0);
    font-weight: 900; color: #ffd700;
    pointer-events: none; z-index: 10;
}
.found-word.show { animation: pop 1.5s ease-out forwards; }
@keyframes pop {
    0% { transform: translate(-50%,-50%) scale(0.3); opacity: 0; }
    20% { transform: translate(-50%,-50%) scale(1.8); opacity: 1; }
    100% { transform: translate(-50%,-50%) scale(1.2); opacity: 0; }
}

.stats {
    display: flex; gap: 16px; background: var(--ui-bg);
    padding: 8px 16px; border-radius: 30px; border: 2px solid #333;
    flex-wrap: wrap; justify-content: center;
}
.stat { display: flex; flex-direction: column; align-items: center; gap: 1px; }
.stat-label { font-size: 0.55rem; text-transform: uppercase; letter-spacing: 2px; color: #888; }
.stat-value { font-size: 1.3rem; font-weight: 900; color: var(--gold); }
.stat-value.words { color: #f5a623; }
.stat-value.level { color: #2ecc71; }

.last-word { background: var(--ui-bg); }
.last-word span { color: var(--success); font-weight: 700; }
.mobile-speed-label { color: #f5a623 !important; font-weight: 700; white-space: nowrap; }
.mobile-speed-label #mobileSpeedLabel { color: #f5a623; }

.controls {
    display: flex; gap: 6px; align-items: center;
    flex-wrap: wrap; justify-content: center; width: 100%;
}
.btn {
    background: #533483; color: #fff;
    padding: 7px 14px; border-radius: 25px;
    font-size: 0.78rem; font-weight: 700; letter-spacing: 1px;
    cursor: pointer; transition: all 0.3s;
    text-transform: uppercase; border: 2px solid transparent; white-space: nowrap;
}
.btn:hover { background: #6b44b3; border-color: #f5a623; }
.btn.activate {
    background: var(--word-ready); color: #000; font-size: 0.82rem;
    animation: pulse-btn 1.5s infinite; border-color: #e67e22;
    font-weight: 900; max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
@keyframes pulse-btn {
    0%,100% { box-shadow: 0 0 8px rgba(243,156,18,0.5); }
    50% { box-shadow: 0 0 20px rgba(243,156,18,0.9); }
}
.btn.activate:disabled { background: #555; color: #999; animation: none; border-color: #555; }
.btn.danger { background: #e94560; }
.btn.danger:hover { background: #ff6b81; }

/* Доступность — фокус с клавиатуры */
:focus-visible {
    outline: 2px solid #f5a623;
    outline-offset: 2px;
}
button:focus-visible {
    outline: 2px solid #f5a623;
    outline-offset: 3px;
    border-radius: 4px;
}
.name-input:focus-visible {
    outline: none; /* уже стилизован через border-color */
}

/* Меню */
.menu-container { display: flex; flex-direction: column; align-items: center; gap: 16px; animation: fadeInUp 0.5s ease-out; }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
.menu-logo { font-size: 4.5rem; animation: float 3s ease-in-out infinite; }
@keyframes float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-12px); } }
.menu-buttons { display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 300px; }
.btn-menu {
    padding: 14px 28px; border-radius: 30px; font-size: 1rem;
    font-weight: 900; letter-spacing: 2px; cursor: pointer;
    transition: all 0.3s; text-transform: uppercase;
    border: 2px solid transparent; width: 100%; text-align: center;
}
.btn-play { background: linear-gradient(135deg, #e94560, #c23152); color: #fff; font-size: 1.2rem; }
.btn-records { background: linear-gradient(135deg, #533483, #3d2560); color: #fff; }
.btn-back { background: rgba(255,255,255,0.1); color: #fff; }
.title {
    font-size: 2.2rem; font-weight: 900; letter-spacing: 4px;
    background: linear-gradient(135deg, #e94560, #f5a623);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; text-align: center;
}
.subtitle { color: #888; font-size: 0.85rem; text-align: center; }
.credits { color: #555; font-size: 0.7rem; text-align: center; letter-spacing: 1px; margin-top: 4px; }

/* Рекорды */
.records-container { animation: fadeInUp 0.5s ease-out; width: 100%; max-width: 600px; }
.records-title { font-size: 1.6rem; font-weight: 900; color: #ffd700; text-align: center; margin-bottom: 14px; }
.records-tabs { display: flex; gap: 6px; margin-bottom: 10px; justify-content: center; flex-wrap: wrap; }
.records-tab {
    background: rgba(255,255,255,0.05); border: 2px solid rgba(255,255,255,0.1);
    color: #888; padding: 7px 15px; border-radius: 16px;
    cursor: pointer; font-size: 0.7rem; font-weight: 700;
    letter-spacing: 1px; text-transform: uppercase; transition: all 0.3s;
}
.records-tab.active { background: #533483; border-color: #f5a623; color: #fff; }
.records-section { display: none; }
.records-section.active { display: block; }
.records-table { width: 100%; border-collapse: collapse; margin-bottom: 12px; font-size: 0.75rem; }
.records-table th {
    background: rgba(255,255,255,0.05); padding: 7px 6px; text-align: center;
    color: #888; font-size: 0.6rem; text-transform: uppercase;
    border-bottom: 2px solid rgba(255,255,255,0.1);
}
.records-table td { padding: 7px 6px; text-align: center; border-bottom: 1px solid rgba(255,255,255,0.05); }
.rank-1 { color: #ffd700; font-weight: 900; }
.rank-2 { color: #c0c0c0; }
.rank-3 { color: #cd7f32; }
.name-cell { color: #f5a623; font-weight: 700; max-width: 70px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.word-cell { color: #e94560; font-weight: 700; }
.score-cell { color: var(--gold); font-weight: 700; }
.no-records { text-align: center; color: #666; padding: 25px; }

/* Модалки */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85); backdrop-filter: blur(5px);
    display: flex; justify-content: center; align-items: center;
    z-index: 1000; animation: fadeInModal 0.3s ease-out; padding: 12px;
}
@keyframes fadeInModal { from { opacity: 0; } to { opacity: 1; } }
.modal-dialog {
    background: linear-gradient(135deg, #1a1a2e, #16213e);
    border: 3px solid #e94560; border-radius: 16px;
    padding: 18px; max-width: 360px; width: 100%;
    text-align: center; animation: scaleIn 0.3s ease-out;
    max-height: 80vh; overflow-y: auto;
}
.modal-dialog.level-complete { border-color: #2ecc71; }
@keyframes scaleIn { from { transform: scale(0.8); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-icon { font-size: 2.2rem; margin-bottom: 3px; }
.modal-title { font-size: 1.2rem; font-weight: 900; color: #e94560; margin-bottom: 3px; }
.modal-title.level-title { color: #2ecc71; }
.modal-subtitle { font-size: 0.7rem; color: #aaa; margin-bottom: 6px; }
.name-input-group { margin: 6px 0; }
.name-input-label { font-size: 0.6rem; color: #888; display: block; margin-bottom: 3px; }
.name-input {
    width: 100%; padding: 8px; background: rgba(255,255,255,0.08);
    border: 2px solid rgba(255,255,255,0.2); border-radius: 8px;
    color: #fff; font-size: 0.85rem; text-align: center; outline: none;
}
.name-input:focus { border-color: #f5a623; }
.modal-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 8px; }
.modal-stat {
    background: rgba(255,255,255,0.05); border: 1px solid rgba(255,255,255,0.1);
    border-radius: 7px; padding: 6px;
}
.modal-stat-label { font-size: 0.55rem; color: #888; text-transform: uppercase; }
.modal-stat-value { font-size: 0.95rem; font-weight: 900; color: var(--gold); }
.modal-encouragement { font-size: 0.65rem; color: #aaa; margin-bottom: 8px; font-style: italic; }
.modal-buttons { display: flex; flex-direction: column; gap: 4px; }
.btn-large {
    padding: 9px 18px; border-radius: 20px; font-size: 0.8rem;
    font-weight: 900; cursor: pointer; text-transform: uppercase;
    border: 2px solid transparent; width: 100%;
}
.btn-continue { background: #2ecc71; color: #fff; }
.btn-save { background: #533483; color: #fff; }
.btn-exit { background: #e94560; color: #fff; }
.btn-menu-return { background: rgba(255,255,255,0.1); color: #fff; }