:root {
    /* --- COLOR PALETTE --- */
    --bg-color: #1e1e1e;
    --panel-bg: #2a2a2a;
    --text-color: #f0f0f0;
    --text-muted: #bbbbbb;
    
    /* Brand Colors */
    --brand-orange: #f26522;
    --brand-orange-dark: #d85415;
    --ore-red: #d93a3a; 
    --accent-grey: #4d4d4d;
    --border-color: #4d4d4d;
    
    /* State Colors */
    --slot-empty: #333333;
    --slot-filled: var(--brand-orange);
    --danger-color: #d6493b; 
    --success-color: #4ecca3; 
    
    /* --- GEOMETRY CONSTANTS (FLUID) --- */
    /* Target: 7 blocks + 2 drills fitting in landscape height/width.
       Calculation: 100vmin / 8.5 units approx = 11.5vmin.
       This ensures the "Max Board" is zoomed in 100% without overflow.
    */
    --block-base: 11.5vmin; 
    --gap-base: 1.2vmin; /* Slightly tighter gap for better cohesion */
    --btn-base: 7.5vmin; /* Slightly smaller drills to prevent edge overlap */
    
    /* Backward compatibility */
    --block-size: var(--block-base); 
    --gap-size: var(--gap-base);
    --btn-size: var(--btn-base);
    
    --dynamic-cell-size: var(--block-base);
}

/* PORTRAIT OVERRIDE 
   Keep text/menus readable in portrait orientation
*/
@media (orientation: portrait) {
    :root {
        --block-base: 60px;
        --gap-base: 8px;
        --btn-base: 44px;
    }
}

/* =========================================
   GLOBAL & RESET
   ========================================= */
body {
    margin: 0; 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-color); 
    color: var(--text-color);
    display: flex; 
    justify-content: center; 
    align-items: center; 
    height: 100vh; 
    overflow: hidden; 
}

h1, h2, h3 { font-weight: 300; color: var(--brand-orange); margin-top: 0; }
.hidden { display: none !important; }

.main-container { 
    position: relative; z-index: 10; width: 100%; height: 100%;
    display: flex; justify-content: center; align-items: center;
}

#main-footer {
    position: absolute; bottom: 10px; width: 100%;
    text-align: center; font-size: 0.7rem; color: var(--text-muted);
    z-index: 5; pointer-events: none;
}
/* Added #main-footer button to restore pointer events and hover states */
#main-footer a, 
#main-footer button { 
    color: #888; 
    text-decoration: none; 
    margin: 0 10px; 
    cursor: pointer; 
    pointer-events: auto; 
}

#main-footer a:hover, 
#main-footer button:hover { 
    color: var(--brand-orange); 
}

/* =========================================
   UI COMPONENTS
   ========================================= */
input[type="text"], input[type="email"], select.full-width-input { 
    background-color: #1e1e1e; color: white;
    border: 1px solid var(--border-color); padding: 12px; 
    font-size: 1rem; border-radius: 5px; width: 100%; box-sizing: border-box;
    transition: border-color 0.2s;
    outline: none;
}
input:focus, select.full-width-input:focus { outline: none; border-color: var(--brand-orange); }

.light-text { font-size: 0.8rem; color: var(--text-muted); font-style: italic; }
.full-width-input { width: 100% !important; margin: 0; }
.checkbox-container { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; color: var(--text-muted); margin: 5px 0; justify-content: center; }
.checkbox-container a { color: var(--brand-orange); text-decoration: none; }
.error-msg { font-size: 0.8rem; color: var(--danger-color); margin-top: 5px; }

/* Standard Buttons */
.primary-btn, .confirm-btn {
    background-color: var(--brand-orange); color: #fff;
    padding: 12px 30px; border: none; border-radius: 5px;
    font-size: 1.1rem; font-weight: bold; cursor: pointer;
    transition: background-color 0.2s, transform 0.1s;
    text-transform: uppercase; letter-spacing: 1px;
}
.primary-btn:hover, .confirm-btn:hover { background-color: var(--brand-orange-dark); transform: translateY(-2px); }
.primary-btn:disabled, .confirm-btn:disabled { background: #555; cursor: not-allowed; transform: none; }

.text-btn { 
    background: none; border: none; color: var(--text-muted); 
    text-decoration: underline; cursor: pointer; font-size: 0.9rem; 
}
.text-btn:hover { color: var(--brand-orange); }

.small-btn {
    background: var(--accent-grey); border: none; color: #fff;
    font-size: 0.8rem; padding: 8px 12px; border-radius: 4px; cursor: pointer; white-space: nowrap;
}
.small-btn:hover { background: #666; }

/* Modal/Overlay Defaults */
.overlay {
    position: fixed; 
    top: 0; left: 0; width: 100%; 
    height: 100vh; height: 100dvh;
    background: rgba(30, 30, 30, 0.95); 
    display: flex; flex-direction: column; 
    align-items: center; justify-content: center; 
    z-index: 9999; /* Strong baseline z-index to sit above normal UI */
    overflow-y: auto; 
}

.modal-box { 
    background: var(--panel-bg); 
    padding: 30px; 
    border-radius: 8px; 
    box-shadow: 0 10px 30px rgba(0,0,0,0.5); 
    margin-top: 5vh; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    gap: 15px;
    max-width: 600px; 
    width: 90%; 
    border: 1px solid var(--border-color);
    
    /* NEW: Prevent vertical overflow */
    max-height: 90dvh; /* Leaves a bit of breathing room at the top/bottom */
    overflow-y: auto;
}

/* --- MVP Overrides: Hide Timed & Extended Modes --- */
#mode-timed-btn,
#end-game-blitz-btn,
#sort-extended-btn {
    display: none !important;
}

/* Centered Mode Select Container (Desktop Baseline) */
.mode-select {
    display: flex;
    flex-direction: row;       /* Aligns buttons side-by-side */
    flex-wrap: wrap;           /* Allows wrapping on narrow screens */
    justify-content: center;   /* Centers a single button perfectly */
    align-items: center;
    gap: 15px;                 /* Adds breathing room between future buttons */
    width: 100%;
    margin: 20px 0;
}

/* =========================================
  FROM HTML
  ========================================== */
/* --- Intro Screen Baseline Styling (Replaces Inline Styles) --- */
.landing-text-wrapper {
    max-width: 600px; 
    margin: 0 auto 30px auto; 
    line-height: 1.6;
}
.intro-welcome {
    font-size: 1.1rem; 
    margin-bottom: 15px;
}
.intro-description {
    color: #ccc;
}
.landing-play {
    font-size: 1.5rem; 
    padding: 15px 40px;
}
.user-name {
    color: var(--brand-orange); 
    font-weight: bold; 
    font-size: 1.2rem; 
    margin-bottom: 5px;
}
.switch-user-wrapper {
    margin-top: 0px;
}
#switch-user-btn {
    font-size: 0.8rem;
}

/* Button & Action Container Flexibility */
.mode-btn-manual {
    background-color: var(--accent-grey);
}
.mode-btn-timed {
    background-color: var(--brand-orange);
}
.btn-subtext {
    font-size: 0.8rem; 
    font-weight: normal; 
    display: block; /* Forces subtext to its own line mimicking the old <br> behavior in baseline view */
}

/* Flexible Wrappers */
.mode-select, .menu-secondary-actions {
    display: flex;
    flex-direction: row;       
    flex-wrap: wrap;           
    justify-content: center;   
    align-items: center;
    gap: 15px;                 
    width: 100%;
    margin: 20px 0;
}
#main-footer {
    margin-top: 30px;
}