/* Pokemon-Style Game World */

html, body.world-body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    min-height: 100dvh;
    overflow: hidden;
    background: #0a0a0a;
    touch-action: none;
    overscroll-behavior: none;
}

body.world-body {
    font-family: 'Press Start 2P', 'Courier New', monospace;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100dvh;
}

.world-root {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--bg-primary, #0a0e27);
}

.world-back {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 20;
    padding: 7px 11px;
    font-family: 'Press Start 2P', monospace;
    font-size: 0.6rem;
    color: var(--text-primary, #00ffff);
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid var(--border-color, #00ffff);
    text-decoration: none;
    text-shadow: 0 0 8px var(--shadow-glow, rgba(0, 255, 255, 0.3));
    transition: background 0.2s ease;
    line-height: 1;
}

.world-back:hover {
    background: var(--shadow-glow-light, rgba(0, 255, 255, 0.2));
}

/* Stage holds the canvas and overlays. Fills screen up to desktop cap. */
.world-stage {
    position: relative;
    /* Portrait: fill most of screen height; landscape: fill width */
    width: min(100vw, 960px);
    height: min(100dvh, 720px);
    overflow: hidden;
    background: #1a2a10;
    box-shadow: 0 0 40px var(--shadow-glow, rgba(0, 255, 255, 0.3));
    border: 2px solid var(--border-color, #00ffff);
}

/* On very small screens, go fully edge-to-edge */
@media (max-width: 600px) {
    .world-stage {
        width: 100vw;
        height: 100dvh;
        border-width: 0;
        box-shadow: none;
    }
    .world-back {
        top: 6px;
        left: 6px;
        font-size: 0.5rem;
        padding: 5px 8px;
    }
}

#worldCanvas {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* Scene transition flash */
.world-stage.transitioning::after {
    content: '';
    position: absolute;
    inset: 0;
    background: #000;
    animation: sceneFlash 0.35s ease forwards;
    pointer-events: none;
    z-index: 30;
}

@keyframes sceneFlash {
    0%   { opacity: 0; }
    40%  { opacity: 1; }
    60%  { opacity: 1; }
    100% { opacity: 0; }
}

/* Help overlay */
.world-help {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 18px 24px;
    background: rgba(0, 0, 0, 0.88);
    border: 3px solid var(--border-color, #00ffff);
    color: #fff;
    font-family: 'Press Start 2P', monospace;
    font-size: 0.65rem;
    line-height: 2;
    text-align: center;
    z-index: 10;
    box-shadow: 0 0 30px var(--shadow-glow, rgba(0, 255, 255, 0.3));
    transition: opacity 0.4s ease;
    max-width: 90%;
}

.world-help.hidden {
    opacity: 0;
    pointer-events: none;
}

.help-dismiss {
    margin-top: 10px;
    font-size: 0.5rem;
    color: var(--text-primary, #00ffff);
    text-shadow: 0 0 8px var(--shadow-glow, rgba(0, 255, 255, 0.4));
}

/* HUD — interaction prompt */
.world-hud {
    position: absolute;
    top: 10px;
    right: 10px;
    pointer-events: none;
    z-index: 5;
}

.hud-label {
    padding: 5px 9px;
    background: rgba(0, 0, 0, 0.78);
    border: 2px solid var(--border-color, #00ffff);
    color: #fff;
    font-family: 'Press Start 2P', monospace;
    font-size: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s ease;
    white-space: nowrap;
}

.hud-label.visible {
    opacity: 1;
}

/* Classic Pokemon dialog box */
.dialog-box {
    position: absolute;
    left: 3%;
    right: 3%;
    bottom: 3%;
    min-height: 100px;
    background: #f8f0d8;
    border: 4px solid #383030;
    border-radius: 8px;
    padding: 14px 18px 18px;
    box-shadow:
        inset 0 0 0 2px #f8f0d8,
        inset 0 0 0 4px #585050,
        0 4px 0 #383030;
    font-family: 'Press Start 2P', monospace;
    color: #383030;
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px);
    transition: opacity 0.18s ease, transform 0.18s ease;
    z-index: 15;
}

.dialog-box.active {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.dialog-name {
    position: absolute;
    top: -14px;
    left: 14px;
    padding: 3px 9px;
    background: #f8f0d8;
    border: 3px solid #383030;
    border-radius: 5px;
    font-size: 0.55rem;
    color: #383030;
    display: none;
}

.dialog-name.visible {
    display: block;
}

.dialog-text {
    font-size: 0.65rem;
    line-height: 1.9;
    white-space: pre-wrap;
    word-break: break-word;
    min-height: 3.5em;
}

.dialog-cursor {
    position: absolute;
    right: 14px;
    bottom: 10px;
    font-size: 0.65rem;
    color: #383030;
    opacity: 0;
    animation: dialogBlink 0.8s steps(2) infinite;
}

.dialog-cursor.visible {
    opacity: 1;
}

@keyframes dialogBlink {
    0%, 49% { opacity: 1; }
    50%, 100% { opacity: 0; }
}

/* Scene label (e.g. "Yibo's House") */
.scene-label {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    padding: 5px 12px;
    background: rgba(0, 0, 0, 0.75);
    border: 2px solid var(--border-color, #00ffff);
    color: var(--text-primary, #00ffff);
    font-family: 'Press Start 2P', monospace;
    font-size: 0.55rem;
    pointer-events: none;
    z-index: 5;
    opacity: 0;
    transition: opacity 0.5s ease;
    white-space: nowrap;
}

.scene-label.visible {
    opacity: 1;
}

/* Mobile D-pad */
.dpad {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 12;
    display: none;
}

.dpad-btn,
.action-btn {
    position: absolute;
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    border: 2px solid rgba(255, 255, 255, 0.55);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    font-family: 'Press Start 2P', monospace;
    font-size: 0.7rem;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dpad-btn:active,
.action-btn:active {
    background: rgba(255, 255, 255, 0.3);
}

/* Position relative to bottom-left */
.dpad-up    { bottom: 158px; left: 59px; }
.dpad-left  { bottom: 107px; left: 7px; }
.dpad-right { bottom: 107px; left: 111px; }
.dpad-down  { bottom: 56px;  left: 59px; }

.action-btn {
    bottom: 100px;
    right: 14px;
    width: 62px;
    height: 62px;
    background: rgba(180, 30, 30, 0.8);
    border-color: rgba(255, 255, 255, 0.8);
    font-size: 0.95rem;
}

/* Show D-pad on touch devices */
@media (hover: none) and (pointer: coarse) {
    .dpad { display: block; }
}

/* Also show on narrow screens regardless */
@media (max-width: 600px) {
    .dpad { display: block; }

    .dialog-text {
        font-size: 0.55rem;
        line-height: 1.75;
    }

    .dialog-box {
        padding: 11px 14px 16px;
        min-height: 88px;
    }

    .world-help {
        font-size: 0.55rem;
        padding: 12px 16px;
    }
}

@media (max-width: 400px) {
    .dialog-text { font-size: 0.48rem; }
    .hud-label   { font-size: 0.42rem; }
    .dpad-btn, .action-btn { width: 44px; height: 44px; }
    .dpad-up    { bottom: 142px; left: 53px; }
    .dpad-left  { bottom: 96px;  left: 7px; }
    .dpad-right { bottom: 96px;  left: 99px; }
    .dpad-down  { bottom: 50px;  left: 53px; }
    .action-btn { bottom: 88px; right: 10px; width: 56px; height: 56px; }
}
