/* ═══════════════ RESET & BASE ═══════════════ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #0d1117;
    color: #e6edf3;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* ═══════════════ SCREENS ═══════════════ */
.screen {
    position: fixed; inset: 0;
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1;
}
.screen.active { display: flex; }

.overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.75);
    display: flex; flex-direction: column;
    justify-content: center; align-items: center;
    gap: 16px;
    z-index: 200;
    backdrop-filter: blur(6px);
}
.overlay.hidden { display: none; }
.overlay h2 { font-size: 2.5rem; }
.pause-monkey {
    font-size: 1.15rem;
    color: #ffd700;
    background: rgba(255,255,255,0.08);
    padding: 8px 18px;
    border-radius: 20px;
    border: 1px solid rgba(255,215,0,0.3);
}

/* ═══════════════ MENU SCREEN ═══════════════ */
.menu-container {
    text-align: center;
    max-width: 680px;
    width: 92%;
    padding: 26px 24px;
    background: rgba(22, 27, 34, 0.94);
    border-radius: 24px;
    backdrop-filter: blur(14px);
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 20px 60px rgba(0,0,0,0.6);
    max-height: 94vh;
    overflow-y: auto;
}
.game-title {
    font-size: 2.2rem;
    line-height: 1.15;
    margin-bottom: 2px;
}
.subtitle-highlight { color: #ffd700; font-size: 1.4rem; }
.tagline { color: #8b949e; margin-bottom: 12px; font-size: 0.95rem; }

.menu-illustration { margin: 8px 0 12px; }
#menu-canvas {
    border-radius: 14px;
    background: linear-gradient(180deg, #4fc3f7 0%, #81c784 75%, #388e3c 100%);
    width: 100%; max-width: 380px; height: auto;
    box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

.story-box {
    background: rgba(255, 215, 0, 0.08);
    border: 1px dashed rgba(255, 215, 0, 0.35);
    border-radius: 12px;
    padding: 10px 14px;
    margin-bottom: 14px;
    font-size: 0.88rem;
    line-height: 1.4;
    color: #e6edf3;
}
.angel-text { color: #58a6ff; font-weight: 700; }
.devil-text { color: #f85149; font-weight: 700; }

.menu-row {
    display: flex; gap: 14px; justify-content: center; flex-wrap: wrap;
    margin-bottom: 14px;
}
.menu-section { flex: 1; min-width: 130px; }
.menu-label {
    display: block; font-weight: 700; margin-bottom: 6px;
    color: #8b949e; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 1.5px;
}
.menu-footer { margin-top: 10px; }

/* ═══════════════ BUTTONS ═══════════════ */
.btn {
    padding: 9px 18px;
    font-size: 0.9rem;
    font-weight: 600;
    border: 2px solid transparent;
    border-radius: 10px;
    cursor: pointer;
    background: rgba(255,255,255,0.08);
    color: #e6edf3;
    transition: all 0.15s;
    user-select: none;
}
.btn:hover { background: rgba(255,255,255,0.16); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }

.btn-primary { background: #238636; border-color: #238636; }
.btn-primary:hover { background: #2ea043; }
.btn-secondary { background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.1); }
.btn-danger { background: #da3633; border-color: #da3633; }
.btn-large { font-size: 1.15rem; padding: 12px 38px; margin-top: 4px; }
.btn-small { padding: 6px 14px; font-size: 0.78rem; }

.btn-group { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.btn-group .btn { padding: 7px 12px; font-size: 0.82rem; }
.btn-group .btn.active { background: #1f6feb; border-color: #1f6feb; }

.hint { font-size: 0.78rem; color: #6e7681; margin-top: 8px; }
.privacy-notice { font-size: 0.72rem; color: #484f58; margin-top: 3px; }
.best-score-display { margin-top: 6px; color: #ffd700; font-weight: 700; font-size: 0.95rem; }

/* ═══════════════ CAMERA SETUP ═══════════════ */
.camera-setup-container {
    text-align: center;
    max-width: 540px; width: 92%;
    padding: 30px 24px;
    background: rgba(22,27,34,0.92);
    border-radius: 24px;
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.08);
}
.camera-preview-wrapper {
    position: relative;
    width: 100%; max-width: 480px;
    margin: 14px auto;
    border-radius: 14px;
    overflow: hidden;
    background: #000;
    aspect-ratio: 4/3;
    border: 2px solid rgba(255,255,255,0.1);
}
.camera-preview-wrapper video {
    width: 100%; height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}
.tracking-status { font-size: 1.05rem; font-weight: 600; margin: 12px 0; min-height: 1.4em; }
.camera-buttons { display: flex; gap: 10px; justify-content: center; margin: 12px 0; }

/* ═══════════════ GAME LAYOUT (3-column) ═══════════════ */
.game-layout {
    display: flex;
    width: 100vw;
    height: 100vh;
    background: #0d1117;
}

/* Side panels */
.panel {
    width: 230px;
    min-width: 210px;
    flex-shrink: 0;
    background: rgba(22, 27, 34, 0.96);
    border: 1px solid rgba(255,255,255,0.06);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 0;
}
.panel-left { border-right: 1px solid rgba(255,255,255,0.08); }
.panel-right { border-left: 1px solid rgba(255,255,255,0.08); }

.panel-header {
    background: rgba(255,255,255,0.04);
    padding: 10px 14px;
    font-weight: 700;
    font-size: 0.9rem;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    letter-spacing: 0.5px;
}

/* Monkey speech section (left panel) */
.monkey-speech-section {
    padding: 10px 12px;
    background: rgba(255, 193, 7, 0.06);
    border-bottom: 1px solid rgba(255, 193, 7, 0.15);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}
.monkey-avatar {
    font-size: 2.2rem;
    animation: monkeyBounce 2s infinite ease-in-out;
}
@keyframes monkeyBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px) scale(1.05); }
}
.speech-bubble {
    position: relative;
    background: #21262d;
    border: 1px solid rgba(255, 215, 0, 0.4);
    border-radius: 12px;
    padding: 8px 10px;
    font-size: 0.8rem;
    color: #ffd700;
    font-weight: 600;
    text-align: center;
    line-height: 1.35;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
}
.speech-bubble::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 0 6px 6px 6px;
    border-style: solid;
    border-color: transparent transparent #21262d transparent;
}

/* Guide (left panel) */
.guide-section { padding: 8px 12px; border-bottom: 1px solid rgba(255,255,255,0.04); }
.guide-title {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 5px;
}
.guide-title.good { color: #3fb950; }
.guide-title.bad { color: #f85149; }

.guide-item {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 2.5px 0;
    font-size: 0.8rem;
    color: #c9d1d9;
}
.guide-item b { color: #3fb950; margin-left: auto; font-size: 0.75rem; }
.guide-item.danger b { color: #f85149; }
.guide-item.golden { background: rgba(255,215,0,0.08); border-radius: 6px; padding: 2px 5px; }
.guide-item.golden b { color: #ffd700; }
.guide-item.bonus { background: rgba(88,166,255,0.08); border-radius: 6px; padding: 2px 5px; }
.guide-item.bonus b { color: #58a6ff; }
.guide-emoji { font-size: 1.2rem; width: 24px; text-align: center; flex-shrink: 0; }

.guide-controls { font-size: 0.8rem; color: #8b949e; margin-top: 3px; }
.controls-section .guide-title { color: #8b949e; }

/* Center game area */
.game-center {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 8px;
    background: #161b22;
    position: relative;
    overflow: hidden;
    padding: 8px 12px;
}

#game-canvas {
    display: block;
    border-radius: 8px;
    box-shadow: 0 0 35px rgba(0,0,0,0.6);
}

/* Dedicated Dialogue Box Below the Screen */
.monkey-dialogue-bar {
    width: 96%;
    max-width: 680px;
    background: rgba(22, 27, 34, 0.94);
    border: 1.5px solid rgba(255, 215, 0, 0.4);
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.45);
    border-radius: 12px;
    padding: 7px 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    transition: all 0.25s ease;
    flex-shrink: 0;
}
.monkey-dialogue-bar.pulse {
    border-color: #ffd700;
    background: rgba(255, 215, 0, 0.12);
    box-shadow: 0 0 20px rgba(255, 215, 0, 0.4);
    transform: scale(1.01);
}
.dialogue-monkey-icon {
    font-size: 1.5rem;
    animation: monkeyIconBounce 2s infinite ease-in-out;
    flex-shrink: 0;
}
@keyframes monkeyIconBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px) scale(1.1); }
}
.dialogue-bar-text {
    font-size: 0.95rem;
    font-weight: 700;
    color: #ffd700;
    text-align: center;
    line-height: 1.35;
    letter-spacing: 0.3px;
}

/* Right panel */
.live-cam-wrapper {
    padding: 8px 12px;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    text-align: center;
}
.live-cam-label {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #8b949e;
    margin-bottom: 4px;
}
.live-cam-wrapper video {
    width: 100%;
    border-radius: 8px;
    background: #000;
    aspect-ratio: 4/3;
    object-fit: cover;
    transform: scaleX(-1);
    border: 1px solid rgba(255,255,255,0.08);
}
.cam-status {
    font-size: 0.68rem;
    color: #6e7681;
    margin-top: 3px;
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 5px;
    padding: 8px 10px;
}
.stat-box {
    background: rgba(255,255,255,0.04);
    border-radius: 8px;
    padding: 6px 4px;
    text-align: center;
    border: 1px solid rgba(255,255,255,0.04);
}
.stat-box .stat-label {
    font-size: 0.6rem;
    font-weight: 700;
    color: #6e7681;
    text-transform: uppercase;
    letter-spacing: 1px;
}
.stat-box .stat-val {
    font-size: 1.1rem;
    font-weight: 800;
    margin-top: 1px;
    font-variant-numeric: tabular-nums;
}
.timer-box { grid-column: span 2; }
.timer-box .stat-val { font-size: 1.5rem; color: #58a6ff; }
.best-box .stat-val { color: #ffd700; }
.stat-mode { font-size: 0.85rem !important; color: #8b949e; }

/* In-game Leaderboard (Right Panel) */
.leaderboard-panel {
    padding: 8px 10px;
    border-top: 1px solid rgba(255,255,255,0.06);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 120px;
}
.lb-title-small {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #ffd700;
    margin-bottom: 6px;
    text-align: center;
}
.lb-list-compact {
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    max-height: 140px;
}
.lb-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255,255,255,0.04);
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-variant-numeric: tabular-nums;
}
.lb-row.highlight {
    background: rgba(255,215,0,0.15);
    border: 1px solid rgba(255,215,0,0.4);
    font-weight: 700;
}
.lb-left {
    display: flex;
    align-items: center;
    gap: 6px;
}
.lb-medal { font-size: 0.85rem; width: 16px; text-align: center; }
.lb-player { color: #c9d1d9; font-weight: 600; max-width: 60px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-mode-tag { font-size: 0.65rem; color: #8b949e; }
.lb-score-val { color: #3fb950; font-weight: 700; }

.panel-buttons {
    display: flex;
    gap: 6px;
    padding: 8px 10px;
    border-top: 1px solid rgba(255,255,255,0.06);
}
.panel-buttons .btn { flex: 1; }

/* ═══════════════ LEADERBOARD SECTION (Menu & Game Over) ═══════════════ */
.leaderboard-section {
    margin-top: 16px;
    background: rgba(255,255,255,0.03);
    border-radius: 14px;
    padding: 12px 14px;
    border: 1px solid rgba(255,255,255,0.06);
}
.lb-title {
    font-size: 0.95rem;
    color: #ffd700;
    margin-bottom: 8px;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.lb-list {
    display: flex;
    flex-direction: column;
    gap: 5px;
    max-height: 180px;
    overflow-y: auto;
}
.lb-empty {
    font-size: 0.82rem;
    color: #6e7681;
    padding: 8px;
}
.lb-full-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255,255,255,0.04);
    padding: 6px 12px;
    border-radius: 8px;
    font-size: 0.82rem;
}
.lb-full-row.rank-1 { background: rgba(255,215,0,0.12); border: 1px solid rgba(255,215,0,0.3); }
.lb-full-row.rank-2 { background: rgba(192,192,192,0.1); }
.lb-full-row.rank-3 { background: rgba(205,127,50,0.1); }

/* ═══════════════ GAME OVER ═══════════════ */
.gameover-container {
    text-align: center;
    max-width: 540px; width: 92%;
    padding: 28px 24px;
    background: rgba(22,27,34,0.96);
    border-radius: 24px;
    backdrop-filter: blur(14px);
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 20px 60px rgba(0,0,0,0.6);
    max-height: 94vh;
    overflow-y: auto;
}
.gameover-monkey {
    font-size: 3.5rem;
    margin-bottom: 4px;
    animation: monkeyReact 1.5s infinite alternate ease-in-out;
}
@keyframes monkeyReact {
    0% { transform: scale(0.95) rotate(-3deg); }
    100% { transform: scale(1.05) rotate(3deg); }
}
.gameover-monkey-speech {
    font-size: 1.15rem;
    font-weight: 700;
    color: #ffd700;
    background: rgba(255,215,0,0.1);
    border: 1px solid rgba(255,215,0,0.3);
    border-radius: 14px;
    padding: 8px 16px;
    margin: 8px auto 12px;
    display: inline-block;
    max-width: 90%;
    line-height: 1.35;
}
.gameover-message { font-size: 0.95rem; color: #8b949e; margin-bottom: 14px; }

.gameover-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 14px 0;
}
.gameover-stats .stat {
    background: rgba(255,255,255,0.05);
    border-radius: 10px;
    padding: 10px 6px;
    border: 1px solid rgba(255,255,255,0.04);
}
.gameover-stats .stat-label { display: block; font-size: 0.65rem; color: #6e7681; text-transform: uppercase; letter-spacing: 1px; }
.gameover-stats .stat-value { display: block; font-size: 1.35rem; font-weight: 800; margin-top: 2px; }
.gameover-buttons { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

/* ═══════════════ RESPONSIVE ═══════════════ */
@media (max-width: 920px) {
    .panel { width: 190px; min-width: 175px; }
    .guide-emoji { font-size: 1.05rem; }
}
@media (max-width: 720px) {
    .panel-left { display: none; }
    .panel-right { width: 175px; min-width: 160px; }
}
