* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    touch-action: none;
}

body {
    background-color: #080709;
    color: #e0d8cc;
    font-family: 'Cinzel', serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

#game-container {
    position: relative;
    width: 960px;
    height: 540px;
    max-width: 100vw;
    max-height: 100vh;
    aspect-ratio: 16 / 9;
    background: #000;
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.9), 0 0 15px rgba(180, 50, 40, 0.25);
    border: 2px solid #2d2427;
    border-radius: 4px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#gameCanvas {
    width: 100%;
    height: 100%;
    image-rendering: -moz-crisp-edges;
    image-rendering: -webkit-crisp-edges;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    display: block;
    background-color: #0d0b0e;
}

/* CRT Scanline & Vignette Effect */
#crt-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 10;
}

#crt-overlay.crt-active {
    opacity: 1;
    background: linear-gradient(
        rgba(18, 16, 16, 0) 50%, 
        rgba(0, 0, 0, 0.25) 50%
    ), linear-gradient(
        90deg,
        rgba(255, 0, 0, 0.03),
        rgba(0, 255, 0, 0.01),
        rgba(0, 0, 255, 0.03)
    );
    background-size: 100% 3px, 6px 100%;
    box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.85);
}

/* Top Mobile / Utility Bar */
#mobile-top-bar {
    position: absolute;
    top: 8px;
    right: 12px;
    display: flex;
    gap: 6px;
    z-index: 25;
}

.touch-icon-btn {
    background: rgba(20, 15, 18, 0.85);
    border: 1px solid #5a1e24;
    color: #f5dfa2;
    padding: 5px 9px;
    font-family: 'Cinzel', serif;
    font-size: 11px;
    font-weight: bold;
    border-radius: 4px;
    cursor: pointer;
    backdrop-filter: blur(4px);
    transition: all 0.15s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}

.touch-icon-btn:hover, .touch-icon-btn:active {
    background: #5a1e24;
    border-color: #c72e3b;
    color: #ffffff;
    transform: scale(1.05);
}

/* Virtual Touch Controls Overlay */
#touch-controls {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 20;
    transition: opacity 0.3s ease;
}

.touch-controls-hidden {
    display: none !important;
}

/* Left Virtual D-Pad */
#touch-dpad {
    position: absolute;
    bottom: 16px;
    left: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    pointer-events: auto;
}

.dpad-middle-row {
    display: flex;
    align-items: center;
}

.dpad-center {
    width: 48px;
    height: 48px;
    background: rgba(18, 14, 17, 0.85);
    border: 1px solid #38242a;
}

.dpad-btn {
    width: 48px;
    height: 48px;
    background: linear-gradient(180deg, rgba(38, 26, 32, 0.9) 0%, rgba(20, 14, 17, 0.95) 100%);
    border: 1.5px solid #6b262f;
    color: #e6c387;
    font-size: 18px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    border-radius: 6px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.7);
    transition: transform 0.05s ease, background 0.05s ease;
    -webkit-tap-highlight-color: transparent;
}

.dpad-btn:active, .dpad-btn.active {
    background: linear-gradient(180deg, #8a2d36 0%, #4a151b 100%);
    border-color: #ff4a5a;
    color: #ffffff;
    transform: scale(0.92);
    box-shadow: 0 0 12px rgba(255, 74, 90, 0.6);
}

/* Right Virtual Action Buttons */
#touch-actions {
    position: absolute;
    bottom: 16px;
    right: 16px;
    display: flex;
    align-items: flex-end;
    gap: 12px;
    pointer-events: auto;
}

.action-btn {
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.8);
    transition: transform 0.05s ease, background 0.05s ease;
    -webkit-tap-highlight-color: transparent;
}

.action-btn .btn-label {
    font-family: 'Cinzel', serif;
    font-weight: 900;
    line-height: 1;
}

.action-btn .btn-sub {
    font-family: 'MedievalSharp', cursive, sans-serif;
    font-size: 9px;
    opacity: 0.8;
    margin-top: 2px;
}

.action-a {
    width: 64px;
    height: 64px;
    background: linear-gradient(180deg, #5e1c22 0%, #300d11 100%);
    border: 2px solid #a32e39;
    color: #ffedcf;
}

.action-a .btn-label {
    font-size: 18px;
}

.action-a:active, .action-a.active {
    background: linear-gradient(180deg, #a32e39 0%, #5e1c22 100%);
    border-color: #ff5e6c;
    transform: scale(0.92);
    box-shadow: 0 0 16px rgba(255, 94, 108, 0.75);
}

.action-b {
    width: 52px;
    height: 52px;
    background: linear-gradient(180deg, #2e2028 0%, #171014 100%);
    border: 1.5px solid #5a3c48;
    color: #d1c2bc;
    margin-bottom: 8px;
}

.action-b .btn-label {
    font-size: 15px;
}

.action-b:active, .action-b.active {
    background: linear-gradient(180deg, #5a3c48 0%, #2e2028 100%);
    border-color: #b08294;
    transform: scale(0.92);
    box-shadow: 0 0 12px rgba(176, 130, 148, 0.6);
}

.action-bag {
    width: 50px;
    height: 50px;
    background: linear-gradient(180deg, #3d3019 0%, #1c1508 100%);
    border: 1.5px solid #7a612b;
    color: #f5dfa2;
    margin-bottom: 24px;
}

.action-bag .btn-label {
    font-size: 12px;
}

.action-bag:active, .action-bag.active {
    background: linear-gradient(180deg, #7a612b 0%, #3d3019 100%);
    border-color: #ffd76a;
    transform: scale(0.92);
    box-shadow: 0 0 14px rgba(255, 215, 106, 0.7);
}

/* Dynamic Positioning for Combat Mode to Prevent Blocking Text / UI */
#touch-dpad, #touch-actions {
    transition: bottom 0.25s ease, left 0.25s ease, right 0.25s ease, opacity 0.25s ease, transform 0.25s ease;
}

.combat-active #touch-dpad {
    bottom: 96px;
    left: 10px;
    opacity: 0.80;
    transform: scale(0.85);
    transform-origin: bottom left;
}

.combat-active #touch-actions {
    bottom: 96px;
    right: 10px;
    opacity: 0.80;
    transform: scale(0.85);
    transform-origin: bottom right;
}

.combat-active #btn-action-bag {
    display: none;
}

/* Instructions & Help Modal Overlay */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(6, 4, 7, 0.94);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 40;
    backdrop-filter: blur(4px);
    padding: 16px;
    animation: fadeIn 0.15s ease-out;
}

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

.modal-content {
    background: #140f13;
    border: 2px solid #5a1e24;
    box-shadow: 0 0 35px rgba(180, 40, 50, 0.4), 0 0 100px rgba(0, 0, 0, 0.9);
    padding: 22px 28px;
    border-radius: 4px;
    max-width: 540px;
    width: 100%;
    max-height: 92vh;
    overflow-y: auto;
    text-align: center;
}

.help-modal-content h2 {
    color: #c72e3b;
    font-size: 18px;
    letter-spacing: 2px;
    margin-bottom: 16px;
    text-shadow: 0 0 10px rgba(200, 46, 59, 0.6);
}

.help-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    text-align: left;
    margin-bottom: 20px;
}

@media (max-width: 520px) {
    .help-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
}

.help-section {
    background: #100b0e;
    border: 1px solid #332026;
    padding: 12px 14px;
    border-radius: 3px;
}

.help-section h3 {
    color: #e6c387;
    font-size: 12px;
    letter-spacing: 1px;
    margin-bottom: 8px;
    border-bottom: 1px solid #4a2830;
    padding-bottom: 4px;
}

.help-section p {
    color: #b3a599;
    font-family: 'MedievalSharp', cursive, sans-serif;
    font-size: 11px;
    line-height: 1.5;
    margin-bottom: 6px;
}

.help-section p:last-child {
    margin-bottom: 0;
}

.help-section p strong {
    color: #ffffff;
}

.gothic-btn {
    background: linear-gradient(180deg, #4a151b 0%, #20080c 100%);
    border: 1.5px solid #82222b;
    color: #f5dfa2;
    padding: 8px 24px;
    font-family: 'Cinzel', serif;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1px;
    cursor: pointer;
    transition: all 0.15s ease;
    border-radius: 2px;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.6);
}

.gothic-btn:hover, .gothic-btn:active {
    background: linear-gradient(180deg, #6b2028 0%, #3a0d14 100%);
    border-color: #c72e3b;
    color: #ffffff;
    box-shadow: 0 0 12px rgba(200, 46, 59, 0.6);
    transform: scale(1.03);
}

kbd {
    background: #221a1e;
    color: #c9b9a6;
    border: 1px solid #4a383f;
    border-radius: 3px;
    padding: 1px 4px;
    font-family: monospace;
    font-size: 10px;
    box-shadow: 0 1px 0 rgba(0,0,0,0.5);
}

.hidden {
    display: none !important;
}

/* Fullscreen / Mobile Responsive Media Queries */
@media (max-width: 900px), (max-height: 550px) {
    #game-container {
        width: 100vw;
        height: 100vh;
        max-width: 100vw;
        max-height: 100vh;
        border: none;
        border-radius: 0;
    }
}

