:root {
    --r-color: #ef4444;
    --g-color: #22c55e;
    --y-color: #eab308;
    --b-color: #3b82f6;
    --yard-r: #fecaca;
    --yard-g: #bbf7d0;
    --yard-y: #fef08a;
    --yard-b: #bfdbfe;
    --home-r: #fca5a5;
    --home-g: #86efac;
    --home-y: #fde047;
    --home-b: #93c5fd;
    --board-frame: #f8fafc;
}

@media (prefers-color-scheme: dark) {
    :root {
        --r-color: #f87171;
        --g-color: #4ade80;
        --y-color: #facc15;
        --b-color: #60a5fa;
        --yard-r: #4c1d1d;
        --yard-g: #14351f;
        --yard-y: #3f3510;
        --yard-b: #1e3a5f;
        --home-r: #5b1f1f;
        --home-g: #1c4028;
        --home-y: #4a3d13;
        --home-b: #234573;
        --board-frame: #0f172a;
    }
}

.layout {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    gap: 40px;
}

.game-area {
    text-align: center;
}

#lobby {
    width: 100%;
    max-width: 380px;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 1px 3px var(--shadow);
    padding: 30px;
}

#lobby h2 { margin-top: 0; text-align: center; font-size: 20px; }
#lobby hr { border: none; border-top: 1px solid var(--border); margin: 25px 0; }
#lobby label { display: block; margin: 10px 0 5px; font-size: 14px; }
#lobby select, #lobby input {
    width: 100%;
    padding: 10px;
    font-size: 15px;
    background: var(--input-bg);
    color: var(--text);
    border: 1px solid var(--input-border);
    border-radius: 8px;
}
#lobby button { width: 100%; margin-top: 10px; }
#lobby .hint { font-size: 12px; color: var(--text-muted); margin: 6px 0 0; }

.lobby-message { margin-top: 15px; text-align: center; font-size: 14px; }
.lobby-message.error { color: var(--error); }

#keyDisplay {
    font-size: 15px;
    margin: 10px 0;
    padding: 10px;
    background: var(--input-bg);
    border: 1px dashed var(--input-border);
    border-radius: 4px;
    display: none;
}

#statsPanel {
    width: 100%;
    max-width: 380px;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 1px 3px var(--shadow);
    padding: 24px 30px;
}
#statsPanel h2 { margin-top: 0; text-align: center; font-size: 20px; }
#statsPanel select {
    width: 100%; padding: 8px; font-size: 15px;
    background: var(--input-bg); color: var(--text);
    border: 1px solid var(--input-border); border-radius: 8px; margin-bottom: 10px;
}

#status, #player, #message { margin: 10px; font-size: 18px; min-height: 26px; }
#status.your-turn { animation: pulse 1.2s ease-in-out infinite; font-weight: bold; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

#seatRequestBanner {
    background: var(--input-bg);
    border: 2px solid var(--brand);
    border-radius: 10px;
    padding: 12px;
    margin: 10px auto;
    max-width: 420px;
    font-size: 14px;
}
#seatRequestBanner button { margin: 6px 6px 0; width: auto; }

#spectatorPanel {
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 10px;
    padding: 12px;
    margin: 10px auto;
    max-width: 420px;
    font-size: 14px;
}
#spectatorPanel .seat-request-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin: 6px 0;
}
#spectatorPanel button { width: auto; padding: 6px 12px; font-size: 13px; }

#diceArea {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin: 15px 0;
}
#diceValue {
    width: 46px; height: 46px;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px; font-weight: bold;
    background: var(--board-frame);
    border: 2px solid var(--input-border);
    border-radius: 10px;
}
#rollBtn { width: auto; }

#board {
    width: min(90vw, 620px);
    aspect-ratio: 1 / 1;
    display: grid;
    grid-template-columns: repeat(15, 1fr);
    grid-template-rows: repeat(15, 1fr);
    background: var(--board-frame);
    border-radius: 14px;
    box-shadow: 0 1px 3px var(--shadow);
    position: relative;
    padding: 6px;
    gap: 1px;
    margin: 10px auto;
}

.cell {
    position: relative;
    background: var(--cell-bg, #ffffff);
    border: 1px solid var(--border);
    box-sizing: border-box;
}

.cell.yard-r { background: var(--yard-r); }
.cell.yard-g { background: var(--yard-g); }
.cell.yard-y { background: var(--yard-y); }
.cell.yard-b { background: var(--yard-b); }
.cell.yard-nest { background: var(--panel-bg); border-radius: 8px; border: 2px solid var(--border); }

.cell.start-r { background: var(--r-color); }
.cell.start-g { background: var(--g-color); }
.cell.start-y { background: var(--y-color); }
.cell.start-b { background: var(--b-color); }

.cell.safe-cell {
    background: var(--input-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6em;
    line-height: 1;
}

.cell.home-r { background: var(--home-r); }
.cell.home-g { background: var(--home-g); }
.cell.home-y { background: var(--home-y); }
.cell.home-b { background: var(--home-b); }

.yard-slot {
    position: absolute;
    inset: 18%;
    border-radius: 9999px;
    border: 2px dashed rgba(127,127,127,0.35);
}

#centerPiece {
    grid-row: 7 / 10;
    grid-column: 7 / 10;
    border-radius: 8px;
    background: conic-gradient(from 225deg,
        var(--b-color) 0deg 90deg,
        var(--g-color) 90deg 180deg,
        var(--r-color) 180deg 270deg,
        var(--y-color) 270deg 360deg);
    display: flex;
    align-items: center;
    justify-content: center;
}
#centerPiece span { font-size: min(4.5vw, 32px); }

.token {
    position: absolute;
    inset: 14%;
    border-radius: 9999px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    color: rgba(0,0,0,0.55);
    font-size: 0.65em;
    box-shadow: 0 2px 4px rgba(0,0,0,0.35), inset 0 -2px 3px rgba(0,0,0,0.2), inset 0 2px 3px rgba(255,255,255,0.4);
    border: 2px solid rgba(0,0,0,0.25);
    z-index: 5;
    transition: transform 0.2s ease;
}
.token.color-r { background: var(--r-color); }
.token.color-g { background: var(--g-color); }
.token.color-y { background: var(--y-color); }
.token.color-b { background: var(--b-color); }

.token.stacked-2 { transform: translate(-15%, -15%) scale(0.85); }
.token.stacked-3 { transform: translate(15%, -15%) scale(0.85); }
.token.stacked-4 { transform: translate(0%, 15%) scale(0.85); }

.token.clickable {
    cursor: pointer;
    z-index: 20;
    box-shadow: 0 0 0 3px #fff, 0 0 10px 3px rgba(250, 204, 21, 0.9);
    animation: token-pulse 1s ease-in-out infinite;
}
.token.clickable:hover { transform: scale(1.15); }
@keyframes token-pulse {
    0%, 100% { box-shadow: 0 0 0 3px #fff, 0 0 10px 3px rgba(250, 204, 21, 0.9); }
    50% { box-shadow: 0 0 0 3px #fff, 0 0 16px 6px rgba(250, 204, 21, 0.5); }
}

.scorecard {
    width: 220px;
    background: var(--panel-bg);
    border: 1px solid var(--border);
    box-shadow: 0 1px 3px var(--shadow);
    padding: 20px;
    border-radius: 14px;
}
.scorecard h2 { margin-top: 0; text-align: center; }
.score-row { display: flex; justify-content: space-between; font-size: 17px; margin: 10px 0; }

@media (max-width: 480px) {
    #board { width: 94vw; }
}
