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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #d4a574; /* Warm cardboard brown background */
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    margin: 0;
    padding: 0;
}

.screen {
    width: 100%;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    position: absolute;
    top: 0;
    left: 0;
    margin: 0;
    padding: 0;
}

/* Hide screens by default - only show when explicitly made visible by JavaScript */
.screen[style*="display: none"] {
    display: none !important;
}

#splash-screen {
    background: #000;
    z-index: 30; /* Highest z-index - shown first */
    overflow: hidden;
}

.splash-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* Use dynamic viewport height for mobile browsers */
    overflow: hidden;
}

.splash-image {
    width: 100vw;
    height: 100vh;
    height: 100dvh; /* Use dynamic viewport height for mobile browsers */
    object-fit: cover; /* Fills height, crops left/right if needed */
    object-position: center;
    display: block;
}

.splash-button {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: 52%; /* Knapp unter der Mitte, etwas höher */
    z-index: 31;
    background: transparent;
    border: none;
    padding: 0;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.splash-button:hover {
    transform: translateX(-50%) scale(1.05);
}

.splash-button:active {
    transform: translateX(-50%) scale(0.95);
}

.splash-button img {
    display: block;
    max-width: 200px; /* Adjust button size as needed */
    height: auto;
}

#intro-screen {
    background: #d4a574;
    z-index: 10;
}

#portrait-screen {
    background: #d4a574;
    z-index: 20; /* Higher than intro-screen to ensure it's on top */
}

.portrait-content {
    text-align: center;
    color: #3d2817;
    max-width: 600px;
    padding: 20px;
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100%;
}

.portrait-icon {
    font-size: 5em;
    margin-bottom: 30px;
    animation: rotate 2s ease-in-out infinite;
}

@keyframes rotate {
    0%, 100% { transform: rotate(0deg); }
    50% { transform: rotate(90deg); }
}

.portrait-content h1 {
    font-size: 3em;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.portrait-content p {
    font-size: 1.5em;
    margin-bottom: 15px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

.intro-content {
    text-align: center;
    color: #3d2817;
    max-width: 600px;
    padding: 20px;
    width: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100%;
}

.intro-content h1 {
    font-size: 3em;
    margin-bottom: 20px;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
}

.intro-content p {
    font-size: 1.3em;
    margin-bottom: 15px;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.1);
}

#intro-character {
    width: 100px;
    height: 100px;
    margin: 30px auto;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    animation: characterEnter 1s ease-out;
}

@keyframes characterEnter {
    from {
        transform: translateX(-200px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

#intro-controls {
    margin: 30px 0;
    font-size: 1.1em;
}

#intro-controls p {
    margin: 10px 0;
}

.skip-btn,
.start-btn {
    background: #8b6f47;
    color: white;
    border: 3px dashed #5a4a32;
    padding: 12px 30px;
    font-size: 1.1em;
    border-radius: 0;
    cursor: pointer;
    margin: 10px;
    transition: all 0.3s;
    box-shadow: 3px 3px 0px rgba(0, 0, 0, 0.2);
    position: relative;
}

.skip-btn::before,
.start-btn::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border: 2px solid #5a4a32;
    border-style: dashed;
    pointer-events: none;
}

.skip-btn:hover,
.start-btn:hover {
    background: #9d7f57;
    transform: translateY(-2px);
    box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.3);
}

.start-btn {
    background: #a67c52;
    font-weight: 600;
    margin-top: 20px;
}

.start-btn:hover {
    background: #b88a62;
}

.fade-in {
    opacity: 0;
    animation: fadeIn 0.8s ease-in forwards;
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

#game-screen {
    background: #d4a574;
    z-index: 5;
    padding: 40px;
    align-items: flex-start; /* Align container to top instead of center */
    padding-top: 80px; /* Space for header (20px top + ~60px header height) */
}

.game-header {
    position: absolute;
    top: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    font-size: 1.2em;
    font-weight: 600;
    color: white;
    z-index: 6;
    gap: 20px;
}

.score,
.target {
    background: #8b6f47;
    padding: 12px 20px;
    border-radius: 0;
    box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.3);
    border: 3px dashed #5a4a32;
    position: relative;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
}

.score::before,
.target::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border: 2px solid #5a4a32;
    border-style: dashed;
    pointer-events: none;
}

.score-icon {
    width: 24px;
    height: 24px;
    background: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.target {
    flex: 1;
    max-width: 400px;
}

.progress-container {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
}

.progress-bar {
    flex: 1;
    height: 20px;
    background: #5a4a32;
    border: 2px solid #3d2817;
    position: relative;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: #f4d03f; /* Golden yellow */
    transition: width 0.3s ease;
    box-shadow: inset 0 2px 4px rgba(255, 255, 255, 0.3);
}

.progress-text {
    white-space: nowrap;
    min-width: 30px;
    text-align: right;
}

#game-canvas-container {
    position: relative;
    display: block; /* Changed from inline-block for better height control */
    padding: 20px;
    background: #8b6f47;
    border: 4px dashed #5a4a32;
    box-shadow: 
        6px 6px 0px rgba(0, 0, 0, 0.3),
        inset 0 0 20px rgba(0, 0, 0, 0.1);
    box-sizing: border-box;
    /* Height controlled by JavaScript - no CSS constraints */
}

#game-canvas-container::before {
    content: '';
    position: absolute;
    top: 16px;
    left: 16px;
    right: 16px;
    bottom: 16px;
    border: 2px dashed #5a4a32;
    pointer-events: none;
}

#game-canvas {
    display: block;
    background: linear-gradient(to bottom, #e8f4f8 0%, #e8f4f8 60%, #b8b8b8 85%, #a0a0a0 100%); /* Sky to concrete */
    border: none;
    box-shadow: inset 0 0 20px rgba(0, 0, 0, 0.1);
    max-width: 100vw;
    max-height: 85vh;
    width: auto;
    height: auto;
}

/* Desktop: Simple rules - JavaScript controls sizing */
@media (min-width: 921px) {
    body {
        background: #d4a574 !important; /* Unified brown background */
        align-items: flex-start !important;
    }
    
    #game-screen {
        height: auto !important; /* Don't force 100vh */
        padding: 40px;
        padding-top: 20px; /* Wenig Padding oben für Header */
        position: relative; /* Wichtig für absolute Positionierung des Headers */
    }
    
    /* NUR Desktop: Header direkt über Canvas-Container, links und rechts bündig */
    .game-header {
        position: absolute;
        top: 20px;
        left: 50%; /* Zentriere horizontal */
        transform: translateX(-50%); /* Zentriere horizontal */
        width: calc(100% - 80px); /* Breite minus Padding (40px links + 40px rechts) */
        max-width: 1248px; /* Canvas-Container max-width (1200px) + Padding/Border (48px) */
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        font-size: 1.2em;
        font-weight: 600;
        color: white;
        z-index: 6;
        gap: 20px;
    }
    
    #game-canvas-container {
        margin: 80px auto 0 auto; /* Top-Margin für Header-Platz, zentriert */
        /* All dimensions set by JavaScript */
    }
    
    #game-canvas {
        /* All dimensions set by JavaScript - no CSS override */
    }
}

.game-controls {
    position: absolute;
    bottom: 20px;
    left: 20px;
    right: 20px;
    display: flex;
    justify-content: space-between;
    z-index: 6;
}

.control-btn {
    width: 50px;
    height: 50px;
    background: #8b6f47;
    border: 3px dashed #5a4a32;
    border-radius: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 3px 3px 0px rgba(0, 0, 0, 0.3);
    transition: all 0.2s;
    position: relative;
}

.control-btn::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border: 2px solid #5a4a32;
    border-style: dashed;
    pointer-events: none;
}

.control-btn:hover {
    background: #9d7f57;
    transform: translateY(-2px);
    box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.4);
}

.control-btn svg {
    width: 24px;
    height: 24px;
    fill: white;
}

#game-over-screen,
#win-screen,
#thanks-screen {
    background: rgba(0, 0, 0, 0.7);
    z-index: 20;
}

.game-over-content,
.win-content,
.thanks-content {
    background: #8b6f47;
    padding: 40px;
    border-radius: 0;
    text-align: center;
    box-shadow: 6px 6px 0px rgba(0, 0, 0, 0.4);
    border: 4px dashed #5a4a32;
    position: relative;
    color: white;
}

.game-over-content::before,
.win-content::before,
.thanks-content::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border: 2px solid #5a4a32;
    border-style: dashed;
    pointer-events: none;
}

.game-over-content h2,
.win-content h2 {
    font-size: 2.5em;
    margin-bottom: 20px;
    color: #ff6b6b;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.win-content h2 {
    color: #51cf66;
}

.game-over-content p,
.win-content p {
    font-size: 1.3em;
    margin-bottom: 30px;
    color: white;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
}

#retry-btn {
    background: #a67c52;
    color: white;
    border: 3px dashed #5a4a32;
    padding: 15px 40px;
    font-size: 1.2em;
    font-weight: 600;
    border-radius: 0;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.3);
    position: relative;
}

#retry-btn::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border: 2px solid #5a4a32;
    border-style: dashed;
    pointer-events: none;
}

#retry-btn:hover {
    background: #b88a62;
    transform: translateY(-2px);
    box-shadow: 5px 5px 0px rgba(0, 0, 0, 0.4);
}

/* Thanks Screen Styles */
#thanks-character-container {
    position: relative;
    width: 300px;
    height: 200px;
    margin: 20px auto;
    overflow: hidden;
}

.character-running {
    position: absolute;
    width: 100px;
    height: 120px;
    background-size: 200px 120px;
    background-repeat: no-repeat;
    background-position: 0 0;
    animation: characterRunIn 1.5s ease-out forwards, characterFadeOut 0.3s ease-in 1.5s forwards;
    left: -150px;
}

@keyframes characterRunIn {
    from {
        left: -150px;
    }
    to {
        left: 100px;
    }
}

@keyframes characterFadeOut {
    to {
        opacity: 0;
    }
}

.character-end {
    position: absolute;
    width: 200px;
    height: 200px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    opacity: 0;
    animation: characterEndFadeIn 0.5s ease-in 1.5s forwards;
    left: 50px;
    top: 0;
}

@keyframes characterEndFadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

#thanks-message {
    font-size: 2.5em;
    margin: 30px 0;
    color: white;
    text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}

.reward-btn {
    background: #a67c52;
    color: white;
    border: 3px dashed #5a4a32;
    padding: 15px 40px;
    font-size: 1.2em;
    font-weight: 600;
    border-radius: 0;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 4px 4px 0px rgba(0, 0, 0, 0.3);
    position: relative;
    margin-top: 20px;
}

.reward-btn::before {
    content: '';
    position: absolute;
    top: -2px;
    left: -2px;
    right: -2px;
    bottom: -2px;
    border: 2px solid #5a4a32;
    border-style: dashed;
    pointer-events: none;
}

.reward-btn:hover {
    background: #b88a62;
    transform: translateY(-2px);
    box-shadow: 5px 5px 0px rgba(0, 0, 0, 0.4);
}

.error {
    color: white;
    text-align: center;
    font-size: 1.5em;
    padding: 40px;
}

/* Desktop only - don't apply to mobile */
@media (min-width: 921px) and (max-width: 1600px) {
    #game-canvas {
        width: 90vw;
        height: auto;
    }
    
    #game-screen {
        padding: 20px;
    }
}

@media (max-width: 920px) {
    body {
        background: #e8f4f8 !important; /* Match canvas background - no brown visible */
        overflow: hidden;
    }
    
    #game-screen {
        padding: 0;
        height: 100vh;
        height: 100dvh; /* Use dynamic viewport height for mobile browsers */
        overflow: hidden;
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        width: 100dvw; /* Use dynamic viewport width for mobile browsers */
        background: #e8f4f8 !important; /* Match canvas background - fills grey areas */
    }
    
    #game-canvas-container {
        width: 100vw;
        width: 100dvw; /* Use dynamic viewport width */
        height: 100vh;
        height: 100dvh; /* Use dynamic viewport height */
        padding: 0;
        border: none;
        box-shadow: none;
        background: transparent; /* Remove brown background in mobile view */
        position: fixed;
        top: 0;
        left: 0;
        margin: 0;
        overflow: hidden;
        /* Remove flexbox centering - canvas should be positioned absolutely */
    }
    
    #game-canvas-container::before {
        display: none; /* Remove decorative border on mobile */
    }
    
    #game-canvas {
        /* Dimensions set by JavaScript resizeCanvas() - maximally fills viewport */
        display: block;
        margin: 0;
        padding: 0;
        position: absolute;
        top: 0;
        left: 0;
        /* Position at top-left so character (at x=50) is visible */
        /* Canvas height fills viewport, width may exceed (will be cropped on right) */
        /* JavaScript sets explicit width/height via inline styles - no CSS should override */
        max-width: none !important;
        max-height: none !important;
        min-width: 0 !important;
        min-height: 0 !important;
        /* Ensure canvas can extend beyond viewport width */
        box-sizing: content-box;
    }
    
    .game-header {
        position: fixed;
        top: 10px;
        left: 10px;
        right: 10px;
        z-index: 10;
        font-size: 0.75em;
        gap: 6px;
        flex-direction: row !important;
        justify-content: space-between !important;
        flex-wrap: nowrap !important;
        align-items: center;
    }
    
    .score {
        padding: 6px 10px;
        font-size: 0.9em;
        flex-shrink: 0;
        white-space: nowrap;
        display: flex !important;
        flex-direction: row !important;
        align-items: center;
        gap: 6px;
    }
    
    .target {
        padding: 6px 10px;
        font-size: 0.9em;
        flex: 1;
        min-width: 0;
        max-width: none;
        display: flex !important;
        flex-direction: row !important;
        align-items: center;
        gap: 6px;
    }
    
    .target > span:first-child {
        display: none !important; /* "Ziel:" Label ausblenden */
    }
    
    .target > .progress-container {
        display: flex !important;
        flex-direction: row !important;
        align-items: center;
        gap: 6px;
        flex: 1;
        min-width: 0;
    }
    
    .score-icon {
        width: 18px;
        height: 18px;
        font-size: 12px;
        flex-shrink: 0;
    }
    
    .score span {
        white-space: nowrap;
    }
    
    .progress-container {
        gap: 6px;
        min-width: 0;
        display: flex !important;
        flex-direction: row !important;
    }
    
    .progress-bar {
        height: 14px;
        flex: 1;
        min-width: 0;
    }
    
    .progress-text {
        font-size: 0.75em;
        min-width: 35px;
        flex-shrink: 0;
        white-space: nowrap;
    }
    
    .target span:first-child {
        display: none; /* "Ziel:" Label ausblenden auf Mobile */
    }
    
    .game-controls {
        display: none;
    }
    
    .screen {
        width: 100dvw;
        height: 100dvh;
        position: fixed;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        align-items: flex-start;
        padding-top: 2px;
        padding-bottom: 2px;
    }
    
    .intro-content {
        padding: 2vh 15px;
        max-width: 100%;
        width: 100%;
        box-sizing: border-box;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        min-height: 100dvh;
        margin: 0 auto;
        gap: 1vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .intro-content h1 {
        font-size: clamp(0.9em, 4vh, 1.5em); /* Aggressiv klein für Querformat */
        margin-bottom: 1vh;
        line-height: 1.05;
        padding: 0 10px;
        word-wrap: break-word;
    }
    
    .intro-content p {
        font-size: clamp(0.65em, 3vh, 1em);
        margin-bottom: 0.5vh;
        line-height: 1.15;
        padding: 0 10px;
    }
    
    #intro-character {
        width: clamp(30px, 10vh, 60px);
        height: clamp(30px, 10vh, 60px);
        margin: 1vh auto;
        flex-shrink: 0;
    }
    
    #intro-controls {
        font-size: clamp(0.6em, 2.5vh, 0.9em);
        margin: 1vh 0;
        padding: 0 10px;
    }
    
    #intro-controls p {
        margin-bottom: 0.5vh;
        line-height: 1.2;
    }
    
    .start-btn {
        font-size: clamp(0.8em, 3.5vh, 1.1em);
        padding: 1.5vh 20px;
        margin-top: 1vh;
        flex-shrink: 0;
    }
}

@media (max-width: 920px) and (min-width: 769px) {
    #game-screen {
        padding: 0;
        height: 100vh;
        overflow: hidden;
    }
    
    #game-canvas-container {
        width: 100vw;
        height: 100vh;
        padding: 0;
        border: none;
        box-shadow: none;
        position: fixed;
        top: 0;
        left: 0;
        margin: 0;
    }
    
    #game-canvas-container::before {
        display: none;
    }
    
    #game-canvas {
        width: 100vw;
        height: 100vh;
        display: block;
        margin: 0;
        padding: 0;
    }
    
    .intro-content h1 {
        font-size: 2em;
    }
    
    .game-header {
        font-size: 1em;
        top: 10px;
        left: 10px;
        right: 10px;
        flex-direction: row;
        gap: 10px;
        position: fixed;
        z-index: 10;
    }
    
    .target {
        max-width: 100%;
    }
    
    .game-controls {
        bottom: 10px;
        left: 10px;
        right: 10px;
    }
}

/* Orientation Hint */
.orientation-hint {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(139, 111, 71, 0.95); /* Cardboard brown */
    color: white;
    padding: 20px 30px;
    border: 3px dashed #5a4a32;
    border-radius: 8px;
    box-shadow: 6px 6px 0px rgba(0, 0, 0, 0.3);
    z-index: 1000;
    text-align: center;
    font-size: 1.2em;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
    animation: pulse 2s infinite;
    max-width: 90%;
    box-sizing: border-box;
}

.orientation-hint-close {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(90, 74, 50, 0.8);
    color: white;
    border: 2px dashed #5a4a32;
    border-radius: 50%;
    width: 30px;
    height: 30px;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-weight: bold;
    padding: 0;
    margin: 0;
}

.orientation-hint-close:hover {
    background: rgba(90, 74, 50, 1);
    transform: scale(1.1);
}

.orientation-hint-close:active {
    transform: scale(0.95);
}

.orientation-hint p {
    margin: 0;
    padding-right: 25px; /* Platz für Close-Button */
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.8; }
}

@media (min-width: 901px) {
    .orientation-hint {
        display: none !important; /* Nur auf mobilen Geräten */
    }
}
