* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Courier New', monospace;
    background-color: #0a0a0a;
    color: #00ff00;
    height: 100vh;
    overflow: hidden;
}

.game-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 10px;
}

header {
    border-bottom: 2px solid #00ff00;
    padding-bottom: 10px;
    margin-bottom: 10px;
    flex-shrink: 0;
}

h1 {
    text-align: center;
    color: #ffff00;
    text-shadow: 0 0 10px #ffff00;
}

.status-bar {
    display: flex;
    justify-content: space-between;
    margin-top: 10px;
    font-size: 14px;
}

@keyframes health-flash {
    0%, 100% { color: #ff2222; text-shadow: 0 0 8px #ff0000; }
    50%       { color: #ff9999; text-shadow: none; }
}

.health-low {
    animation: health-flash 0.8s ease-in-out infinite;
    font-weight: bold;
}

#mana {
    color: #6699ff;
}

@keyframes mana-flash {
    0%, 100% { color: #3344aa; text-shadow: 0 0 8px #3333ff; }
    50%       { color: #9999ff; text-shadow: none; }
}

.mana-low {
    animation: mana-flash 1.2s ease-in-out infinite;
    font-weight: bold;
}

#hidden-status {
    color: #00ffaa;
    font-weight: bold;
    animation: hidden-pulse 2s ease-in-out infinite;
    letter-spacing: 0.05em;
}

.chat-room {
    color: #ffff77;
}

.chat-world {
    color: #ff99ff;
}

.chat-whisper {
    color: #cc88ff;
    font-style: italic;
}

@keyframes hidden-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.35; }
}

.main-content {
    display: flex;
    flex: 1;
    gap: 15px;
    min-height: 0;
    overflow: hidden;
}

.visual-panel {
    flex: 1;
    border: 2px solid #00ff00;
    padding: 10px;
    background-color: #001100;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: hidden;
}

#gameCanvas {
    border: 1px solid #004400;
    background-color: #000;
    display: block;
    width: 100%;
}

#mapScrollContainer {
    flex-shrink: 0;
    height: 200px;
    overflow: hidden;
    border: 1px solid #00ff00;
    background-color: #000;
}

#cytoMap {
    width: 100%;
    height: 100%;
}

.text-panel {
    flex: 1.5;
    display: flex;
    flex-direction: column;
    border: 2px solid #00ff00;
    padding: 10px;
    background-color: #001100;
    min-height: 0;
    overflow: hidden;
}

.output-area {
    flex: 1;
    overflow-y: auto;
    padding: 10px;
    border: 1px solid #004400;
    background-color: #000;
    margin-bottom: 10px;
    min-height: 0;
    line-height: 1.4;
}

.input-area {
    display: flex;
    gap: 10px;
}

#commandInput {
    flex: 1;
    padding: 8px;
    background-color: #000;
    color: #00ff00;
    border: 1px solid #00ff00;
    font-family: inherit;
    font-size: 14px;
}

#commandInput:focus {
    outline: none;
    box-shadow: 0 0 5px #00ff00;
}

#chatInput {
    flex: 1;
    padding: 8px;
    background-color: #000;
    color: #ffff77;
    border: 1px solid #ffff77;
    font-family: inherit;
    font-size: 14px;
}

#chatInput:focus {
    outline: none;
    box-shadow: 0 0 5px #ffff77;
}

#submitBtn {
    padding: 8px 16px;
    background-color: #004400;
    color: #00ff00;
    border: 1px solid #00ff00;
    cursor: pointer;
    font-family: inherit;
}

#submitBtn:hover {
    background-color: #006600;
}

.inventory-panel {
    border: 2px solid #00ff00;
    padding: 10px;
    margin-top: 10px;
    background-color: #001100;
    max-height: 120px;
    overflow-y: auto;
    flex-shrink: 0;
}

.inventory-panel h3 {
    color: #ffff00;
    margin-bottom: 10px;
}

#inventory {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.item {
    background-color: #004400;
    padding: 4px 8px;
    border: 1px solid #00ff00;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
}

.item:hover {
    background-color: #006600;
}

/* ── Item context menu ───────────────────────────────────────────────────── */

#item-context-menu {
    position: fixed;
    z-index: 500;
    background: #001a00;
    border: 1px solid #00ff00;
    border-radius: 4px;
    padding: 4px 0;
    min-width: 140px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.7);
    font-family: 'Courier New', monospace;
    font-size: 12px;
}

#item-context-menu button {
    display: block;
    width: 100%;
    background: none;
    border: none;
    color: #00ff00;
    padding: 6px 14px;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
    font-size: inherit;
}

#item-context-menu button:hover {
    background: #003300;
    color: #ffffff;
}

#item-context-menu .menu-separator {
    border: none;
    border-top: 1px solid #003300;
    margin: 3px 0;
}

.text-line {
    margin-bottom: 8px;
}

.room-description {
    color: #00ffff;
    margin-bottom: 10px;
}

.item-description {
    color: #ffff00;
}

.cmd-link {
    color: #ffff00;
    text-decoration: underline;
    cursor: pointer;
}

.cmd-link:hover {
    color: #ffffff;
    text-shadow: 0 0 6px #ffff00;
}

.combat-text {
    color: #ff4444;
}

.monster-encounter {
    color: #ff2222;
    font-weight: bold;
    text-shadow: 0 0 8px #ff0000;
}

.sneak-attack {
    color: #ffaa00;
    font-weight: bold;
    text-shadow: 0 0 8px #ff6600;
}

.xp-gain {
    color: #44dd88;
    font-style: italic;
}

.level-up {
    color: #ffdd00;
    font-weight: bold;
    text-shadow: 0 0 10px #ffaa00;
}

.system-message {
    color: #888888;
    font-style: italic;
}

.npc-message {
    color: #e8a020;
    font-style: italic;
}

.error-message {
    color: #ff0000;
}

.player-message {
    color: #00ff00;
}

.cmd-link {
    color: #00dd00;
    text-decoration: underline;
    cursor: pointer;
}

.cmd-link:hover {
    color: #ffffff;
}

/* ── Map toggle button ───────────────────────────────────────────────────── */

#mapToggleBtn {
    display: none;
    background: #002200;
    color: #00ff00;
    border: 1px solid #00ff00;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    cursor: pointer;
    padding: 4px 10px;
    align-self: flex-start;
    white-space: nowrap;
    flex-shrink: 0;
}

#mapToggleBtn:hover {
    background: #004400;
}

/* ── Direction pad ───────────────────────────────────────────────────────── */

#direction-pad {
    display: grid;
    grid-template-columns: repeat(3, 44px);
    grid-template-rows: repeat(3, 44px) 36px;
    gap: 4px;
    justify-content: center;
    margin: 6px 0;
    flex-shrink: 0;
}

.dir-btn {
    background: #003300;
    color: #00ff00;
    border: 1px solid #00ff00;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    cursor: pointer;
    border-radius: 4px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.dir-btn:hover:not(:disabled) {
    background: #005500;
}

.dir-btn:active:not(:disabled) {
    background: #006600;
}

.dir-btn:disabled {
    opacity: 0.25;
    cursor: default;
    border-color: #004400;
}

.dir-btn.dir-locked:disabled {
    opacity: 0.5;
    color: #ff8800;
    border-color: #885500;
}

/* Diagonal buttons and bottom row are slightly smaller */
.dir-btn[data-dir="northwest"],
.dir-btn[data-dir="northeast"],
.dir-btn[data-dir="southwest"],
.dir-btn[data-dir="southeast"],
.dir-btn[data-dir="up"],
.dir-btn[data-dir="down"],
.dir-btn[data-dir="surface"] {
    font-size: 11px;
    min-height: 36px;
}

/* Bottom row (U/SRF/D) is shorter */
.dir-btn[data-dir="up"],
.dir-btn[data-dir="down"],
.dir-btn[data-dir="surface"] {
    min-height: 36px;
}

.dir-spacer {
    background: transparent;
    border: none;
    cursor: default;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #004400;
    font-size: 18px;
}

/* ── Action bar ──────────────────────────────────────────────────────────── */

#action-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 0 0 6px 0;
    flex-shrink: 0;
}

.action-btn {
    background: #002200;
    color: #00ff00;
    border: 1px solid #005500;
    font-family: 'Courier New', monospace;
    font-size: 11px;
    cursor: pointer;
    border-radius: 3px;
    padding: 6px 10px;
    min-height: 36px;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    flex: 1 1 auto;
}

.action-btn:hover:not(:disabled) {
    background: #004400;
}

.action-btn:active:not(:disabled) {
    background: #006600;
}

.action-btn:disabled {
    opacity: 0.35;
    cursor: default;
}

/* ── Mobile layout (≤700 px) ─────────────────────────────────────────────── */

@media (max-width: 700px) {
    body {
        overflow: auto;
        height: auto;
    }

    .game-container {
        height: auto;
        min-height: 100vh;
        padding: 6px;
    }

    h1 {
        font-size: 1.1em;
    }

    .status-bar {
        flex-wrap: wrap;
        gap: 4px 10px;
        font-size: 12px;
    }

    .main-content {
        flex-direction: column;
        gap: 8px;
        overflow: visible;
        align-items: stretch;
    }

    #mapToggleBtn {
        display: block;
        align-self: stretch;
    }

    .visual-panel {
        flex: none;
        max-height: 0;
        overflow: hidden;
        border: none;
        padding: 0;
        transition: max-height 0.3s ease, padding 0.3s ease, border 0.3s ease;
    }

    .visual-panel.map-visible {
        max-height: 360px;
        border: 2px solid #00ff00;
        padding: 6px;
    }

    .text-panel {
        flex: none;
        height: auto;
    }

    .output-area {
        height: 40vh;
        flex: none;
    }

    #commandInput {
        font-size: 16px;
        padding: 10px 8px;
    }

    #submitBtn {
        padding: 10px 14px;
        font-size: 14px;
    }

    .inventory-panel {
        max-height: 90px;
    }

    .item {
        padding: 7px 10px;
        font-size: 13px;
    }
}

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: #001100;
}

::-webkit-scrollbar-thumb {
    background: #004400;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #006600;
}