/* ============================================
   GemVortex — Styles
   ============================================ */

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

body {
    font-family: 'Poppins', sans-serif;
    background: #0a0a1a;
    color: #fff;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

/* ---- SCREENS ---- */
.screen {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1;
}
.screen.active { display: flex; }

/* ---- MENU SCREEN ---- */
#screen-menu {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse at 30% 20%, rgba(108,92,231,0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 70% 80%, rgba(0,206,201,0.1) 0%, transparent 50%),
        #0a0a1a;
    gap: 24px;
}

.menu-title {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(2.2rem, 8vw, 4rem);
    font-weight: 900;
    text-align: center;
    background: linear-gradient(135deg, #ffd700 0%, #ff6b6b 25%, #a29bfe 50%, #00cec9 75%, #ffd700 100%);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: shimmer 3s ease infinite;
    text-shadow: none;
}

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

.menu-subtitle {
    font-size: clamp(0.85rem, 2.5vw, 1.1rem);
    color: #808090;
    text-align: center;
    max-width: 400px;
    line-height: 1.5;
}

.menu-marble-preview {
    display: flex;
    gap: 8px;
    margin: 8px 0;
}

.menu-marble-preview .marble-dot {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    box-shadow: inset -3px -3px 6px rgba(0,0,0,0.4), inset 3px 3px 6px rgba(255,255,255,0.2), 0 2px 8px rgba(0,0,0,0.3);
}

.btn-primary {
    font-family: 'Orbitron', sans-serif;
    font-size: 1rem;
    font-weight: 700;
    padding: 14px 48px;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    background: linear-gradient(135deg, #6c5ce7, #a29bfe);
    color: #fff;
    transition: all 0.3s;
    box-shadow: 0 4px 20px rgba(108,92,231,0.4);
    text-transform: uppercase;
    letter-spacing: 1px;
}
.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 30px rgba(108,92,231,0.6);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
    font-family: 'Poppins', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 10px 28px;
    border: 1px solid rgba(108,92,231,0.3);
    border-radius: 50px;
    cursor: pointer;
    background: rgba(108,92,231,0.08);
    color: #a29bfe;
    transition: all 0.25s;
}
.btn-secondary:hover {
    background: rgba(108,92,231,0.2);
    border-color: rgba(108,92,231,0.5);
    color: #fff;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.menu-pseudo-row {
    width: 100%;
    max-width: 260px;
}
.menu-pseudo-row .score-input {
    width: 100%;
    text-align: center;
    font-size: 1rem;
    padding: 12px 16px;
}

.auto-saved-msg {
    font-size: 0.75rem;
    color: #50fa7b;
    margin: 10px 0 4px;
    opacity: 0.8;
}

.menu-controls-hint {
    margin-top: 16px;
    font-size: 0.72rem;
    color: #555;
    text-align: center;
    line-height: 1.6;
}

/* ---- LEVEL SELECT ---- */
#screen-levels {
    flex-direction: column;
    align-items: center;
    background: #0a0a1a;
    overflow-y: auto;
    padding: 20px;
    gap: 20px;
}

.levels-header {
    display: flex;
    align-items: center;
    gap: 16px;
    width: 100%;
    max-width: 700px;
}

.levels-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.3rem;
    font-weight: 700;
    color: #fff;
    flex: 1;
}

.btn-back {
    padding: 8px 18px;
    border-radius: 50px;
    font-size: 0.8rem;
    font-weight: 600;
    color: #a29bfe;
    text-decoration: none;
    border: 1px solid rgba(108,92,231,0.25);
    background: rgba(108,92,231,0.08);
    cursor: pointer;
    transition: all 0.25s;
}
.btn-back:hover {
    background: rgba(108,92,231,0.2);
    color: #fff;
}

#level-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
    width: 100%;
    max-width: 700px;
    padding-bottom: 40px;
}

.level-card {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 14px;
    padding: 20px 16px;
    cursor: pointer;
    transition: all 0.3s;
    text-align: center;
    color: #fff;
    font-family: 'Poppins', sans-serif;
}
.level-card:hover {
    background: rgba(108,92,231,0.12);
    border-color: rgba(108,92,231,0.35);
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(108,92,231,0.2);
}

.level-card.level-locked {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
    border-color: rgba(255,255,255,0.04);
}
.level-card.level-locked:hover {
    transform: none;
    box-shadow: none;
    background: rgba(255,255,255,0.04);
}

.level-num {
    font-family: 'Orbitron', sans-serif;
    font-size: 2rem;
    font-weight: 900;
    background: linear-gradient(135deg, #a29bfe, #00cec9);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.level-num-locked {
    background: none;
    -webkit-text-fill-color: #555;
}

.level-name {
    font-size: 0.85rem;
    font-weight: 600;
    margin: 6px 0 4px;
    color: #e0e0e0;
}

.level-info {
    font-size: 0.7rem;
    color: #888;
}

/* ---- GAME SCREEN ---- */
#screen-game {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #0a0a1a;
}

#game-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    position: relative;
}

#game-canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
    touch-action: none;
}

.game-toolbar {
    position: fixed;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 6px;
    z-index: 20;
}

.toolbar-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(0,0,0,0.5);
    color: #aaa;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    backdrop-filter: blur(8px);
}
.toolbar-btn:hover {
    background: rgba(108,92,231,0.3);
    color: #fff;
}

.mobile-controls {
    position: fixed;
    bottom: 12px;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    gap: 12px;
    z-index: 20;
}

@media (pointer: coarse) {
    .mobile-controls { display: flex; }
}

.mobile-btn {
    padding: 10px 22px;
    border-radius: 50px;
    border: 1px solid rgba(108,92,231,0.3);
    background: rgba(10,10,26,0.85);
    color: #a29bfe;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: all 0.2s;
}
.mobile-btn:active {
    background: rgba(108,92,231,0.3);
    color: #fff;
}

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

.modal-box {
    background: #16162a;
    border: 1px solid rgba(108,92,231,0.2);
    border-radius: 20px;
    padding: 32px 28px;
    max-width: 380px;
    width: 100%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    animation: modalIn 0.3s ease;
}

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

.modal-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.modal-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 16px;
}

.modal-stats {
    display: flex;
    justify-content: center;
    gap: 20px;
    margin-bottom: 20px;
}

.stat-item {
    text-align: center;
}
.stat-value {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.3rem;
    font-weight: 700;
    color: #ffd700;
}
.stat-label {
    font-size: 0.7rem;
    color: #888;
    margin-top: 2px;
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.modal-buttons .btn-primary { font-size: 0.85rem; padding: 12px 32px; }
.modal-buttons .btn-secondary { font-size: 0.8rem; }

/* Score submit */
.score-submit-row {
    display: flex;
    gap: 8px;
    margin-top: 16px;
}

.score-input {
    flex: 1;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid rgba(108,92,231,0.3);
    background: rgba(255,255,255,0.06);
    color: #fff;
    font-size: 0.9rem;
    font-family: 'Poppins', sans-serif;
    outline: none;
    transition: border-color 0.2s;
}
.score-input:focus { border-color: #a29bfe; }
.score-input.error { border-color: #ff4444; }
.score-input::placeholder { color: #555; }

.score-submit-btn {
    padding: 10px 18px;
    border-radius: 10px;
    border: none;
    background: linear-gradient(135deg, #6c5ce7, #a29bfe);
    color: #fff;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}
.score-submit-btn:hover { box-shadow: 0 4px 15px rgba(108,92,231,0.4); }
.score-submit-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- LEADERBOARD ---- */
.lb-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}
.lb-rank { font-size: 1.1rem; width: 32px; text-align: center; }
.lb-name { font-weight: 600; flex: 1; color: #e0e0e0; font-size: 0.9rem; }
.lb-score { font-family: 'Orbitron', sans-serif; font-weight: 700; color: #ffd700; font-size: 0.9rem; }
.lb-detail { font-size: 0.7rem; color: #888; width: 80px; text-align: right; }
.lb-empty { color: #666; padding: 20px; font-style: italic; }

/* ---- RESPONSIVE ---- */
@media (max-width: 600px) {
    .menu-title { font-size: clamp(1.8rem, 10vw, 2.5rem); }
    .modal-box { padding: 24px 20px; }
    .modal-stats { gap: 14px; }
    .stat-value { font-size: 1.1rem; }
    #level-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
    .level-card { padding: 14px 10px; }
    .level-num { font-size: 1.5rem; }
    .score-submit-row { flex-direction: column; }
}

@media (max-height: 500px) {
    .modal-box { padding: 16px; }
    .modal-icon { font-size: 2rem; margin-bottom: 6px; }
    .modal-title { font-size: 1.1rem; margin-bottom: 8px; }
}

/* ---- LANDSCAPE MOBILE ---- */
@media (max-height: 450px) and (orientation: landscape) {
    .mobile-controls { bottom: 4px; }
    .game-toolbar { top: 4px; right: 4px; }
    .toolbar-btn { width: 32px; height: 32px; font-size: 0.8rem; }
}

/* ---- BACK LINK ---- */
.back-home {
    position: fixed;
    bottom: 10px;
    left: 10px;
    padding: 6px 14px;
    border-radius: 50px;
    font-size: 0.7rem;
    color: #666;
    text-decoration: none;
    border: 1px solid rgba(255,255,255,0.05);
    background: rgba(0,0,0,0.3);
    z-index: 5;
    transition: all 0.2s;
}
.back-home:hover { color: #a29bfe; border-color: rgba(108,92,231,0.3); }
