/* --- Tlaolli: Maize Sortilege Style --- */

/* 1. DEFINE VARIABLES (Crucial for Napkin Colors) */
:root {
    --bg-color: #1a1a1a;
    /* Dark void */
    --napkin-color: #f4f1ea;
    /* Linen/Cloth color (Beige) */
    --napkin-texture: #e8e4db;
    /* Texture color (Darker Beige) */

    --corn-alive: #ffcc00;
    /* Bright Gold */
    --corn-dead: #5c5c5c;
    /* Grey stone */
    --corn-selected: #ff4500;
    /* Red highlight */

    --font-ritual: 'Georgia', 'Times New Roman', serif;
    --font-ui: 'Verdana', sans-serif;
    --jade: #3A8A7B;
    --red: #cb294f;
}

body.tlaolli-portal-body {
    background-color: var(--bg-color);
    margin: 0;
    overflow: hidden;
    /* Use dvh to account for the browser's UI bars appearing/disappearing */
    height: 100vh; 
    height: 100dvh; 
    display: flex;
    flex-direction: column;
}

.game-portal-header {
    background: #111;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #333;
    color: #fff;
    z-index: 1000;
}

.back-btn {
    color: #d4a017;
    text-decoration: none;
    font-weight: bold;
}

.game-portal-main {
    flex-grow: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    /* Full bleed for overlay effect */
    position: relative;
    width: 100%;
    min-height: 0;
    /* Allow main to fit within the flex body */
    /* height: 100%; */
    /* Removed as per instruction */
    overflow: hidden;
}

/* --- GAME CONTAINER (The Napkin) --- */


/* --- HEADER HUD --- */
#tlaolli-game-container h1,
#tlaolli-game-container h2,
#tlaolli-game-container h3,
#tlaolli-game-container button {
    margin-top: 0 !important;
    margin-bottom: 0 !important;
}

/* --- GAME CONTAINER --- */
#tlaolli-game-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column; /* This stacks Header -> Canvas -> Footer */
    overflow: hidden;
    background-color: var(--napkin-color);
}

/* --- HEADER HUD --- */
.t-hud-panel {
    position: relative; /* Changed from absolute */
    width: 100%;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    padding: 10px 1rem;
    background: rgba(0, 0, 0, 0.05);
    border-bottom: 1px solid rgba(139, 69, 19, 0.2);
    z-index: 10;
}

/* --- MAIN CANVAS AREA --- */
canvas#tlaolliCanvas {
    position: relative; /* Changed from absolute */
    flex: 1; /* Tells canvas to take up all remaining space */
    width: 100%;
    height: auto;
    min-height: 0;
    object-fit: contain;
    background-image: radial-gradient(circle, var(--napkin-color) 40%, var(--napkin-texture) 100%);
    display: block;
}

/* --- BOTTOM CONTROLS --- */
.t-control-panel {
    position: relative;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    background: rgba(0, 0, 0, 0.05);
    border-top: 1px solid rgba(139, 69, 19, 0.2);
    
    /* Standard padding for PC */
    padding: 20px 10px;

    /* The Fix: Adds extra space ONLY on phones with bottom bars */
    padding-bottom: calc(20px + env(safe-area-inset-bottom)); 
    
    z-index: 10;
}


/* Header Buttons */
.header-icon-btn {
    background: rgba(255, 255, 255, 0.4);
    /* Subtle backing for visibility */
    border: 1px solid rgba(0, 0, 0, 0.1);
    color: #555;
    /* Darker for contrast on napking */
    font-size: 1.5rem;
    cursor: pointer;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    padding: 0 !important;
    margin: 0 !important;
    backdrop-filter: blur(4px);
}

.header-icon-btn:hover {
    background: rgba(255, 255, 255, 0.8);
    color: #d4a017;
    /* Gold */
    transform: scale(1.1);
}

/* --- FRANGIPANI SCORE DISPLAY --- */
.t-score-wrapper {
    position: relative;
    width: 200px;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 11;
    pointer-events: auto;
    /* Allow hovering if needed */
    margin: 0 auto !important;
    transform: translateY(0);
}

#t-flowers-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    pointer-events: none;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.4));
}

.t-score-text-overlay {
    position: relative;
    z-index: 2;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    margin-top: 4px;
    padding: 0 !important;
}

.t-label {
    font-family: var(--font-ui);
    font-size: 0.7rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    font-weight: 900;
    color: #f9f99d;
    /* Pale Yellow */
    margin-bottom: 2px !important;
    text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000;
}

#t-score-value {
    font-family: var(--font-ritual);
    font-size: 2.8rem;
    line-height: 0.9;
    font-weight: bold;
    color: #ffffff;
    margin: 0 !important;
    text-shadow: 2px 2px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 0 4px 10px rgba(0, 0, 0, 0.8);
}

.primary-btn,
.secondary-btn,
.action-btn {
    border: none;
    padding: 12px 24px;
    color: #fff;
    border-radius: 30px;
    cursor: pointer;
    font-weight: bold;
    font-size: 1rem;
    white-space: nowrap;
    transition: transform 0.1s, box-shadow 0.2s;
    margin: 0 !important;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
}

.primary-btn {
    background: #d4a017;
}

.secondary-btn {
    background: #78909c;
}

.action-btn {
    background: var(--jade);
}

.primary-btn:hover,
.secondary-btn:hover,
.action-btn:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

.primary-btn:disabled,
.secondary-btn:disabled,
.action-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    filter: none;
    transform: none;
    box-shadow: none;
}

/* --- MODALS (Taxonomy, Start, End) --- */
.overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
}

.start-card {
    background: #fff;
    padding: 2.5rem;
    border-radius: 15px;
    text-align: center;
    max-width: 400px;
    color: #1a1a1a;
}

.start-card h1 {
    color: #d4a017 !important;
    margin-top: 0;
}

.start-card h2 {
    color: #008b58 !important;
    margin-top: 0 !important;
}

.start-card .subtitle {
    color: #555;
    margin-bottom: 1.5rem;
}

.inst-list {
    color: #333;
    text-align: left;
    margin-bottom: 1.5rem;
}

.modal-controls {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 20px;
}

.canvas-wrapper {
    background: #000;
    border: 2px solid #333;
    border-radius: 8px;
    margin: 15px 0;
    overflow: hidden;
}

#constellationCanvas {
    width: 100%;
    height: auto;
    max-height: 50vh;
}

#t-taxonomy-modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.t-taxonomy-card {
    background: transparent;
    border: none;
    padding: 15px;
    width: auto;
    max-height: 90vh;
    text-align: center;
    animation: cardPopIn 0.4s ease forwards;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.t-taxonomy-card canvas {
    background: transparent;
    border: none;
    margin: 10px auto;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 45vh;
}

.t-card-title {
    color: #ffdb4d;
    font-family: var(--font-ritual);
    font-size: 2.0rem;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.9);
}

.t-card-subtitle {
    color: #eee;
    font-size: 1.0rem;
    font-style: italic;
    margin-bottom: 8px;
}

.t-card-points {
    color: var(--jade);
    font-weight: bold;
    font-size: 1.5rem;
    margin-top: 5px;
}

.t-card-hint {
    font-size: 0.8rem;
    color: #ccc;
    margin-top: 10px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

@keyframes cardPopIn {
    0% {
        transform: scale(0.5);
        opacity: 0;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes flyToScore {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    100% {
        transform: scale(0.4) translateY(-400px);
        opacity: 0;
    }
}

.fly-away-animation {
    animation: flyToScore 0.5s ease-in forwards !important;
    pointer-events: none;
}

.hidden {
    display: none !important;
}

/* --- RESPONSIVE TWEAKS --- */
@media (max-width: 600px) {
    .t-hud-panel {
        padding: 5px 10px !important;
    }

    .t-score-wrapper {
        transform: scale(0.85);
    }

    .t-control-panel {
        padding: 20px 10px;
        padding-bottom: max(40px, env(safe-area-inset-bottom));
        gap: 10px;
    }

    .primary-btn,
    .secondary-btn,
    .action-btn {
        padding: 12px 24px;
        font-size: 0.9rem;
        flex: 1;
        /* Stretch buttons on small screens */
    }

    /* Ensure modals don't clip */
    .start-card {
        width: 90%;
        padding: 1.5rem;
    }
}