/* === BASE STYLES & VARIABLES === */
:root {
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --danger-light: #fee2e2;
    --success: #10b981;
    --warning: #f59e0b;
    --bg: #f3f4f6;
    --card-bg: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --border: #e5e7eb;
}

* {
    box-sizing: border-box;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--bg);
    color: var(--text-main);
    margin: 0;
    padding: 15px;
    display: flex;
    justify-content: center;
}

.container {
    width: 100%;
    max-width: 500px;
}

.card {
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    padding: 20px;
    margin-bottom: 20px;
}

h1, h2, h3 {
    margin-top: 0;
    text-align: center;
    color: #111827;
}

p.subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 20px;
}

/* === FORM & INPUTS === */
.form-group { margin-bottom: 15px; }
label { display: block; margin-bottom: 5px; font-weight: 600; font-size: 14px; }

input[type="text"], input[type="number"], select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.2s;
}
input:focus, select:focus {
    outline: none;
    border-color: var(--primary);
}

button {
    width: 100%;
    padding: 14px;
    background-color: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}
button:active { background-color: var(--primary-hover); transform: scale(0.98); }
button.danger { background-color: var(--danger); margin-top: 10px; }
button.danger:active { background-color: var(--danger-hover); }
button.secondary { background-color: #64748b; margin-top: 10px; }
button.secondary:active { background-color: #475569; }

button.outline-dashed {
    background-color: #f3f4f6;
    color: #4b5563;
    border: 2px dashed #9ca3af;
    box-shadow: none;
}
button.outline-dashed:active { background-color: #e5e7eb; }

/* === GAME BOARD === */
.board-header {
    display: flex;
    background: rgba(249, 250, 251, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 8px;
    padding: 15px 0;
    margin-bottom: 15px;
    border: 1px solid var(--border);
    gap: 5px;
    
    position: -webkit-sticky;
    position: sticky;
    top: 10px;
    z-index: 100;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
}
.player-col {
    flex: 1;
    text-align: center;
    border-right: 1px solid var(--border);
    padding: 5px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    border-radius: 8px;
    transition: background-color 0.3s;
}
.player-col:last-child { border-right: none; }
.player-col.is-lowest { background-color: #fff1f2; border: 1px solid #fda4af; }

.player-avatar {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    object-fit: cover;
    margin-bottom: 8px;
    border: 2px solid #d1d5db;
    background-color: #e5e7eb;
}
.is-lowest .player-avatar { border-color: var(--danger); }

.player-name { 
    font-size: 13px; 
    font-weight: 700; 
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis; 
    max-width: 100%;
}
.player-score { font-size: 26px; font-weight: 800; margin: 4px 0; }
.score-change { font-size: 12px; height: 16px; font-weight: bold; margin-bottom: 4px; }

.badge-lowest {
    font-size: 10px;
    background: var(--danger);
    color: white;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: bold;
    margin-top: auto;
}

/* === HISTORY TABLE === */
.history-list {
    max-height: 250px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 15px;
    background: #fafafa;
}
.history-row {
    display: flex;
    padding: 8px 0;
    border-bottom: 1px solid #e5e7eb;
    font-size: 14px;
    align-items: center;
}
.history-row:last-child { border-bottom: none; }
.history-index { width: 40px; text-align: center; color: var(--text-muted); font-weight: 600; font-size: 12px; }

.history-val { 
    flex: 1; 
    text-align: center; 
    font-weight: 500; 
    padding: 4px;
    margin: 0 4px;
    border-radius: 6px;
    border: 1px solid transparent;
}
.history-val.is-lowest-history { background-color: var(--danger-light); border-color: #fca5a5; }

.text-green { color: var(--success); }
.text-red { color: var(--danger); }
.text-reset { font-size: 10px; color: var(--danger); font-weight: 800; display: block; line-height: 1; margin-top: 2px;}

/* === GAME INPUT === */
.input-row { display: flex; gap: 8px; margin-bottom: 15px; }
.input-row input { text-align: center; font-weight: bold; padding: 10px; font-size: 18px; width: 100%; }

.streak-banner {
    background: #fef3c7;
    color: #d97706;
    padding: 10px;
    border-radius: 8px;
    text-align: center;
    font-size: 13px;
    font-weight: bold;
    margin-bottom: 15px;
    border: 1px solid #fde68a;
    display: none;
}

.result-table { width: 100%; text-align: left; border-collapse: collapse; margin-bottom: 20px; }
.result-table th { padding: 12px 10px; background: #f9fafb; border-bottom: 2px solid var(--border); }
.result-table td { padding: 12px 10px; border-bottom: 1px solid var(--border); }
.highlight-win { background-color: #d1fae5; border: 2px solid var(--success) !important; }
.highlight-lose { background-color: #fee2e2; border: 2px solid var(--danger) !important; }

@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}
.animate-pop { animation: pop 0.4s ease-out; }

/* === CUSTOM MODAL === */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    display: none; /* hidden by default */
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 15px;
    backdrop-filter: blur(2px);
}
.modal-content {
    background: white;
    border-radius: 12px;
    padding: 20px;
    width: 100%;
    max-width: 350px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    animation: modalPop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    text-align: center;
}
@keyframes modalPop {
    0% { transform: scale(0.9); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}
.modal-avatar-container {
    margin-bottom: 15px;
    display: none; /* Hidden by default */
}
.modal-avatar-img {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 3px solid var(--danger);
    object-fit: cover;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.modal-content h3 { margin-top: 0; font-size: 18px; margin-bottom: 8px; }
.modal-content p { color: #4b5563; font-size: 14px; margin-bottom: 20px; line-height: 1.5; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }
.modal-actions button { width: auto; padding: 10px 18px; font-size: 14px; margin: 0; }
.modal-btn-cancel { background: #f3f4f6; color: #374151; }
.modal-btn-cancel:hover { background: #e5e7eb; }
.modal-btn-cancel:active { background: #d1d5db; }

/* === JOKER OVERLAY (KOBONG) === */
.joker-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.85);
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    z-index: 2000;
    backdrop-filter: blur(5px);
}
.joker-content {
    animation: modalPop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
}
.joker-content img {
    max-width: 90vw;
    max-height: 55vh;
    border-radius: 16px;
    box-shadow: none; 
}
.joker-content h2 {
    color: #ffffff;
    margin-top: 25px;
    font-size: 26px;
    font-weight: 900;
    text-shadow: 2px 2px 8px #000000;
    text-align: center;
}
.joker-btn {
    margin-top: 20px;
    background: var(--danger);
    width: 200px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
}
