@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;500;700;900&display=swap');

:root{
    --bg: #0A0519;
    --card: #0F0B1A;
    --panel: #17122A;
    --accent-x: #1892EA;
    --accent-o: #A737FF;
    --muted: rgba(255,255,255,0.12);
    --gold: #FFD700;
    --cell-size: 90px;
    --text-primary: #fff;
    --text-secondary: rgba(255,255,255,0.9);
}

/* light mode */
:root[data-theme="light"] {
    --bg: #F5F5F7;
    --card: #FFFFFF;
    --panel: #E8E8EB;
    --accent-x: #0066FF;
    --accent-o: #9933FF;
    --muted: rgba(0,0,0,0.08);
    --gold: #FF9500;
    --text-primary: #1a1a1a;
    --text-secondary: rgba(0,0,0,0.85);
}

*{box-sizing:border-box}
html,body{height:100%}
body{
    margin:0;
    font-family:'Poppins',system-ui,Segoe UI,Roboto,Helvetica,Arial,sans-serif;
    background:var(--bg);
    color:var(--text-primary);
    -webkit-font-smoothing:antialiased;
    -moz-osx-font-smoothing:grayscale;
    transition: background-color 0.3s ease, color 0.3s ease;
}

main{
    min-height:100vh;
    display:flex;
    flex-direction:column;
    align-items:center;
    gap:18px;
    padding:28px 20px;
}

/* Header */
#header{
    width:100%;
    max-width:980px;
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:18px;
    position:relative;
}

/* theme toggle button */
.theme-toggle {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 24px;
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 8px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    background: var(--muted);
    transform: scale(1.1);
}

.theme-icon {
    display: inline-block;
    transition: transform 0.3s ease;
}

.theme-toggle:active .theme-icon {
    transform: rotate(20deg);
}

.score-box{
    display:flex;
    align-items:center;
    gap:12px;
}

.player{
    background:linear-gradient(180deg, rgba(23,18,42,0.7), rgba(17,12,32,0.6));
    padding:10px 12px;
    border-radius:12px;
    display:flex;
    gap:10px;
    align-items:center;
    border:2px solid transparent;
    min-width:120px;
    justify-content:space-between;
    transition:transform .12s ease, box-shadow .12s ease, border-color .12s ease;
}

:root[data-theme="light"] .player {
    background: linear-gradient(180deg, rgba(232,232,235,0.9), rgba(224,224,228,0.8));
}

.player .label{ font-weight:700; font-size:14px; opacity:0.95; }
.player .score{
    background:var(--panel);
    padding:6px 10px;
    border-radius:10px;
    font-weight:700;
    font-size:14px;
    color:var(--text-primary);
    border:1px solid rgba(255,255,255,0.03);
}

:root[data-theme="light"] .player .score {
    border-color: rgba(0,0,0,0.08);
}

/* active player highlight */
.player.player-active{
    box-shadow:0 6px 20px rgba(24,146,234,0.08);
    transform:translateY(-2px);
    border-color: rgba(255,255,255,0.06);
}

:root[data-theme="light"] .player.player-active {
    box-shadow: 0 6px 20px rgba(0,102,255,0.12);
    border-color: rgba(0,0,0,0.1);
}

/* X/O color hints */
#xPlayerDisplay .label::after{ content: ' (X)'; color:var(--accent-x); font-weight:600; margin-left:6px; opacity:0.9; font-size:12px;}
#oPlayerDisplay .label::after{ content: ' (O)'; color:var(--accent-o); font-weight:600; margin-left:6px; opacity:0.9; font-size:12px;}

/* Title center block */
.title-wrap{
    flex:1;
    text-align:center;
}
#titleHeader{
    margin:0;
    font-size:20px;
    letter-spacing:0.6px;
    font-weight:700;
    color:var(--text-primary);
}
.round-info{ font-size:13px; opacity:0.85; margin-top:6px; color:var(--text-secondary); }

/* Board wrapper */
#boardsWrap{
    width:100%;
    max-width:920px;
    display:flex;
    justify-content:center;
}
#board{
    background:linear-gradient(180deg, rgba(23,18,42,0.35), rgba(17,12,32,0.2));
    padding:18px;
    border-radius:14px;
    box-shadow:0 10px 30px rgba(4,2,8,0.6), inset 0 1px 0 rgba(255,255,255,0.02);
    display:grid;
    gap:10px;
    justify-content:center;
    align-content:center;
    width:100%;
    max-width:720px;
    grid-template-columns: repeat(11, var(--cell-size));
}

:root[data-theme="light"] #board {
    background: linear-gradient(180deg, rgba(248,248,250,0.9), rgba(240,240,244,0.8));
    box-shadow: 0 10px 30px rgba(0,0,0,0.08), inset 0 1px 0 rgba(0,0,0,0.02);
}

/* Cell */
#board .cell{
    width:var(--cell-size);
    height:var(--cell-size);
    background:var(--panel);
    border-radius:12px;
    display:flex;
    align-items:center;
    justify-content:center;
    font-size:calc(var(--cell-size) * 0.48);
    font-weight:900;
    color:var(--text-primary);
    cursor:pointer;
    user-select:none;
    position:relative;
    border:2px solid rgba(255,255,255,0.02);
    transition:transform .08s ease, background .12s ease, box-shadow .12s ease;
}

:root[data-theme="light"] #board .cell {
    background: var(--panel);
    border-color: rgba(0,0,0,0.06);
}

/* hover subtle lift */
#board .cell:hover{
    transform:translateY(-4px);
    box-shadow:0 8px 18px rgba(0,0,0,0.45);
    background:linear-gradient(180deg, #201733, #17122A);
}

:root[data-theme="light"] #board .cell:hover {
    box-shadow: 0 8px 18px rgba(0,0,0,0.12);
    background: #DDD;
}

/* occupied slightly different */
#board .cell[data-filled="true"]{
    cursor:default;
    opacity:0.98;
}

/* winning visuals */
#board .cell.win{ border-color: var(--gold); background: linear-gradient(90deg, rgba(255,215,0,0.06), rgba(255,215,0,0.02)); }
#board .cell.win::after{
    content:'';
    position:absolute;
    left:50%;
    top:50%;
    width:calc(100% - 20%);
    height:calc(max(4px, var(--cell-size) * 0.12));
    background:linear-gradient(90deg, rgba(255,215,0,0.98), rgba(255,215,0,0.9));
    transform-origin:center;
    transform:translate(-50%, -50%) rotate(0deg);
    border-radius:6px;
    z-index:2;
}
#board .cell.win.h::after{ transform:translate(-50%, -50%) rotate(0deg); }
#board .cell.win.v::after{ transform:translate(-50%, -50%) rotate(90deg); }
#board .cell.win.d1::after{ transform:translate(-50%, -50%) rotate(45deg); }
#board .cell.win.d2::after{ transform:translate(-50%, -50%) rotate(-45deg); }

/* instructions */
.instructions{
    max-width:760px;
    background: rgba(255,255,255,0.02);
    padding:10px 14px;
    border-radius:10px;
    font-size:13px;
    color:var(--text-secondary);
    text-align:center;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.01);
}

:root[data-theme="light"] .instructions {
    background: rgba(0,0,0,0.02);
    box-shadow: inset 0 1px 0 rgba(0,0,0,0.02);
    color: var(--text-secondary);
}

/* controls */
.controls{ display:flex; gap:12px; }
.btn{
    padding:10px 16px;
    border-radius:12px;
    background:transparent;
    color:var(--text-primary);
    border:1px solid rgba(255,255,255,0.04);
    cursor:pointer;
    transition:all .12s;
}

:root[data-theme="light"] .btn {
    border-color: rgba(0,0,0,0.1);
    color: var(--text-primary);
}

.btn.primary{
    background:linear-gradient(90deg,var(--accent-x),var(--accent-o));
    color:#030313;
    font-weight:700;
    border:none;
    box-shadow:0 8px 20px rgba(0,0,0,0.45);
}

:root[data-theme="light"] .btn.primary {
    color: #FFFFFF;
}

.btn:hover{ transform:translateY(-3px); }

/* modal styles */
.modal{
    position:fixed;
    inset:0;
    display:flex;
    align-items:center;
    justify-content:center;
    background:rgba(1,4,12,0.6);
    z-index:9999;
    padding:20px;
}

:root[data-theme="light"] .modal {
    background: rgba(0,0,0,0.3);
}

.modal.hidden{ display:none; }
.modal-dialog{
    width:100%;
    max-width:420px;
    background:linear-gradient(180deg,#0f0b18,#0b0814);
    border-radius:12px;
    padding:18px;
    box-shadow:0 12px 30px rgba(0,0,0,0.6);
    border:1px solid rgba(255,255,255,0.03);
    color:var(--text-primary);
}

:root[data-theme="light"] .modal-dialog {
    background: linear-gradient(180deg, #FFFFFF, #F9F9FB);
    border-color: rgba(0,0,0,0.08);
    box-shadow: 0 12px 30px rgba(0,0,0,0.12);
}

.modal-dialog h3{ margin:0 0 10px; font-size:18px; text-align:center; }
.modal-body{ display:flex; flex-direction:column; gap:10px; margin-bottom:12px; }
.modal-label{ font-size:13px; color:var(--text-secondary); display:flex; flex-direction:column; gap:6px; }
.modal-label input{
    padding:10px 12px;
    border-radius:10px;
    border:1px solid rgba(255,255,255,0.04);
    background:rgba(255,255,255,0.02);
    color:var(--text-primary);
    outline:none;
    font-size:14px;
}

:root[data-theme="light"] .modal-label input {
    border-color: rgba(0,0,0,0.1);
    background: rgba(0,0,0,0.02);
    color: var(--text-primary);
}

.modal-label input:focus{ box-shadow:0 6px 18px rgba(24,146,234,0.08); border-color:rgba(24,146,234,0.25); }

:root[data-theme="light"] .modal-label input:focus {
    border-color: rgba(0,102,255,0.3);
    box-shadow: 0 6px 18px rgba(0,102,255,0.1);
}

.modal-actions{ display:flex; gap:10px; justify-content:center; }
.modal-actions .btn{ min-width:100px; }

/* segmented control (pill) */
.segmented{
    display:inline-flex;
    background: rgba(255,255,255,0.02);
    border-radius: 999px;
    padding: 4px;
    gap:6px;
    align-items:center;
    justify-content:center;
}

:root[data-theme="light"] .segmented {
    background: rgba(0,0,0,0.04);
}

.seg-btn{
    border: none;
    background: transparent;
    color: var(--text-secondary);
    padding: 8px 14px;
    border-radius: 999px;
    cursor: pointer;
    font-weight:600;
    transition: all .12s ease;
    font-size:14px;
    outline: none;
    box-shadow: none;
}
.seg-btn:hover{ transform: translateY(-3px); }
.seg-btn.active{
    background: linear-gradient(90deg, var(--accent-x), var(--accent-o));
    color: #FFFFFF;
    box-shadow: 0 8px 24px rgba(8,6,20,0.6);
}

:root[data-theme="light"] .seg-btn.active {
    color: #FFFFFF;
    box-shadow: 0 8px 24px rgba(0,102,255,0.2);
}

.modal-segment{ display:flex; justify-content:center; padding:6px 0 8px; }

#playerOLabel[aria-disabled="true"]{ opacity:0.65; }
#playerOLabel[aria-disabled="true"] input{ background: rgba(255,255,255,0.02); opacity:0.9; }

:root[data-theme="light"] #playerOLabel[aria-disabled="true"] input {
    background: rgba(0,0,0,0.03);
}

.modal-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    cursor: pointer;
    padding: 8px 0;
}

.modal-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--accent-x);
}

.modal-checkbox span {
    color: var(--text-secondary);
    user-select: none;
}

/* keyframes */
@keyframes bounce {
    0% {
        transform: scale(0.3) translateY(-30px);
        opacity: 0;
    }
    50% {
        transform: scale(1.1);
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

@keyframes slideInDown {
    0% {
        transform: translateY(-50px);
        opacity: 0;
    }
    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

/* modal styling lebih meriah */
.modal-dialog {
    animation: slideInDown 0.5s ease-out;
}

#winModalText {
    font-size: 24px;
    animation: pulse 1s ease-in-out infinite;
    white-space: pre-line;
    line-height: 1.6;
}

.btn.primary {
    animation: pulse 1.5s ease-in-out infinite;
}

.btn.primary:hover {
    animation: none;
    transform: scale(1.05);
}

@keyframes fall {
    0% {
        opacity: 1;
        transform: translateY(0) rotate(0deg);
    }
    100% {
        opacity: 0;
        transform: translateY(300px) rotate(360deg);
    }
}

@keyframes rainFall {
    0% {
        opacity: 1;
        transform: translateY(-100vh) rotateZ(0deg);
    }
    100% {
        opacity: 0;
        transform: translateY(100vh) rotateZ(720deg);
    }
}

@keyframes horizontalSway {
    0% { transform: translateX(0); }
    25% { transform: translateX(40px); }
    50% { transform: translateX(0); }
    75% { transform: translateX(-40px); }
    100% { transform: translateX(0); }
}

.confetti {
    position: fixed;
    pointer-events: none;
    z-index: 9997;
    border-radius: 50%;
    will-change: transform, opacity;
}

.confetti[style*="--sway"] {
    animation: horizontalSway var(--sway-duration, 2s) ease-in-out var(--sway-delay, 0s) infinite;
}

/* responsive */
@media (max-width:720px){
    :root{ --cell-size:48px; }
    #header{ flex-direction:column; gap:12px; align-items:center; }
    .player{ min-width:100px; padding:8px 10px; }
    #board{ padding:12px; max-width:92vw; grid-template-columns: repeat(11, var(--cell-size)); gap:8px; }
    .instructions{ font-size:12px; padding:8px 10px; }
}

