/* ==========================================================
   3Letters — Premium Modern UI
   ========================================================== */

/* ---------- CSS Custom Properties ---------- */
:root {
    --bg-primary: #f0f2f5;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-glass: rgba(255, 255, 255, 0.7);
    --text-primary: #1a1a2e;
    --text-secondary: #5a6178;
    --text-muted: #9ca3af;
    --accent: #6366f1;
    --accent-light: #818cf8;
    --accent-dark: #4f46e5;
    --accent-glow: rgba(99, 102, 241, 0.15);
    --accent-gradient: linear-gradient(135deg, #6366f1, #8b5cf6, #a855f7);
    --success: #10b981;
    --success-bg: rgba(16, 185, 129, 0.08);
    --error: #ef4444;
    --error-bg: rgba(239, 68, 68, 0.08);
    --warning: #f59e0b;
    --border: rgba(0, 0, 0, 0.06);
    --border-light: rgba(0, 0, 0, 0.03);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.04), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.06), 0 2px 4px rgba(0,0,0,0.04);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.1), 0 4px 12px rgba(0,0,0,0.05);
    --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.15);
    --radius-sm: 10px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-full: 9999px;
    --font-main: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --transition: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --key-bg: #ffffff;
    --key-text: #1a1a2e;
    --key-border: rgba(0,0,0,0.08);
    --key-shadow: 0 1px 3px rgba(0,0,0,0.08);
    --star-color: #f59e0b;
    --machine-body: linear-gradient(145deg, #667eea 0%, #764ba2 100%);
    --machine-body-alt: linear-gradient(145deg, #f093fb 0%, #f5576c 100%);
    --reel-1: linear-gradient(180deg, #ff6b6b, #ee5a24);
    --reel-2: linear-gradient(180deg, #0abde3, #0984e3);
    --reel-3: linear-gradient(180deg, #1dd1a1, #10ac84);
}

/* ---------- Dark Mode ---------- */
[data-theme="dark"] {
    --bg-primary: #0c0c1d;
    --bg-secondary: #151530;
    --bg-card: rgba(25, 25, 60, 0.6);
    --bg-glass: rgba(20, 20, 50, 0.7);
    --text-primary: #e8eaf6;
    --text-secondary: #9fa8da;
    --text-muted: #5c6bc0;
    --accent: #7c4dff;
    --accent-light: #b388ff;
    --accent-dark: #651fff;
    --accent-glow: rgba(124, 77, 255, 0.2);
    --accent-gradient: linear-gradient(135deg, #7c4dff, #e040fb, #ff4081);
    --success: #69f0ae;
    --success-bg: rgba(105, 240, 174, 0.08);
    --error: #ff5252;
    --error-bg: rgba(255, 82, 82, 0.08);
    --border: rgba(255, 255, 255, 0.06);
    --border-light: rgba(255, 255, 255, 0.03);
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.5);
    --shadow-glow: 0 0 40px rgba(124, 77, 255, 0.2);
    --key-bg: rgba(30, 30, 70, 0.8);
    --key-text: #e8eaf6;
    --key-border: rgba(255, 255, 255, 0.08);
    --key-shadow: 0 1px 3px rgba(0,0,0,0.3);
    --machine-body: linear-gradient(145deg, #1a1a4e 0%, #2d1b69 50%, #1a1a4e 100%);
    --machine-body-alt: linear-gradient(145deg, #4a148c 0%, #1a237e 100%);
    --reel-1: linear-gradient(180deg, #ff5252, #d32f2f);
    --reel-2: linear-gradient(180deg, #40c4ff, #0288d1);
    --reel-3: linear-gradient(180deg, #69f0ae, #00c853);
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-main);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: background var(--transition), color var(--transition);
    overflow-x: hidden;
    position: relative;
}

/* Subtle animated background gradient */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 30% 20%, rgba(99, 102, 241, 0.06) 0%, transparent 50%),
                radial-gradient(circle at 70% 80%, rgba(168, 85, 247, 0.05) 0%, transparent 50%),
                radial-gradient(circle at 50% 50%, rgba(236, 72, 153, 0.03) 0%, transparent 50%);
    animation: bgShift 20s ease-in-out infinite;
    pointer-events: none;
    z-index: 0;
}

[data-theme="dark"] body::before {
    background: radial-gradient(circle at 30% 20%, rgba(124, 77, 255, 0.08) 0%, transparent 50%),
                radial-gradient(circle at 70% 80%, rgba(224, 64, 251, 0.06) 0%, transparent 50%),
                radial-gradient(circle at 50% 50%, rgba(255, 64, 129, 0.04) 0%, transparent 50%);
}

@keyframes bgShift {
    0%, 100% { transform: translate(0, 0); }
    25% { transform: translate(2%, -1%); }
    50% { transform: translate(-1%, 2%); }
    75% { transform: translate(1%, -2%); }
}

/* Make all content above the background */
body > * { position: relative; z-index: 1; }

/* ---------- Header ---------- */
.header {
    width: 100%;
    max-width: 520px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    z-index: 50;
}

.header-title {
    font-size: 1.4rem;
    font-weight: 900;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

.header-title span {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.header-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.header-btn {
    background: var(--bg-glass);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    font-size: 1.15rem;
    cursor: pointer;
    padding: 7px 9px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    transition: all var(--transition);
    line-height: 1;
}
.header-btn:hover {
    background: var(--accent-glow);
    color: var(--accent);
    border-color: var(--accent);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

/* ---------- Language Selector ---------- */
.lang-selector {
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    backdrop-filter: blur(10px);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
    font-family: var(--font-main);
    transition: all var(--transition);
}
.lang-selector:hover {
    border-color: var(--accent);
}

/* ---------- Main Container ---------- */
.game-container {
    width: 100%;
    max-width: 520px;
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    flex: 1;
}

/* ================================================================
   SLOT MACHINE — Premium Vegas Style
   ================================================================ */
.slot-machine {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    cursor: pointer;
    padding: 10px 0 4px;
    user-select: none;
    gap: 0;
    flex-wrap: wrap;
    transition: transform 0.3s ease;
}
.slot-machine:hover {
    transform: scale(1.02);
}
.slot-machine:active {
    transform: scale(0.98);
}

.machine-body {
    background: var(--machine-body);
    border-radius: 20px 20px 12px 12px;
    padding: 0;
    box-shadow:
        0 10px 30px rgba(0,0,0,0.25),
        0 0 0 1px rgba(255,255,255,0.1),
        inset 0 1px 0 rgba(255,255,255,0.2);
    overflow: hidden;
    position: relative;
}

/* Shine effect on machine */
.machine-body::before {
    content: '';
    position: absolute;
    top: 0;
    left: -50%;
    width: 50%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.08), transparent);
    transform: skewX(-20deg);
    animation: machineShine 4s ease-in-out infinite;
    pointer-events: none;
    z-index: 2;
}

@keyframes machineShine {
    0%, 100% { left: -50%; }
    50% { left: 150%; }
}

/* Machine top with lights */
.machine-top {
    padding: 10px 14px 6px;
    text-align: center;
}

.machine-lights {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.light {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #ffd700;
    box-shadow: 0 0 8px #ffd700, 0 0 16px rgba(255, 215, 0, 0.4);
    animation: lightPulse 2s ease-in-out infinite;
}

.light:nth-child(2) { animation-delay: 0.4s; background: #ff6b6b; box-shadow: 0 0 8px #ff6b6b, 0 0 16px rgba(255, 107, 107, 0.4); }
.light:nth-child(3) { animation-delay: 0.8s; background: #48dbfb; box-shadow: 0 0 8px #48dbfb, 0 0 16px rgba(72, 219, 251, 0.4); }
.light:nth-child(4) { animation-delay: 1.2s; background: #ff9ff3; box-shadow: 0 0 8px #ff9ff3, 0 0 16px rgba(255, 159, 243, 0.4); }
.light:nth-child(5) { animation-delay: 1.6s; background: #1dd1a1; box-shadow: 0 0 8px #1dd1a1, 0 0 16px rgba(29, 209, 161, 0.4); }

@keyframes lightPulse {
    0%, 100% { opacity: 0.4; transform: scale(0.85); }
    50% { opacity: 1; transform: scale(1.15); }
}

.machine-active .light {
    animation: lightBlinkFast 0.15s ease-in-out infinite alternate;
}

@keyframes lightBlinkFast {
    0% { opacity: 0.2; transform: scale(0.8); }
    100% { opacity: 1; transform: scale(1.2); }
}

/* Reels frame — frosted glass inset */
.reels-frame {
    margin: 6px 12px;
    background: rgba(0, 0, 0, 0.35);
    border-radius: 12px;
    padding: 8px;
    box-shadow: inset 0 4px 16px rgba(0,0,0,0.5), inset 0 0 0 1px rgba(255,255,255,0.05);
}

.reels {
    display: flex;
    gap: 8px;
}

/* Reel — container that clips the drum strip */
.reel {
    width: 64px;
    height: 76px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 900;
    color: #fff;
    font-family: var(--font-mono);
    overflow: hidden;
    position: relative;
}

/* Each reel — vibrant gradient with glow */
.reel:nth-child(1) {
    background: var(--reel-1);
    box-shadow: 0 4px 15px rgba(255, 107, 107, 0.4), inset 0 1px 0 rgba(255,255,255,0.25);
}
.reel:nth-child(2) {
    background: var(--reel-2);
    box-shadow: 0 4px 15px rgba(10, 189, 227, 0.4), inset 0 1px 0 rgba(255,255,255,0.25);
}
.reel:nth-child(3) {
    background: var(--reel-3);
    box-shadow: 0 4px 15px rgba(29, 209, 161, 0.4), inset 0 1px 0 rgba(255,255,255,0.25);
}

/* Inner shine overlay on reels — sits on top of the strip */
.reel::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 40%;
    background: linear-gradient(180deg, rgba(255,255,255,0.2), transparent);
    border-radius: 10px 10px 0 0;
    pointer-events: none;
    z-index: 2;
}

/* Top/bottom shadow to simulate drum curvature */
.reel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        linear-gradient(180deg, rgba(0,0,0,0.25) 0%, transparent 25%, transparent 75%, rgba(0,0,0,0.2) 100%);
    pointer-events: none;
    z-index: 2;
    border-radius: 10px;
}

/* Drum strip — vertical column of 3 cells, scrolls inside the reel */
.reel-strip {
    display: flex;
    flex-direction: column;
    width: 100%;
    position: relative;
    z-index: 1;
    will-change: transform;
}

.reel-cell {
    width: 100%;
    height: 76px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.5rem;
    font-weight: 900;
    color: #fff;
    font-family: var(--font-mono);
    text-shadow: 0 2px 4px rgba(0,0,0,0.25);
    flex-shrink: 0;
}

/* When spinning — add a subtle motion blur via text shadow */
.reel-spinning .reel-cell {
    text-shadow:
        0 -4px 6px rgba(255,255,255,0.15),
        0 4px 6px rgba(255,255,255,0.15),
        0 2px 4px rgba(0,0,0,0.3);
}

/* Final state — crisp letter */
.reel-final {
    color: #fff;
    text-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

/* Bounce animation when reel stops */
.reel-stopped {
    animation: reelBounce 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes reelBounce {
    0% { transform: translateY(-6px); }
    50% { transform: translateY(3px); }
    100% { transform: translateY(0); }
}

/* Machine tray */
.machine-tray {
    height: 10px;
    margin: 6px 16px 12px;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 0 0 8px 8px;
    box-shadow: inset 0 3px 8px rgba(0,0,0,0.3);
}

/* Lever assembly */
.lever-assembly {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-left: -2px;
    margin-top: 22px;
    position: relative;
    width: 34px;
}

.lever-track {
    width: 8px;
    height: 52px;
    background: linear-gradient(180deg, #8e8e93, #c7c7cc, #8e8e93);
    border-radius: 4px;
    box-shadow: inset -1px 0 2px rgba(0,0,0,0.2), 0 2px 4px rgba(0,0,0,0.1);
}

.lever-arm {
    width: 8px;
    height: 48px;
    background: linear-gradient(90deg, #c7c7cc, #f2f2f7, #c7c7cc);
    border-radius: 4px;
    position: absolute;
    top: 0;
    transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    transform-origin: bottom center;
    box-shadow: 1px 0 4px rgba(0,0,0,0.15);
}

.lever-pulled {
    transform: translateY(22px);
}

.lever-knob {
    width: 28px;
    height: 28px;
    background: radial-gradient(circle at 35% 35%, #ff6b6b, #ee5a24);
    border-radius: 50%;
    position: absolute;
    top: -14px;
    left: 50%;
    transform: translateX(-50%);
    box-shadow:
        0 4px 12px rgba(238, 90, 36, 0.4),
        inset 0 -2px 6px rgba(0,0,0,0.2),
        inset 0 2px 6px rgba(255,255,255,0.4);
    transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.knob-pulled {
    transform: translateX(-50%) translateY(22px);
}

[data-theme="dark"] .lever-knob {
    background: radial-gradient(circle at 35% 35%, #b388ff, #7c4dff);
    box-shadow:
        0 4px 12px rgba(124, 77, 255, 0.4),
        inset 0 -2px 6px rgba(0,0,0,0.3),
        inset 0 2px 6px rgba(255,255,255,0.2);
}

.slot-tagline {
    width: 100%;
    text-align: center;
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-top: 10px;
    margin-bottom: -8px;
    font-weight: 600;
    letter-spacing: 0.3px;
}

/* ---------- Target Letters ---------- */
#target-letters {
    font-size: 2rem;
    font-weight: 900;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-transform: uppercase;
    letter-spacing: 12px;
    font-family: var(--font-mono);
}

/* ---------- Input Area ---------- */
.input-area {
    width: 100%;
    position: relative;
}

#word-input {
    width: 100%;
    padding: 15px 22px;
    font-size: 1.3rem;
    font-weight: 700;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 3px;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-glass);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: var(--text-primary);
    font-family: var(--font-main);
    outline: none;
    transition: all var(--transition);
    caret-color: var(--accent);
}

#word-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-glow), var(--shadow-md);
    background: var(--bg-card);
}

#word-input::placeholder {
    color: var(--text-muted);
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
    font-size: 1rem;
}

/* ---------- Feedback ---------- */
.feedback {
    width: 100%;
    text-align: center;
    padding: 10px 16px;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.95rem;
    opacity: 0;
    transform: translateY(-8px) scale(0.95);
    transition: opacity 0.3s ease, transform 0.3s ease;
    min-height: 40px;
    backdrop-filter: blur(10px);
}

.feedback-show {
    opacity: 1;
    transform: translateY(0) scale(1);
}

.feedback-success {
    background: var(--success-bg);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.15);
}

.feedback-victory {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.1), rgba(245, 158, 11, 0.1));
    color: var(--success);
    font-size: 1.1rem;
    border: 1px solid rgba(16, 185, 129, 0.15);
    animation: victoryPulse 0.5s ease;
}

@keyframes victoryPulse {
    0% { transform: scale(0.9); opacity: 0; }
    50% { transform: scale(1.05); }
    100% { transform: scale(1); opacity: 1; }
}

.feedback-error {
    background: var(--error-bg);
    color: var(--error);
    border: 1px solid rgba(239, 68, 68, 0.1);
}

/* ---------- Info Cards — Glass Morphism ---------- */
.info-card {
    width: 100%;
    padding: 16px 20px;
    background: var(--bg-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    transition: all var(--transition);
}

.info-card:hover {
    box-shadow: var(--shadow-md);
}

.info-card-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.info-card-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* ---------- Best Word Section ---------- */
.best-word-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

#best-word {
    font-size: 1.25rem;
    font-weight: 800;
    text-transform: uppercase;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

#best-score {
    font-size: 1rem;
    font-weight: 700;
    color: var(--success);
}

#stars {
    font-size: 1.3rem;
    color: var(--star-color);
    letter-spacing: 2px;
    filter: drop-shadow(0 1px 2px rgba(245, 158, 11, 0.3));
}

/* Words above indicator */
.words-above {
    margin-top: 8px;
    padding: 6px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--warning);
    background: rgba(245, 158, 11, 0.08);
    border-radius: var(--radius-sm);
    text-align: center;
    animation: fadeSlideIn 0.3s ease;
}

/* Victory banner — permanent celebration */
.victory-banner {
    margin-top: 10px;
    padding: 8px 14px;
    font-size: 0.85rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, var(--success), #059669);
    border-radius: var(--radius-sm);
    text-align: center;
    animation: victoryAppear 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes victoryAppear {
    0% { opacity: 0; transform: scale(0.8) translateY(-8px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

/* Card glow when won */
.info-card-victory {
    border-color: var(--success) !important;
    box-shadow: 0 0 20px rgba(16, 185, 129, 0.15), var(--shadow-md) !important;
}

@keyframes fadeSlideIn {
    0% { opacity: 0; transform: translateY(-6px); }
    100% { opacity: 1; transform: translateY(0); }
}

/* ---------- Progress Bar ---------- */
.progress-container {
    width: 100%;
}

.progress-bar-bg {
    width: 100%;
    height: 8px;
    background: var(--border);
    border-radius: var(--radius-full);
    overflow: hidden;
    box-shadow: inset 0 1px 3px rgba(0,0,0,0.06);
}

#progress-bar {
    height: 100%;
    background: var(--accent-gradient);
    border-radius: var(--radius-full);
    width: 0%;
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

#progress-bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 50%;
    background: linear-gradient(180deg, rgba(255,255,255,0.3), transparent);
    border-radius: var(--radius-full);
}

#progress-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: right;
    margin-top: 6px;
    font-weight: 500;
}

/* ---------- Timer ---------- */
.timer-section {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding: 6px 14px;
    background: var(--bg-glass);
    backdrop-filter: blur(10px);
    border-radius: var(--radius-full);
    border: 1px solid var(--border);
}

.timer-icon { font-size: 1rem; }

#timer {
    font-family: var(--font-mono);
    font-weight: 600;
}

/* ---------- Found Words ---------- */
#found-words-list {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.7;
    word-break: break-word;
}

/* ---------- Definition ---------- */
.definition-card {
    border-left: 4px solid var(--success);
    background: var(--success-bg) !important;
}

#definition-text {
    font-style: italic;
    color: var(--text-secondary);
    line-height: 1.6;
}

/* ---------- Virtual Keyboard ---------- */
#keyboard {
    width: 100%;
    max-width: 520px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 10px 4px;
    margin-top: auto;
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
}

/* ---------- Below Keyboard Section ---------- */
.below-keyboard {
    width: 100%;
    max-width: 520px;
    padding: 12px 18px 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.keyboard-row {
    display: flex;
    justify-content: center;
    gap: 5px;
}

.key {
    min-width: 33px;
    height: 50px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--key-bg);
    color: var(--key-text);
    font-size: 1rem;
    font-weight: 700;
    font-family: var(--font-main);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 120ms ease;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    padding: 0 8px;
    box-shadow: var(--key-shadow);
    border: 1px solid var(--key-border);
}

.key:active, .key-pressed {
    transform: scale(0.9) translateY(2px);
    background: var(--accent);
    color: white;
    box-shadow: 0 0 12px var(--accent-glow);
    border-color: var(--accent);
}

.key-wide {
    min-width: 58px;
    font-size: 0.8rem;
    padding: 0 12px;
}

.key-submit {
    background: var(--accent-gradient);
    color: white;
    border-color: transparent;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}
.key-submit:active {
    background: var(--accent-dark);
    transform: scale(0.9) translateY(2px);
}

.key-delete {
    background: var(--text-muted);
    color: white;
    border-color: transparent;
}

/* ---------- Dialogs ---------- */
dialog {
    border: none;
    border-radius: var(--radius-lg);
    padding: 0;
    max-width: 440px;
    width: 92%;
    margin: auto;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    color: var(--text-primary);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    animation: dialogIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

dialog[open] {
    display: flex;
    flex-direction: column;
}

@keyframes dialogIn {
    0% { transform: scale(0.9); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

dialog::backdrop {
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

.dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
}

.dialog-title {
    font-size: 1.1rem;
    font-weight: 800;
}

.dialog-close {
    background: none;
    border: none;
    font-size: 1.3rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: all var(--transition);
    line-height: 1;
}
.dialog-close:hover {
    background: var(--error-bg);
    color: var(--error);
    transform: rotate(90deg);
}

.dialog-content {
    padding: 22px;
    line-height: 1.7;
    color: var(--text-secondary);
}

.dialog-content ul {
    padding-left: 20px;
}

.dialog-content li {
    margin-bottom: 10px;
}

/* ---------- Clue List ---------- */
.clue-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.clue-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    margin-bottom: 0;
}

.clue-item.clue-revealed {
    border-color: var(--accent);
    background: rgba(99, 102, 241, 0.06);
}

.clue-number {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.clue-text {
    flex: 1;
    line-height: 1.5;
}

.clue-locked .clue-text {
    color: var(--text-muted);
    font-style: italic;
}

.clue-reveal-btn {
    padding: 6px 14px;
    border: 1px solid var(--accent);
    background: transparent;
    color: var(--accent);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
}

.clue-reveal-btn:hover {
    background: var(--accent);
    color: #fff;
}

/* ---------- Leaderboard ---------- */
.lb-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    padding: 4px;
}

.lb-tab {
    flex: 1;
    padding: 8px 12px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition);
}

.lb-tab-active {
    background: var(--accent);
    color: #fff;
}

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

.lb-table thead th {
    text-align: left;
    padding: 8px 6px;
    font-size: 0.75rem;
    color: var(--text-muted);
    text-transform: uppercase;
    border-bottom: 2px solid var(--border);
}

.lb-table tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background var(--transition);
}

.lb-table tbody tr:hover {
    background: var(--bg-secondary);
}

.lb-row-me {
    background: rgba(99, 102, 241, 0.08) !important;
    font-weight: 600;
}

.lb-pos {
    width: 36px;
    text-align: center;
    padding: 10px 4px;
    font-weight: 700;
}

.lb-name {
    padding: 10px 6px;
}

.lb-word {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-style: italic;
}

.lb-score {
    padding: 10px 6px;
    font-weight: 700;
    color: var(--accent);
}

.lb-extra {
    padding: 10px 6px;
    color: var(--text-muted);
    text-align: center;
}

.lb-you {
    font-size: 0.7rem;
    color: var(--accent);
    font-weight: 400;
}

.lb-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 30px 10px;
    font-style: italic;
}

.lb-loading {
    text-align: center;
    padding: 30px;
    color: var(--text-muted);
}

/* ---------- Nickname Dialog ---------- */
#nickname-input {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 1rem;
    margin: 12px 0;
    box-sizing: border-box;
    transition: border-color var(--transition);
}

#nickname-input:focus {
    outline: none;
    border-color: var(--accent);
}

.nickname-save-btn {
    width: 100%;
    padding: 12px;
    background: var(--accent-gradient);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all var(--transition);
}

.nickname-save-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.nickname-error {
    color: var(--error);
    font-size: 0.8rem;
    margin-top: 8px;
    text-align: center;
}

/* ---------- Stats Grid ---------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}

.stat-item {
    text-align: center;
    padding: 16px 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    transition: all var(--transition);
}

.stat-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-value {
    font-size: 1.6rem;
    font-weight: 900;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
}

/* ---------- Menu ---------- */
.menu-container {
    position: relative;
}

#menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    min-width: 220px;
    z-index: 100;
    display: none;
    overflow: hidden;
    animation: menuIn 0.2s ease;
}

@keyframes menuIn {
    0% { transform: translateY(-8px) scale(0.96); opacity: 0; }
    100% { transform: translateY(0) scale(1); opacity: 1; }
}

.menu-open { display: block !important; }

.menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 13px 18px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-secondary);
    transition: all var(--transition);
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: var(--font-main);
    font-weight: 500;
}

.menu-item:hover {
    background: var(--accent-glow);
    color: var(--accent);
    padding-left: 22px;
}

.menu-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

/* ---------- Toast ---------- */
#toast {
    position: fixed;
    top: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(-120px);
    background: var(--text-primary);
    color: var(--bg-primary);
    padding: 14px 28px;
    border-radius: var(--radius-full);
    font-weight: 600;
    font-size: 0.9rem;
    z-index: 1000;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    white-space: nowrap;
    box-shadow: var(--shadow-lg);
    backdrop-filter: blur(10px);
}

.toast-show {
    transform: translateX(-50%) translateY(0) !important;
}

/* ---------- Hidden utility ---------- */
.hidden { display: none !important; }

/* ---------- Error message ---------- */
.error-message {
    width: 100%;
    padding: 16px;
    background: var(--error-bg);
    color: var(--error);
    border-radius: var(--radius-md);
    text-align: center;
    font-weight: 600;
    border: 1px solid rgba(239, 68, 68, 0.15);
}

/* ---------- Responsive ---------- */
@media (max-width: 380px) {
    .key {
        min-width: 27px;
        height: 44px;
        font-size: 0.85rem;
        padding: 0 5px;
    }
    .key-wide {
        min-width: 46px;
        font-size: 0.7rem;
    }
    .reel {
        width: 54px;
        height: 68px;
        font-size: 2.1rem;
    }
    .reel-cell {
        height: 68px;
        font-size: 2.1rem;
    }
    #word-input {
        font-size: 1.1rem;
        padding: 12px 16px;
    }
}

@media (min-width: 500px) {
    .key {
        min-width: 42px;
        height: 54px;
    }
    .key-wide {
        min-width: 74px;
    }
}

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

.shake { animation: shake 0.4s ease; }

@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1); }
}

.pop { animation: pop 0.3s ease; }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ---------- Selection color ---------- */
::selection {
    background: var(--accent-glow);
    color: var(--accent);
}

/* ---------- Crazy Mode ---------- */
.crazy-unlock {
    text-align: center;
    padding: 20px;
    margin-top: 12px;
    background: linear-gradient(135deg, rgba(245, 87, 108, 0.08), rgba(240, 147, 251, 0.08));
    border: 2px dashed rgba(245, 87, 108, 0.3);
    border-radius: var(--radius-lg);
    animation: crazyPulse 2s ease-in-out infinite;
}

@keyframes crazyPulse {
    0%, 100% { border-color: rgba(245, 87, 108, 0.3); }
    50% { border-color: rgba(240, 147, 251, 0.5); }
}

.crazy-unlock p {
    color: var(--text-secondary);
    margin-bottom: 14px;
    font-weight: 500;
}

.crazy-start-btn {
    padding: 14px 32px;
    border: none;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, #f5576c, #f093fb);
    color: #fff;
    font-size: 1rem;
    font-weight: 800;
    font-family: var(--font-main);
    cursor: pointer;
    transition: all var(--transition);
    box-shadow: 0 4px 15px rgba(245, 87, 108, 0.3);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.crazy-start-btn:hover {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 6px 20px rgba(245, 87, 108, 0.4);
}

.crazy-hud {
    text-align: center;
    margin-bottom: 8px;
}

.crazy-banner {
    font-size: 1rem;
    font-weight: 900;
    letter-spacing: 3px;
    background: linear-gradient(135deg, #f5576c, #f093fb, #f5576c);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: crazyGradient 3s ease infinite;
    margin-bottom: 8px;
}

@keyframes crazyGradient {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

.crazy-stats {
    display: flex;
    justify-content: center;
    gap: 24px;
    margin-bottom: 10px;
}

.crazy-stat {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.crazy-stat b {
    color: #f5576c;
    font-size: 1.1rem;
}

.crazy-back-btn {
    padding: 8px 20px;
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--bg-secondary);
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    font-family: var(--font-main);
    cursor: pointer;
    transition: all var(--transition);
}

.crazy-back-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* Crazy mode active — change machine gradient */
.crazy-active .machine-body {
    background: linear-gradient(145deg, #f5576c 0%, #f093fb 100%) !important;
}

.crazy-active .header-title {
    background: linear-gradient(135deg, #f5576c, #f093fb);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
