@font-face {
    font-family: 'GameFont';
    src: url('../assets/fonts/FZG_CN.ttf') format('truetype');
}

:root {
    --bg-color: #121212;
    --text-color: #f0f0f0;
    --human-accent: #a8a8a8;
    --heaven-accent: #81d4fa;
    --hell-accent: #ff6f00;

    /* Default Font Sizes (Chinese) */
    --fs-h1: 32px;
    --fs-p: 14px;
    --fs-hud: 18px;
    --fs-btn: 20px;
    --fs-mask: 24px;
    --fs-dialog: 18px;
    --fs-hint: 20px;
}

/* Language Specific Overrides */
body.lang-en {
    --fs-h1: 32px;
    --fs-p: 14px;
    --fs-hud: 18px;
    --fs-btn: 20px;
    --fs-mask: 24px;
    --fs-dialog: 18px;
    --fs-hint: 20px;
}

body {
    background-color: var(--bg-color);
    background-image: url('../assets/ui/game_bg.png');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    color: var(--text-color);
    font-family: 'GameFont', monospace;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    margin: 0;
    overflow: hidden;
    user-select: none;
}

/* Landscape Container */
#game-container {
    position: relative;
    width: 800px;
    height: 600px;
    box-shadow: 0 0 30px rgba(0,0,0,0.8);
    border: 4px solid #333;
}

canvas {
    display: block;
    image-rendering: pixelated;
}

/* UI Layer - Adjusted for Landscape */
#ui-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* Top HUD */
.hud {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    width: 480px; /* Match grid width roughly */
    display: flex;
    justify-content: space-between;
    font-size: var(--fs-hud);
    text-shadow: 2px 2px 0 #000;
    z-index: 2;
    align-items: center;
}

/* Bottom Controls */
.mask-controls {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 20px;
    pointer-events: auto;
    z-index: 2;
}

.mask-btn {
    width: 80px;
    height: 80px;
    border: none;
    background-color: transparent;
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    /* color: transparent; Hide any text if present */
    font-family: inherit;
    font-size: var(--fs-mask);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    position: relative;
    border-radius: 0;
    filter: grayscale(20%);
    opacity: 0.7;
}

.mask-btn:hover { transform: translateY(-2px); filter: brightness(1.2) grayscale(0%); opacity: 1; }
.mask-btn.active {
    transform: translateY(-8px);
    filter: drop-shadow(0 0 5px rgba(255, 255, 255, 0.8)) grayscale(0%);
    z-index: 10;
    opacity: 0.9;
}

/* Dimension Specific Styles with Images */
.mask-btn[data-type="human"] {
    background-image: url('../assets/level/masks/1.png');
}
.mask-btn[data-type="heaven"] {
    background-image: url('../assets/level/masks/2.png');
}
.mask-btn[data-type="hell"] {
    background-image: url('../assets/level/masks/3.png');
}

.mask-btn[data-type="human"].active { }
.mask-btn[data-type="heaven"].active { }
.mask-btn[data-type="hell"].active { }

.mask-btn.locked {
    opacity: 0.3;
    cursor: not-allowed;
    filter: grayscale(20%);
}
.mask-btn.locked::after {
    content: "X";
    position: absolute;
    color: red;
    font-size: 40px;
}

/* Dialog Box - Centered over grid */
#dialog-box {
    position: absolute;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    width: 460px;
    background: rgba(0, 0, 0, 0.95);
    border: 2px solid white;
    padding: 20px;
    display: none;
    pointer-events: auto;
    text-align: left;
    z-index: 20;
    box-shadow: 0 10px 20px rgba(0,0,0,0.5);
}

#dialog-text {
    font-size: var(--fs-dialog);
    line-height: 1.6;
    margin-bottom: 15px;
    color: #fff;
    min-height: 48px; /* Fixed height to prevent jumpiness */
    white-space: pre-wrap; /* Preserve whitespace and wrap text */
    word-wrap: break-word; /* Ensure long words break */
}

#dialog-avatar {
    position: absolute;
    top: -150px;
    left: -230px;
    width: 370px;
    height: 370px;
    border: none;
    background: transparent;
    image-rendering: pixelated;
    box-shadow: none;
    z-index: 25;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5));
}

#dialog-item-img {
    position: absolute;
    top: -50px;
    right: 20px;
    width: 60px;
    height: 60px;
    border: 3px solid #fff;
    background: #7f7f7f;
    image-rendering: pixelated;
    z-index: 100;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
}

#dialog-next {
    float: right;
    font-size: calc(var(--fs-dialog) - 2px);
    color: #ffff00;
    cursor: pointer;
    animation: blink 1s infinite;
}

/* Overlay Screens */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    pointer-events: auto;
    z-index: 30;
}

#title-avatar {
    position: absolute;
    right: 220px;
    bottom: -50px;
    height: 100%;
    pointer-events: none;
    z-index: -1; /* Place behind buttons but above background */
    image-rendering: pixelated;
    animation: avatar-glow 4s infinite alternate ease-in-out;
}

@keyframes avatar-glow {
    0% {
        filter: brightness(0.9) contrast(1);
    }
    50% {
        filter: brightness(1.1) contrast(1.05) drop-shadow(0 0 10px rgba(255, 255, 255, 0.2));
    }
    100% {
        filter: brightness(1) contrast(1);
    }
}

#start-screen {
    /* Background image is set via body class below */
    background-size: contain; /* Ensure the whole image is visible */
    background-repeat: no-repeat;
    background-position: center;
    background-color: transparent; 
    justify-content: flex-start; /* Align to top */
    align-items: flex-end; /* Align to right */

    .lang-select {
        padding-top: 180px; 
        padding-right: 40px;
    }
    .start-btn {
        margin-right: 40px; 

    }
}

/* Language Specific Backgrounds */
body.lang-zh #start-screen {
    background-image: url('../assets/ui/title_cn.png');
}

body.lang-en #start-screen {
    background-image: url('../assets/ui/title_eng.png');
}

#start-screen.overlay {
    background-color: transparent; /* Only override color, not the image */
    box-shadow: none; /* Remove any default shadows if present */
}

/* Hide overlapping elements during start state */
body.state-start .hud,
body.state-start .controls-hint,
body.state-start .scanlines,
body.state-start .mask-controls {
    display: none !important;
}

/* Ensure other overlays keep the dark background */
#game-over-screen, #victory-screen {
    background: rgba(0,0,0,0.95);
}

.hidden { display: none !important; }

h1 { font-size: var(--fs-h1); color: #fff; margin-bottom: 30px; line-height: 1.4; text-transform: uppercase; letter-spacing: 2px; }
p { font-size: var(--fs-p); color: #ccc; margin-bottom: 40px; max-width: 600px; line-height: 1.8; }

button.start-btn {
    padding: 20px 40px;
    font-family: inherit;
    font-size: var(--fs-btn);
    background: #fff;
    border: 4px solid #888;
    cursor: pointer;
    text-transform: uppercase;
    font-weight: bold;
}
button.start-btn:hover { background: #ddd; transform: scale(1.05); }

.scanlines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(to bottom, rgba(255,255,255,0), rgba(255,255,255,0) 50%, rgba(0,0,0,0.1) 50%, rgba(0,0,0,0.1));
    background-size: 100% 4px;
    pointer-events: none;
    z-index: 10;
    opacity: 0.6;
}

.shake {
    animation: shake 0.5s cubic-bezier(.36,.07,.19,.97) both;
}

@keyframes shake {
  10%, 90% { transform: translate3d(-4px, 0, 0); }
  20%, 80% { transform: translate3d(6px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-8px, 0, 0); }
  40%, 60% { transform: translate3d(8px, 0, 0); }
}

@keyframes blink { 50% { opacity: 0; } }

.controls-hint {
    position: absolute;
    bottom: 20px;
    width: 100%;
    color: #fff;
    padding: 15px 0;
    font-size: var(--fs-hint);
    text-align: center;
    background: rgba(0, 0, 0, 0.6);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 5;
    letter-spacing: 1px;
}

.lang-btn {
    background: transparent;
    border: 2px solid #555;
    color: #888;
    padding: 5px 15px;
    margin: 0 5px;
    cursor: pointer;
    font-family: inherit;
    font-weight: bold;
    font-size: 12px;
}
.lang-btn.active {
    border-color: #fff;
    color: #fff;
    box-shadow: 0 0 10px rgba(255,255,255,0.5);
}
.lang-btn:hover {
    border-color: #aaa;
    color: #aaa;
}