/* ============================================
   Love Runner - Styles
   Fonts loaded via <link> in HTML <head>
   ============================================ */

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

html {
    touch-action: manipulation;
    -webkit-text-size-adjust: 100%;
}

body {
    overflow: hidden;
    background: #1a0011;
    font-family: 'Nunito', sans-serif;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
    position: fixed;
    width: 100%;
    height: 100%;
    overscroll-behavior: none;
}

canvas {
    display: block;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    image-rendering: pixelated;
    touch-action: none;
}

/* Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
    pointer-events: none;
}

.overlay.hidden {
    display: none;
}

/* Screens */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    background: linear-gradient(135deg, #ff69b4aa, #9b5de5aa);
    backdrop-filter: blur(5px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 1rem 0;
}

.screen.active {
    display: flex;
}

/* Utility */
.hidden {
    display: none !important;
}

/* Main Menu */
#mainMenu {
    background: linear-gradient(135deg, #FFE5EC, #E8D5F5, #FFE5EC);
    background-size: 400% 400%;
    animation: gradientShift 8s ease infinite;
}

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

/* Language Toggle */
.lang-toggle {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: flex;
    gap: 0;
    z-index: 20;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid rgba(155, 93, 229, 0.4);
}

.lang-btn {
    background: rgba(255, 255, 255, 0.3);
    border: none;
    color: #9B5DE5;
    font-family: 'Fredoka One', 'Nunito', sans-serif;
    font-size: 0.85rem;
    padding: 6px 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    letter-spacing: 1px;
}

.lang-btn:hover {
    background: rgba(155, 93, 229, 0.2);
}

.lang-btn.active {
    background: linear-gradient(135deg, #9B5DE5, #6C63FF);
    color: white;
}

/* Game Title */
.game-title {
    font-family: 'Fredoka One', 'Nunito', sans-serif;
    font-size: 5rem;
    color: #E63946;
    text-shadow: 3px 3px 0 #FFB4A2, 6px 6px 0 rgba(0,0,0,0.1);
    animation: pulse 2s ease-in-out infinite;
    margin-bottom: 0.5rem;
    letter-spacing: 2px;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.subtitle {
    font-size: 1.5rem;
    color: #9B5DE5;
    font-weight: 600;
    margin-bottom: 3rem;
    letter-spacing: 3px;
    text-transform: uppercase;
}

/* Buttons */
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    align-items: center;
}

.btn {
    font-family: 'Fredoka One', 'Nunito', sans-serif;
    font-size: 1.3rem;
    padding: 14px 48px;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s ease;
    letter-spacing: 1px;
    min-width: 260px;
    position: relative;
    overflow: hidden;
}

.btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.2);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: linear-gradient(135deg, #E63946, #FF69B4);
    color: white;
    box-shadow: 0 4px 15px rgba(230, 57, 70, 0.4);
}

.btn-primary:disabled {
    background: linear-gradient(135deg, #999, #bbb);
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    background: linear-gradient(135deg, #9B5DE5, #6C63FF);
    color: white;
    box-shadow: 0 4px 15px rgba(155, 93, 229, 0.4);
}

.btn-info {
    background: linear-gradient(135deg, #2EC4B6, #4ECDC4);
    color: white;
    box-shadow: 0 4px 15px rgba(46, 196, 182, 0.4);
}

.btn-back {
    background: linear-gradient(135deg, #666, #888);
    color: white;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    font-size: 1.1rem;
    padding: 10px 36px;
    min-width: auto;
}

/* Screen Titles */
.screen-title {
    font-family: 'Fredoka One', 'Nunito', sans-serif;
    font-size: 3rem;
    color: white;
    text-shadow: 2px 2px 0 rgba(0,0,0,0.2);
    margin-bottom: 1.5rem;
}

.level-complete-title {
    color: #FFD700;
    animation: pulse 1s ease-in-out infinite;
}

.game-over-title {
    color: #E63946;
}

.victory-title {
    color: #FFD700;
    font-size: 3.5rem;
    animation: pulse 1.5s ease-in-out infinite;
}

.game-over-text {
    color: rgba(255,255,255,0.8);
    font-size: 1.2rem;
    margin-bottom: 2rem;
}

.victory-message {
    font-family: 'Fredoka One', 'Nunito', sans-serif;
    font-size: 1.8rem;
    color: #FF69B4;
    margin: 1.5rem 0;
    text-shadow: 1px 1px 0 rgba(0,0,0,0.2);
}

/* Character Select */
.select-prompt {
    color: white;
    font-size: 1.3rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
}

.characters-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.2rem;
    max-width: 750px;
    width: 90%;
    margin-bottom: 2rem;
}

.character-card {
    background: rgba(255,255,255,0.15);
    border: 3px solid rgba(255,255,255,0.3);
    border-radius: 16px;
    padding: 1rem 1.2rem 1.2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    align-items: center;
}

.character-card:hover {
    background: rgba(255,255,255,0.25);
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}

.character-card.selected-p1 {
    border-color: #FFD700;
    background: rgba(255, 215, 0, 0.2);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.4);
}

.character-card.selected-p2 {
    border-color: #00BFFF;
    background: rgba(0, 191, 255, 0.2);
    box-shadow: 0 0 20px rgba(0, 191, 255, 0.4);
}

.character-card.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.char-avatar {
    width: 55%;
    height: 0;
    padding-bottom: 55%;
    border-radius: 14px;
    margin: 0 auto 0.8rem;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}

.char-avatar canvas {
    display: block;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.char-name {
    font-family: 'Fredoka One', 'Nunito', sans-serif;
    font-size: 1.2rem;
    color: white;
    margin-bottom: 0.3rem;
}

.char-ability {
    font-size: 0.85rem;
    color: rgba(255,255,255,0.7);
    margin-bottom: 0.2rem;
}

.char-description {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.5);
}

.select-footer {
    display: flex;
    gap: 1rem;
    align-items: center;
}

/* How to Play */
.instructions {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    max-width: 600px;
    width: 90%;
    margin-bottom: 2rem;
}

.instruction-group {
    background: rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 1.2rem;
    backdrop-filter: blur(5px);
}

.instruction-group h3 {
    font-family: 'Fredoka One', 'Nunito', sans-serif;
    color: #FFD700;
    margin-bottom: 0.5rem;
    font-size: 1.2rem;
}

.instruction-group p {
    color: rgba(255,255,255,0.9);
    line-height: 1.8;
}

.key {
    display: inline-block;
    background: rgba(255,255,255,0.2);
    border: 1px solid rgba(255,255,255,0.4);
    border-radius: 6px;
    padding: 2px 10px;
    font-family: 'Nunito', sans-serif;
    font-weight: 700;
    font-size: 0.9rem;
    margin: 0 2px;
}

/* Level Stats */
.level-stats, .victory-stats {
    background: rgba(255,255,255,0.1);
    border-radius: 12px;
    padding: 1.5rem 2.5rem;
    margin-bottom: 1.5rem;
    backdrop-filter: blur(5px);
    text-align: center;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    color: white;
    font-size: 1.1rem;
    padding: 0.4rem 0;
    gap: 3rem;
}

.stat-row .stat-label {
    color: rgba(255,255,255,0.7);
}

.stat-row .stat-value {
    font-family: 'Fredoka One', 'Nunito', sans-serif;
    color: #FFD700;
}

/* Floating hearts background animation (CSS only, for menu) */
.hearts-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
    z-index: -1;
}

.hearts-bg::before,
.hearts-bg::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background-image:
        radial-gradient(circle, #E6394630 2px, transparent 2px),
        radial-gradient(circle, #FF69B430 3px, transparent 3px),
        radial-gradient(circle, #9B5DE530 2px, transparent 2px);
    background-size: 80px 80px, 120px 120px, 60px 60px;
    background-position: 0 0, 40px 40px, 20px 20px;
    animation: floatHearts 20s linear infinite;
}

.hearts-bg::after {
    animation-delay: -10s;
    opacity: 0.5;
}

@keyframes floatHearts {
    0% { transform: translateY(0); }
    100% { transform: translateY(-100px); }
}

/* ---- Online Multiplayer UI ---- */

/* Menu divider */
.menu-divider {
    display: flex;
    align-items: center;
    width: 260px;
    margin: 0.3rem 0;
    color: rgba(155, 93, 229, 0.6);
    font-family: 'Fredoka One', 'Nunito', sans-serif;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.menu-divider::before, .menu-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: rgba(155, 93, 229, 0.3);
}

.menu-divider span {
    padding: 0 12px;
}

.btn-online-create {
    background: linear-gradient(135deg, #FF6B9D, #E63946);
    color: white;
    box-shadow: 0 4px 15px rgba(255, 107, 157, 0.4);
}

.btn-online-find {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    color: #2B2D42;
    box-shadow: 0 4px 15px rgba(255, 215, 0, 0.4);
}

/* Lobby */
.lobby-box {
    background: rgba(255,255,255,0.1);
    border-radius: 16px;
    padding: 2rem 2.5rem;
    margin-bottom: 1.5rem;
    backdrop-filter: blur(10px);
    text-align: center;
    min-width: 400px;
}

.lobby-status {
    font-family: 'Fredoka One', 'Nunito', sans-serif;
    font-size: 1.3rem;
    color: #FFD700;
    margin-bottom: 1rem;
}

.lobby-room-id {
    font-size: 1.1rem;
    color: rgba(255,255,255,0.7);
    margin-bottom: 1rem;
}

.lobby-room-id strong {
    font-family: 'Fredoka One', 'Nunito', sans-serif;
    font-size: 2rem;
    color: #FF69B4;
    letter-spacing: 6px;
    display: block;
    margin-top: 0.3rem;
}

.lobby-invite {
    margin-bottom: 1.5rem;
}

.lobby-invite p {
    color: rgba(255,255,255,0.6);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.invite-link-box {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.invite-link-box input {
    flex: 1;
    background: rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 8px;
    color: white;
    font-size: 0.85rem;
    padding: 8px 12px;
    font-family: 'Nunito', sans-serif;
    outline: none;
}

.btn-copy {
    background: linear-gradient(135deg, #FF69B4, #E63946);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    font-family: 'Fredoka One', 'Nunito', sans-serif;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-copy:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(230,57,70,0.4);
}

.copy-feedback {
    color: #2EC4B6;
    font-size: 0.85rem;
    min-height: 1.2em;
    margin-top: 0.3rem;
}

.lobby-players {
    display: flex;
    justify-content: center;
    gap: 2rem;
    margin: 1rem 0;
}

.lobby-player {
    font-family: 'Fredoka One', 'Nunito', sans-serif;
    font-size: 1.1rem;
    color: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.lobby-player-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}

.dot-empty {
    background: rgba(255,255,255,0.2);
    border: 2px solid rgba(255,255,255,0.3);
}

.dot-connected {
    background: #2EC4B6;
    border: 2px solid #4ECDC4;
    box-shadow: 0 0 8px rgba(46,196,182,0.6);
}

.lobby-ping {
    font-size: 0.8rem;
    color: rgba(255,255,255,0.4);
    margin-top: 0.5rem;
}

/* Searching screen */
.searching-box {
    background: rgba(255,255,255,0.1);
    border-radius: 16px;
    padding: 3rem 3rem;
    margin-bottom: 1.5rem;
    backdrop-filter: blur(10px);
    text-align: center;
}

.searching-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255,255,255,0.1);
    border-top-color: #FF69B4;
    border-right-color: #FFD700;
    border-radius: 50%;
    margin: 0 auto 1.5rem;
    animation: spin 1s linear infinite;
}

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

.searching-text {
    font-family: 'Fredoka One', 'Nunito', sans-serif;
    color: white;
    font-size: 1.3rem;
    margin-bottom: 0.5rem;
}

.searching-sub {
    color: rgba(255,255,255,0.5);
    font-size: 0.9rem;
}

/* Online char select */
#onlineCharSelect .characters-grid {
    max-width: 750px;
}

.char-selected-remote {
    border-color: #00BFFF !important;
    background: rgba(0, 191, 255, 0.15) !important;
}

/* ============================================
   Touch Controls
   ============================================ */
.touch-controls {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 15;
    pointer-events: none;
}

.touch-controls.hidden {
    display: none;
}

.touch-btn {
    pointer-events: auto;
    position: absolute;
    width: 60px;
    height: 60px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: rgba(255, 255, 255, 0.7);
    font-size: 1.3rem;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    touch-action: none;
    -webkit-touch-callout: none;
    backdrop-filter: blur(4px);
    transition: background 0.1s, transform 0.1s;
}

.touch-btn.touch-active {
    background: rgba(255, 105, 180, 0.4);
    border-color: rgba(255, 105, 180, 0.8);
    transform: scale(0.92);
}

/* D-pad: left side */
.touch-btn-left {
    bottom: 30px;
    left: 15px;
}

.touch-btn-right {
    bottom: 30px;
    left: 145px;
}

.touch-btn-down {
    bottom: 30px;
    left: 80px;
}

/* Jump button: above d-pad */
.touch-btn-jump {
    bottom: 100px;
    left: 80px;
    width: 70px;
    height: 70px;
    font-size: 1.6rem;
    background: rgba(255, 215, 0, 0.2);
    border-color: rgba(255, 215, 0, 0.5);
}

.touch-btn-jump.touch-active {
    background: rgba(255, 215, 0, 0.45);
    border-color: rgba(255, 215, 0, 0.9);
}

/* Special ability: right side */
.touch-btn-special {
    bottom: 50px;
    right: 20px;
    width: 70px;
    height: 70px;
    font-size: 1.8rem;
    background: rgba(155, 93, 229, 0.2);
    border-color: rgba(155, 93, 229, 0.5);
}

.touch-btn-special.touch-active {
    background: rgba(155, 93, 229, 0.45);
    border-color: rgba(155, 93, 229, 0.9);
}

/* Pause button: top-right */
.touch-btn-pause {
    top: 15px;
    right: 15px;
    width: 44px;
    height: 44px;
    font-size: 0.8rem;
    letter-spacing: -2px;
    border-radius: 10px;
}

/* ============================================
   Responsive Breakpoints
   ============================================ */

/* Tablet and small desktop */
@media (max-width: 768px) {
    .game-title {
        font-size: 3rem;
    }

    .subtitle {
        font-size: 1rem;
        margin-bottom: 2rem;
    }

    .characters-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.8rem;
    }

    .btn {
        font-size: 1.1rem;
        padding: 12px 36px;
        min-width: 220px;
    }

    .screen-title {
        font-size: 2rem;
    }

    .victory-title {
        font-size: 2.5rem;
    }

    .character-card {
        padding: 0.7rem 0.8rem 0.8rem;
    }

    .char-name {
        font-size: 1rem;
    }

    .char-ability {
        font-size: 0.75rem;
    }

    .char-description {
        font-size: 0.65rem;
    }

    .lobby-box {
        min-width: auto;
        width: 90%;
        padding: 1.5rem;
    }

    .instructions {
        max-width: 100%;
    }

    .level-stats, .victory-stats {
        padding: 1rem 1.5rem;
    }

    .stat-row {
        gap: 1.5rem;
        font-size: 1rem;
    }

    .searching-box {
        padding: 2rem;
    }

    .lang-toggle {
        top: 0.5rem;
        right: 0.5rem;
    }

    .lang-btn {
        padding: 5px 10px;
        font-size: 0.75rem;
    }
}

/* Mobile phones */
@media (max-width: 480px) {
    .screen {
        padding: 0.5rem 0;
        justify-content: flex-start;
        padding-top: 2rem;
    }

    .game-title {
        font-size: 2.2rem;
        margin-bottom: 0.3rem;
    }

    .subtitle {
        font-size: 0.85rem;
        margin-bottom: 1.5rem;
        letter-spacing: 2px;
    }

    .menu-buttons {
        gap: 0.7rem;
    }

    .btn {
        font-size: 1rem;
        padding: 10px 28px;
        min-width: 200px;
    }

    .btn-back {
        font-size: 0.9rem;
        padding: 8px 24px;
    }

    .screen-title {
        font-size: 1.6rem;
        margin-bottom: 1rem;
    }

    .victory-title {
        font-size: 1.8rem;
    }

    .characters-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
        width: 95%;
        margin-bottom: 1rem;
    }

    .character-card {
        padding: 0.5rem 0.5rem 0.6rem;
        border-radius: 10px;
        border-width: 2px;
    }

    .char-avatar {
        width: 50%;
        padding-bottom: 50%;
        margin-bottom: 0.4rem;
    }

    .char-name {
        font-size: 0.85rem;
    }

    .char-ability {
        font-size: 0.65rem;
    }

    .char-description {
        font-size: 0.6rem;
    }

    .select-prompt {
        font-size: 1rem;
        margin-bottom: 0.8rem;
    }

    .select-footer {
        gap: 0.5rem;
    }

    .lobby-box {
        padding: 1rem;
        width: 95%;
    }

    .lobby-status {
        font-size: 1rem;
    }

    .lobby-room-id strong {
        font-size: 1.5rem;
    }

    .invite-link-box {
        flex-direction: column;
        gap: 0.3rem;
    }

    .invite-link-box input {
        font-size: 0.75rem;
        padding: 6px 10px;
    }

    .searching-box {
        padding: 1.5rem;
    }

    .searching-text {
        font-size: 1rem;
    }

    .instruction-group {
        padding: 0.8rem;
    }

    .instruction-group h3 {
        font-size: 1rem;
    }

    .instruction-group p {
        font-size: 0.85rem;
        line-height: 1.6;
    }

    .level-stats, .victory-stats {
        padding: 0.8rem 1rem;
    }

    .stat-row {
        font-size: 0.9rem;
        gap: 1rem;
    }

    .game-over-text {
        font-size: 1rem;
        margin-bottom: 1.5rem;
    }

    .victory-message {
        font-size: 1.3rem;
        margin: 1rem 0;
    }

    .menu-divider {
        width: 200px;
    }

    .lang-toggle {
        top: 0.4rem;
        right: 0.4rem;
    }

    .lang-btn {
        padding: 4px 8px;
        font-size: 0.7rem;
    }
}

/* Extra small phones */
@media (max-width: 360px) {
    .game-title {
        font-size: 1.8rem;
    }

    .subtitle {
        font-size: 0.75rem;
        margin-bottom: 1rem;
    }

    .btn {
        font-size: 0.9rem;
        padding: 8px 20px;
        min-width: 180px;
    }

    .characters-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.4rem;
    }

    .screen-title {
        font-size: 1.4rem;
    }
}

/* Landscape mobile: adjust touch controls */
@media (max-height: 500px) and (orientation: landscape) {
    .touch-btn-left {
        bottom: 15px;
    }

    .touch-btn-right {
        bottom: 15px;
    }

    .touch-btn-down {
        bottom: 15px;
    }

    .touch-btn-jump {
        bottom: 80px;
    }

    .touch-btn-special {
        bottom: 30px;
    }

    .touch-btn {
        width: 50px;
        height: 50px;
        font-size: 1.1rem;
    }

    .touch-btn-jump,
    .touch-btn-special {
        width: 58px;
        height: 58px;
    }

    .screen {
        padding-top: 0.5rem;
    }

    .screen-title {
        font-size: 1.4rem;
        margin-bottom: 0.5rem;
    }

    .game-title {
        font-size: 2rem;
    }

    .subtitle {
        margin-bottom: 0.5rem;
    }

    .menu-buttons {
        gap: 0.4rem;
    }

    .btn {
        padding: 8px 24px;
        font-size: 0.9rem;
    }
}

/* Safe area insets for notched phones */
@supports (padding: env(safe-area-inset-bottom)) {
    .touch-btn-left,
    .touch-btn-right,
    .touch-btn-down {
        bottom: calc(30px + env(safe-area-inset-bottom));
    }

    .touch-btn-jump {
        bottom: calc(100px + env(safe-area-inset-bottom));
    }

    .touch-btn-special {
        bottom: calc(50px + env(safe-area-inset-bottom));
    }

    .touch-btn-pause {
        top: calc(15px + env(safe-area-inset-top));
    }
}
