/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body, html {
    width: 100%;
    height: 100%;
    background-color: #111;
    overflow: hidden; /* Prevent scrolling on mobile */
    font-family: 'Press Start 2P', cursive;
    touch-action: none; /* Prevent default touch actions like pinch-zoom */
}

/* Game container - optimized for portrait */
#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    max-width: 600px; /* Optional: limit width on desktop to keep portrait feel */
    margin: 0 auto;
    background-color: #64b5f6; /* Sky blue background */
    overflow: hidden;
}

/* Canvas covers the whole container */
#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated; /* Retro aesthetic */
}

/* UI Overlay Layer */
#ui-layer {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 80px;
    background-color: #ffeb3b;
    color: #b71c1c;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 15px;
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 10;
    border-top: 6px solid #b71c1c;
}

#score-display {
    font-size: 14px;
    font-weight: bold;
    color: #b71c1c;
}

#ammo-display {
    display: flex;
    gap: 5px;
}

.bullet {
    width: 15px;
    height: 25px;
    background-color: #b71c1c;
    border: 2px solid #000;
    border-radius: 5px 5px 0 0;
}

#lives-display {
    display: flex;
    gap: 5px;
}

.heart {
    width: 20px;
    height: 20px;
    background-color: #b71c1c;
    border: 2px solid #000;
    transform: rotate(-45deg);
    margin: 5px;
}
.heart::before, .heart::after {
    content: '';
    width: 20px;
    height: 20px;
    background-color: #b71c1c;
    border: 2px solid #000;
    border-bottom: 0;
    position: absolute;
}
.heart::before { top: -11px; left: -2px; border-radius: 50% 50% 0 0; border-right: 0; }
.heart::after { top: -2px; left: 9px; border-radius: 0 50% 50% 0; border-top: 0; }

@keyframes pulseHeart {
    0% { transform: rotate(-45deg) scale(0.9); }
    100% { transform: rotate(-45deg) scale(1.1); }
}

.heart.pulse {
    animation: pulseHeart 0.5s infinite alternate ease-in-out;
}

#round-display {
    font-size: 14px;
    font-weight: bold;
    color: #b71c1c;
}

/* Start Screen Overlay */
#start-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

#intro-canvas {
    width: 250px;
    height: 200px;
    image-rendering: pixelated;
    margin-bottom: 15px;
    z-index: 105;
}

.game-title {
    font-size: 64px;
    color: #ffeb3b;
    text-shadow: 6px 6px 0 #b71c1c;
    margin-bottom: 5px;
    text-align: center;
    letter-spacing: -4px;
}

.game-subtitle {
    font-size: 8px;
    color: #fff;
    margin-bottom: 40px;
    text-transform: uppercase;
    text-align: center;
}

.btn {
    font-family: inherit;
    font-size: 10px;
    font-weight: normal;
    color: #b71c1c;
    background-color: #ffeb3b;
    border: 4px solid #b71c1c;
    padding: 12px 20px;
    cursor: pointer;
    box-shadow: 6px 6px 0 #000;
    text-transform: uppercase;
    line-height: 1.5;
    transition: all 0.1s;
}

.btn:hover {
    background-color: #b71c1c;
    color: #ffeb3b;
    border-color: #ffeb3b;
}

.btn:active {
    transform: translate(6px, 6px);
    box-shadow: 0 0 0 #000;
}

#toggle-fs {
    position: absolute;
    top: 15px;
    top: calc(15px + env(safe-area-inset-top));
    right: 15px;
    right: calc(15px + env(safe-area-inset-right));
    z-index: 50;
    opacity: 0.5;
    font-family: inherit;
    font-size: 20px;
    font-weight: bold;
    color: white;
    background-color: #4caf50;
    border: 2px solid #fff;
    width: 40px;
    height: 40px;
    cursor: pointer;
    box-shadow: 2px 2px 0 #000;
    line-height: 1;
}

#toggle-fs:active {
    transform: translate(2px, 2px);
    box-shadow: 0 0 0 #000;
    opacity: 0.8;
}

/* Character Selection Screen */
#char-selection {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #5d4037; /* Brown base */
    /* Wooden plank pattern using linear gradients */
    background-image: 
        linear-gradient(90deg, transparent 95%, rgba(0,0,0,0.3) 100%),
        linear-gradient(rgba(255,255,255,0.05) 50%, transparent 50%);
    background-size: 80px 100%, 100% 40px;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 101;
    border: 10px solid #3e2723;
}

.char-title {
    font-size: 16px;
    color: #ffeb3b;
    text-shadow: 2px 2px 0 #000;
    margin-bottom: 30px;
    text-align: center;
}

.char-container {
    display: flex;
    flex-direction: column;
    gap: 10px; /* Reduced gap for mobile */
    width: 90%;
}

.char-card {
    background: rgba(0,0,0,0.4);
    border: 4px solid #fff;
    padding: 10px;
    display: flex;
    flex-direction: column; /* Stack vertically for mobile */
    align-items: center;
    gap: 8px;
    cursor: pointer;
    box-shadow: 4px 4px 0 #000;
    transition: transform 0.1s;
    text-align: center;
}

.char-card:hover {
    background: rgba(255,255,255,0.1);
    transform: scale(1.02);
}

.char-card:active {
    transform: scale(0.98);
}

.char-p-box {
    width: 64px;
    height: 60px;
    background: #424242;
    border: 2px solid #8bc34a;
    flex-shrink: 0;
}

.char-desc {
    font-size: 8px;
    color: white;
    line-height: 1.4;
}

/* Larger screens can keep the horizontal feel */
@media (min-width: 600px) {
    .char-card {
        flex-direction: row;
        text-align: left;
    }
}

/* Shadowy Figure Screen */
#shadowy-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #0c0c0c; /* Near black dark gray */
    z-index: 200;
    display: none; /* Changed from flex to none by default */
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 30px;
}

#shadowy-content {
    display: flex;
    flex-direction: column;
    width: 100%;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

#shadowy-portrait-container {
    width: 120px;
    height: 120px;
    background: #111;
    border: 4px solid #333;
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
}

#shadowy-char-canvas {
    image-rendering: pixelated;
}

#shadowy-main {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 25px;
    width: 100%;
}

#shadowy-monk-canvas {
    image-rendering: pixelated;
    height: 400px; /* 2x larger roughly */
    width: auto;
}

#shadowy-bubble {
    background: #fff;
    border: 4px solid #000;
    padding: 15px;
    position: relative;
    max-width: 350px;
    min-height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 6px 6px 0 rgba(0,0,0,0.5);
}

#shadowy-bubble::after {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    margin-left: -10px;
    border-width: 12px;
    border-style: solid;
    border-color: transparent transparent #000 transparent;
}

#shadowy-text {
    color: #000;
    font-size: 10px;
    font-weight: bold;
    text-align: center;
    line-height: 1.8;
}

#shadowy-companion {
    position: absolute;
    top: 150px;
    right: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    z-index: 5;
}

#shadowy-companion-canvas {
    image-rendering: pixelated;
    width: 96px; /* 1.5x scale */
    height: 96px;
    background: rgba(0,0,0,0.5);
    border: 2px solid #555;
}

#companion-bubble {
    background: #fff;
    border: 2px solid #000;
    padding: 8px;
    position: relative;
    max-width: 140px;
    margin-top: 10px;
    box-shadow: 4px 4px 0 rgba(0,0,0,0.5);
}

#companion-bubble::after {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 8px;
    border-style: solid;
    border-color: transparent transparent #000 transparent;
}

#companion-text {
    color: #000;
    font-size: 10px;
    font-weight: bold;
    text-align: center;
    line-height: 1.2;
}

#shadowy-continue {
    /* Reusing .btn styles via manual copy for simplicity if class not applied */
    font-family: inherit;
    font-size: 20px;
    font-weight: bold;
    color: white;
    background-color: #4caf50;
    border: 4px solid #fff;
    padding: 15px 30px;
    cursor: pointer;
    box-shadow: 4px 4px 0 #000;
    text-transform: uppercase;
    margin-top: 20px;
}

#shadowy-continue:active {
    transform: translate(4px, 4px);
    box-shadow: 0 0 0 #000;
}

/* Vending Machine Screen */
#vending-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 210;
    display: none;
    justify-content: center;
    align-items: center;
}

#vending-machine {
    background: #ffeb3b;
    border: 6px solid #b71c1c;
    padding: 30px;
    box-shadow: 10px 10px 0 #000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 25px;
    max-width: 90%;
    border-radius: 0;
}

#vending-machine h2 {
    font-size: 14px;
    color: #b71c1c;
    margin-bottom: 5px;
    text-transform: uppercase;
}

#vending-title {
    color: #b71c1c;
    font-size: 10px;
    margin-bottom: 20px;
}

#vending-options {
    display: flex;
    flex-direction: column;
    gap: 15px;
    width: 100%;
}

.vending-btn {
    background: #b71c1c;
    border: 4px solid #000;
    color: #ffeb3b;
    padding: 15px;
    display: flex;
    align-items: center;
    gap: 20px;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
    font-family: inherit;
}

.vending-btn:hover:not(:disabled) {
    background: #d32f2f;
    transform: scale(1.03);
}

.vending-btn:active:not(:disabled) {
    transform: scale(0.98);
}

.vending-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    border-color: #546e7a;
}

.vending-icon {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    position: relative;
}

.heart-icon {
    background: #f44336;
    clip-path: polygon(50% 15%, 75% 0%, 100% 25%, 50% 100%, 0% 25%, 25% 0%);
}

.star-icon {
    background: #ffeb3b;
    clip-path: polygon(50% 0%, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%);
}

.wings-icon {
    background: #90caf9;
    clip-path: polygon(0% 50%, 40% 20%, 60% 20%, 100% 50%, 60% 80%, 40% 80%);
}

.vending-text {
    font-size: 10px;
    font-weight: normal;
}

.vending-text small {
    color: #ffeb3b;
    font-size: 8px;
    opacity: 0.9;
}

/* Almanach Screen */
#almanach-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(18, 18, 18, 0.98);
    background-image: radial-gradient(circle, rgba(255,255,255,0.05) 1px, transparent 1px);
    background-size: 20px 20px;
    z-index: 500;
    display: none;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    overflow-y: auto;
}

.almanach-title {
    font-size: 16px;
    color: #ffeb3b;
    text-shadow: 2px 2px 0 #000;
    margin-bottom: 5px;
    text-align: center;
}

.almanach-subtitle {
    font-size: 10px;
    color: #eee;
    margin-bottom: 25px;
    text-align: center;
    font-style: italic;
}

.almanach-sections {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    max-width: 500px;
    margin-bottom: 30px;
}

.almanach-section h3 {
    color: #90caf9;
    font-size: 8px;
    border-bottom: 2px solid #555;
    padding-bottom: 5px;
    margin-bottom: 10px;
    text-transform: uppercase;
}

.almanach-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 12px;
}

.almanach-tile {
    background: #263238;
    border: 2px solid #fff;
    padding: 8px;
    text-align: center;
    cursor: pointer;
    box-shadow: 3px 3px 0 #000;
    transition: all 0.1s;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.almanach-tile:hover:not(.locked) {
    background: #37474f;
    transform: translateY(-2px);
    box-shadow: 5px 5px 0 #000;
}

.almanach-tile.locked {
    opacity: 0.4;
    cursor: not-allowed;
    filter: grayscale(100%);
}

.almanach-tile-icon {
    width: 48px;
    height: 48px;
    margin: 0 auto 5px;
    background: #111;
    image-rendering: pixelated;
    display: flex;
    justify-content: center;
    align-items: center;
}

.almanach-tile-icon canvas {
    width: 100%;
    height: 100%;
}

.almanach-tile span {
    color: #fff;
    font-size: 9px;
    font-weight: bold;
    line-height: 1.2;
}

#almanach-detail {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
    max-width: 500px;
}

#almanach-scene-container {
    width: 100%;
    aspect-ratio: 4 / 3;
    background: #000;
    border: 6px solid #b0bec5;
    box-shadow: 0 0 30px rgba(0,0,0,0.8);
    overflow: hidden;
}

#almanach-scene-canvas {
    width: 100%;
    height: 100%;
}

#almanach-article {
    background: #fff;
    border: 4px solid #000;
    padding: 20px;
    color: #000;
    position: relative;
    box-shadow: 8px 8px 0 rgba(0,0,0,0.5);
    width: 100%;
}

#article-title {
    font-size: 14px;
    margin-bottom: 10px;
    color: #e64a19;
    border-bottom: 2px solid #ddd;
}

#article-content {
    font-size: 9px;
    line-height: 1.8;
}

/* Scrollbar for index */
#almanach-screen::-webkit-scrollbar {
    width: 8px;
}
#almanach-screen::-webkit-scrollbar-track {
    background: #111;
}
#almanach-screen::-webkit-scrollbar-thumb {
    background: #444;
}
#almanach-screen::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* Settings Screen */
#settings-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(18, 18, 18, 0.98);
    background-image: radial-gradient(circle, rgba(255,255,255,0.05) 1px, transparent 1px);
    background-size: 20px 20px;
    z-index: 500;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.settings-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 400px;
    background: rgba(0,0,0,0.4);
    border: 4px solid #fff;
    padding: 30px;
    box-shadow: 6px 6px 0 #000;
}

.settings-title {
    font-size: 16px;
    color: #ffeb3b;
    text-shadow: 2px 2px 0 #000;
    margin-bottom: 30px;
}

.settings-options {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    font-size: 10px;
}

.toggle-btn {
    min-width: 80px;
    padding: 8px 12px;
}

/* Night Mode Overlay applied to the container */
#game-container.night-mode {
    filter: brightness(0.7);
}

/* Radio Sub-menu Styles */
#radio-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(18, 18, 18, 0.98);
    background-image: radial-gradient(circle, rgba(255,255,255,0.05) 1px, transparent 1px);
    background-size: 20px 20px;
    z-index: 500;
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.radio-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #fff;
    font-size: 8px;
    padding: 10px;
    border: 2px solid #555;
    background: rgba(255, 255, 255, 0.05);
    width: 100%;
    margin-bottom: 5px;
}

.radio-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex: 1;
}

.radio-name {
    font-weight: bold;
    color: #ffeb3b;
}

.radio-genre {
    color: #aaa;
    font-size: 7px;
}

.radio-select-btn {
    min-width: 60px;
    padding: 5px 8px;
    font-size: 8px;
}

/* Scrollbar for radio list */
#radio-list::-webkit-scrollbar {
    width: 8px;
}
#radio-list::-webkit-scrollbar-track {
    background: #111;
}
#radio-list::-webkit-scrollbar-thumb {
    background: #444;
}
#radio-list::-webkit-scrollbar-thumb:hover {
    background: #555;
}

#radio-notification {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: #fff;
    padding: 10px 20px;
    border: 4px solid #fff;
    font-size: 12px;
    z-index: 1000;
    white-space: nowrap;
    pointer-events: none;
    text-align: center;
    image-rendering: pixelated;
    box-shadow: 4px 4px 0 rgba(0,0,0,0.5);
}

.fade-in {
    animation: fadeIn 0.5s forwards;
}

.fade-out {
    animation: fadeOut 0.5s forwards;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translate(-50%, -10px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

@keyframes fadeOut {
    from { opacity: 1; transform: translate(-50%, 0); }
    to { opacity: 0; transform: translate(-50%, -10px); }
}
