/* Root Variables for Theme - Matching Fruit Rabbit Suite */
:root {
    --bg-color: #020617;
    --panel-bg: rgba(255, 255, 255, 0.1);
    --glass-bg: rgba(255, 255, 255, 0.12);
    --accent-red: #ff4d6d;
    --accent-blue: #60a5fa;
    --accent-yellow: #fbbf24;
    --text-primary: #f8fafc;
    --text-muted: #94a3b8;
    --font-main: 'Outfit', 'Nanum Gothic', sans-serif;
    --glass-border: 1px solid rgba(255, 255, 255, 0.15);
    --vh: 1vh;
    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 8px;
}

/* Reset and Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}

body.virtual-fullscreen {
    position: fixed;
    width: 100vw;
    height: 100dvh;
    overflow: hidden;
    background: var(--bg-color);
}

body {
    margin: 0;
    padding: 0;
    background: #020617;
    background-image: radial-gradient(rgba(255, 255, 255, 0.05) 1px, transparent 1px);
    background-size: 30px 30px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text-primary);
    overflow: hidden;
    position: relative;
    width: 100%;
    height: 100dvh;

    overscroll-behavior-y: none;
    touch-action: none;
    position: fixed;
    width: 100%;
    height: 100dvh;
}

.app-container {
    position: relative;
    background: linear-gradient(180deg, #0f172a 0%, #020617 100%);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#game-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 10;
}

#game-screen.active {
    display: flex;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: linear-gradient(180deg, #0f172a 0%, #020617 100%);
    z-index: 100;
    overflow: hidden;
}

.screen.active {
    display: flex !important;
}

/* Background Decorations */
.bg-decor {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
}

.butterfly {
    position: absolute;
    width: 50px;
    opacity: 0.3;
    animation: fly 25s linear infinite;
}

@keyframes fly {
    0% {
        transform: translate(-100px, 100vh) rotate(0deg);
    }

    100% {
        transform: translate(120vw, -100px) rotate(360deg);
    }
}

.butterfly:nth-child(2) {
    animation-delay: -5s;
    animation-duration: 30s;
}

.butterfly:nth-child(3) {
    animation-delay: -12s;
    animation-duration: 22s;
}

/* Header */
.game-header {
    height: calc(44px + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 12px 0 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.4);
    z-index: 100;
    flex-shrink: 0;
}

.hud-left,
.hud-right {
    display: flex;
    gap: 2px;
    align-items: center;
}

.header-logo {
    height: 32px;
    width: auto;
}

.icon-btn {
    background: transparent !important;
    background-color: transparent !important;
    border: none !important;
    box-shadow: none !important;
    color: white;
    width: 38px;
    height: 38px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
    overflow: hidden;
    padding: 0;
    -webkit-appearance: none;
    appearance: none;
}

.icon-btn:active {
    transform: scale(0.9);
}

.header-ico-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.icon-btn img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
}

#exit-btn,
#close-app-btn,
#game-reset-btn,
#settings-btn {
    background: transparent !important;
    background-image: none !important;
    box-shadow: none !important;
    border: none !important;
}

#game-reset-btn::before,
#game-reset-btn::after {
    display: none !important;
}

/* Main Game Area */
.game-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0;
    position: relative;
    overflow: hidden;
    min-height: 0;
    /* Exactly reserve the 70px control height + safe area bottom */
    margin-bottom: calc(70px + env(safe-area-inset-bottom, 0px));
}

#game-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.game-board-container {
    flex: 1;
    /* Expand to fill space below HUD */
    width: 100%;
    position: relative;
    display: flex;
    justify-content: center;
    align-items: flex-end; /* Changed back to flex-end to sit exactly on top of controls */
    background: transparent;
    overflow: hidden;
    margin: 0;
    padding: 0;
    min-height: 0;
}

#tetris-board {
    display: block;
    background: rgba(0, 0, 0, 0.2);
}

/* Top HUD - Optimized */
.game-top-hud {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0px 6px;
    background: rgba(15, 23, 42, 0.95);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    gap: 0;
    flex-shrink: 0;
    margin-top: -1px;
}

.unified-stats {
    background: none;
    border: none;
    box-shadow: none;
    border-radius: 0;
    padding: 1px 0;
    display: flex;
    width: 100%;
    justify-content: space-around;
    align-items: center;
    gap: 4px;
}

.hud-item label {
    font-size: 0.6rem;
    color: var(--accent-blue);
    font-weight: 800;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.next-preview {
    flex-direction: row;
    padding: 4px 10px;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), transparent);
}

#next-board {
    width: 44px;
    height: 44px;
}

.stat-group {
    flex: 1;
    justify-content: space-around;
    padding: 4px 0;
}

.stat-unit {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    background: rgba(255, 255, 255, 0.04);
    padding: 1px 6px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.stat-unit span {
    display: block;
    font-size: 0.95rem;
    /* Slightly smaller to fit rows */
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1;
    margin-top: 0;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.stat-unit label {
    color: var(--text-muted);
}

.secondary-stats {
    background: none;
    border: none;
    box-shadow: none;
}

.secondary-stats .stat-unit span {
    font-size: 0.9rem;
    color: var(--accent-yellow);
}

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

/* Unified Start Screen Styles */
.overlay-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 20px;
}

.start-logo {
    width: 200px;
    height: 120px;
    object-fit: contain;
    filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.5));
    margin-bottom: 10px;
    animation: startLogoFloat 3s ease-in-out infinite;
}

@keyframes startLogoFloat {

    0%,
    100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-10px);
    }
}

.start-title {
    font-size: 1.8rem;
    font-weight: 900;
    color: #fff;
    margin-bottom: 5px;
    text-shadow: 0 4px 10px rgba(0, 0, 0, 0.5);
    line-height: 1.2;
}

.start-desc {
    color: #94a3b8;
    font-size: 0.9rem;
    margin-bottom: 30px;
}

.start-btn-primary {
    width: 220px;
    height: 64px;
    background: linear-gradient(135deg, #ec4899 0%, #be185d 100%);
    color: white !important;
    border: none !important;
    border-radius: 32px !important;
    font-size: 1.4rem !important;
    font-weight: 950 !important;
    cursor: pointer;
    box-shadow: 0 8px 0 #9d174d, 0 15px 30px rgba(236, 72, 153, 0.4) !important;
    transition: transform 0.1s;
    margin-top: 0 !important;
    margin-bottom: 20px !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

.start-btn-primary:active {
    transform: translateY(4px);
    box-shadow: 0 4px 0 #9d174d, 0 10px 20px rgba(236, 72, 153, 0.3) !important;
}

.start-secondary-row {
    display: flex;
    gap: 12px;
    margin-bottom: 40px;
}

.start-btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    padding: 10px 20px;
    border-radius: 12px;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
}

.start-btn-secondary:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.2);
}

.start-footer-mini {
    position: absolute;
    bottom: 20px;
    text-align: center;
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.3);
    width: 100%;
    pointer-events: none;
}

.version-tag {
    font-weight: 700;
    color: rgba(255, 255, 255, 0.2);
    margin-bottom: 2px;
}

/* Screen Overlays (Start, Login, Settings) */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 5000;
    padding: 20px;
    box-sizing: border-box;
}

.overlay.active {
    display: flex !important;
    visibility: visible !important;
    opacity: 1 !important;
    z-index: 1000000 !important;
    /* Ensure it's above EVERYTHING */
}

.overlay-content {
    width: 100%;
    max-width: 320px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    /* Animation removed to prevent sequential flickering/delays */
    opacity: 1;
    transform: none;
}

@keyframes fadeInScale {
    from {
        opacity: 0;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.screen-overlay {
    padding: 20px;
}

.glass {
    background: rgba(30, 41, 59, 0.85);
    backdrop-filter: blur(8px);
    border: var(--glass-border);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 380px;
    padding: 30px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.card-title {
    font-size: 2rem;
    margin-bottom: 30px;
    text-align: center;
    background: linear-gradient(to right, #60a5fa, #f472b6);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

/* Social Login Grid */
.social-login-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 25px;
}

.social-btn {
    padding: 12px;
    border-radius: var(--radius-sm);
    border: none;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
}

.social-btn.google {
    background: #fff;
    color: #333;
}

.social-btn.apple {
    background: #000;
    color: #fff;
}

.social-btn.naver {
    background: #03c75a;
    color: #fff;
}

.social-btn.kakao {
    background: #fef01b;
    color: #3e2723;
}

.divider {
    display: flex;
    align-items: center;
    margin: 20px 0;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.divider::before,
.divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: rgba(255, 255, 255, 0.1);
}

.divider span {
    padding: 0 10px;
}

/* Form Styles */
.input-group {
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.input-group input {
    width: 100%;
    background: rgba(0, 0, 0, 0.3);
    border: var(--glass-border);
    border-radius: var(--radius-sm);
    padding: 12px 15px;
    color: white;
    font-size: 1rem;
}

.submit-btn {
    width: 100%;
    padding: 15px;
    border-radius: var(--radius-sm);
    border: none;
    background: var(--panel-bg);
    color: white;
    font-weight: 700;
    cursor: pointer;
    border: var(--glass-border);
}

.close-btn {
    width: 100%;
    margin-top: 20px;
    background: none;
    border: none;
    color: var(--text-muted);
    text-decoration: underline;
    cursor: pointer;
    font-size: 0.9rem;
}

/* Settings List */
.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.toggle-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--text-muted);
    padding: 8px 16px;
    border-radius: 20px;
    font-weight: 700;
    cursor: pointer;
}

.toggle-btn.active {
    background: #10b981;
    color: white;
}

.legal-content {
    background: rgba(0, 0, 0, 0.3);
    padding: 15px;
    border-radius: 12px;
    margin: 10px 0;
    max-height: 200px;
    overflow-y: auto;
    text-align: left;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.legal-content h3 {
    font-size: 0.9rem;
    color: var(--accent-blue);
    margin: 10px 0 5px 0;
}

.legal-content p {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.4;
    margin-bottom: 10px;
}

.mobile-controls-row {
    position: absolute;
    bottom: 0px;
    width: 100%;
    padding: 2px 4px calc(2px + env(safe-area-inset-bottom, 0px));
    background: transparent;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    height: calc(70px + env(safe-area-inset-bottom, 0px));
    /* Scientifically correct height */
    z-index: 2000;
    transition: opacity 0.3s;
}

.secondary-controls {
    position: absolute;
    top: 60px;
    right: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 1000;
}

.ctrl-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    color: white;
    width: 60px;
    /* Precise width */
    height: 54px;
    /* Precise height */
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.8rem;
    /* Corrected font size */
    cursor: pointer;
}



.ctrl-img {
    width: 32px;
    /* Set specific size for images like flip.png */
    height: 32px;
    object-fit: contain;
    pointer-events: none;
}

.ctrl-btn:active {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(2px);
}

.ctrl-btn.action {
    flex: 1.5;
    /* Slightly bigger drop button */
    background: linear-gradient(135deg, var(--accent-blue), #1e40af);
    font-weight: 800;
    font-size: 1rem;
    letter-spacing: 0.5px;
}

.ctrl-btn.tiny {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    font-size: 1.2rem;
}

/* Puzzle Mode Styles */
.puzzle-slot {
    width: 28%;
    height: 60px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px dashed rgba(255, 255, 255, 0.1);
    cursor: grab;
}

.puzzle-slot:active {
    cursor: grabbing;
}

.puzzle-slot canvas {
    max-width: 90%;
    max-height: 90%;
}

/* Stage Intro Overlay */
#stage-intro {
    background: rgba(0, 0, 0, 0.4);
    z-index: 2000;
}

.stage-card {
    background: rgba(30, 41, 59, 0.95);
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-radius: 20px;
    padding: 16px 24px !important;
    text-align: center;
    min-width: 180px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
    animation: stageIn 0.5s cubic-bezier(0.18, 0.89, 0.32, 1.28);
}

.stage-card h2 {
    font-size: 2.8rem;
    margin: 4px 0;
    line-height: 1;
    color: var(--accent-blue);
    text-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.stage-prefix {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 800;
}

#stage-title-intro {
    font-size: 1.2rem;
    margin-bottom: 4px;
}

#stage-desc-intro {
    font-size: 0.85rem;
    opacity: 0.8;
}

.stage-card.gold {
    background: linear-gradient(135deg, #fbbf24, #f59e0b) !important;
    border: 2px solid #fff !important;
    color: #000 !important;
}

.stage-card.gold h2 {
    color: #fff;
}

@keyframes stageIn {
    from {
        transform: scale(0.8) translateY(30px);
        opacity: 0;
    }

    to {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

/* Landscape on PC - Keep Portrait Aspect Ratio */
/* Landscape on PC - Keep Portrait Aspect Ratio with modern bezel & aspect-ratio */
@media (min-width: 481px) {
    .app-container {
        width: calc(96vh * (9 / 19.5));
        height: 96vh;
        max-width: 480px;
        max-height: 96vh;
        border-radius: 36px;
        border: 12px solid #1e293b;
        box-shadow: 0 25px 60px rgba(0, 0, 0, 0.8);
        margin: auto;
    }
}

@media (max-width: 480px) {
    .app-container {
        width: 100%;
        height: 100dvh;
        max-width: none;
        max-height: none;
        border: none;
        border-radius: 0;
        box-shadow: none;
        margin: 0;
    }
}

/* --- Unified Premium Login System (Compact) --- */
#login-screen {
    background: radial-gradient(circle at center, rgba(30, 27, 75, 0.95) 0%, rgba(3, 7, 18, 0.98) 100%) !important;
    z-index: 9999;
}

.login-card {
    background: linear-gradient(145deg, rgba(30, 27, 75, 0.85) 0%, rgba(49, 46, 129, 0.85) 100%) !important;
    backdrop-filter: blur(8px);
    color: #f3f4f6;
    border: 1px solid rgba(255, 255, 255, 0.2);
    width: 90%;
    max-width: 340px;
    padding: 15px 20px;
    border-radius: 24px;
    text-align: center;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.5), inset 0 0 15px rgba(255, 255, 255, 0.1);
    max-height: 92vh;
    overflow-y: auto;
}

.login-compact {
    padding: 10px 20px !important;
}

.login-compact .login-logo-mini img {
    height: 60px !important;
    width: auto;
    margin-bottom: 2px !important;
}

.login-compact .login-title {
    margin: 2px 0 10px 0 !important;
    font-size: 1.1rem !important;
    letter-spacing: 2px;
}

.login-compact .input-group {
    margin-bottom: 8px !important;
    text-align: left;
}

.login-compact .input-group label {
    font-size: 0.6rem !important;
    margin-bottom: 2px !important;
    display: block;
    opacity: 0.8;
}

.login-compact input {
    height: 38px !important;
    font-size: 0.85rem !important;
    padding: 0 12px !important;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: white;
    width: 100%;
}

.login-compact .login-submit {
    margin-top: 10px !important;
    margin-bottom: 10px !important;
    padding: 12px !important;
    font-size: 0.95rem !important;
}

.login-compact .login-policy-note {
    font-size: 0.6rem !important;
    margin-top: 5px;
    opacity: 0.6;
}

.login-compact .login-policy-note span {
    text-decoration: underline;
    cursor: pointer;
}

body:has(#photo-zone-screen.active) .butterfly,
body:has(#login-screen.active) .butterfly {
    display: none !important;
}


#mobile-controls.hidden {
    display: none !important;
}

/* v40.40 Unified Login Design Refinement */
.login-card-unified {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 320px;
    gap: 0;
    animation: loginIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

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

    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

#unified-login-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 20px;
}

.logo-container-compact {
    margin-bottom: 12px;
}

.start-logo-standard {
    width: 200px;
    height: auto;
    max-width: 90vw;
    filter: drop-shadow(0 8px 25px rgba(0, 0, 0, 0.5));
}

.unified-nickname-input {
    width: 240px;
    padding: 12px 15px;
    border-radius: 20px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    background: rgba(0, 0, 0, 0.3);
    color: white;
    text-align: center;
    font-size: 1.1rem;
    outline: none;
    backdrop-filter: blur(10px);
    transition: all 0.2s;
}

.unified-nickname-input:focus {
    border-color: rgba(255, 255, 255, 0.4);
    background: rgba(0, 0, 0, 0.4);
}

.btn-row-compact {
    display: flex;
    gap: 12px;
    margin-bottom: 40px;
}

.footer-v-tag {
    position: absolute;
    bottom: 30px;
    text-align: center;
    color: rgba(255, 255, 255, 0.3);
    font-size: 0.8rem;
    pointer-events: none;
}