:root{
    --radius:16px;

    /* theme tokens */
    --bg0:#070A10;
    --text:#EAF0FF;
    --muted:#9AA7C2;
    --border:rgba(255,255,255,0.10);
    --shadow: 0 20px 60px rgba(0,0,0,.55);

    --surfaceA: rgba(14,22,43,.92);
    --surfaceB: rgba(11,18,36,.92);
    --surfaceFlat: rgba(255,255,255,0.05);

    --boardBg: rgba(0,0,0,0.18);
    --cellBg: rgba(255,255,255,0.04);
    --cellEmptyText: rgba(234,240,255,.80);

    --btnBg: rgba(255,255,255,.08);
    --btnBgHover: rgba(255,255,255,.12);
    --btnBorder: rgba(255,255,255,.14);

    --btnPrimaryBg: rgba(90,120,255,.90);
    --btnPrimaryText: #0A1020;

    /* top header */
    --topbarBg: rgba(7,10,16,.55);
}

html[data-theme="light"]{
    /* eggshell / off-white */
    --bg0:#F4F1EA;
    --text:#0E1426;
    --muted:#4B5872;
    --border:rgba(10,16,32,0.14);
    --shadow: 0 18px 48px rgba(10,16,32,.18);

    /* light UI surfaces (so text stays visible) */
    --surfaceA: rgba(255,255,255,.92);
    --surfaceB: rgba(255,255,255,.86);
    --surfaceFlat: rgba(255,255,255,.92);

    /* light board/cells: eggshell */
    --boardBg: rgba(244,241,234,.55);
    --cellBg: rgba(244,241,234,.92);
    --cellEmptyText: rgba(10,16,32,.70);

    /* solid buttons */
    --btnBg: rgba(10,16,32,.08);
    --btnBgHover: rgba(10,16,32,.12);
    --btnBorder: rgba(10,16,32,.18);

    --btnPrimaryBg: rgba(10,16,32,.92);
    --btnPrimaryText: #F7F7F7;

    /* top header */
    --topbarBg: rgba(244,241,234,.72);
}

/* Light-theme polish for the brand lockup */
html[data-theme="light"] .brand__title{
    color: var(--text);
}
html[data-theme="light"] .brand__titleAccent{
    /* deeper gradient for contrast on light bg */
    background: linear-gradient(90deg, #0B5FDB 0%, #2742FF 45%, #7B2BFF 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: none;
}
html[data-theme="light"] .brand__badge{
    background: rgba(10,16,32,0.06);
    border-color: rgba(10,16,32,0.18);
    color: rgba(10,16,32,0.92);
}
html[data-theme="light"] .brand__logo{
    filter: drop-shadow(0 10px 24px rgba(10,16,32,.18));
}

*{ box-sizing:border-box; }

html, body { height:100%; }

body {
    margin: 0;
    padding: 0;
    background: var(--bg0);
    font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    color: var(--text);
}

.btn, .cell, select, input { touch-action: manipulation; }

.app{
    min-height:100%;
    display:flex;
    flex-direction:column;
}

.topbar{
    position:sticky;
    top:0;
    z-index:10;
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:16px;
    padding:14px 16px;
    border-bottom:1px solid var(--border);
    background: var(--topbarBg);
    backdrop-filter: blur(14px);
}

.brand{ display:flex; flex-direction:column; line-height:1.1; }

.brand__row{
    display:flex;
    align-items:center;
    gap:10px;
    min-width: 0;
}

.brand__logo{
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    filter: drop-shadow(0 10px 24px rgba(0,0,0,.35));
}

.brand__stack{
    display:flex;
    flex-direction:column;
    min-width:0;
}

.brand__title{
    font-weight: 950;
    font-size: 18px;
    letter-spacing: .2px;
    display:flex;
    align-items:baseline;
    gap:6px;
    white-space:nowrap;
}

.brand__titleAccent{
    background: linear-gradient(90deg, #9AE6FF 0%, #5A78FF 45%, #B46BFF 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0 10px 32px rgba(90,120,255,.20);
}

.brand__badge{
    font-size: 10px;
    font-weight: 950;
    letter-spacing: .55px;
    padding: 5px 8px;
    border-radius: 999px;
    border: 1px solid var(--btnBorder);
    background: rgba(255,255,255,0.06);
    color: var(--text);
    transform: translateY(-1px);
}

.brand__subtitle{
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
}

.topbar__actions{ display:flex; gap:10px; align-items:center; }

.btn{
    appearance:none;
    border:1px solid var(--btnBorder);
    border-radius:12px;
    padding:10px 12px;
    font-weight:700;
    color:var(--text);
    background: var(--btnBg);
    cursor:pointer;
    transition: transform .12s ease, background .18s ease, border-color .18s ease;
}
.btn:hover{ transform: translateY(-1px); background: var(--btnBgHover); border-color: var(--border); }
.btn:active{ transform: translateY(0px) scale(.99); }
.btn--primary{
    border-color: var(--btnBorder);
    background: var(--btnPrimaryBg);
    color: var(--btnPrimaryText);
}
.btn--ghost{
    background: transparent;
}

.layout{
    flex:1;
    display:grid;
    grid-template-columns: 320px 1fr;
    gap:16px;
    padding:16px;
    max-width:1200px;
    width:100%;
    margin:0 auto;
}

.panel{
    border:1px solid var(--border);
    border-radius: var(--radius);
    background: linear-gradient(180deg, var(--surfaceA), var(--surfaceB));
    box-shadow: var(--shadow);
    overflow:hidden;
}
.panel__section{
    padding:14px 14px;
    border-bottom:1px solid rgba(255,255,255,0.06);
}
.panel__section:last-child{ border-bottom:none; }
.panel__label{ font-size:12px; color:var(--muted); letter-spacing:.2px; }

.turn{
    margin:8px 0 0 0;
    font-size:22px;
    font-weight:900;
    transition: color 0.3s ease;
}

.playersList{
    display:flex;
    flex-direction:column;
    gap:8px;
    margin-top:10px;
}
.playerPill{
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:10px;
    padding:10px 10px;
    border-radius:12px;
    border:1px solid rgba(255,255,255,0.08);
    background: rgba(255,255,255,0.04);
}
.playerPill--active{
    border-color: rgba(255,255,255,0.18);
    background: rgba(255,255,255,0.07);
}
.playerPill__left{ display:flex; align-items:center; gap:10px; min-width:0; }
.dot{
    width:12px; height:12px;
    border-radius:999px;
    box-shadow: 0 0 0 3px rgba(255,255,255,0.08);
}
.playerName{
    font-weight:800;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
}
.playerMeta{
    font-size:12px;
    color:var(--muted);
    font-weight:700;
}

.hint{
    color: var(--muted);
    font-size:12px;
    line-height:1.35;
}

.stage{
    display:flex;
    align-items:flex-start;
    justify-content:center;
}
.gameContainer{
    width:100%;
    display:flex;
    justify-content:center;
    padding:6px 0;
}

/* BOARD */
.board, #board {
    display: grid;
    grid-template-columns: repeat(9, min(9.6vw, 56px));
    grid-template-rows: repeat(6, min(9.6vw, 56px));
    justify-content: center;
    margin-top: 4px;
    gap: 6px;
    padding: 14px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--boardBg);
    box-shadow: var(--shadow);
}

/* CELL */
.cell {
    width: min(9.6vw, 56px);
    height: min(9.6vw, 56px);
    background: var(--cellBg);
    border: 2px solid var(--turnBorder, rgba(255,255,255,0.10));
    border-radius: 12px;

    display: flex;
    align-items: center;
    justify-content: center;

    font-size: 16px;
    font-weight: bold;

    cursor: pointer;
    user-select: none;

    transition: transform 0.15s ease, background 0.25s ease, box-shadow .18s ease, border-color .18s ease;
}

.cell:hover {
    transform: scale(1.05);
    border-color: rgba(255,255,255,0.18);
    box-shadow: 0 10px 28px rgba(0,0,0,.35);
}

.cell:active{
    transform: scale(1.02);
}

/* POP */
@keyframes pop {
    0% { transform: scale(1); }
    50% { transform: scale(1.25); }
    100% { transform: scale(1); }
}

.pop {
    animation: pop 0.2s ease;
}

/* SHAKE */
@keyframes shake {
    0% { transform: translate(0px, 0px); }
    25% { transform: translate(1px, -1px); }
    50% { transform: translate(-1px, 1px); }
    75% { transform: translate(1px, 1px); }
    100% { transform: translate(0px, 0px); }
}

.shake {
    animation: shake 0.15s ease;
}

/* MODAL */
.modal{
    position:fixed;
    inset:0;
    display:flex;
    align-items:center;
    justify-content:center;
    padding:16px;
}
.modal__backdrop{
    position:absolute;
    inset:0;
    background: rgba(0,0,0,.55);
    backdrop-filter: blur(6px);
}
.modal__card{
    position:relative;
    width:min(520px, 100%);
    border-radius: 18px;
    border:1px solid rgba(255,255,255,0.12);
    background: linear-gradient(180deg, var(--surfaceA), var(--surfaceB));
    box-shadow: var(--shadow);
    overflow:hidden;
}
.modal__header{
    padding:16px 16px 10px 16px;
    border-bottom:1px solid rgba(255,255,255,0.08);
}
.modal__title{ font-weight:900; font-size:16px; }
.modal__subtitle{ margin-top:4px; font-size:12px; color:var(--muted); }
.modal__actions{
    padding:12px 16px 16px 16px;
    display:flex;
    justify-content:flex-end;
    gap:10px;
}

.formRow{
    padding:14px 16px 10px 16px;
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:12px;
}
.label{ color:var(--muted); font-size:12px; font-weight:700; }
.select{
    width:140px;
    padding:10px 10px;
    border-radius:12px;
    border:1px solid rgba(255,255,255,0.12);
    background: var(--surfaceFlat);
    color: var(--text);
    outline:none;
}

.names{
    padding: 0 16px 2px 16px;
    display:flex;
    flex-direction:column;
    gap:10px;
}
.input{
    width:100%;
    padding:11px 12px;
    border-radius:12px;
    border:1px solid rgba(255,255,255,0.12);
    background: var(--surfaceFlat);
    color: var(--text);
    outline:none;
}
.input::placeholder{ color: rgba(154,167,194,.75); }

@media (max-width: 880px){
    .layout{ grid-template-columns: 1fr; }
    .panel{ order: 2; }
    .stage{ order: 1; }
}

@media (max-width: 460px){
    .layout{ padding:12px; gap:12px; }
    .topbar{ padding:12px 12px; }

    .board, #board{
        gap: 4px;
        padding: 10px;
        grid-template-columns: repeat(9, min(9.2vw, 44px));
        grid-template-rows: repeat(6, min(9.2vw, 44px));
    }
    .cell{
        width: min(9.2vw, 44px);
        height: min(9.2vw, 44px);
        border-width: 2px;
        font-size: 14px;
    }
}

/* STATS */
.stats{
    padding: 12px 16px 6px 16px;
}
.stats__grid{
    display:grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap:10px;
}

/* FOOTER */
.footer{
    padding: 18px 16px 26px 16px;
    color: var(--muted);
    font-size: 12px;
    letter-spacing: 0.25px;
}

.footer__inner{
    max-width: 1200px;
    margin: 0 auto;
    display:flex;
    align-items:center;
    justify-content:space-between;
    gap:12px;
    padding: 10px 12px;
    border-radius: 16px;
    border: 1px solid var(--border);
    background: linear-gradient(180deg, var(--surfaceA), var(--surfaceB));
    box-shadow: var(--shadow);
}

.footer__credits{
    display:flex;
    align-items:center;
    gap:8px;
    min-width: 0;
}

.footer__label{
    color: var(--muted);
    font-weight: 800;
}

.footer__author{
    color: var(--text);
    font-weight: 900;
    white-space:nowrap;
    overflow:hidden;
    text-overflow:ellipsis;
}

.footer__social{
    display:inline-flex;
    align-items:center;
    justify-content:center;
    gap:8px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--btnBorder);
    color: var(--text);
    background: var(--btnBg);
    text-decoration:none;
    font-weight: 900;
    transition: transform .12s ease, background .18s ease, border-color .18s ease;
}
.footer__social:hover{
    transform: translateY(-1px);
    background: var(--btnBgHover);
    border-color: var(--border);
}
.footer__social:active{ transform: translateY(0px) scale(.99); }

@media (max-width: 520px){
    .footer__inner{
        flex-direction:column;
        align-items:stretch;
    }
    .footer__social{
        width:100%;
    }
}
.stat{
    border:1px solid rgba(255,255,255,0.10);
    background: rgba(255,255,255,0.05);
    border-radius: 14px;
    padding:10px 10px;
}
.stat__label{
    font-size:12px;
    color: var(--muted);
    font-weight:800;
}
.stat__value{
    margin-top:4px;
    font-size:14px;
    font-weight:900;
}