/* ==========================================================================
   MathTricks - Shared Game Layout & Chrome
   Provides the uniform frame around every game (scoreboard, leaderboard
   sidebar, start/game-over overlays, mobile controls, ad slot).
   Each game page sets its own accent via --game-hue / --game-hue-2.
   ========================================================================== */

:root {
    --game-hue: #5ea2ff;      /* primary accent, per-game override */
    --game-hue-2: #a48bff;     /* secondary accent */
    --game-bg: rgba(14, 20, 40, 0.82);
}

#game-frame-container {
    display: flex;
    flex: 1;
    width: 100%;
    position: relative;
}

#game-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 20px 14px 24px;
    box-sizing: border-box;
    width: 100%;
    min-height: 0;
}

#main-container {
    width: 100%;
    max-width: 1080px;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: flex-start;
    gap: 22px;
    flex-wrap: wrap;
    margin: 0 auto;
    box-sizing: border-box;
}

/* ============ Game UI column ============ */

#game-ui {
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 100%;
    flex: 0 1 auto;
    position: relative;
}

/* Score board */
#score-board {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    box-sizing: border-box;
    padding: 12px 20px;
    margin-bottom: 12px;
    font-weight: 800;
    font-size: 1rem;
    color: var(--text-0);
    background: var(--panel);
    border: 1px solid var(--border-strong);
    border-radius: 14px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35), inset 0 0 0 1px rgba(255, 255, 255, 0.03);
}

#score-board .score-label { color: var(--text-2); font-weight: 700; }

#canvas-container {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    background: #05070f;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid var(--border);
    box-shadow: 0 18px 44px rgba(0, 0, 0, 0.55);
}

canvas {
    display: block;
    max-width: 100%;
    height: auto;
    touch-action: none;
}

/* ============ Mobile controls ============ */

#mobile-controls {
    display: flex;
    width: 100%;
    gap: 10px;
    margin-top: 12px;
}

.control-tile {
    flex: 1;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 800;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    background: rgba(255, 255, 255, 0.05);
    border: 1.5px solid var(--border-strong);
    border-radius: 14px;
    color: var(--game-hue);
    transition: background 0.15s, transform 0.1s;
}

.control-tile:active { background: rgba(255, 255, 255, 0.12); transform: scale(0.97); }

/* ============ Overlays (start / game over) ============ */

#start-screen,
#game-over {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 100;
    width: min(360px, 92%);
    box-sizing: border-box;
    padding: 28px;
    text-align: center;
    background: linear-gradient(180deg, rgba(20, 28, 54, 0.97), rgba(10, 14, 30, 0.97));
    border: 1px solid var(--border-strong);
    border-radius: 20px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6), 0 0 40px rgba(93, 162, 255, 0.18);
    backdrop-filter: blur(6px);
}

#start-screen h2,
#game-over h2 {
    margin: 0 0 8px;
    font-size: 1.5rem;
    font-weight: 800;
    background: var(--gradient);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

#start-screen p,
#game-over p { color: var(--text-1); margin: 6px 0 16px; }

#start-screen .btn,
#game-over .btn { margin: 4px; }

#start-screen button,
#game-over button {
    display: inline-block;
    min-width: 150px;
    padding: 12px 22px;
    margin: 6px 4px;
    border: none;
    border-radius: 999px;
    font-weight: 800;
    font-size: 0.95rem;
    cursor: pointer;
    background: var(--gradient);
    color: #0b1020;
    box-shadow: 0 6px 20px rgba(93, 162, 255, 0.35);
    transition: transform 0.2s, box-shadow 0.2s;
}

#start-screen button:hover,
#game-over button:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(164, 139, 255, 0.5); }

#player-name-input {
    width: 100%;
    box-sizing: border-box;
    padding: 12px 14px;
    margin: 8px 0;
    border-radius: 12px;
    border: 1px solid var(--border-strong);
    background: rgba(5, 9, 20, 0.8);
    color: var(--text-0);
    font-size: 1rem;
    text-align: center;
    outline: none;
}

#player-name-input:focus { border-color: var(--game-hue); box-shadow: 0 0 0 3px rgba(93, 162, 255, 0.18); }

#save-status { font-weight: 800; color: var(--green); min-height: 1.2em; }

/* ============ Highscore sidebar ============ */

#highscore-sidebar {
    width: clamp(260px, 30vw, 320px);
    max-width: 100%;
    flex: 0 0 clamp(260px, 30vw, 320px);
    padding: 20px;
    color: var(--text-0);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    backdrop-filter: blur(10px);
    box-shadow: var(--shadow);
    max-height: calc(100vh - 110px);
    overflow-y: auto;
}

#highscore-sidebar .record-box {
    text-align: center;
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px dashed var(--border-strong);
}

#highscore-sidebar .record-box h3 {
    margin: 0 0 6px;
    font-size: 0.75rem;
    letter-spacing: 1.4px;
    text-transform: uppercase;
    color: var(--text-2);
}

#highscore-sidebar .record-box .record-score {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--game-hue);
}

#highscore-sidebar h2 {
    text-align: center;
    margin: 0 0 14px;
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: 0.4px;
    color: var(--text-0);
}

#leaderboard-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#leaderboard-list li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 10px;
    border: 1px solid transparent;
    font-size: 0.92rem;
    transition: background 0.15s;
}

#leaderboard-list li:hover { background: rgba(255, 255, 255, 0.04); }

#leaderboard-list li:nth-child(1) { border-color: rgba(253, 196, 79, 0.45); background: rgba(253, 196, 79, 0.08); }
#leaderboard-list li:nth-child(2) { border-color: rgba(205, 215, 255, 0.3); background: rgba(205, 215, 255, 0.05); }
#leaderboard-list li:nth-child(3) { border-color: rgba(255, 122, 138, 0.3); background: rgba(224, 128, 84, 0.07); }

.lb-rank { min-width: 22px; font-weight: 800; color: var(--text-2); }
.lb-avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; border: 1.5px solid var(--game-hue); }
.lb-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 800; color: var(--gold); }

/* ============ Ad slot ============ */

.game-ad-container {
    width: 100%;
    max-width: 820px;
    margin: 26px auto 6px;
    display: flex;
    justify-content: center;
    min-height: 0;
    overflow: hidden;
}

ins.adsbygoogle[data-ad-status="unfilled"] { display: none !important; height: 0 !important; }

/* ============ Online players overlay ============ */

#online-players-container {
    position: fixed;
    bottom: 18px;
    right: 18px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    z-index: 1000;
    pointer-events: none;
}

@media (max-width: 760px) {
    #main-container { flex-direction: column; align-items: center; gap: 16px; }
    #highscore-sidebar { width: 100%; flex: none; max-height: none; }
    #game-over, #start-screen { width: 92%; }
}