/* ===== BASE ===== */
* { -webkit-tap-highlight-color: transparent; box-sizing: border-box; }
body { margin: 0; background: #000; color: white; overflow: hidden; font-family: 'Courier New', Courier, monospace; touch-action: none; }
canvas { display: block; margin: 0 auto; background: #000; }

/* ===== UI BAR ===== */
#ui { 
    position: fixed; top: 10px; left: 20px; z-index: 50; 
    font-size: 1rem; font-weight: bold; text-shadow: 2px 2px 4px #000; 
    background: rgba(0,0,0,0.5); padding: 4px 10px; border-radius: 4px;
}

/* ===== OVERLAYS ===== */
.full-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: black; z-index: 200; flex-direction: column; 
    justify-content: center; align-items: center; text-align: center;
    padding: 20px; box-sizing: border-box;
}
.full-overlay img { max-width: 90%; max-height: 45vh; border: 2px solid #333; object-fit: contain; }
.full-overlay .text-content { font-size: 1.3rem; margin: 20px 0; color: #fff; max-width: 90%; line-height: 1.6; }
.hint { color: #666; font-size: 1rem; margin-top: 10px; }

/* ===== START SCREEN ===== */
#start-screen { display: flex; z-index: 300; background: rgba(0,0,0,0.95); }
#start-screen h1 { font-size: clamp(2rem, 8vw, 4rem); }
#start-btn, .retry-btn { 
    padding: 18px 36px; font-size: 1.4rem; 
    background: #440000; color: white; border: 2px solid red; cursor: pointer;
    border-radius: 4px; font-family: 'Courier New', Courier, monospace;
    min-width: 200px; margin-top: 10px;
    -webkit-tap-highlight-color: transparent;
}
#start-btn:hover, .retry-btn:hover, #start-btn:active, .retry-btn:active { background: #ff0000; }

/* ===== STORY SCREEN ===== */
#story-screen { cursor: pointer; }
#story-screen .hint { font-size: 1rem; padding: 10px 20px; background: rgba(255,255,255,0.1); border-radius: 20px; }

/* ===== JUMPSCARE ===== */
#jumpscare-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: black;
    z-index: 500;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}
#jumpscare-img {
    /* Fill entire screen while preserving aspect — use 100vmax to always cover */
    min-width: 100%;
    min-height: 100%;
    width: 100vw;
    height: 100vh;
    object-fit: cover;
    object-position: center;
}

/* ===== JOYSTICK (di chuyển) ===== */
#joystick-container {
    position: fixed;
    bottom: 30px;
    left: 30px;
    width: 130px;
    height: 130px;
    z-index: 100;
    display: none;
    touch-action: none;
    user-select: none;
}
#joystick-base {
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.08);
    border: 2px solid rgba(255, 255, 255, 0.25);
    border-radius: 50%;
}
#joystick-stick {
    position: absolute;
    width: 54px;
    height: 54px;
    background: rgba(255, 60, 60, 0.6);
    border: 2px solid rgba(255,100,100,0.8);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: none;
    pointer-events: none;
}

/* ===== DODGE JOYSTICK ===== */
#dodge-joystick-container {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 120px;
    height: 120px;
    z-index: 200;
    touch-action: none;
    user-select: none;
}
#dodge-joystick-base {
    width: 100%;
    height: 100%;
    background: rgba(0, 120, 255, 0.12);
    border: 2px solid rgba(0, 120, 255, 0.4);
    border-radius: 50%;
}
#dodge-joystick-stick {
    position: absolute;
    width: 48px;
    height: 48px;
    background: rgba(0, 120, 255, 0.55);
    border: 2px solid rgba(100, 180, 255, 0.9);
    border-radius: 50%;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}
#dodge-label {
    position: absolute;
    top: -24px;
    left: 50%;
    transform: translateX(-50%);
    color: #aaa;
    font-size: 11px;
    font-family: 'Courier New', Courier, monospace;
    white-space: nowrap;
}

/* ===== PAUSE BUTTON ===== */
#pause-btn {
    position: fixed;
    top: 10px;
    right: 65px;
    z-index: 400;
    width: 42px;
    height: 42px;
    background: #1a1a1a;
    color: #fff;
    border: 2px solid #555;
    border-radius: 6px;
    font-size: 1rem;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
    line-height: 1;
    -webkit-tap-highlight-color: transparent;
}

/* ===== ACTION BUTTON (tiếp tục / J trên mobile) ===== */
#action-btn {
   
}
#action-btn:active { background: rgba(120,120,120,0.9); }

/* ===== BATTLE SCREEN ===== */
#battle-screen {
    background: black;
    display: none;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    padding: 8px 8px 12px;
    box-sizing: border-box;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 100;
    overflow: hidden;
}

.battle-scene {
    flex: 1 1 auto;
    display: flex;
    justify-content: center;
    align-items: center;
    animation: float 3s ease-in-out infinite;
    position: relative;
    z-index: 5;
    width: 100%;
    min-height: 0;
    max-height: 38vh;
    overflow: hidden;
}
/* Boss image scales with viewport height */
.battle-scene img {
    height: clamp(90px, 28vh, 220px);
    width: auto;
    object-fit: contain;
}

@keyframes float {
    0% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
    100% { transform: translateY(0px); }
}

.battle-ui-container {
    width: 100%;
    max-width: 800px;
    flex-shrink: 0;
    border: 3px solid white;
    background: #000;
    padding: 8px 10px 10px;
    box-sizing: border-box;
    position: relative;
    z-index: 5;
}

.battle-dialog { font-size: 1rem; color: white; margin-bottom: 8px; position: relative; }

.battle-stats {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    font-weight: bold;
    margin-bottom: 8px;
    border-bottom: 2px solid white;
    padding-bottom: 6px;
    flex-wrap: wrap;
    gap: 4px;
}

.battle-menu {
    display: flex;
    justify-content: space-between;
    position: relative;
    z-index: 5;
    gap: 4px;
}
.battle-menu button {
    background: black;
    color: white;
    border: 2px solid white;
    padding: 10px 2px;
    font-size: clamp(0.7rem, 2.8vw, 1rem);
    font-family: 'Courier New', Courier, monospace;
    font-weight: bold;
    cursor: pointer;
    flex: 1;
    margin: 0 2px;
    transition: 0.15s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    min-height: 52px;
}
.battle-menu button:hover, .battle-menu button:active { background: white; color: black; }

/* ===== DIALOGUE BOX ===== */
#dialogue-box {
    position: relative;
    width: 100%;
    min-height: 55px;
    background: black;
    border: 3px solid white;
    color: white;
    font-family: Courier New;
    font-size: clamp(13px, 3.2vw, 18px);
    padding: 10px 12px;
    box-sizing: border-box;
    z-index: 15;
    display: none;
}
#dialog-text { white-space: pre-wrap; }

#skip-dialog-btn {
    display: block;
    width: 100%;
    margin-top: 8px;
    padding: 8px;
    background: rgba(80,80,80,0.8);
    color: #ccc;
    border: 1px solid #555;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.85rem;
    cursor: pointer;
    border-radius: 4px;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
#skip-dialog-btn:active { background: rgba(140,140,140,0.8); }

/* ===== HELP BUTTON & OVERLAY ===== */
#help-btn {
    position: fixed;
    top: 10px;
    right: 20px;
    z-index: 400;
    width: 42px;
    height: 42px;
    background: #1a1a1a;
    color: #fff;
    border: 2px solid #ff4444;
    border-radius: 50%;
    font-size: 1.4rem;
    font-family: 'Courier New', Courier, monospace;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s, box-shadow 0.2s;
    box-shadow: 0 0 8px rgba(255,68,68,0.4);
    line-height: 1;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}
#help-btn:hover, #help-btn:active { background: #ff4444; color: #fff; box-shadow: 0 0 16px rgba(255,68,68,0.8); }

#help-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,0,0,0.92);
    z-index: 500;
    justify-content: center;
    align-items: center;
    overflow-y: auto;
}
#help-overlay.active { display: flex; }
#help-overlay img {
    max-width: 92%;
    max-height: 85vh;
    border: 2px solid #ff4444;
    box-shadow: 0 0 30px rgba(255,68,68,0.5);
    object-fit: contain;
}
#help-close-btn {
    position: fixed;
    top: 20px; right: 25px;
    background: #1a1a1a;
    color: #fff;
    border: 2px solid #ff4444;
    border-radius: 50%;
    width: 48px; height: 48px;
    font-size: 1.4rem;
    font-family: 'Courier New', Courier, monospace;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 501;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}
#help-close-btn:hover, #help-close-btn:active { background: #ff4444; }

/* ===== RESPAWN ===== */
#respawn-container { z-index: 300; }
#respawn-btn {
    padding: 20px 50px;
    font-size: 1.5rem;
    background: #002200;
    color: white;
    border: 2px solid lime;
    cursor: pointer;
    font-family: 'Courier New', Courier, monospace;
    border-radius: 4px;
    min-width: 200px;
    -webkit-tap-highlight-color: transparent;
}
#respawn-btn:active { background: #004400; }

/* ===== MEMORY BOOK ===== */
#memory-book-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.93);
    z-index: 600;
    justify-content: center;
    align-items: flex-start;
    padding: 60px 16px 20px;
    box-sizing: border-box;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
#memory-book-overlay.active { display: flex; }
#memory-book-content {
    width: 100%;
    max-width: 720px;
    background: #0a0a1a;
    border: 2px solid #0055cc;
    box-shadow: 0 0 40px rgba(0, 85, 204, 0.4);
    padding: 24px 16px;
    box-sizing: border-box;
    border-radius: 4px;
}
#memory-book-title {
    color: #4da6ff;
    font-size: 1.5rem;
    text-align: center;
    margin: 0 0 20px 0;
    border-bottom: 2px solid #003380;
    padding-bottom: 12px;
    font-family: 'Courier New', Courier, monospace;
    letter-spacing: 2px;
}
.memory-entry {
    border-left: 3px solid #0055cc;
    padding: 10px 14px;
    margin-bottom: 16px;
    background: rgba(0, 85, 204, 0.07);
    border-radius: 0 4px 4px 0;
}
.memory-year {
    display: block;
    color: #4da6ff;
    font-weight: bold;
    font-size: 1rem;
    margin-bottom: 5px;
    font-family: 'Courier New', Courier, monospace;
}
.memory-entry p { margin: 0; color: #ccdeff; font-size: 0.9rem; line-height: 1.6; }

#memory-book-close {
    position: fixed;
    top: 16px; right: 22px;
    background: #0a0a1a;
    color: #fff;
    border: 2px solid #0055cc;
    border-radius: 50%;
    width: 48px; height: 48px;
    font-size: 1.4rem;
    font-family: 'Courier New', Courier, monospace;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 601;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}
#memory-book-close:hover, #memory-book-close:active { background: #0055cc; }

/* ===== BOSS INTRO ===== */
#boss-intro-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%;
    /* Cover the full battle screen minus the UI panel at bottom */
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: black;
    z-index: 50;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}
#boss-intro-overlay.active { opacity: 1; pointer-events: all; }
#boss-intro-gif {
    height: clamp(120px, 30vh, 250px);
    width: auto;
    filter: drop-shadow(0 0 30px red) drop-shadow(0 0 60px darkred);
    animation: bossIntroZoom 0.6s ease-out forwards;
}
@keyframes bossIntroZoom {
    0%   { transform: scale(0.2) translateY(80px); opacity: 0; filter: drop-shadow(0 0 0px red) brightness(5); }
    60%  { transform: scale(1.15) translateY(-10px); opacity: 1; filter: drop-shadow(0 0 40px red) brightness(2); }
    100% { transform: scale(1) translateY(0px); opacity: 1; filter: drop-shadow(0 0 30px red); }
}
#boss-intro-flash { position: absolute; inset: 0; background: white; opacity: 0; pointer-events: none; }
#boss-intro-flash.flash { animation: bossFlash 0.5s ease-out forwards; }
@keyframes bossFlash { 0% { opacity: 0.9; } 100% { opacity: 0; } }
@keyframes bossShakeIntro {
    0%, 100% { transform: translateX(0); }
    20%  { transform: translateX(-8px); }
    40%  { transform: translateX(8px); }
    60%  { transform: translateX(-5px); }
    80%  { transform: translateX(5px); }
}

/* ===== RESPONSIVE BREAKPOINTS ===== */
@media (max-width: 480px) {
    #ui { font-size: 0.78rem; top: 6px; left: 8px; }
    .full-overlay .text-content { font-size: 1.1rem; }
    .battle-menu button { font-size: 0.7rem; padding: 10px 2px; }
    #start-screen h1 { font-size: 2.2rem; }
}

/* Touch device: show joystick + pause btn */
@media (pointer: coarse) {
    #joystick-container { display: block; }
    #pause-btn { display: flex; }
}

/* Landscape on mobile */
@media (max-height: 500px) and (orientation: landscape) {
    .battle-scene { max-height: 20vh; }
    .battle-scene img { height: clamp(60px, 16vh, 110px); }
    .full-overlay .text-content { font-size: 0.95rem; margin: 8px 0; }
    .full-overlay img { max-height: 28vh; }
    #joystick-container { width: 100px; height: 100px; bottom: 16px; left: 16px; }
    #dodge-joystick-container { width: 100px; height: 100px; bottom: 8px; right: 8px; }
    .battle-ui-container { padding: 5px 8px 8px; }
    .battle-stats { font-size: 0.75rem; margin-bottom: 5px; padding-bottom: 4px; }
    .battle-menu button { min-height: 40px; font-size: 0.7rem; }
    #dialogue-box { min-height: 40px; font-size: 12px; padding: 6px 10px; }
}
/* ===== BOSS WARNING ===== */
@keyframes warningPulse {
    0%   { transform: scale(1);    opacity: 1; }
    100% { transform: scale(1.06); opacity: 0.85; }
}
@keyframes warningShake {
    0%,100% { transform: translateX(0); }
    20%     { transform: translateX(-10px); }
    40%     { transform: translateX(10px); }
    60%     { transform: translateX(-6px); }
    80%     { transform: translateX(6px); }
}
#boss-warning-overlay.shaking { animation: warningShake 0.4s ease-out; }

/* ===== SECRET BOSS ===== */
@keyframes secretFlicker {
    0%   { opacity: 1;    text-shadow: 0 0 20px #ff00ff, 0 0 40px #ff00ff; }
    100% { opacity: 0.7;  text-shadow: 0 0 5px #ff00ff; }
}
@keyframes secretBossFloat {
    0%   { transform: translateY(0px) rotate(-2deg); }
    50%  { transform: translateY(-14px) rotate(2deg); }
    100% { transform: translateY(0px) rotate(-2deg); }
}
#boss-shortcut-btn:hover, #boss-shortcut-btn:active { background: #440000 !important; box-shadow: 0 0 16px rgba(255,68,68,0.6); }

/* ===== WHITE SOULS SKILL BUTTONS ===== */
.ws-skill-btn {
    flex: 1 1 calc(50% - 4px);
    min-width: 140px;
    padding: 10px 6px;
    background: #000;
    color: #fff;
    border: 2px solid #ff00ff;
    font-family: 'Courier New', Courier, monospace;
    font-size: clamp(0.68rem, 2.4vw, 0.9rem);
    font-weight: bold;
    cursor: pointer;
    border-radius: 3px;
    min-height: 46px;
    transition: background 0.15s, color 0.15s;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}
.ws-skill-btn:hover, .ws-skill-btn:active { background: #ff00ff; color: #000; }
.ws-skill-btn.ws-cd { border-color: #444; color: #555; cursor: not-allowed; }
.ws-skill-btn.ws-cd:hover { background: #000; color: #555; }

@media (max-height: 500px) and (orientation: landscape) {
    #ws-boss-img { height: clamp(50px, 10vh, 80px) !important; }
}