/* ============================================
   LEXISCALE — Styles
   © 2024-2026 PRESTATIC (SARL) — SOUILAH AKIM
   ============================================ */

:root {
    --primary: #00b894;
    --primary-light: #55efc4;
    --primary-dark: #00856a;
    --accent: #fdcb6e;
    --accent-dark: #e17055;
    --bg: #0a0a1a;
    --surface: #12122a;
    --surface-light: #1e1e3a;
    --surface-hover: #2a2a4a;
    --text: #e0e0f0;
    --text-dim: #8888a0;
    --danger: #d63031;
    --success: #00b894;
    --tile-size: 44px;
    --tile-gap: 4px;
}

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

body {
    font-family: 'Poppins', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}

/* ============ SCREENS ============ */

.screen {
    display: none;
    min-height: 100vh;
    flex-direction: column;
}
.screen.active { display: flex; }

/* ============ LOADING SCREEN ============ */

#screenLoading {
    justify-content: center;
    align-items: center;
    background: radial-gradient(ellipse at center, #0d2137 0%, var(--bg) 70%);
}

.loading-container { text-align: center; padding: 24px; }

.loading-logo {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 20px;
}

.logo-letter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: 8px;
    font-family: 'Orbitron', monospace;
    font-weight: 800;
    font-size: 18px;
    color: #fff;
    animation: logoFloat 2s ease-in-out infinite;
    animation-delay: calc(var(--i) * 0.1s);
}

@keyframes logoFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-8px); }
}

.loading-title {
    font-family: 'Orbitron', monospace;
    font-size: 2rem;
    font-weight: 900;
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 6px;
}

.loading-subtitle { color: var(--text-dim); font-size: 0.9rem; margin-bottom: 30px; }

.loading-bar-container {
    width: 260px;
    height: 6px;
    background: rgba(255,255,255,0.08);
    border-radius: 3px;
    margin: 0 auto 16px;
    overflow: hidden;
}

.loading-bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    border-radius: 3px;
    transition: width 0.4s;
}

.loading-text { color: var(--text-dim); font-size: 0.8rem; }

/* ============ HOME SCREEN ============ */

#screenHome {
    justify-content: center;
    align-items: center;
    background: radial-gradient(ellipse at 50% 30%, #0d2a22 0%, var(--bg) 60%);
    position: relative;
    overflow: hidden;
}

.back-to-hub {
    position: absolute;
    top: 16px;
    left: 16px;
    color: var(--primary);
    text-decoration: none;
    font-size: 0.85rem;
    z-index: 5;
    transition: opacity 0.3s;
}
.back-to-hub:hover { opacity: 0.7; }

.floating-letters {
    position: absolute;
    inset: 0;
    overflow: hidden;
    z-index: 0;
    pointer-events: none;
}

.floating-tile {
    position: absolute;
    bottom: -60px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-family: 'Orbitron', monospace;
    font-weight: 700;
    color: rgba(0, 184, 148, 0.25);
    animation: floatUp linear infinite;
}

@keyframes floatUp {
    0% { transform: translateY(0) rotate(0deg); opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { transform: translateY(-110vh) rotate(360deg); opacity: 0; }
}

.home-container {
    position: relative;
    z-index: 2;
    text-align: center;
    padding: 20px;
    max-width: 460px;
    width: 100%;
}

.home-title {
    font-family: 'Orbitron', monospace;
    font-size: 2.8rem;
    font-weight: 900;
    color: #fff;
    letter-spacing: 2px;
    margin-bottom: 6px;
}

.home-title span {
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.home-subtitle { color: var(--text-dim); font-size: 0.95rem; margin-bottom: 16px; }

.home-stats-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(0, 184, 148, 0.1);
    border: 1px solid rgba(0, 184, 148, 0.2);
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 0.8rem;
    color: var(--primary-light);
    margin-bottom: 30px;
}

.home-menu { display: flex; flex-direction: column; gap: 10px; margin-bottom: 30px; }

.menu-btn {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 14px 18px;
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    font-family: 'Poppins', sans-serif;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s;
    gap: 12px;
    text-align: left;
}

.menu-btn:hover { background: var(--surface-hover); border-color: rgba(0, 184, 148, 0.3); transform: translateX(4px); }
.menu-btn.primary { background: linear-gradient(135deg, var(--primary-dark), var(--primary)); border-color: transparent; color: #fff; font-weight: 600; }
.menu-btn.primary:hover { filter: brightness(1.15); }
.btn-icon { font-size: 1.2rem; flex-shrink: 0; }
.btn-label { flex: 1; }
.btn-arrow { color: var(--text-dim); font-size: 1.1rem; }

.home-footer { font-size: 0.75rem; color: var(--text-dim); }
.home-footer p { margin-bottom: 8px; }
.home-legal { display: flex; flex-wrap: wrap; gap: 6px 16px; justify-content: center; margin-bottom: 8px; }
.home-legal a { color: var(--text-dim); text-decoration: none; font-size: 0.7rem; }
.home-legal a:hover { color: var(--primary); }
.home-cookie-btn {
    background: none; border: 1px solid rgba(255,255,255,0.1); color: var(--text-dim);
    padding: 3px 12px; border-radius: 20px; cursor: pointer; font-size: 0.7rem; font-family: 'Poppins'; transition: all 0.3s;
}
.home-cookie-btn:hover { border-color: rgba(0,184,148,0.5); color: var(--primary-light); }
.home-version { font-size: 0.7rem; color: #444; }

/* ============ SCORES SCREEN ============ */

#screenScores {
    background: var(--bg);
}

.screen-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 24px;
}

.back-btn {
    background: none; border: none; color: var(--primary); cursor: pointer;
    font-family: 'Poppins'; font-size: 0.9rem; margin-bottom: 16px; padding: 0;
}
.back-btn:hover { opacity: 0.7; }

.screen-title {
    font-family: 'Orbitron', monospace;
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 20px;
    color: #fff;
}

.scores-tabs { display: flex; gap: 8px; margin-bottom: 20px; }

.score-tab {
    flex: 1;
    padding: 8px;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-dim);
    font-family: 'Poppins'; font-size: 0.8rem;
    cursor: pointer; transition: all 0.3s;
}
.score-tab.active { background: var(--primary-dark); border-color: var(--primary); color: #fff; }

.scores-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.scores-table th {
    text-align: left;
    padding: 10px 8px;
    border-bottom: 1px solid rgba(0,184,148,0.2);
    color: var(--primary-light);
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
}

.scores-table td {
    padding: 10px 8px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    color: var(--text);
}

.scores-table tr:nth-child(1) td { color: var(--accent); font-weight: 600; }
.scores-table tr:nth-child(2) td { color: #c0c0c0; }
.scores-table tr:nth-child(3) td { color: #cd7f32; }

.scores-empty { color: var(--text-dim); text-align: center; padding: 40px; font-size: 0.9rem; }

/* ============ GAME SCREEN ============ */

#screenGame.active {
    background: var(--bg);
    height: 100vh;
    height: -webkit-fill-available;
    height: 100dvh;
    flex-direction: column;
    overflow: hidden;
}

.game-top-bar {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid rgba(0,184,148,0.15);
    gap: 12px;
    flex-shrink: 0;
}

.game-back-btn {
    background: none; border: none; color: var(--text-dim);
    cursor: pointer; padding: 4px; display: flex; transition: color 0.3s;
}
.game-back-btn:hover { color: var(--primary); }

.game-title {
    font-family: 'Orbitron', monospace;
    font-size: 1.1rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.game-header-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.game-mode-badge {
    font-size: 0.7rem;
    background: rgba(0,184,148,0.15);
    color: var(--primary-light);
    padding: 3px 10px;
    border-radius: 12px;
    border: 1px solid rgba(0,184,148,0.2);
}

.game-timer {
    font-family: 'Orbitron', monospace;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--primary-light);
    background: rgba(0,184,148,0.1);
    padding: 4px 12px;
    border-radius: 8px;
}
.game-timer.warning { color: var(--accent); background: rgba(253,203,110,0.1); }
.game-timer.danger { color: var(--danger); background: rgba(214,48,49,0.1); animation: timerPulse 1s infinite; }

@keyframes timerPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.game-score-badge {
    font-family: 'Orbitron', monospace;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--accent);
}

.puzzle-info-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    font-size: 0.75rem;
    color: var(--text-dim);
    background: rgba(0,0,0,0.2);
    flex-shrink: 0;
}

.neighbors-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    background: rgba(0,0,0,0.35);
    border-bottom: 2px solid rgba(255,255,255,0.06);
    flex-shrink: 0;
}
.neighbors-count {
    font-family: 'Chakra Petch', sans-serif;
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1;
}
.neighbors-label {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text-dim);
}
.neighbors-banner.plenty .neighbors-count { color: #00e676; }
.neighbors-banner.plenty .neighbors-label { color: #a5d6a7; }
.neighbors-banner.few .neighbors-count { color: #ffab00; }
.neighbors-banner.few .neighbors-label { color: #ffe082; }
.neighbors-banner.none .neighbors-count { color: #ff1744; }
.neighbors-banner.none .neighbors-label { color: #ef9a9a; }

.hidden { display: none !important; }

/* ============ CHAIN AREA ============ */

.chain-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    scroll-behavior: smooth;
    min-height: 0;
}

.chain-row {
    display: flex;
    align-items: center;
    gap: var(--tile-gap);
    position: relative;
}

.chain-row-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.chain-label {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 4px;
    margin-bottom: 2px;
}

.chain-label.start { color: var(--primary-light); }
.chain-label.target { color: var(--accent); }
.chain-label.step { color: var(--text-dim); }

.chain-link {
    width: 2px;
    height: 16px;
    background: rgba(255,255,255,0.1);
    position: relative;
}

.chain-link.active { background: var(--primary); box-shadow: 0 0 8px rgba(0,184,148,0.3); }

.chain-tile {
    width: var(--tile-size);
    height: var(--tile-size);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-family: 'Chakra Petch', sans-serif;
    font-weight: 700;
    font-size: 1.2rem;
    letter-spacing: 0.5px;
    transition: all 0.3s;
    border: 2px solid transparent;
}

.chain-start .chain-tile {
    background: linear-gradient(135deg, rgba(0,184,148,0.25), rgba(0,184,148,0.1));
    border-color: var(--primary);
    color: var(--primary-light);
}

.chain-target .chain-tile {
    background: linear-gradient(135deg, rgba(253,203,110,0.2), rgba(225,112,85,0.1));
    border-color: var(--accent);
    color: var(--accent);
}

.chain-step .chain-tile {
    background: var(--surface-light);
    border-color: rgba(0,206,201,0.3);
    color: var(--text);
}

.chain-step .chain-tile.changed {
    background: rgba(0,184,148,0.15);
    border-color: var(--primary);
    color: var(--primary-light);
}

.chain-input .chain-tile {
    background: var(--surface);
    border-color: rgba(255,255,255,0.1);
    color: var(--text);
}

.chain-input .chain-tile.filled {
    border-color: rgba(0,184,148,0.4);
    background: var(--surface-light);
}

.chain-input .chain-tile.cursor {
    border-color: var(--primary);
    animation: cursorPulse 1.2s ease-in-out infinite;
}

@keyframes cursorPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(0,184,148,0.4); }
    50% { box-shadow: 0 0 12px 2px rgba(0,184,148,0.3); }
}

.chain-input .chain-tile.changed { color: var(--primary-light); }

.chain-step.just-added .chain-tile {
    animation: tilePopIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes tilePopIn {
    0% { transform: scale(0.5); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

.chain-row.shake { animation: shake 0.5s; }

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

.chain-changes-badge {
    font-size: 0.65rem;
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600;
    white-space: nowrap;
}

.chain-changes-badge.ok { background: rgba(0,184,148,0.15); color: var(--primary-light); }
.chain-changes-badge.bad { background: rgba(214,48,49,0.15); color: var(--danger); }

/* ============ GAME ACTIONS ============ */

.game-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
    padding: 8px 16px;
    flex-shrink: 0;
}

.action-btn {
    padding: 8px 20px;
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text-dim);
    font-family: 'Poppins';
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.3s;
}

.action-btn:hover:not(:disabled) { background: var(--surface-hover); border-color: rgba(0,184,148,0.3); color: var(--text); }
.action-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ============ KEYBOARD ============ */

.game-keyboard {
    padding: 8px 4px calc(env(safe-area-inset-bottom, 0px) + 6px);
    background: var(--surface);
    border-top: 1px solid rgba(0,184,148,0.1);
    flex-shrink: 0;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 4px;
    margin-bottom: 4px;
}

.key {
    min-width: 32px;
    height: 46px;
    border: none;
    border-radius: 6px;
    background: var(--surface-light);
    color: var(--text);
    font-family: 'Chakra Petch', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.key:hover { background: var(--surface-hover); }
.key:active { transform: scale(0.92); }
.key.wide { min-width: 54px; font-size: 0.75rem; background: rgba(0,184,148,0.15); color: var(--primary-light); }

/* ============ TOAST ============ */

.toast-container {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--surface-light);
    border: 1px solid rgba(0,184,148,0.3);
    color: var(--text);
    padding: 10px 24px;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 500;
    animation: toastIn 0.3s ease-out, toastOut 0.3s 2s ease-in forwards;
    backdrop-filter: blur(10px);
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}

.toast.error { border-color: var(--danger); }
.toast.success { border-color: var(--primary); }
.toast.used { border-color: var(--accent-dark); background: rgba(225,112,85,0.15); color: var(--accent); }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
    from { opacity: 1; }
    to { opacity: 0; transform: translateY(-10px); }
}

/* ============ MODAL ============ */

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 500;
    justify-content: center;
    align-items: center;
    padding: 24px;
    backdrop-filter: blur(4px);
}

.modal-overlay.active { display: flex; }

.modal {
    background: var(--surface);
    border: 1px solid rgba(0,184,148,0.2);
    border-radius: 16px;
    padding: 28px;
    max-width: 440px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    animation: modalIn 0.3s ease-out;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.9) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal h2 {
    font-family: 'Orbitron', monospace;
    font-size: 1.3rem;
    color: #fff;
    margin-bottom: 16px;
    text-align: center;
}

.modal h3 {
    font-size: 0.9rem;
    color: var(--primary-light);
    margin: 16px 0 8px;
}

.modal p {
    color: var(--text-dim);
    font-size: 0.85rem;
    margin-bottom: 12px;
    line-height: 1.5;
}

.modal-stars {
    text-align: center;
    font-size: 2.5rem;
    margin: 12px 0;
    letter-spacing: 4px;
}

.modal-score {
    text-align: center;
    font-family: 'Orbitron', monospace;
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary-light);
    margin: 8px 0 16px;
}

.modal-stat {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    font-size: 0.85rem;
}

.modal-stat span:first-child { color: var(--text-dim); }
.modal-stat span:last-child { color: var(--text); font-weight: 600; }

.modal-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid rgba(0,184,148,0.3);
    border-radius: 8px;
    background: rgba(0,0,0,0.3);
    color: var(--text);
    font-family: 'Poppins';
    font-size: 0.9rem;
    margin: 10px 0;
    outline: none;
}

.modal-input:focus { border-color: var(--primary); }

.modal-btn {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 10px;
    font-family: 'Poppins';
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    margin-top: 8px;
}

.modal-btn.primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
}
.modal-btn.primary:hover { filter: brightness(1.15); }

.modal-btn.secondary {
    background: var(--surface-light);
    border: 1px solid rgba(255,255,255,0.08);
    color: var(--text-dim);
}
.modal-btn.secondary:hover { background: var(--surface-hover); color: var(--text); }

/* Settings modal specifics */

.setting-group {
    margin-bottom: 16px;
}

.setting-label {
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 8px;
    font-weight: 600;
}

.setting-options {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.setting-opt {
    padding: 8px 16px;
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 8px;
    background: var(--surface-light);
    color: var(--text-dim);
    font-family: 'Poppins';
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s;
}

.setting-opt:hover { border-color: rgba(0,184,148,0.3); color: var(--text); }
.setting-opt.active { background: var(--primary-dark); border-color: var(--primary); color: #fff; font-weight: 600; }

/* How to play */

.howto-example {
    display: flex;
    align-items: center;
    gap: 4px;
    margin: 8px 0;
    justify-content: center;
}

.howto-tile {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-family: 'Orbitron', monospace;
    font-weight: 700;
    font-size: 0.85rem;
    background: var(--surface-light);
    border: 2px solid rgba(255,255,255,0.1);
    color: var(--text);
}

.howto-tile.changed {
    background: rgba(0,184,148,0.15);
    border-color: var(--primary);
    color: var(--primary-light);
}

.howto-arrow { color: var(--text-dim); font-size: 1.2rem; margin: 0 4px; }

/* ============ CONFETTI ============ */

#confettiCanvas {
    position: fixed;
    inset: 0;
    z-index: 999;
    pointer-events: none;
}

/* ============ GENERATING OVERLAY ============ */

.generating-overlay {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px;
    gap: 16px;
}

.generating-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(0,184,148,0.2);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.generating-text { color: var(--text-dim); font-size: 0.85rem; }

/* ============ RESPONSIVE ============ */

@media (max-width: 480px) {
    :root {
        --tile-size: 36px;
    }

    .home-title { font-size: 2rem; }
    .logo-letter { width: 32px; height: 32px; font-size: 14px; }
    .loading-title { font-size: 1.5rem; }

    .game-top-bar { padding: 4px 10px; }
    .game-title { font-size: 0.85rem; }
    .puzzle-info-bar { padding: 3px 10px; font-size: 0.65rem; }
    .neighbors-banner { padding: 5px 10px; }
    .neighbors-count { font-size: 1.3rem; }
    .neighbors-label { font-size: 0.85rem; }
    .chain-area { padding: 6px 6px; flex: 1; min-height: 0; overflow-y: auto; }
    .game-actions { padding: 3px 8px; }
    .action-btn { padding: 5px 14px; font-size: 0.75rem; }

    #screenGame .game-keyboard {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 100;
        padding: 6px 2px calc(env(safe-area-inset-bottom, 0px) + 4px);
    }
    .keyboard-row { gap: 3px; margin-bottom: 3px; padding: 0 1px; }
    .key { flex: 1; min-width: 0; height: 46px; font-size: 1.05rem; border-radius: 5px; }
    .key.wide { flex: 1.6; min-width: 0; font-size: 0.75rem; }
    .game-actions { padding-bottom: 170px; }

    .modal { padding: 20px; }
    .modal h2 { font-size: 1.1rem; }
}

@media (max-width: 360px) {
    :root {
        --tile-size: 30px;
    }
    .chain-tile { font-size: 0.85rem !important; }
    .key { height: 44px; font-size: 0.95rem; }
}
