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

body {
    font-family: "Cinzel", serif;
    background-color: #03060c;
    background-image:
        linear-gradient(to bottom, rgba(5, 8, 15, 0.1), rgba(2, 4, 10, 0.8)),
        url("img/bg.png");
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

@media (orientation: portrait) {
    body {
        background-image:
            linear-gradient(to bottom, rgba(5, 8, 15, 0.5), rgba(2, 4, 10, 0.8)),
            url("img/bg portrait.png");
    }
}

#app {
    position: relative;
    width: 100%;
    height: 100%;
}

/* Screens */
.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    /* Allows scrolling */
    background: linear-gradient(135deg, rgba(10, 15, 30, 0.4), rgba(3, 6, 12, 0.6));
    backdrop-filter: blur(2px);
    z-index: 10;
    transition: all 0.3s ease;
    opacity: 0;
    visibility: hidden;
}

.screen.active {
    opacity: 1;
    visibility: visible;
    z-index: 20;
}

.screen-content {
    margin: auto;
    /* Centers perfectly but allows top-to-bottom scroll overflow cleanly */
    text-align: center;
    padding: 2rem 1rem;
    max-width: 800px;
    width: 90%;
}

.game-logo {
    max-width: 80%;
    height: auto;
    margin-bottom: 0.5rem;
    filter: drop-shadow(0 0 10px rgba(74, 222, 128, 0.3));
    user-select: none;
    -webkit-user-drag: none;
}

@media (min-width: 768px) {
    .game-logo {
        max-width: 60%;
    }
}

.game-subtitle {
    color: #a3e635;
    font-size: 0.8rem;
    margin-bottom: 2rem;
}

.section-title {
    color: #4ade80;
    font-size: 1.5rem;
    margin-bottom: 1.5rem;
}

.controls-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin: 1.5rem 0;
}

@media (min-width: 768px) {
    .controls-grid {
        grid-template-columns: 1fr 1fr;
    }
}

.control-card {
    background: rgba(30, 41, 59, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 1rem;
    text-align: left;
}

.control-card h3 {
    color: #fbbf24;
    font-size: 0.9rem;
    margin-bottom: 0.8rem;
}

.control-card p {
    color: #cbd5e1;
    font-size: 0.7rem;
    margin: 0.5rem 0;
    line-height: 1.5;
}

.mobile-note {
    color: #94a3b8;
    font-size: 0.6rem;
    margin: 1rem 0;
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 4px;
}

.button-group {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 1.5rem;
}

.instructions-card {
    background: rgba(30, 41, 59, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    text-align: left;
    color: #cbd5e1;
    line-height: 1.6;
}

.instructions-card p {
    font-size: 0.85rem;
}

.instructions-card ul {
    list-style: none;
    padding-left: 0;
}

.instructions-card li::before {
    content: '•';
    color: #4ade80;
    display: inline-block;
    width: 1em;
    margin-left: -1em;
}

.character-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin: 1rem 0;
}

@media (min-width: 768px) {
    .character-grid {
        grid-template-columns: 1fr 1fr;
    }
}

.character-card {
    background: rgba(30, 41, 59, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 1.5rem;
    color: #cbd5e1;
    text-align: left;
}

.character-card h3 {
    color: #facc15;
    margin-bottom: 0.75rem;
}

.character-card p {
    margin-bottom: 1rem;
    font-size: 0.85rem;
    line-height: 1.6;
}

.btn {
    font-family: "Cinzel", serif;
    font-size: 0.8rem;
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: transform 0.1s ease;
    font-weight: bold;
}

.btn:active {
    transform: scale(0.97);
}

.btn-primary {
    background: #166534;
    color: #bbf7d0;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.btn-primary:hover {
    background: #15803d;
}

.btn-secondary {
    background: #1e293b;
    color: #cbd5e1;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-secondary:hover {
    background: #334155;
}

/* Game Layout Override */
#gameScreen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    /* Strict fit for mobile browsers */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: stretch;
    padding: 0;
    margin: 0;
    background: transparent;
    overflow: hidden;
}

/* Base heights for Mobile Portrait Stack */
.game-hud {
    flex: 0 0 12%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 10px;
    z-index: 15;
    pointer-events: auto;
    background: rgba(10, 15, 30, 0.95);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
}

.hud-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.btn-quit {
    font-family: "Cinzel", serif;
    font-size: 0.5rem;
    padding: 4px 8px;
    background: #7f1d1d;
    color: #fecaca;
    border: 2px solid #ef4444;
    border-radius: 4px;
    cursor: pointer;
}

.btn-quit:hover {
    background: #991b1b;
}

.health-bar-container {
    flex: 1;
    max-width: 35%;
    background: rgba(0, 0, 0, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 4px 8px;
}

.health-label {
    color: white;
    font-size: 0.6rem;
    margin-bottom: 5px;
    text-align: center;
}

.health-bar {
    background: #450a0a;
    height: 15px;
    border-radius: 4px;
    overflow: hidden;
}

.health-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #22c55e, #4ade80);
    transition: width 0.1s ease;
}

.timer {
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(4px);
    border-radius: 8px;
    padding: 5px 10px;
    color: #fef08a;
    font-size: 1.2rem;
    font-weight: bold;
    margin: 0;
    min-width: 60px;
    text-align: center;
    font-family: "Cinzel", serif;
}

/* Canvas Section */
.canvas-wrapper {
    flex: 1 1 63%;
    /* Expands gracefully */
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0;
    background: transparent;
    overflow: hidden;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: contain;
    /* PERFECT SCALING without distortion */
    image-rendering: crisp-edges;
    image-rendering: pixelated;
    border: none;
    box-shadow: none;
}

/* Mobile Controls Section */
.mobile-controls {
    flex: 0 0 25%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 15px;
    background: transparent;
    border-top: none;
    z-index: 15;
    width: 100%;
    box-sizing: border-box;
}

.controls-left,
.controls-right {
    display: flex;
    gap: 8px;
    /* Reduced gap */
    align-items: center;
    justify-content: center;
}

.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.75);
    z-index: 50;
    padding: 1rem;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: rgba(15, 23, 42, 0.98);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 2rem;
    max-width: 400px;
    width: 100%;
    text-align: center;
}

.modal-content h2 {
    color: #fbbf24;
    margin-bottom: 1rem;
}

.modal-content p {
    color: #cbd5e1;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
    line-height: 1.6;
}

@media (min-width: 768px) {

    /* Stop forcing column stack on large screens, make an expanded layout */
    .mobile-controls {
        display: none !important;
    }

    .game-hud {
        flex: 0 0 10%;
        padding: 0 40px;
    }

    .canvas-wrapper {
        flex: 1 1 90%;
        padding: 20px;
    }
}

.ctrl-img-btn {
    width: clamp(85px, 24vw, 120px);
    height: clamp(85px, 24vw, 120px);
    object-fit: contain;
    cursor: pointer;
    transition: all 0.1s ease;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: auto;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.6));
    opacity: 0.85;
}

.ctrl-img-btn:active {
    transform: scale(0.9) translateY(4px);
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.8));
    opacity: 1;
}

.winner-title {
    font-size: 2rem;
    color: #fbbf24;
    margin-bottom: 1.5rem;
    animation: pulse 0.5s ease-out;
}

@keyframes pulse {
    0% {
        transform: scale(0.8);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Hit Flash Effect */
.hit-flash {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    background: rgba(255, 80, 40, 0.3);
    animation: flash 0.1s ease-out;
    z-index: 100;
}

@keyframes flash {
    0% {
        opacity: 0;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0;
    }
}