:root {
    --madura-red: #D32F2F;
    --madura-black: #212121;
    --madura-gold: #FFD700;
    --sand-color: #e6c288;
    --sky-color: #87CEEB;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--madura-black);
    color: white;
    overflow: hidden; /* Default, override di sejarah */
    touch-action: manipulation;
    user-select: none;
}

/* --- UI UTAMA & MENU --- */
#game-container {
    width: 100vw;
    height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: rgba(0, 0, 0, 0.95);
    z-index: 100;
    transition: opacity 0.5s;
    padding: 20px;
    box-sizing: border-box;
}

/* Background Menu Utama */
#menu-screen {
    background: linear-gradient(rgba(0, 0, 0, 0.6), rgba(0, 0, 0, 0.8)), 
                url('karapansapi.jpeg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

#menu-screen h1 { margin-top: 60px; margin-bottom: 10px; }
#tutorial-screen, #credits-screen, #topic-screen { justify-content: flex-start; padding-top: 40px; }
.hidden { opacity: 0; pointer-events: none; z-index: -1; }

h1 {
    color: var(--madura-gold);
    text-shadow: 2px 2px var(--madura-red);
    font-size: 2.5rem;
    margin-bottom: 15px;
    text-align: center;
}

h2 { color: var(--madura-gold); margin-bottom: 15px; }

/* CONTENT BOX & SCROLL */
.content-box {
    background: rgba(255, 255, 255, 0.1);
    padding: 20px;
    border-radius: 10px;
    border: 1px solid var(--madura-gold);
    max-width: 800px;
    width: 100%;
    margin-bottom: 20px;
    text-align: left;
}

.scrollable-content {
    overflow-y: auto;
    max-height: 60vh;
}
.scrollable-content::-webkit-scrollbar { width: 8px; }
.scrollable-content::-webkit-scrollbar-track { background: rgba(255, 255, 255, 0.1); }
.scrollable-content::-webkit-scrollbar-thumb { background: var(--madura-gold); border-radius: 4px; }

.content-box ul { list-style-type: none; padding: 0; }
.content-box li { margin-bottom: 10px; padding-left: 25px; position: relative; }
.content-box li::before { content: "🐂"; position: absolute; left: 0; font-size: 1rem; }
.content-box h3 { color: var(--madura-gold); border-bottom: 1px dashed rgba(255,255,255,0.3); padding-bottom: 5px; margin-top: 15px; }

/* BUTTONS */
.btn {
    background: var(--madura-red); color: white;
    border: 2px solid var(--madura-gold); padding: 12px 25px;
    font-size: 1.1rem; margin: 8px; cursor: pointer;
    border-radius: 8px; font-weight: bold; min-width: 200px;
    transition: transform 0.2s, background 0.2s;
}
.btn:hover { transform: scale(1.05); background: #b71c1c; }
.btn:active { transform: scale(0.95); }
.btn-blue { background: #1976D2; }
.btn-green { background: #388E3C; }
.btn-secondary { background: #616161; border-color: #9E9E9E; }
.btn-menu-small { min-width: 250px; font-size: 1rem; padding: 10px; margin: 5px; }

/* TOPIC GRID */
.topic-grid {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px;
    width: 100%; max-width: 600px;
}
.topic-btn {
    background: #424242; border: 2px solid var(--madura-gold);
    color: white; padding: 15px; font-size: 1rem; cursor: pointer;
    border-radius: 8px; display: flex; flex-direction: column;
    align-items: center; justify-content: center; min-height: 80px;
    transition: all 0.2s;
}
.topic-btn:hover { background: var(--madura-red); transform: translateY(-3px); }
.topic-icon { font-size: 1.5rem; margin-bottom: 5px; }

/* UTILITY BAR */
.utility-bar {
    position: absolute; top: 10px; right: 10px; display: flex; gap: 10px; z-index: 200;
}
.util-btn {
    background: rgba(0, 0, 0, 0.6); border: 2px solid var(--madura-gold);
    color: white; width: 45px; height: 45px; border-radius: 50%;
    font-size: 1.3rem; cursor: pointer; display: flex;
    justify-content: center; align-items: center; transition: background 0.2s;
}
.util-btn:hover { background: var(--madura-red); }

.dev-photo {
    width: 120px; height: 120px; border-radius: 50%;
    border: 4px solid var(--madura-gold); object-fit: cover;
    margin-bottom: 15px; background-color: #eee;
    display: block; margin-left: auto; margin-right: auto;
}

/* --- GAME VISUALS --- */
#race-track {
    flex: 1; background: linear-gradient(to bottom, var(--sky-color) 30%, var(--sand-color) 30%);
    position: relative; overflow: hidden; border-bottom: 5px solid #5d4037;
}
.crowd-layer {
    position: absolute; top: 24%; width: 100%; height: 40px;
    background-image: radial-gradient(circle at 50% 100%, #8D6E63 8px, transparent 8.5px),
                      radial-gradient(circle at 50% 100%, #6D4C41 6px, transparent 6.5px);
    background-size: 20px 25px, 15px 20px; background-position: 0 0, 7px -5px;
    background-repeat: repeat-x; opacity: 0.8;
}
.lane {
    position: absolute; width: 100%; height: 30%;
    display: flex; align-items: center; border-bottom: 2px dashed rgba(255,255,255,0.3);
}
#lane-red { bottom: 35%; }
#lane-blue { bottom: 5%; }
.finish-line {
    position: absolute; right: 5%; top: 30%; bottom: 0; width: 20px;
    background: repeating-linear-gradient(45deg, #000, #000 10px, #fff 10px, #fff 20px);
    z-index: 1;
}

/* SAPI ANIMATIONS */
.racer {
    position: absolute; left: 0; transition: left 0.5s ease-out;
    width: 180px; height: 100px; z-index: 10;
}
.racer-visual { position: relative; width: 100%; height: 100%; }
.bull-sprite { position: absolute; font-size: 3.5rem; line-height: 0.8; transform: scaleX(-1); top: 10px; }
.bull-back { left: 60px; z-index: 1; filter: brightness(0.7) drop-shadow(2px 4px 4px rgba(0,0,0,0.4)); top: 5px; }
.kaleles-svg { position: absolute; bottom: 10px; left: 0; width: 100%; height: 100%; z-index: 2; pointer-events: none; }
.bull-front { left: 55px; z-index: 3; filter: drop-shadow(2px 4px 4px rgba(0,0,0,0.4)); }
.jockey { font-size: 2rem; position: absolute; bottom: 25px; left: 5px; z-index: 4; transform: scaleX(-1); }
.racer-label {
    position: absolute; top: -20px; left: 40px;
    padding: 4px 8px; border-radius: 4px; font-size: 0.9rem; font-weight: bold;
    white-space: nowrap; z-index: 10; box-shadow: 1px 1px 3px rgba(0,0,0,0.5);
}
.dust {
    position: absolute; bottom: 10px; left: -10px; width: 40px; height: 20px;
    background: rgba(139, 69, 19, 0.4); border-radius: 50%; opacity: 0; z-index: 1;
}
.running .dust { animation: dust-anim 0.5s infinite; }
.running .racer-visual { animation: vibration 0.2s infinite; }
.running .bull-sprite { animation: gallop 0.4s infinite alternate; }

@keyframes dust-anim { 0% { transform: scale(0.5) translate(0, 0); opacity: 0.8; } 100% { transform: scale(2) translate(-40px, -15px); opacity: 0; } }
@keyframes gallop { 0% { transform: scaleX(-1) translateY(0); } 100% { transform: scaleX(-1) translateY(-3px); } }
@keyframes vibration { 0% { transform: translate(0, 0); } 25% { transform: translate(1px, 1px); } 50% { transform: translate(0, 0); } 75% { transform: translate(-1px, 1px); } 100% { transform: translate(0, 0); } }

/* --- CONTROL PANEL (SHARED) --- */
#control-panel {
    background: #333; display: flex; padding: 10px; gap: 10px;
    box-shadow: 0 -5px 15px rgba(0,0,0,0.5);
    height: auto; min-height: 260px;
}
.player-control {
    flex: 1; background: #424242; border-radius: 10px; padding: 10px;
    display: flex; flex-direction: column; align-items: center;
    border: 3px solid transparent; position: relative;
    justify-content: flex-start;
}
.player-control.red { border-color: var(--madura-red); }
.player-control.blue { border-color: #1976D2; }

.question-box {
    font-size: 1.8rem; font-weight: bold; color: white;
    background: rgba(0,0,0,0.3); padding: 10px 20px;
    border-radius: 5px; width: 90%; text-align: center; margin-bottom: 15px;
}

/* MODE ISIAN SINGKAT (GAME 1) */
.input-display {
    width: 90%; height: 45px; background: #fff; color: #333;
    font-family: 'Courier New', Courier, monospace; font-size: 1.5rem;
    font-weight: bold; display: flex; align-items: center; justify-content: flex-end;
    padding: 0 10px; box-sizing: border-box; border-radius: 4px;
    margin-bottom: 10px; border: 2px inset #ccc; overflow: hidden;
}
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; width: 100%; flex: 1; }
.key-btn {
    background: #616161; border: none; color: white;
    font-size: 1.2rem; font-weight: bold; border-radius: 4px;
    cursor: pointer; padding: 10px; touch-action: manipulation;
}
.key-btn:active { background: #9E9E9E; transform: translateY(2px); }
.key-c { background: #D32F2F; color: white; }
.key-bs { background: #F57C00; color: white; }
.key-ok { grid-column: span 3; background: #388E3C; font-size: 1.3rem; text-transform: uppercase; letter-spacing: 1px; }

/* MODE PILIHAN GANDA (GAME 2) */
.options-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; width: 100%; flex: 1; }
.opt-btn {
    background: #616161; border: none; color: white;
    padding: 15px; font-size: 1.2rem; border-radius: 5px;
    cursor: pointer; transition: background 0.1s;
}
.opt-btn:active { background: #757575; }
.opt-btn.correct { background: #4CAF50 !important; }
.opt-btn.wrong { background: #F44336 !important; }
.opt-btn:disabled {
    opacity: 0.5; cursor: not-allowed; background-color: #424242 !important;
    color: #888; transform: none !important; border-color: #555 !important;
}

.ai-overlay { 
    position: absolute; top:0; left:0; width: 100%; height: 100%; 
    background: rgba(0,0,0,0.7); z-index: 50; display: flex; flex-direction: column;
    justify-content: center; align-items: center; color: #90CAF9; font-style: italic; border-radius: 5px;
}
#hud {
    position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
    background: rgba(0,0,0,0.6); padding: 5px 15px; border-radius: 20px;
    display: flex; gap: 15px; font-size: 1rem; z-index: 50; white-space: nowrap;
}

@media (max-width: 768px) {
    #control-panel { height: auto; flex-direction: column; }
    .key-btn { font-size: 1rem; padding: 12px; }
    .question-box { font-size: 1.2rem; margin-bottom: 5px; }
    .input-display { height: 35px; font-size: 1.2rem; }
    h1 { font-size: 1.8rem; }
    .racer { width: 100px; height: 60px; }
    .bull-sprite { font-size: 2rem; }
    .jockey { font-size: 1.2rem; }
    .options-grid { grid-template-columns: repeat(4, 1fr); }
    .opt-btn { padding: 10px; font-size: 1rem; }
    .player-control { flex-direction: row; flex-wrap: wrap; }
    .keypad { max-width: 400px; margin: 0 auto; }
}
