/*
 * LYRA AND THE STOLEN LYRE - Game Stylesheet
 *
 * This stylesheet creates a retro Sierra-style adventure game look.
 * Key design choices:
 * - Dark background to make the game "pop"
 * - Monospace font for that classic DOS feel
 * - EGA-inspired color palette
 * - Fully responsive layout for all screen sizes
 *
 * Layout Strategy:
 * - Uses viewport height (dvh) for mobile compatibility
 * - Canvas takes 65-70% of available space, maintains aspect ratio
 * - Text area fills remaining space, always visible
 * - JavaScript handles precise canvas sizing
 */

/* ============================================
   CSS VARIABLES - Easy to customize colors
   ============================================ */
:root {
    /* EGA-inspired palette */
    --ega-black: #000000;
    --ega-blue: #0000AA;
    --ega-green: #00AA00;
    --ega-cyan: #00AAAA;
    --ega-red: #AA0000;
    --ega-magenta: #AA00AA;
    --ega-brown: #AA5500;
    --ega-light-gray: #AAAAAA;
    --ega-dark-gray: #555555;
    --ega-light-blue: #5555FF;
    --ega-light-green: #55FF55;
    --ega-light-cyan: #55FFFF;
    --ega-light-red: #FF5555;
    --ega-light-magenta: #FF55FF;
    --ega-yellow: #FFFF55;
    --ega-white: #FFFFFF;

    /* UI colors */
    --bg-color: #1a1a2e;
    --container-bg: #16213e;
    --border-color: #0f3460;
    --text-color: #e0e0e0;
    --accent-color: #e94560;
    --input-bg: #0a0a15;
}

/* ============================================
   RESET & BASE STYLES
   ============================================ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    /* Prevent iOS bounce/rubber-banding */
    overflow: hidden;
}

body {
    /* Fill the entire viewport - no scroll, no padding */
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Courier New', Courier, monospace;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: stretch;
}

/* ============================================
   MAIN GAME CONTAINER
   ============================================ */
#game-container {
    /*
     * Fills the viewport, flexbox column layout
     * Each child gets appropriate flex behavior
     */
    background-color: var(--container-bg);
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ============================================
   TITLE BAR - Game name and menu buttons
   ============================================ */
#title-bar {
    flex: 0 0 auto; /* Fixed size, don't grow or shrink */
    background: linear-gradient(to bottom, #2a2a4a, #1a1a2e);
    padding: 8px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--border-color);
}

#game-title {
    font-size: 16px;
    font-weight: bold;
    color: var(--ega-yellow);
    text-shadow: 2px 2px 0 var(--ega-brown);
}

#menu-buttons {
    display: flex;
    gap: 8px;
}

#menu-buttons button {
    /* Retro-style buttons */
    background: linear-gradient(to bottom, #4a4a6a, #2a2a4a);
    border: 2px solid var(--border-color);
    color: var(--text-color);
    padding: 5px 12px;
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
    border-radius: 3px;
    transition: all 0.1s;
}

#menu-buttons button:hover {
    background: linear-gradient(to bottom, #5a5a7a, #3a3a5a);
    border-color: var(--accent-color);
}

#menu-buttons button:active {
    /* Pressed state - inset look */
    background: linear-gradient(to bottom, #2a2a4a, #4a4a6a);
}

/* ============================================
   MAIN AREA - Two-column layout on desktop
   ============================================ */
#main-area {
    /*
     * Side-by-side on desktop: image left, text right
     * Stacked on mobile (overridden in media queries)
     * Takes all remaining vertical space between title bar and input
     */
    flex: 1 1 0;
    display: flex;
    flex-direction: row;
    overflow: hidden;
    min-height: 0; /* Allow flex children to shrink below content size */
}

/* Left pane: canvas + inventory stacked vertically */
#left-pane {
    flex: 1 1 50%;
    display: flex;
    flex-direction: column;
    min-width: 0; /* Prevent flex blowout */
    border-right: 2px solid var(--border-color);
}

/* ============================================
   CANVAS WRAPPER - Controls responsive sizing
   ============================================ */
#canvas-wrapper {
    /*
     * Takes all available space in the left pane
     */
    flex: 1 1 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--ega-black);
    overflow: hidden;
    min-height: 0; /* Allow shrinking within flexbox */
}

/* ============================================
   GAME CANVAS - Where the adventure happens
   ============================================ */
#game-canvas {
    /*
     * Canvas display size is set by JavaScript for precise control
     * These styles provide fallback and ensure crisp pixels
     */
    display: block;
    max-width: 100%;
    max-height: 100%;
    background-color: var(--ega-black);
    /* Crisp pixel scaling - no blur */
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    -ms-interpolation-mode: nearest-neighbor;
}

/* ============================================
   INVENTORY BAR - Shows collected items
   ============================================ */
#inventory-bar {
    flex: 0 0 auto; /* Fixed size, full width between main-area and input */
    background-color: var(--input-bg);
    padding: 8px 15px;
    display: flex;
    align-items: center;
    gap: 15px;
    border-top: 2px solid var(--border-color);
    min-height: 50px;
}

#inventory-label {
    color: var(--ega-light-cyan);
    font-size: 14px;
    white-space: nowrap;
}

#inventory-slots {
    /* Horizontal scrollable container for item icons */
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
}

.inventory-slot {
    /* Each item slot shows icon + text label */
    width: auto;
    height: 28px;
    min-width: 28px;
    padding: 4px 10px;
    gap: 6px;
    background-color: var(--container-bg);
    border: 2px solid var(--border-color);
    border-radius: 4px;
    display: flex;
    align-items: center;
    cursor: pointer;
    transition: all 0.1s;
    position: relative;
    white-space: nowrap;
}

.inventory-slot:hover {
    border-color: var(--ega-yellow);
    transform: scale(1.1);
}

.inventory-slot.selected {
    /* Highlight when item is selected for use */
    border-color: var(--accent-color);
    box-shadow: 0 0 8px var(--accent-color);
}

.inventory-slot img {
    max-width: 24px;
    max-height: 24px;
    image-rendering: pixelated;
    flex-shrink: 0;
}

/* Text label next to icon */
.inventory-label {
    color: var(--ega-yellow);
    font-size: 11px;
    white-space: nowrap;
}

/* ============================================
   TEXT INPUT AREA - Command entry
   ============================================ */
#input-area {
    flex: 0 0 auto; /* Fixed size */
    /* DOS-style command prompt */
    background-color: var(--input-bg);
    padding: 12px 15px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 2px solid var(--border-color);
}

#prompt {
    /* The ">" prompt character */
    color: var(--ega-light-green);
    font-size: 18px;
    font-weight: bold;
}

#command-input {
    /* Text input field */
    flex: 1;
    background-color: transparent;
    border: none;
    color: var(--ega-white);
    font-family: inherit;
    font-size: 18px;
    outline: none;
    caret-color: var(--ega-light-green);
}

#command-input::placeholder {
    color: var(--ega-dark-gray);
}

/* ============================================
   TEXT OUTPUT AREA - Game responses
   ============================================ */
#output-area {
    /*
     * Right pane on desktop: fills right half, scrollable
     * Takes remaining space below canvas on mobile
     */
    flex: 1 1 50%;
    background-color: var(--input-bg);
    padding: 20px;
    min-height: 0; /* Allow shrinking within flexbox */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

#output-text {
    /* Text content — sized for vertical reading in the right pane */
    line-height: 1.8;
    font-size: 15px;
}

/* Different text styles for various message types */
#output-text .room-name {
    color: var(--ega-yellow);
    font-weight: bold;
    font-size: 17px;
    margin-bottom: 8px;
}

#output-text .description {
    color: var(--ega-light-gray);
}

#output-text .action {
    color: var(--ega-light-green);
}

#output-text .error {
    color: var(--ega-light-red);
}

#output-text .dialogue {
    color: var(--ega-light-cyan);
    font-style: italic;
}

#output-text .item-get {
    color: var(--ega-yellow);
}

#output-text .hint {
    color: var(--ega-light-magenta);
}

/* Paragraph spacing in output */
#output-text p {
    margin-bottom: 10px;
}

/* ============================================
   MODAL DIALOG - Save/Load screens
   ============================================ */
#modal-overlay {
    /* Dark overlay behind modal */
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100;
}

#modal-overlay.hidden {
    display: none;
}

#modal {
    /* The modal box itself */
    background-color: var(--container-bg);
    border: 3px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    min-width: 300px;
    max-width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

#modal-title {
    color: var(--ega-yellow);
    text-align: center;
    margin-bottom: 15px;
    font-size: 18px;
}

#save-slots {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px;
}

.save-slot {
    /* Each save slot button */
    background-color: var(--input-bg);
    border: 2px solid var(--border-color);
    color: var(--text-color);
    padding: 12px 15px;
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
    border-radius: 4px;
    text-align: left;
    transition: all 0.1s;
}

.save-slot:hover {
    border-color: var(--ega-yellow);
    background-color: var(--container-bg);
}

.save-slot .slot-name {
    color: var(--ega-light-cyan);
    font-weight: bold;
}

.save-slot .slot-info {
    color: var(--ega-dark-gray);
    font-size: 12px;
    margin-top: 4px;
}

.save-slot.empty {
    color: var(--ega-dark-gray);
    font-style: italic;
}

#modal-close {
    /* Cancel button */
    width: 100%;
    background: linear-gradient(to bottom, #4a4a6a, #2a2a4a);
    border: 2px solid var(--border-color);
    color: var(--text-color);
    padding: 10px;
    font-family: inherit;
    font-size: 14px;
    cursor: pointer;
    border-radius: 4px;
}

#modal-close:hover {
    background: linear-gradient(to bottom, #5a5a7a, #3a3a5a);
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */

/* Tablets and small laptops — stack vertically */
@media (max-width: 800px) {
    /* Switch to stacked layout on narrow screens */
    #main-area {
        flex-direction: column;
    }

    #left-pane {
        /* In stacked mode, canvas takes ~65% of main area */
        flex: 3 1 0;
        border-right: none;
    }

    #canvas-wrapper {
        max-height: 80vh;
        max-height: 80dvh;
    }

    #output-area {
        /* Text area takes ~35% of main area */
        flex: 1 1 0;
        min-height: 80px;
    }

    #title-bar {
        padding: 6px 10px;
    }

    #game-title {
        font-size: 14px;
    }

    #menu-buttons button {
        padding: 4px 8px;
        font-size: 11px;
    }

    #inventory-bar {
        padding: 6px 10px;
        min-height: 44px;
    }

    #inventory-label {
        font-size: 12px;
    }

    .inventory-slot {
        height: 26px;
        padding: 3px 8px;
        font-size: 10px;
    }

    #input-area {
        padding: 10px 12px;
    }

    #prompt {
        font-size: 16px;
    }

    #command-input {
        font-size: 16px;
    }

    #output-area {
        padding: 12px;
    }

    #output-text {
        font-size: 14px;
        line-height: 1.6;
    }

    #output-text .room-name {
        font-size: 15px;
    }
}

/* Mobile phones */
@media (max-width: 500px) {
    #title-bar {
        padding: 5px 8px;
    }

    #game-title {
        font-size: 12px;
    }

    #menu-buttons {
        gap: 4px;
    }

    #menu-buttons button {
        padding: 3px 6px;
        font-size: 10px;
    }

    #canvas-wrapper {
        /* On mobile, allow canvas to take more vertical space */
        max-height: 60vh;
        max-height: 60dvh;
    }

    #left-pane {
        /* On mobile, canvas pane takes ~60% */
        flex: 2 1 0;
    }

    #output-area {
        /* Text takes ~40% */
        flex: 1.5 1 0;
    }

    #inventory-bar {
        padding: 5px 8px;
        min-height: 40px;
        gap: 8px;
    }

    #inventory-label {
        font-size: 11px;
    }

    .inventory-slot {
        height: 24px;
        padding: 2px 6px;
        font-size: 9px;
    }

    #input-area {
        padding: 8px 10px;
    }

    #prompt {
        font-size: 14px;
    }

    #command-input {
        font-size: 16px; /* Keep 16px to prevent iOS zoom on focus */
    }

    #output-area {
        padding: 10px;
    }

    #output-text {
        font-size: 13px;
        line-height: 1.5;
    }

    #output-text .room-name {
        font-size: 14px;
    }

    #output-text p {
        margin-bottom: 8px;
    }
}

/* Landscape mobile - use side-by-side layout (wider than tall) */
@media (max-height: 500px) and (orientation: landscape) {
    #main-area {
        /* Keep row layout even on small landscape screens */
        flex-direction: row;
    }

    #left-pane {
        border-right: 2px solid var(--border-color);
    }

    #inventory-bar {
        padding: 4px 8px;
        min-height: 36px;
    }

    .inventory-slot {
        height: 22px;
        padding: 2px 5px;
        font-size: 8px;
    }

    #input-area {
        padding: 6px 10px;
    }

    #output-area {
        padding: 8px;
    }

    #output-text {
        font-size: 12px;
        line-height: 1.4;
    }
}

/* ============================================
   SCROLLBAR STYLING
   ============================================ */
#output-area::-webkit-scrollbar {
    width: 10px;
}

#output-area::-webkit-scrollbar-track {
    background: var(--input-bg);
}

#output-area::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 5px;
}

#output-area::-webkit-scrollbar-thumb:hover {
    background: var(--ega-dark-gray);
}

/* Firefox scrollbar */
#output-area {
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) var(--input-bg);
}

/* ============================================
   TOUCH DEVICE OPTIMIZATIONS
   ============================================ */
@media (hover: none) and (pointer: coarse) {
    /* Touch devices - larger tap targets */
    #menu-buttons button {
        padding: 8px 12px;
        min-height: 36px;
    }

    .inventory-slot {
        min-height: 36px;
        padding: 6px 12px;
    }

    /* Disable hover effects that don't work well on touch */
    .inventory-slot:hover {
        transform: none;
    }
}

/* ============================================
   INTRO/TITLE SCREEN
   ============================================ */
#intro-screen {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
    z-index: 1000;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow-y: auto;
    padding: 20px;
}

#intro-screen.hidden {
    display: none;
}

#intro-content {
    max-width: 700px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 25px;
}

/* Title image area */
#intro-image-container {
    position: relative;
    text-align: center;
    border: 4px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    /* Gradient fallback if image doesn't load */
    background: linear-gradient(
        to bottom,
        #2a1a4a 0%,
        #4a2a3a 30%,
        #6a4a2a 60%,
        #8a6a1a 100%
    );
    min-height: 150px;
    /* Maintain 16:10 aspect ratio like the game canvas */
    aspect-ratio: 16 / 10;
    max-height: 45vh;
}

#intro-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* Hide broken image icon if image fails to load */
#intro-image.hidden,
#intro-image[src=""] {
    display: none;
}

#intro-title {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: linear-gradient(transparent, rgba(0,0,0,0.9));
    color: var(--ega-yellow);
    font-size: 28px;
    padding: 40px 15px 15px;
    text-shadow: 3px 3px 0 var(--ega-brown), -1px -1px 0 var(--ega-black);
    font-family: 'Times New Roman', serif;
    letter-spacing: 2px;
}

/* Instructions section */
#intro-instructions {
    background-color: var(--container-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
}

#intro-instructions h2 {
    color: var(--ega-light-cyan);
    font-size: 18px;
    margin-bottom: 12px;
    text-align: center;
}

#intro-instructions p {
    color: var(--ega-light-gray);
    margin-bottom: 12px;
    text-align: center;
}

#intro-instructions ul {
    list-style: none;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 8px;
}

#intro-instructions li {
    color: var(--text-color);
    font-size: 13px;
    padding: 6px 10px;
    background-color: var(--input-bg);
    border-radius: 4px;
}

#intro-instructions li strong {
    color: var(--ega-light-green);
}

.intro-tip {
    color: var(--ega-light-magenta) !important;
    font-style: italic;
    margin-top: 12px !important;
    margin-bottom: 0 !important;
}

/* New Game section */
#intro-new-game {
    background-color: var(--container-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    text-align: center;
}

#intro-new-game h2 {
    color: var(--ega-yellow);
    font-size: 18px;
    margin-bottom: 15px;
}

#name-input-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 15px;
}

#name-input-container label {
    color: var(--ega-light-gray);
    font-size: 14px;
}

#player-name {
    background-color: var(--input-bg);
    border: 2px solid var(--border-color);
    border-radius: 4px;
    color: var(--ega-white);
    font-family: inherit;
    font-size: 16px;
    padding: 10px 15px;
    width: 200px;
    outline: none;
}

#player-name:focus {
    border-color: var(--ega-yellow);
}

#player-name::placeholder {
    color: var(--ega-dark-gray);
}

#btn-play {
    background: linear-gradient(to bottom, #4a7c59, #2d5a3a);
    border: 3px solid #6b9b5c;
    color: var(--ega-white);
    font-family: inherit;
    font-size: 18px;
    font-weight: bold;
    padding: 15px 40px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.5);
}

#btn-play:hover {
    background: linear-gradient(to bottom, #5a9c69, #3d7a4a);
    border-color: var(--ega-yellow);
    transform: scale(1.05);
}

#btn-play:active {
    transform: scale(0.98);
}

/* Saved Games section */
#intro-saved-games {
    background-color: var(--container-bg);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
}

#intro-saved-games.hidden {
    display: none;
}

#intro-saved-games h2 {
    color: var(--ega-light-cyan);
    font-size: 18px;
    margin-bottom: 15px;
    text-align: center;
}

#saved-games-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.saved-game-slot {
    background-color: var(--input-bg);
    border: 2px solid var(--border-color);
    border-radius: 6px;
    padding: 15px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.saved-game-slot:hover {
    border-color: var(--ega-yellow);
    background-color: var(--container-bg);
}

.saved-game-info {
    flex: 1;
}

.saved-game-name {
    color: var(--ega-yellow);
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 4px;
}

.saved-game-details {
    color: var(--ega-dark-gray);
    font-size: 12px;
}

.saved-game-delete {
    background-color: transparent;
    border: 2px solid var(--ega-red);
    color: var(--ega-light-red);
    padding: 5px 10px;
    font-family: inherit;
    font-size: 12px;
    border-radius: 4px;
    cursor: pointer;
    margin-left: 15px;
}

.saved-game-delete:hover {
    background-color: var(--ega-red);
    color: var(--ega-white);
}

/* Chapter selection buttons on intro screen */
#chapter-select-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}

#chapter-select-container label {
    color: var(--ega-light-cyan);
    font-size: 14px;
}

#chapter-buttons {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

.chapter-btn {
    background: transparent;
    border: 1px solid var(--ega-dark-gray);
    color: var(--ega-light-gray);
    padding: 8px 16px;
    font-family: inherit;
    font-size: 13px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
}

.chapter-btn:hover {
    border-color: var(--ega-light-cyan);
    color: var(--ega-white);
}

.chapter-btn.selected {
    background-color: var(--ega-blue);
    border-color: var(--ega-light-cyan);
    color: var(--ega-white);
}

/* Responsive intro screen */
@media (max-width: 800px) {
    #intro-image-container {
        max-height: 35vh;
    }
}

@media (max-width: 600px) {
    #intro-content {
        gap: 15px;
    }

    #intro-image-container {
        max-height: 30vh;
        min-height: 120px;
    }

    #intro-title {
        font-size: 20px;
        padding: 30px 10px 10px;
    }

    #intro-instructions,
    #intro-new-game,
    #intro-saved-games {
        padding: 15px;
    }

    #intro-instructions h2,
    #intro-new-game h2,
    #intro-saved-games h2 {
        font-size: 16px;
    }

    #intro-instructions ul {
        grid-template-columns: 1fr;
    }

    #name-input-container {
        flex-direction: column;
        gap: 8px;
    }

    #player-name {
        width: 100%;
        max-width: 250px;
    }

    #btn-play {
        font-size: 16px;
        padding: 12px 30px;
    }
}

/* Landscape mobile - compact intro */
@media (max-height: 500px) and (orientation: landscape) {
    #intro-screen {
        padding: 10px;
    }

    #intro-content {
        gap: 10px;
        flex-direction: row;
        flex-wrap: wrap;
        max-width: 100%;
    }

    #intro-image-container {
        max-height: 40vh;
        flex: 1 1 40%;
        min-width: 250px;
    }

    #intro-instructions {
        display: none; /* Hide instructions in landscape to save space */
    }

    #intro-new-game,
    #intro-saved-games {
        flex: 1 1 45%;
        min-width: 200px;
        padding: 10px;
    }

    #intro-title {
        font-size: 16px;
        padding: 20px 10px 8px;
    }
}
