/* =========================================
   1. PORTAL LAYOUT & CORE (RESTORED & FIXED)
   ========================================= */
:root {
    --color-jade: #3A8A7B;
    --color-maya-red: #cb294f;
    --color-gold: #ffd700;
    --bg-dark: #050505;
}

/* Global Reset - Ensuring no inherited margins break the layout */
html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    background-color: var(--bg-dark);
}

body.game-portal-body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* --- HEADER (Restoring your original styling) --- */
.game-portal-header {
    background: #111;
    padding: 0 20px; /* Vertical padding handled by height/flex */
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #333;
    color: #fff;
    z-index: 1000;
    height: 50px;
    box-sizing: border-box;
    flex-shrink: 0; /* Prevents the game area from squishing the header */
}

.back-btn {
    color: var(--color-jade);
    text-decoration: none;
    font-weight: bold;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.back-btn:hover {
    color: #fff;
}

.game-title {
    text-transform: uppercase;
    letter-spacing: 2px;
    font-size: 0.8rem;
    opacity: 0.5;
    color: #fff;
}

/* --- GAMEPLAY AREA (The Canvas Alignment Fixes) --- */
.game-portal-main {
    flex-grow: 1;
    position: relative;
    display: flex;
    align-items: stretch; /* Forces container to fill vertical space */
    justify-content: center;
    background: radial-gradient(circle, #1a1418 0%, #000 100%);
    overflow: hidden;
    margin: 0 !important;
    padding: 0 !important;
}

#game-container {
    position: relative;
    width: 100%;
    height: 100%;
    margin: 0 !important;
    padding: 0 !important;
}

#gameCanvas {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: fill; /* Ensures canvas occupies every pixel of the container */
    outline: none;
}

/* =========================================
   2. HUD & CONTROLS
   ========================================= */

/* Moves Counter */
#moves-display {
    position: absolute;
    top: 20px;
    left: 20px;
    color: #ccc;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9rem;
    z-index: 90;
    background: rgba(0, 0, 0, 0.6);
    padding: 8px 15px;
    border-radius: 20px;
    border: 1px solid #333;
}

#moves-display span {
    color: var(--color-jade);
    font-weight: bold;
}

/* Tool Sidebar */
#sidebar-overlay {
    position: absolute;
    z-index: 95;
    display: flex;
    gap: 12px;
    transition: opacity 0.3s;
}

.tool-btn {
    background: rgba(20, 20, 20, 0.85);
    border: 1px solid #444;
    border-radius: 12px;
    width: 48px;
    height: 48px;
    padding: 10px;
    color: #aaa;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.tool-btn svg {
    width: 100%;
    height: 100%;
    fill: currentColor;
}

.tool-btn:hover:not(.locked) {
    border-color: var(--color-jade);
    color: #fff;
    transform: scale(1.1);
}

.tool-btn.locked {
    opacity: 0.2;
    cursor: not-allowed;
    filter: grayscale(1);
}

/* Action Buttons (Surrender/Exit) */
#btn-exit-game, #fs-toggle-btn {
    position: absolute;
    top: 20px;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid #444;
    color: #fff;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

#btn-exit-game { right: 20px; color: #ff6b6b; }
#fs-toggle-btn { right: 70px; }

#btn-exit-game:hover { background: #331111; border-color: #ff4d4d; color: #fff; }

#btn-surrender {
    position: absolute;
    bottom: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid #444;
    color: #888;
    padding: 8px 16px;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.75rem;
    z-index: 90;
    text-transform: uppercase;
}

#btn-surrender:hover { color: #fff; border-color: #666; }

/* =========================================
   3. OVERLAYS & CARDS
   ========================================= */
.overlay {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 500;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    padding: 20px;
    box-sizing: border-box;
}

.start-card {
    background-color: rgba(12, 18, 16, 0.98);
    border: 1px solid rgba(58, 138, 123, 0.4);
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.9);
    border-radius: 20px;
    color: #fff;
    text-align: center;
    width: 100%;
    max-width: 420px;
    padding: 2.5rem;
    box-sizing: border-box;
    animation: zoomInFade 0.4s ease-out;
}

@keyframes zoomInFade {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.start-card h1 {
    font-size: 1.8rem;
    color: var(--color-jade);
    margin: 0 0 0.5rem 0;
    text-transform: uppercase;
}

.subtitle { color: #888; font-size: 0.9rem; margin-bottom: 2rem; }

/* Buttons inside cards */
.action-btn {
    width: 100%;
    padding: 15px;
    border-radius: 50px;
    font-size: 1rem;
    font-weight: bold;
    text-transform: uppercase;
    cursor: pointer;
    border: none;
    margin-top: 1rem;
    transition: transform 0.2s, background 0.2s;
}

.primary-btn {
    background: var(--color-jade);
    color: #fff;
}

.primary-btn:hover {
    background: #2e6b5f;
    transform: translateY(-2px);
}

.secondary-btn {
    background: transparent;
    color: #ccc;
    border: 1px solid #444;
}

.secondary-btn:hover {
    border-color: #fff;
    color: #fff;
}

/* Mode Toggles */
.mode-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 2rem;
}

.mode-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid #333;
    padding: 12px;
    color: #888;
    border-radius: 12px;
    cursor: pointer;
    font-weight: bold;
}

.mode-btn.active {
    border-color: var(--color-jade);
    color: #fff;
    background: rgba(58, 138, 123, 0.2);
}

/* =========================================
   4. RITUAL ELEMENTS (Intention & Reading)
   ========================================= */

/* Intention Input */
#intention-input {
    width: 100%;
    background: transparent;
    border: none;
    border-bottom: 2px solid #333;
    color: #fff;
    font-size: 1.2rem;
    text-align: center;
    padding: 10px;
    margin: 1.5rem 0;
    outline: none;
    font-family: 'Georgia', serif;
    font-style: italic;
}

#intention-input:focus {
    border-color: var(--color-jade);
}

/* Reading Display */
.oracle-glyph-large {
    width: 120px;
    height: 120px;
    margin: 0 auto 1.5rem auto;
    display: block;
    filter: drop-shadow(0 0 15px rgba(58, 138, 123, 0.5));
}

#oracle-title {
    font-size: 2rem;
    color: #fff;
    margin: 0;
}

#oracle-text {
    font-family: 'Georgia', serif;
    font-style: italic;
    color: #bbb;
    line-height: 1.5;
    margin: 1rem 0 2rem 0;
}

/* =========================================
   5. RESPONSIVENESS
   ========================================= */

/* Desktop: Vertical Sidebar */
@media (min-width: 769px) {
    #sidebar-overlay {
        left: 30px;
        top: 50%;
        transform: translateY(-50%);
        flex-direction: column;
    }
}

/* Mobile: Horizontal Tool bar at bottom */
@media (max-width: 768px) {
    #sidebar-overlay {
        left: 50%;
        bottom: 25px;
        transform: translateX(-50%);
        flex-direction: row;
    }

    .start-card {
        padding: 1.5rem;
    }

    .game-portal-header .game-title {
        display: none; /* Hide title on small phones */
    }
}

/* Sidebar help button specific style */
.tool-btn span {
    line-height: 1;
}

/* Link-style button on start card */
.text-link-btn:hover {
    color: var(--color-jade) !important;
}

/* Ensure reading card images are visible */
.oracle-glyph-large {
    background: rgba(255,255,255,0.05);
    border-radius: 50%;
    padding: 10px;
}

/* Utilities */
.hidden { display: none !important; }
.hidden-controls { opacity: 0; pointer-events: none; visibility: hidden; }