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

:root {
    --bg: #0a0a14;
    --surface: #12121e;
    --surface-light: #1a1a2e;
    --surface-hover: #222238;
    --primary: #ff6b35;
    --primary-light: #ff8c5a;
    --primary-glow: rgba(255, 107, 53, 0.3);
    --accent: #ffd166;
    --accent-glow: rgba(255, 209, 102, 0.3);
    --danger: #ef476f;
    --success: #06d6a0;
    --text: #e8e8f0;
    --text-dim: #7a7a90;
    --glass-border: rgba(255, 107, 53, 0.12);
    --tile-size: 48px;
}

body {
    font-family: 'Poppins', sans-serif;
    background: var(--bg);
    color: var(--text);
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

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

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

.loading-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 24px;
}

.loading-logo {
    display: flex;
    gap: 6px;
    margin-bottom: 10px;
}

.logo-letter {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--primary), #e55039);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Orbitron', monospace;
    font-weight: 800;
    font-size: 16px;
    color: #fff;
    animation: letterBounce 1.2s ease-in-out infinite;
    animation-delay: calc(var(--i) * 0.1s);
    box-shadow: 0 4px 15px var(--primary-glow);
}

@keyframes letterBounce {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-8px) scale(1.05); }
}

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

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

.loading-bar-container {
    width: 260px;
    height: 4px;
    background: var(--surface-light);
    border-radius: 2px;
    overflow: hidden;
}

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

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

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

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

.floating-tile {
    position: absolute;
    font-family: 'Orbitron', monospace;
    font-weight: 700;
    font-size: 14px;
    color: var(--primary);
    opacity: 0.08;
    animation: floatUp linear infinite;
}

@keyframes floatUp {
    from { transform: translateY(100vh) rotate(0deg); opacity: 0.08; }
    to { transform: translateY(-10vh) rotate(360deg); opacity: 0; }
}

.back-to-hub {
    position: fixed;
    top: 16px;
    left: 16px;
    z-index: 50;
    padding: 8px 18px;
    background: rgba(255, 107, 53, 0.1);
    border: 1px solid rgba(255, 107, 53, 0.25);
    border-radius: 50px;
    color: var(--primary-light);
    text-decoration: none;
    font-size: 0.8rem;
    transition: all 0.3s;
    backdrop-filter: blur(10px);
}
.back-to-hub:hover { background: rgba(255, 107, 53, 0.2); color: #fff; }

.home-container {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 24px 40px;
    gap: 30px;
}

.home-header { text-align: center; }

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

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

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

.home-stats-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    background: rgba(255, 107, 53, 0.08);
    border: 1px solid rgba(255, 107, 53, 0.15);
    border-radius: 50px;
    font-size: 0.8rem;
    color: var(--text-dim);
}

.home-menu {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
    max-width: 400px;
}

.menu-btn {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 20px;
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: 14px;
    color: var(--text);
    font-family: 'Poppins', sans-serif;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s;
}

.menu-btn:hover {
    background: var(--surface-light);
    border-color: rgba(255, 107, 53, 0.3);
    transform: translateX(4px);
}

.menu-btn.primary {
    background: linear-gradient(135deg, rgba(255, 107, 53, 0.15), rgba(255, 107, 53, 0.05));
    border-color: rgba(255, 107, 53, 0.3);
}

.btn-icon { font-size: 1.3rem; }
.btn-label { flex: 1; text-align: left; }
.btn-arrow { color: var(--text-dim); font-size: 1.2rem; }

.home-footer {
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-dim);
    margin-top: auto;
    line-height: 2;
}
.home-footer strong { color: var(--primary-light); }
.home-legal { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
.home-legal a { color: var(--text-dim); text-decoration: none; transition: color 0.3s; }
.home-legal a:hover { color: var(--primary-light); }
.home-cookie-btn { background: none; border: none; color: var(--text-dim); font-size: 0.7rem; cursor: pointer; font-family: inherit; }
.home-version { margin-top: 8px; opacity: 0.4; }

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

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

.back-btn {
    background: none;
    border: 1px solid rgba(255, 107, 53, 0.2);
    color: var(--primary-light);
    padding: 8px 18px;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'Poppins', sans-serif;
    font-size: 0.85rem;
    transition: all 0.3s;
    margin-bottom: 24px;
}
.back-btn:hover { background: rgba(255, 107, 53, 0.1); }

.screen-title {
    font-family: 'Orbitron', monospace;
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 20px;
    text-align: center;
}

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

.score-tab {
    padding: 8px 16px;
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
    color: var(--text-dim);
    font-family: 'Poppins', sans-serif;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.3s;
}
.score-tab.active {
    background: rgba(255, 107, 53, 0.15);
    border-color: var(--primary);
    color: var(--primary-light);
    font-weight: 600;
}

.scores-table-container { overflow-x: auto; }

.scores-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.scores-table th {
    padding: 10px 12px;
    text-align: left;
    color: var(--text-dim);
    font-weight: 500;
    border-bottom: 1px solid var(--glass-border);
    font-size: 0.75rem;
    text-transform: uppercase;
}
.scores-table td {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}
.scores-table tr:first-child td { color: var(--accent); font-weight: 700; }
.scores-empty { text-align: center; color: var(--text-dim); font-size: 0.85rem; margin-top: 30px; }

/* ============ 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 var(--glass-border);
    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(255, 107, 53, 0.15);
    color: var(--primary-light);
    padding: 3px 10px;
    border-radius: 12px;
    border: 1px solid rgba(255, 107, 53, 0.2);
}

.game-timer {
    font-family: 'Orbitron', monospace;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--primary-light);
    background: rgba(255, 107, 53, 0.1);
    padding: 4px 12px;
    border-radius: 8px;
}
.game-timer.warning { color: var(--accent); background: rgba(255, 209, 102, 0.1); }
.game-timer.danger { color: var(--danger); background: rgba(239, 71, 111, 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);
}

/* ============ BOMB AREA ============ */

.bomb-area {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 16px;
    background: linear-gradient(180deg, rgba(255, 107, 53, 0.06) 0%, transparent 100%);
    flex-shrink: 0;
}

.bomb-letters {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
}

.bomb-tile {
    width: var(--tile-size);
    height: var(--tile-size);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    font-family: 'Chakra Petch', sans-serif;
    font-weight: 700;
    font-size: 1.3rem;
    letter-spacing: 0.5px;
    background: linear-gradient(145deg, rgba(255, 107, 53, 0.2), rgba(255, 107, 53, 0.08));
    border: 2px solid rgba(255, 107, 53, 0.4);
    color: var(--primary-light);
    transition: all 0.3s;
    cursor: pointer;
}

.bomb-tile:hover {
    transform: scale(1.08);
    border-color: var(--primary);
    box-shadow: 0 0 15px var(--primary-glow);
}

.bomb-tile.used {
    opacity: 0.25;
    transform: scale(0.9);
    border-color: rgba(255, 107, 53, 0.1);
}

.shuffle-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid rgba(255, 107, 53, 0.2);
    background: var(--surface);
    color: var(--text-dim);
    font-size: 1.1rem;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}
.shuffle-btn:hover { background: var(--surface-light); border-color: var(--primary); color: var(--primary-light); }
.shuffle-btn:active { transform: rotate(180deg); }

/* ============ WORDS FOUND BAR ============ */

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

#wordsRemaining { color: var(--primary-light); font-weight: 600; }

/* ============ FOUND WORDS AREA ============ */

.found-words-area {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
    display: flex;
    flex-wrap: wrap;
    align-content: flex-start;
    gap: 6px;
    min-height: 0;
}

.found-word {
    padding: 4px 12px;
    border-radius: 6px;
    font-family: 'Chakra Petch', sans-serif;
    font-size: 0.8rem;
    font-weight: 600;
    animation: wordPopIn 0.3s ease-out;
}

.found-word.len2, .found-word.len3 {
    background: rgba(122, 122, 144, 0.15);
    border: 1px solid rgba(122, 122, 144, 0.2);
    color: var(--text-dim);
}
.found-word.len4 {
    background: rgba(6, 214, 160, 0.1);
    border: 1px solid rgba(6, 214, 160, 0.25);
    color: var(--success);
}
.found-word.len5 {
    background: rgba(255, 209, 102, 0.1);
    border: 1px solid rgba(255, 209, 102, 0.25);
    color: var(--accent);
}
.found-word.len6 {
    background: rgba(255, 107, 53, 0.12);
    border: 1px solid rgba(255, 107, 53, 0.3);
    color: var(--primary-light);
}
.found-word.len7, .found-word.len8, .found-word.len9 {
    background: linear-gradient(135deg, rgba(255, 107, 53, 0.2), rgba(239, 71, 111, 0.15));
    border: 1px solid rgba(239, 71, 111, 0.4);
    color: #ff8c5a;
    font-size: 0.9rem;
}

@keyframes wordPopIn {
    from { transform: scale(0.7); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* ============ INPUT AREA ============ */

.game-input-area {
    padding: 8px 16px;
    flex-shrink: 0;
}

.input-hint {
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 6px;
}
.input-hint strong {
    color: var(--accent);
}

.input-row {
    display: flex;
    gap: 8px;
    max-width: 400px;
    margin: 0 auto;
}

.word-input {
    flex: 1;
    padding: 10px 16px;
    background: var(--surface-light);
    border: 2px solid rgba(255, 107, 53, 0.2);
    border-radius: 10px;
    color: var(--text);
    font-family: 'Chakra Petch', sans-serif;
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: 2px;
    text-transform: uppercase;
    outline: none;
    transition: border-color 0.3s;
}
.word-input:focus { border-color: var(--primary); }
.word-input::placeholder { color: var(--text-dim); font-size: 0.85rem; letter-spacing: 0; text-transform: none; }

.submit-btn {
    width: 48px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), #e55039);
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
    transition: all 0.2s;
}
.submit-btn:hover { transform: scale(1.05); box-shadow: 0 0 20px var(--primary-glow); }
.submit-btn:active { transform: scale(0.95); }

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

.game-keyboard {
    padding: 8px 4px calc(env(safe-area-inset-bottom, 0px) + 6px);
    background: var(--surface);
    border-top: 1px solid var(--glass-border);
    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(255, 107, 53, 0.15); color: var(--primary-light); }
.key.unavailable { opacity: 0.25; }

.hidden { display: none !important; }

/* ============ 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 {
    padding: 10px 24px;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 600;
    animation: toastIn 0.3s ease-out, toastOut 0.3s ease-in forwards;
    white-space: nowrap;
}

.toast.success {
    background: rgba(6, 214, 160, 0.9);
    color: #fff;
    border: 1px solid rgba(6, 214, 160, 0.5);
}
.toast.error {
    background: rgba(239, 71, 111, 0.9);
    color: #fff;
    border: 1px solid rgba(239, 71, 111, 0.5);
}
.toast.bonus {
    background: linear-gradient(135deg, rgba(255, 209, 102, 0.95), rgba(255, 107, 53, 0.95));
    color: #fff;
    border: 1px solid rgba(255, 209, 102, 0.5);
    font-size: 1rem;
}
.toast.duplicate {
    background: rgba(255, 165, 0, 0.9);
    color: #fff;
    border: 1px solid rgba(255, 165, 0, 0.5);
}

@keyframes toastIn {
    from { transform: translateY(-20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
@keyframes toastOut {
    0%, 70% { opacity: 1; }
    100% { opacity: 0; transform: translateY(-10px); }
}

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

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

.modal {
    background: var(--surface);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 28px;
    max-width: 440px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    animation: modalIn 0.3s ease-out;
}
.modal h2 {
    font-family: 'Orbitron', monospace;
    font-size: 1.3rem;
    text-align: center;
    margin-bottom: 16px;
}
.modal h3 {
    font-size: 0.9rem;
    color: var(--primary-light);
    margin: 14px 0 8px;
}
.modal p {
    font-size: 0.85rem;
    color: var(--text-dim);
    line-height: 1.6;
}

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

.modal-btn {
    display: block;
    width: 100%;
    padding: 12px;
    margin-top: 16px;
    border: 1px solid var(--glass-border);
    border-radius: 10px;
    background: var(--surface-light);
    color: var(--text);
    font-family: 'Poppins', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}
.modal-btn.primary {
    background: linear-gradient(135deg, rgba(255, 107, 53, 0.2), rgba(255, 107, 53, 0.1));
    border-color: rgba(255, 107, 53, 0.3);
    color: var(--primary-light);
}
.modal-btn:hover { transform: scale(1.02); }

.modal-score {
    text-align: center;
    font-family: 'Orbitron', monospace;
    font-size: 2.5rem;
    font-weight: 900;
    color: var(--accent);
    margin: 10px 0;
}

.modal-stat {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    font-size: 0.85rem;
}
.modal-stat span:first-child { color: var(--text-dim); }
.modal-stat span:last-child { font-weight: 700; color: var(--primary-light); }

.modal-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--surface-light);
    border: 2px solid var(--glass-border);
    border-radius: 8px;
    color: var(--text);
    font-family: 'Poppins', sans-serif;
    font-size: 0.9rem;
    outline: none;
    margin-top: 8px;
}
.modal-input:focus { border-color: var(--primary); }

/* ============ HOWTO ============ */

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

.howto-tile {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-family: 'Chakra Petch', sans-serif;
    font-weight: 700;
    font-size: 0.85rem;
    background: var(--surface-light);
    border: 2px solid rgba(255, 107, 53, 0.3);
    color: var(--text);
}
.howto-tile.highlight {
    background: rgba(255, 107, 53, 0.2);
    border-color: var(--primary);
    color: var(--primary-light);
}

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

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

/* ============ GENERATING SPINNER ============ */

.generating {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 40px;
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--surface-light);
    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: 40px;
    }

    .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; }
    .bomb-area { padding: 10px 8px; }
    .bomb-tile { font-size: 1.1rem; }
    .words-found-bar { padding: 4px 12px; font-size: 0.7rem; }
    .found-words-area { padding: 8px 10px; }
    .game-input-area { padding: 6px 10px; }
    .word-input { padding: 8px 12px; font-size: 1rem; }

    .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-input-area { padding-bottom: 170px; }

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

@media (max-width: 360px) {
    :root {
        --tile-size: 36px;
    }
    .bomb-tile { font-size: 1rem; }
    .key { height: 44px; font-size: 0.95rem; }
}
