/* style.css - Chibi Boat Race Edition */
/* style.css - Updated UI */

/* --- CẤU TRÚC CHUNG --- */
body {
    margin: 0;
    overflow: hidden;
    font-family: 'Nunito', sans-serif;
    background: #2c3e50;
}

/* SIDEBAR LAYOUT */
#control-panel {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: 300px; /* Rộng hơn xíu cho đẹp */
    background: #ffffff;
    z-index: 2000;
    display: flex;
    flex-direction: column; /* Xếp dọc */
    box-shadow: 5px 0 20px rgba(0, 0, 0, 0.15);
    border-right: 1px solid #eee;
}

/* Header đẹp hơn */
.panel-header {
    background: linear-gradient(135deg, #3498db, #2980b9);
    padding: 20px;
    color: white;
    text-align: center;
    box-shadow: 0 2px 10px rgba(52, 152, 219, 0.3);
}

.panel-header h2 { margin: 0; font-family: 'Fredoka One', cursive; font-size: 24px; }
.panel-subtitle { font-size: 14px; opacity: 0.9; margin-top: 5px; }

/* Phần nội dung ở giữa (có thể cuộn nếu màn hình thấp) */
.panel-scroll-content {
    flex: 1; /* Chiếm hết khoảng trống còn lại */
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Footer chứa nút Reset */
.panel-footer {
    padding: 15px 20px;
    background: #f8f9fa;
    border-top: 1px solid #eee;
}

/* FORM ELEMENTS */
textarea {
    width: 100%;
    height: 100px;
    padding: 10px;
    border-radius: 8px;
    border: 2px solid #e0e0e0;
    font-family: inherit;
    resize: vertical;
    box-sizing: border-box; /* Fix lỗi tràn lề */
    transition: border 0.3s;
}
textarea:focus { border-color: #3498db; outline: none; }

.settings-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

input[type="number"] {
    padding: 8px;
    border-radius: 5px;
    border: 2px solid #e0e0e0;
    width: 100%;
    box-sizing: border-box;
    text-align: center;
    font-weight: bold;
}

.toggles-container {
    background: #f8f9fa;
    padding: 10px;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-weight: 700;
    font-size: 14px;
    color: #555;
    margin-bottom: 5px;
    display: block;
}

.form-group.row {
    display: flex; justify-content: space-between; align-items: center; margin: 0;
}

/* BUTTONS */
.btn-group { display: flex; gap: 10px; margin-top: 5px; }

.btn {
    padding: 12px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    color: white;
    font-weight: 800;
    transition: all 0.2s;
    font-family: 'Nunito', sans-serif;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
}
.btn:active { transform: translateY(2px); box-shadow: none; }

.btn-prepare { background: #f39c12; flex: 1; }
.btn-start { background: #2ecc71; flex: 1; }
.btn-reset { 
    background: #e13b29; width: 100%; 
    box-shadow: none; 
    border: 2px solid #c0392b;
}
.btn-reset:hover { background: #c0392b; }

.btn-close-modal {
    background: #3498db;
    padding: 10px 30px;
    font-size: 18px;
    margin-top: 20px;
}

/* HISTORY SECTION - Cải tiến */
#winners-history-section {
    margin-top: 15px;
    border-top: 2px dashed #eee;
    padding-top: 15px;
    flex: 1; /* Giãn ra */
    display: flex;
    flex-direction: column;
    min-height: 150px; /* Chiều cao tối thiểu */
}

#winners-history-section h3 {
    font-size: 16px; color: #d35400;
    margin-bottom: 10px;
    display: flex; align-items: center; gap: 8px;
}

#winners-history-list {
    flex: 1;
    overflow-y: auto; /* Cuộn danh sách */
    padding-right: 5px;
}

/* Scrollbar đẹp */
#winners-history-list::-webkit-scrollbar { width: 6px; }
#winners-history-list::-webkit-scrollbar-track { background: #f1f1f1; }
#winners-history-list::-webkit-scrollbar-thumb { background: #bdc3c7; border-radius: 10px; }

.history-round {
    background: #fff;
    border: 1px solid #eee;
    border-left: 4px solid #3498db;
    border-radius: 6px;
    padding: 8px;
    margin-bottom: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.history-time {
    font-size: 11px; color: #999; margin-bottom: 4px; font-weight: bold;
    display: flex; justify-content: space-between;
}

.winner-chip {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #f0f8ff;
    padding: 4px 8px;
    border-radius: 4px;
    margin-top: 4px;
    font-size: 13px;
    font-weight: bold;
    color: #2c3e50;
}

.btn-readd {
    background: none; border: none;
    color: #3498db; cursor: pointer;
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 4px;
    transition: 0.2s;
}
.btn-readd:hover { background: #d6eaf8; text-decoration: underline; }

.empty-history { text-align: center; color: #bdc3c7; font-style: italic; font-size: 13px; margin-top: 20px; }

/* Switch Toggle (Giữ nguyên hoặc chỉnh nhẹ) */
.switch { position: relative; display: inline-block; width: 40px; height: 20px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #bdc3c7; transition: .4s; border-radius: 20px; }
.slider:before { position: absolute; content: ""; height: 14px; width: 14px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked+.slider { background-color: #2ecc71; }
input:checked+.slider:before { transform: translateX(20px); }



/* --- KHUNG CẢNH --- */
#race-track-container {
    position: fixed;
    left: 320px;
    right: 0;
    top: 0;
    bottom: 0;
    background: #3498db;
    left: 300px; /* Khớp với width sidebar */
    /* Màu nước biển tươi sáng */
    will-change: background-position;
}

#timer-display {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.9);
    border: 5px solid #2980b9;
    border-radius: 20px;
    padding: 8px 40px;
    font-family: 'Consolas', monospace;
    font-size: 45px;
    color: #2980b9;
    z-index: 1500;
}


/* static/css/race_style.css */

.modal-header {
    text-align: center;      /* Canh giữa văn bản */
    width: 100%;             /* Đảm bảo khung header chiếm hết chiều ngang */
    display: block;          /* Đảm bảo nó là khối để canh giữa hoạt động */
    
    /* Trang trí thêm cho đẹp (tùy chọn) */
    font-size: 32px;
    color: #e67e22;          /* Màu cam nổi bật */
    margin-bottom: 20px;     /* Cách đoạn kết quả bên dưới một chút */
    font-family: 'Fredoka One', cursive; /* Font chữ hoạt hình */
    text-transform: uppercase; /* Chữ in hoa */
}
/* Bờ cỏ */
.grass-bank {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 120px;
    background: #2ecc71;
    z-index: 50;
    border-bottom: 8px solid #27ae60;
}

.grass-edge {
    position: absolute;
    bottom: -15px;
    left: 0;
    width: 100%;
    height: 15px;
    background: repeating-linear-gradient(90deg, #2ecc71 0, #2ecc71 15px, transparent 15px, transparent 30px);
}

/* Mặt nước */
#world {
    position: absolute;
    top: 10px;
    left: 0;
    bottom: 0;
    width: 100%;
    background-image: radial-gradient(circle, rgba(255, 255, 255, 0.2) 2px, transparent 2.5px);
    background-size: 60px 60px;
    z-index: 40;
}

/* Vạch đích */
#finish-line {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 50px;
    left: -500px;
    background: repeating-linear-gradient(45deg, #e74c3c, #e74c3c 10px, #fff 10px, #fff 20px);
    border: 2px solid #fff;
    z-index: 90;
    box-shadow: 0 0 15px rgba(0, 0, 0, 0.3);
}

.finish-flag {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    background: #f1c40f;
    color: #d35400;
    padding: 5px 15px;
    font-weight: bold;
    border: 3px solid #d35400;
    border-radius: 8px;
    font-size: 18px;
    white-space: nowrap;
}

/* --- NHÂN VẬT & THUYỀN (CORE) --- */
.game-character-container {
    position: absolute;
    width: 180px;
    height: 160px;
    transform-origin: bottom center;
    will-change: transform;
    z-index: 100;
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    will-change: transform;
}

/* Tên thí sinh */
.player-name {
    position: absolute;
    top: -35px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    padding: 4px 12px;
    border-radius: 15px;
    font-size: 24px;
    font-weight: bold;
    white-space: nowrap;
    border: 1px solid rgba(255, 255, 255, 0.4);
    z-index: 200;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.game-character-container.is-leader .player-name {
    background: #e67e22;
    transform: translateX(-50%) scale(1.15);
    z-index: 2000;
    box-shadow: 0 0 15px #f1c40f;
    border-color: #f1c40f;
}

/* --- CẤU TRÚC THUYỀN 3D LAYER --- */
.boat-container {
    position: absolute;
    width: 100%;
    height: 100%;
    z-index: 10;
}

/* 1. Mạn sau & Đáy (Layer dưới cùng) */
.boat-hull {
    position: absolute;
    bottom: 25px;
    left: 10px;
    width: 160px;
    height: 50px;
    background: #6d4c41;
    /* Màu tối hơn mạn trước */
    border-radius: 10px 20px 60px 80px;
    z-index: 10;
    box-shadow: inset 0 5px 15px rgba(0, 0, 0, 0.3);
}

/* 2. Cột buồm (Layer giữa) */
.boat-sail {
    position: absolute;
    bottom: 30px;
    left: 95px;
    width: 6px;
    height: 110px;
    background: #5d4037;
    z-index: 20;
}

/* Cánh buồm trái */
.boat-sail::before {
    content: '';
    position: absolute;
    top: 10px;
    right: 5px;
    width: 60px;
    height: 85px;
    background: linear-gradient(135deg, #ffffff 0%, #ecf0f1 100%);
    clip-path: polygon(100% 0, 0 40%, 90% 100%);
    border-radius: 0 5px 0 20px;
    transform-origin: right center;
}

/* Cánh buồm phải */
.boat-sail::after {
    content: '';
    position: absolute;
    top: 18px;
    left: 5px;
    width: 40px;
    height: 70px;
    background: linear-gradient(135deg, #f7f7f7 0%, #bdc3c7 100%);
    clip-path: polygon(0 0, 100% 50%, 10% 100%);
    transform-origin: left center;
}

@keyframes sail-flap-left {
    0% {
        transform: scaleX(1) skewY(0deg);
    }

    100% {
        transform: scaleX(0.85) skewY(-3deg);
    }
}

@keyframes sail-flap-right {
    0% {
        transform: scaleX(1) skewY(0deg);
    }

    100% {
        transform: scaleX(0.9) skewY(3deg);
    }
}


/* 3. NGƯỜI LÁI CHIBI (Layer giữa - Ngồi trong thuyền) */
.rider-container {
    position: absolute;
    top: 25px;
    left: 20px;
    z-index: 10;
    /* Ngồi sau thân thuyền nhưng trước ghế */
}

.rider-head {
    width: 55px;
    height: 60px;
    background: radial-gradient(circle at 30% 30%, #ffdfc4, #e6b89c);
    border-radius: 50% 50% 45% 45%;
    position: relative;
    box-shadow: inset -2px -5px 10px rgba(0, 0, 0, 0.1);
}

/* Tóc */
.rider-hair-top {
    position: absolute;
    top: -5px;
    left: -5px;
    right: -5px;
    height: 35px;
    background: linear-gradient(to bottom, #5D4037, #3E2723);
    border-radius: 30px 30px 10px 10px;
}

.rider-hair-side {
    position: absolute;
    top: 20px;
    left: -8px;
    width: 15px;
    height: 30px;
    background: #3E2723;
    border-radius: 20px 0 10px 20px;
}

.rider-hair-side.right {
    left: auto;
    right: -8px;
    transform: scaleX(-1);
}

/* Mặt */
.rider-face-features::before,
.rider-face-features::after {
    content: '';
    position: absolute;
    top: 32px;
    left: 14px;
    width: 8px;
    height: 10px;
    background: #333;
    border-radius: 50%;
}

.rider-face-features::after {
    left: auto;
    right: 14px;
}

.rider-mouth {
    position: absolute;
    bottom: 12px;
    left: 22px;
    width: 12px;
    height: 5px;
    border-bottom: 3px solid #f45847;
    border-radius: 0 0 50% 50%;
}

.rider-torso {
    position: absolute;
    top: 55px;
    left: 5px;
    width: 45px;
    height: 50px;
    background: linear-gradient(135deg, #2ecc71, #27ae60);
    border-radius: 30% 30% 0 0;
    box-shadow: inset 0 -10px 20px rgba(0, 0, 0, 0.2);
}

@keyframes blink {

    0%,
    90%,
    100% {
        transform: scaleY(1);
    }

    95% {
        transform: scaleY(0.1);
    }
}


/* 4. Mạn trước (Layer trên cùng - Che người) */
.boat-hull-front {
    position: absolute;
    bottom: 25px;
    left: 10px;
    width: 160px;
    height: 40px;
    background: #8d6e63;
    /* Màu sáng hơn mạn sau */
    border-radius: 10px 20px 60px 80px;
    z-index: 30;
    /* Cao nhất để che người */
    clip-path: polygon(0 20%, 100% 0, 100% 100%, 0 100%);
    /* Cắt vát để lộ vai người */
    border-top: 2px solid rgba(255, 255, 255, 0.2);
}

.boat-bow-deco {
    position: absolute;
    bottom: 40px;
    right: 20px;
    width: 18px;
    height: 18px;
    background: #ecf0f1;
    border-radius: 50%;
    z-index: 31;
    border: 2px solid #95a5a6;
}

/* Hiệu ứng nước */
.water-wake-container {
    position: absolute;
    bottom: 20px;
    left: -20px;
    width: 80px;
    height: 30px;
    z-index: -1;
    opacity: 0.8;
    pointer-events: none;
}

.wake-ripple {
    position: absolute;
    top: 50%;
    right: 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(to left, rgba(255, 255, 255, 0.8), transparent);
}

.wake-ripple.left {
    transform: translateY(-50%) rotate(-15deg);
    animation: wakeFlow 0.8s infinite alternate;
}

.wake-ripple.right {
    transform: translateY(-50%) rotate(15deg);
    animation: wakeFlow 0.8s infinite alternate-reverse;
}

.water-reflection {
    position: absolute;
    bottom: 15px;
    left: 20px;
    width: 140px;
    height: 15px;
    background: rgba(0, 0, 0, 0.15);
    border-radius: 50%;
    animation: scale-reflection 2s infinite;
}

@keyframes wakeFlow {
    0% {
        opacity: 0.5;
        transform: translateY(-50%) rotate(var(--wake-angle)) scaleX(0.9);
    }

    100% {
        opacity: 0.9;
        transform: translateY(-50%) rotate(var(--wake-angle)) scaleX(1.1);
    }
}

.wake-ripple.left {
    --wake-angle: -15deg;
}

.wake-ripple.right {
    --wake-angle: 15deg;
}

@keyframes scale-reflection {

    0%,
    100% {
        transform: scaleX(1);
    }

    50% {
        transform: scaleX(0.85);
    }
}

/* CINEMATIC & MODAL */
.world-zoom-active {
    transform: scale(1.05);
    transform-origin: center center;
    transition: transform 1.5s cubic-bezier(0.25, 1, 0.5, 1);
}

#cinematic-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 999;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.cine-bar {
    width: 100%;
    height: 5%;
    background: black;
    transform: scaleY(0);
    transition: transform 0.5s ease-out;
    transform-origin: top;
}

.cine-bar.bottom {
    transform-origin: bottom;
}

.cinematic-active .cine-bar {
    transform: scaleY(1);
}


#cine-flash {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: white;
    opacity: 0;
    pointer-events: none;
    z-index: 1000;
    /* [QUAN TRỌNG] Ép GPU xử lý để không bị lag khi đè lên 170 con thuyền */
    will-change: opacity; 
    transform: translateZ(0); 
}

.flash-active {
    /* Giảm thời gian chớp xuống 0.3s (nhanh hơn) để đỡ che màn hình lâu */
    animation: flashAnim 0.3s ease-out forwards; 
}

@keyframes flashAnim {
    0% {
        opacity: 0.6;
    }

    100% {
        opacity: 0;
    }
}

#result-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 3000;
    justify-content: center;
    align-items: center;
}

.result-box {
    background: white;
    padding: 40px;
    border-radius: 15px;
    text-align: center;
    min-width: 350px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

/* RANKING */
.game-character-container.rank-1::after {
    content: '👑';
    position: absolute;
    top: -85px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 35px;
    animation: bounce 0.5s infinite alternate;
    z-index: 2000;
}

@keyframes bounce {
    from {
        transform: translateX(-50%) translateY(0);
    }

    to {
        transform: translateX(-50%) translateY(-10px);
    }
}

/* ... (Các phần cũ giữ nguyên) ... */

/* [MỚI] Nút Xuất Phát Nổi trên mặt nước */
#btn-floating-start {
    display: none; /* Ẩn mặc định, chỉ hiện khi đã Setup */
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 1000;
    
    padding: 20px 40px;
    font-size: 28px;
    font-family: 'Fredoka One', cursive;
    color: white;
    background: linear-gradient(45deg, #e67e22, #d35400);
    border: 4px solid white;
    border-radius: 50px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.3);
    cursor: pointer;
    animation: pulseBtn 1.5s infinite;
}

#btn-floating-start:hover {
    transform: translate(-50%, -55%) scale(1.05);
    background: linear-gradient(45deg, #f39c12, #e67e22);
}

@keyframes pulseBtn {
    0% { box-shadow: 0 0 0 0 rgba(230, 126, 34, 0.7); }
    70% { box-shadow: 0 0 0 20px rgba(230, 126, 34, 0); }
    100% { box-shadow: 0 0 0 0 rgba(230, 126, 34, 0); }
}

/* [MỚI] Màn hình đếm ngược */
#countdown-layer {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.4); /* Làm tối nền một chút cho kịch tính */
    z-index: 2500;
    justify-content: center;
    align-items: center;
}

#countdown-number {
    font-family: 'Fredoka One', cursive;
    font-size: 150px;
    color: #f1c40f;
    text-shadow: 5px 5px 0 #fb8006;
    animation: zoomCount 0.9s ease-out;
}

@keyframes zoomCount {
    0% { transform: scale(0.5); opacity: 0; }
    50% { transform: scale(1.2); opacity: 1; }
    100% { transform: scale(1); opacity: 1; }
}

/* Hiệu ứng chớp trắng */
#replay-flash {
    position: fixed;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background: white;
    opacity: 0;
    pointer-events: none;
    z-index: 20000;
}
.flash-trigger {
    animation: flashAnim 0.5s ease-out forwards;
}
@keyframes flashAnim {
    0% { opacity: 1; }
    100% { opacity: 0; }
}

/* Chữ REPLAY góc màn hình */
#replay-label {
    position: fixed;
    top: 30px; right: 30px;
    font-family: 'Arial Black', sans-serif;
    font-size: 24px;
    color: #e74c3c;
    text-transform: uppercase;
    letter-spacing: 2px;
    z-index: 15000;
    display: none; /* Mặc định ẩn */
}
.replay-blink {
    animation: blinkText 1s infinite;
}
@keyframes blinkText {
    0% { opacity: 1; }
    50% { opacity: 0; }
    100% { opacity: 1; }
}