/* CSS Custom Properties - Easy Customization */
:root {
    /* Brand Colors - Change these to customize */
    --primary-color: #1e7a3e;
    --secondary-color: #c41e3a;
    --accent-color: #ffd700;
    --text-color: #111111;
    --background-gradient: linear-gradient(135deg, #d3cebb 0%, #e2d7b4 50%, #dfcda8 100%);
    --bg-color: #0a1929;
    --snow-color: #ffffff;
    --glow-color: #ffd700;
    
    /* Tree Part Colors - Easy to customize */
    --trunk-color: #8B4513;
    --trunk-accent: #654321;
    --branch-bottom-color: #1e7a3e;
    --branch-middle-color: #228B22;
    --branch-top-color: #32CD32;
    --tree-top-color: #3CB371;
    --star-color: #FFD700;
    --ornament-color: #c41e3a;
    --ornament-accent: #dc143c;
    
    /* Shadows and Transitions */
    --shadow-light: 0 2px 10px rgba(0, 0, 0, 0.1);
    --shadow-medium: 0 4px 20px rgba(0, 0, 0, 0.15);
    --shadow-heavy: 0 8px 30px rgba(0, 0, 0, 0.25);
    
    --transition-fast: 0.2s ease;
    --transition-medium: 0.4s ease;
    --transition-slow: 0.6s ease;
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--background-gradient);
    color: var(--text-color);
    min-height: 100vh;
    min-height: calc(var(--vh, 1vh) * 100); /* Fallback for older browsers */
    min-height: 100dvh; /* Dynamic viewport height for modern browsers */
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

body.dark {
    --text-color: #ffffff;
    --background-gradient: linear-gradient(135deg, #0a1929 25%, #162e4e 50%, #1b3c5c 75%);
}

#app {
    position: relative;
    width: 100vw;
    width: 100dvw; /* Dynamic viewport width */
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100); /* Fallback for older browsers */
    height: 100dvh; /* Dynamic viewport height for modern browsers */
    overflow: hidden;
}

/* Screen Management */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    opacity: 0;
    transform: translateY(20px);
    transition: all var(--transition-medium);
    pointer-events: none;
}

.screen.active {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}

/* Welcome Screen */
#welcome-screen {
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 2rem;
}

.logo-container {
    margin-bottom: 2rem;
}

.company-logo {
    max-width: 120px;
    max-height: 80px;
    filter: drop-shadow(var(--shadow-medium));
}

#welcome-screen h1 {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-color);
    margin-bottom: 1rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

#welcome-screen p {
    font-size: 1.1rem;
    color: var(--text-color);
    opacity: 0.9;
    margin-bottom: 3rem;
    max-width: 400px;
}

.cta-button {
    background: linear-gradient(135deg, var(--primary-color), #2d8f47);
    color: var(--text-color);
    border: none;
    padding: 1rem 2.5rem;
    font-size: 1.2rem;
    font-weight: 600;
    border-radius: 50px;
    cursor: pointer;
    transition: all var(--transition-medium);
    box-shadow: var(--shadow-medium);
    font-family: inherit;
}

.cta-button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-heavy);
    background: linear-gradient(135deg, #2d8f47, var(--primary-color));
}

.cta-button:active {
    transform: translateY(0);
}

/* Game Screen */
#game-screen {
    justify-content: flex-start;
}


.game-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Tree Area */
.tree-area {
    flex: 1;
    position: relative;
    background: transparent;
    min-height: 40vh;
}

.ground {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 120px; /* nicht zu hoch */
    background: linear-gradient(180deg, #ffffff 0%, #f8fbff 50%, #e1ecf7 100%);
    border-radius: 50% 50% 0 0 / 60px 60px 0 0; /* Rundung behalten */
    box-shadow: 
        0 -5px 20px rgba(255, 255, 255, 0.8),
        inset 0 5px 10px rgba(0, 0, 0, 0.05);
    border-top: 2px solid rgba(255, 255, 255, 0.8);
    z-index: 1;
}

.drop-zone {
    position: absolute;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    transition: all var(--transition-fast);
    z-index: 1000;
    pointer-events: none;
}

.drop-zone.highlight {
    background: radial-gradient(circle, rgba(255, 215, 0, 0.4) 0%, rgba(255, 215, 0, 0.1) 70%);
    border: 3px dashed var(--accent-color);
    transform: translateX(-50%) scale(1.3) !important;
    z-index: 1001;
    box-shadow: 
        0 0 30px rgba(255, 215, 0, 0.6),
        inset 0 0 20px rgba(255, 215, 0, 0.2);
    animation: drop-zone-pulse 1.5s ease-in-out infinite;
}

@keyframes drop-zone-pulse {
    0%, 100% {
        box-shadow: 
            0 0 30px rgba(255, 215, 0, 0.6),
            inset 0 0 20px rgba(255, 215, 0, 0.2);
    }
    50% {
        box-shadow: 
            0 0 50px rgba(255, 215, 0, 0.8),
            inset 0 0 30px rgba(255, 215, 0, 0.4);
    }
}

/* SVG Tree Parts */
.tree-part {
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.4));
    transition: all var(--transition-fast);
}

.tree-part:hover {
    filter: drop-shadow(0 6px 16px rgba(0, 0, 0, 0.5));
    transform: scale(1.05);
}

.tree-part.dragging {
    filter: drop-shadow(0 10px 25px rgba(0, 0, 0, 0.6));
    transform: scale(1.15) rotate(5deg);
}

.tree-part.placed {
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.4));
}

.tree-part.active {
    animation: lights-twinkle 2s ease-in-out infinite alternate;
}

@keyframes lights-twinkle {
    0% { 
        filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.4)) brightness(1) saturate(1); 
    }
    100% { 
        filter: drop-shadow(0 6px 20px rgba(255, 215, 0, 0.3)) brightness(1.4) saturate(1.3) hue-rotate(15deg); 
    }
}

/* Step Info Bar */
.step-info {
    background: linear-gradient(180deg, #e1ecf7 0%, #c9ddef 70%, #b1cde7 100%);
    backdrop-filter: blur(15px);
    border-top: 2px solid rgb(0, 0, 0, 0.6);
    padding: 1.5rem;
    text-align: center;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.8);
}

.step-counter {
    color: var(--text-color);
    opacity: 0.9;
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

.step-description {
    color: var(--text-color);
    font-size: 1rem;
    margin-bottom: 1rem;
    font-weight: 500;
}

.choose-part-button {
    background: linear-gradient(135deg, var(--primary-color), #2d8f47);
    color: var(--text-color);
    border: none;
    padding: 0.8rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 25px;
    cursor: pointer;
    transition: all var(--transition-medium);
    box-shadow: var(--shadow-medium);
    font-family: inherit;
}

.choose-part-button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-heavy);
    background: linear-gradient(135deg, #2d8f47, var(--primary-color));
}

.choose-part-button:active {
    transform: translateY(0);
}

/* Dialog System */
.dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-medium);
}

.dialog-overlay.active {
    opacity: 1;
    visibility: visible;
}

.dialog-content {
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.95), rgba(255, 255, 255, 0.9));
    border-radius: 20px;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    border: 2px solid rgba(255, 215, 0, 0.3);
    transform: scale(0.9) translateY(20px);
    transition: all var(--transition-medium);
}

.dialog-overlay.active .dialog-content {
    transform: scale(1) translateY(0);
}

.dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 2px solid rgba(255, 215, 0, 0.2);
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.1), rgba(255, 215, 0, 0.05));
}

.dialog-header h3 {
    color: var(--text-color);
    font-size: 1.4rem;
    font-weight: 700;
    margin: 0;
}

.close-button {
    background: none;
    border: none;
    font-size: 1.8rem;
    color: var(--text-color);
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all var(--transition-fast);
}

.close-button:hover {
    background: rgba(255, 0, 0, 0.1);
    color: #dc3545;
    transform: scale(1.1);
}

.dialog-body {
    padding: 1.5rem;
}

.part-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

.part-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.8), rgba(255, 255, 255, 0.6));
    border-radius: 12px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    cursor: pointer;
    transition: all var(--transition-medium);
    position: relative;
    overflow: hidden;
}

.part-option:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    border-color: var(--accent-color);
}

.part-option.selected {
    border-color: var(--accent-color);
    background: linear-gradient(145deg, rgba(255, 215, 0, 0.2), rgba(255, 215, 0, 0.1));
    box-shadow: 0 8px 20px rgba(255, 215, 0, 0.3);
}

.part-option.selected::before {
    content: '*';
    position: absolute;
    top: 8px;
    right: 8px;
    background: var(--accent-color);
    color: var(--text-color);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 0.8rem;
}

.part-option-title {
    color: var(--text-color);
    font-size: 0.9rem;
    font-weight: 600;
    text-align: center;
    margin-top: 0.5rem;
}

.dialog-footer {
    padding: 1rem 1.5rem;
    border-top: 2px solid rgba(255, 215, 0, 0.2);
    background: linear-gradient(135deg, rgba(255, 215, 0, 0.05), transparent);
    text-align: center;
}

.confirm-button {
    background: linear-gradient(135deg, var(--primary-color), #2d8f47);
    color: var(--text-color);
    border: none;
    padding: 0.8rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 25px;
    cursor: pointer;
    transition: all var(--transition-medium);
    box-shadow: var(--shadow-medium);
    font-family: inherit;
}

.confirm-button:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.confirm-button:not(:disabled):hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-heavy);
    background: linear-gradient(135deg, #2d8f47, var(--primary-color));
}

/* Parts Palette (Hidden Templates) */
#parts-templates {
    display: none;
}


.draggable {
    cursor: grab;
    transition: all var(--transition-fast);
    transform-origin: center;
}

.draggable:hover {
    transform: scale(1.1);
}

.draggable.dragging {
    cursor: grabbing;
    transform: scale(1.2) rotate(5deg);
    z-index: 1000;
    filter: drop-shadow(0 10px 30px rgba(0, 0, 0, 0.5));
}

.draggable.placed {
    pointer-events: none;
}

/* Z-index stacking for placed tree parts during gameplay */
.tree-area .tree-part.placed {
    z-index: 50;
}

.tree-area .tree-part[data-part="trunk"].placed {
    z-index: 10;
}

.tree-area .tree-part[data-part="branch-bottom"].placed {
    z-index: 20;
}

.tree-area .tree-part[data-part="branch-middle"].placed {
    z-index: 30;
}

.tree-area .tree-part[data-part="branch-top"].placed {
    z-index: 40;
}

.tree-area .tree-part[data-part="tree-top"].placed {
    z-index: 50;
}

.tree-area .tree-part[data-part="lights"].placed {
    z-index: 60;
}

.tree-area .tree-part[data-part="ornaments"].placed {
    z-index: 70;
}

.tree-area .tree-part[data-part="star"].placed {
    z-index: 80;
}

/* Success Screen */
#success-screen {
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 1rem;
    overflow-y: auto;
    overflow-x: hidden;
}

.success-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 10;
    width: 100%;
    max-width: 600px;
    margin: 0 auto;
    min-height: 100%;
    justify-content: center;
}

.completed-tree {
    position: relative;
    width: min(280px, 80vw);
    height: min(480px, 60vh);
    animation: tree-celebration 3s ease-in-out;
    flex-shrink: 0;
}

@keyframes tree-celebration {
    0% { transform: scale(0.5) rotate(-10deg); opacity: 0; }
    50% { transform: scale(1.1) rotate(5deg); }
    100% { transform: scale(1) rotate(0deg); opacity: 1; }
}

.completed-tree .tree-part[data-part="star"] {
    animation: star-twinkle 1.5s ease-in-out infinite;
}

@keyframes star-twinkle {
    0%, 100% { filter: drop-shadow(0 0 15px var(--accent-color)); }
    50% { filter: drop-shadow(0 0 30px var(--accent-color)) brightness(1.5); }
}

.success-message {
    width: 100%;
    max-width: 500px;
    flex-shrink: 0;
}

.success-message h2 {
    font-size: clamp(1.8rem, 4vw, 2.5rem);
    color: var(--text-color);
    margin-bottom: 0.75rem;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.success-message p {
    font-size: clamp(1rem, 2.5vw, 1.2rem);
    color: var(--text-color);
    opacity: 0.9;
    margin-bottom: 0.75rem;
    line-height: 1.5;
    padding: 0 1rem;
}

.company-message {
    font-weight: 600;
    color: var(--text-color) !important;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
    margin-bottom: 1rem !important;
}

/* Snowfall Animation */
.snowfall {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    z-index: 1;
}

/* Add subtle background pattern */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(255, 255, 255, 0.05) 0%, transparent 50%),
        radial-gradient(circle at 40% 60%, rgba(255, 215, 0, 0.02) 0%, transparent 50%);
    z-index: -1;
}

.snowfall::before,
.snowfall::after {
    content: '*';
    position: absolute;
    color: var(--snow-color);
    user-select: none;
    pointer-events: none;
    font-size: 1rem;
    animation: snowfall-animation 10s linear infinite;
}

.snowfall::before {
    left: 10%;
    animation-duration: 8s;
    animation-delay: -2s;
}

.snowfall::after {
    left: 80%;
    animation-duration: 12s;
    animation-delay: -5s;
    font-size: 0.8rem;
}

@keyframes snowfall-animation {
    0% {
        transform: translateY(-100px) rotate(0deg);
        opacity: 1;
    }
    100% {
        transform: translateY(calc(100vh + 100px)) rotate(360deg);
        opacity: 0.3;
    }
}

.snowfall.intense::before,
.snowfall.intense::after {
    animation-duration: 4s;
}

/* Rich Snowfall - many dynamic flakes */
.snowfall .snowflake {
	position: absolute;
	top: -10vh;
	left: var(--x, 0%);
	color: var(--snow-color);
	font-size: var(--size, 1rem);
	opacity: 0.9;
	filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.6));
	animation: snowflake-fall var(--duration, 10s) linear var(--delay, 0s) infinite;
}

@keyframes snowflake-fall {
	0% {
		transform: translateY(-10vh) translateX(0) rotate(0deg);
		opacity: 0.95;
	}
	50% {
		transform: translateY(50vh) translateX(var(--sway, 40px)) rotate(180deg);
	}
	100% {
		transform: translateY(110vh) translateX(0) rotate(360deg);
		opacity: 0.3;
	}
}

/* Canvas Elements */
#particles-canvas,
#fireworks-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    #welcome-screen h1 {
        font-size: 2rem;
    }
    
    #welcome-screen p {
        font-size: 1rem;
    }
    
    .parts-palette {
        padding: 1rem;
        gap: 0.75rem;
        min-height: 260px;
    }
    
    .part-item {
        max-width: 100px;
        padding: 0.75rem;
        gap: 0.25rem;
    }
    
    .part-item span {
        font-size: 0.75rem;
    }
    
    /* Success Screen Mobile Optimizations */
    #success-screen {
        padding: 0.75rem;
        align-items: flex-start;
        padding-top: max(1rem, env(safe-area-inset-top));
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
    
    .success-content {
        justify-content: flex-start;
        min-height: auto;
        padding-top: 1rem;
    }
    
    .completed-tree {
        width: min(240px, 85vw);
        height: min(320px, 45vh);
    }
    
    .success-message p {
        padding: 0 0.5rem;
        margin-bottom: 0.5rem;
    }
    
    .company-logo {
        max-width: 100px;
        max-height: 60px;
    }
    
    .logo-container {
        margin-bottom: 1rem;
    }
}

/* Small Mobile Devices */
@media (max-width: 480px) {
    #success-screen {
        padding: 0.5rem;
    }
    
    .completed-tree {
        width: min(200px, 90vw);
        height: min(280px, 40vh);
    }
    
    .success-message h2 {
        font-size: clamp(1.5rem, 5vw, 2rem);
        margin-bottom: 0.5rem;
    }
    
    .success-message p {
        font-size: clamp(0.9rem, 3vw, 1.1rem);
        padding: 0 0.25rem;
        margin-bottom: 0.4rem;
    }
    
    .company-logo {
        max-width: 80px;
        max-height: 50px;
    }
}

/* Landscape Mobile */
@media (max-height: 500px) and (orientation: landscape) {
    #success-screen {
        padding: 0.5rem;
        overflow-y: auto;
    }
    
    .success-content {
        flex-direction: row;
        align-items: center;
        justify-content: center;
        max-width: none;
        width: 100%;
    }
    
    .completed-tree {
        width: min(200px, 35vw);
        height: min(300px, 80vh);
        flex-shrink: 0;
    }
    
    .success-message {
        flex: 1;
        max-width: none;
        text-align: left;
    }
    
    .success-message h2 {
        font-size: clamp(1.3rem, 3vw, 1.8rem);
        margin-bottom: 0.5rem;
    }
    
    .success-message p {
        font-size: clamp(0.8rem, 2vw, 1rem);
        padding: 0;
        margin-bottom: 0.5rem;
    }
    
    .logo-container {
        margin-bottom: 0.5rem;
    }
    
    .company-logo {
        max-width: 60px;
        max-height: 40px;
    }
}

@media (max-height: 700px) {
    .tree-area {
        min-height: 40vh;
    }
    
    .parts-palette {
        min-height: 200px;
    }
}

/* Touch Improvements */
@media (hover: none) and (pointer: coarse) {
    .draggable:hover {
        transform: none;
    }
    
    .part-item {
        min-height: 60px;
    }
    
    .cta-button {
        padding: 1.2rem 2.5rem;
    }
}

/* Safe area handling for devices with notches */
@supports(padding: max(0px)) {
    #app {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* Additional mobile viewport fixes */
@media only screen and (max-width: 768px) {
    html {
        height: -webkit-fill-available;
    }
    
    body {
        min-height: -webkit-fill-available;
    }
    
    #app {
        min-height: -webkit-fill-available;
    }
}