*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body, html {
    min-height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    font-family: 'Arial', sans-serif;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-y: auto;
}

/* ── Page wrapper (game + stats side by side) ────── */
.page-wrapper {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    gap: 16px;
    width: 100%;
    max-width: 960px;
    padding: 16px;
}

/* ── Container ─────────────────────────────────── */
.game-container {
    background: white;
    border-radius: 24px;
    padding: 20px 24px 24px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.35);
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
    position: relative;  /* required for win overlay positioning */
}

/* ── Stats panel ─────────────────────────────────── */
.stats-panel {
    width: 190px;
    flex-shrink: 0;
    background: white;
    border-radius: 24px;
    padding: 20px 16px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.35);
    display: flex;
    flex-direction: column;
    gap: 14px;
    position: sticky;
    top: 16px;
}

.stats-title {
    font-size: 17px;
    font-weight: 900;
    background: linear-gradient(135deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    text-align: center;
    letter-spacing: -0.3px;
}

.stat-games-block {
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.stat-games-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: #bbb;
    font-weight: bold;
}

.stat-games-value {
    font-size: 42px;
    font-weight: 900;
    color: #667eea;
    line-height: 1;
}

.stat-divider {
    height: 1px;
    background: #f0ecff;
}

.stat-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-token {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    flex-shrink: 0;
    border: 2px solid rgba(0,0,0,0.1);
}

.stat-token.p1 { background: #ffd700; }
.stat-token.p2 { background: #42b3f5; }
.stat-token.p3 { background: #ff7043; }

.stat-player-name {
    font-size: 12px;
    font-weight: bold;
    color: #444;
    flex: 1;
}

.stat-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0;
}

.stat-wins {
    font-size: 18px;
    font-weight: 900;
    color: #333;
    line-height: 1.1;
}

.stat-pct {
    font-size: 10px;
    color: #aaa;
    font-weight: bold;
    line-height: 1;
}

/* ── Header ─────────────────────────────────────── */
.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 4px;
    border-bottom: 2px solid #f0ecff;
}

.header-titles {
    text-align: center;
    flex: 1;
}

.game-title {
    font-size: 32px;
    font-weight: 900;
    background: linear-gradient(135deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

.game-subtitle {
    font-size: 13px;
    color: #999;
    letter-spacing: 3px;
    text-transform: uppercase;
    margin-top: 2px;
}

.btn-auto {
    padding: 8px 16px;
    font-size: 13px;
    font-weight: bold;
    border: none;
    border-radius: 8px;
    background: #f0ecff;
    color: #667eea;
    cursor: pointer;
    transition: all 0.2s ease;
    letter-spacing: 0.5px;
    flex-shrink: 0;
    white-space: nowrap;
}

.btn-auto:hover {
    background: #667eea;
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 3px 10px rgba(102, 126, 234, 0.35);
}

.btn-auto.running {
    background: #e05252;
    color: white;
    animation: autoPulse 1s ease-in-out infinite;
}

.btn-auto.running:hover {
    background: #c03030;
    box-shadow: 0 3px 10px rgba(224, 82, 82, 0.4);
}

@keyframes autoPulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.7; }
}

/* ── Board ───────────────────────────────────────── */
.board-wrapper {
    display: flex;
    justify-content: center;
}

.game-board {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    grid-template-rows: repeat(10, 1fr);
    width: min(calc(100vw - 80px), 640px);
    aspect-ratio: 1;
    border: 3px solid #764ba2;
    border-radius: 8px;
    overflow: hidden;
}

.square {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 1px solid #d8d0bc;
    overflow: hidden;
    cursor: default;
    min-width: 0;
    min-height: 0;
}

.square.light { background: #f5f0e8; }
.square.dark  { background: #e8dcc8; }

.square.has-snake {
    background: #fdf0f0 !important;
    border-left: 3px solid #e05252 !important;
}

.square.has-ladder {
    background: #f0fdf5 !important;
    border-left: 3px solid #4caf7d !important;
}

.square-num {
    position: absolute;
    top: 2px;
    left: 3px;
    font-size: clamp(6px, 1.1vw, 11px);
    font-weight: bold;
    color: #aaa;
    line-height: 1;
    pointer-events: none;
}

.dest-badge {
    position: absolute;
    top: 1px;
    right: 2px;
    font-size: clamp(4px, 0.75vw, 8px);
    font-weight: bold;
    padding: 1px 2px;
    border-radius: 3px;
    line-height: 1.3;
    color: white;
    pointer-events: none;
}

.snake-badge { background: #e05252; }
.ladder-badge { background: #4caf7d; }

.square-icon {
    font-size: clamp(13px, 2.4vw, 24px);
    line-height: 1;
    display: block;
    pointer-events: none;
}

.tokens-row {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.token {
    width: clamp(12px, 5.2vw, 51px);
    height: clamp(12px, 5.2vw, 51px);
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.7);
    flex-shrink: 0;
    box-shadow: 0 1px 4px rgba(0,0,0,0.35);
}

/* Overlap tokens when multiple on same square */
.token + .token { margin-left: clamp(-8px, -3.5vw, -32px); }
.token + .token + .token { margin-left: clamp(-30px, -6vw, -54px); z-index: 1; }

.token.p1 { background: #ffd700; }
.token.p2 { background: #42b3f5; }
.token.p3 { background: #ff7043; }

/* Square 100 special */
.square.square-100 {
    background: linear-gradient(135deg, #667eea, #764ba2) !important;
    border-color: #764ba2 !important;
}
.square.square-100 .square-num {
    color: rgba(255,255,255,0.7);
}
.square.square-100 .square-icon {
    font-size: clamp(14px, 2.8vw, 26px);
}

/* ── Bottom section ─────────────────────────────── */
.bottom-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ── Turn banner ─────────────────────────────────── */
.turn-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    border-radius: 10px;
    padding: 8px 20px;
    color: white;
}

.turn-token {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.5);
    flex-shrink: 0;
}

.turn-token.p1 { background: #ffd700; }
.turn-token.p2 { background: #42b3f5; }
.turn-token.p3 { background: #ff7043; }

.turn-text {
    font-size: 16px;
    font-weight: bold;
    letter-spacing: 0.5px;
}

/* ── Player cards ────────────────────────────────── */
.players-row {
    display: flex;
    gap: 10px;
}

.player-card {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 10px;
    background: #f8f6ff;
    border: 2px solid #e8e4f4;
    transition: all 0.2s ease;
}

.player-card.active {
    border-color: #667eea;
    background: #ede9ff;
    box-shadow: 0 2px 10px rgba(102, 126, 234, 0.2);
}

.player-token-large {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 3px solid rgba(0, 0, 0, 0.12);
    flex-shrink: 0;
}

.player-token-large.p1 { background: #ffd700; }
.player-token-large.p2 { background: #42b3f5; }
.player-token-large.p3 { background: #ff7043; }

.player-info {
    display: flex;
    flex-direction: column;
}

.player-name {
    font-size: 13px;
    font-weight: bold;
    color: #333;
}

.player-pos {
    font-size: 11px;
    color: #999;
    margin-top: 1px;
}

/* ── Controls row ───────────────────────────────── */
.controls-row {
    display: flex;
    gap: 12px;
    align-items: stretch;
}

/* ── Dice area ──────────────────────────────────── */
.dice-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.dice-display {
    display: flex;
    justify-content: center;
}

.die {
    width: 64px;
    height: 64px;
    background: white;
    border-radius: 12px;
    border: 3px solid #667eea;
    box-shadow: 0 3px 10px rgba(102, 126, 234, 0.25);
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    padding: 9px;
    gap: 4px;
}

.pip {
    border-radius: 50%;
    background: #333;
    width: 100%;
    height: 100%;
}

.pip.empty {
    background: transparent;
}

.dice-result {
    font-size: 12px;
    color: #999;
    text-align: center;
    min-height: 16px;
}

.btn-roll {
    padding: 10px 22px;
    font-size: 15px;
    font-weight: bold;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.btn-roll:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(102, 126, 234, 0.5);
}

.btn-roll:active {
    transform: translateY(0);
}

.btn-roll:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: 0 2px 6px rgba(102, 126, 234, 0.15);
}

/* ── Game log ───────────────────────────────────── */
.game-log {
    flex: 1;
    background: #1a1a2e;
    border: 2px solid #667eea;
    border-radius: 10px;
    padding: 10px 14px;
    min-height: 90px;
    overflow-y: auto;
    display: flex;
    flex-direction: column-reverse;
}

.log-messages {
    font-size: 12px;
    color: #a0c4ff;
    line-height: 1.7;
    font-family: monospace;
}

/* ── Log line colors ─────────────────────────────── */
.log-line {
    line-height: 1.7;
}

.log-p1      { color: #ffd700; font-weight: bold; }
.log-p2      { color: #42b3f5; font-weight: bold; }
.log-p3      { color: #ff7043; font-weight: bold; }
.log-neutral { color: #a0c4ff; }
.log-ladder  { color: #4caf7d; font-weight: bold; }
.log-snake   { color: #e05252; font-weight: bold; }

/* ── Die rolling animation ───────────────────────── */
@keyframes dieShake {
    0%   { transform: rotate(0deg)   scale(1);    }
    20%  { transform: rotate(-10deg) scale(1.08); }
    40%  { transform: rotate(10deg)  scale(1.08); }
    60%  { transform: rotate(-6deg)  scale(1.04); }
    80%  { transform: rotate(6deg)   scale(1.04); }
    100% { transform: rotate(0deg)   scale(1);    }
}

.die.rolling {
    animation: dieShake 0.16s linear infinite;
}

/* ── Win overlay ─────────────────────────────────── */
.win-overlay {
    position: absolute;
    inset: 0;
    background: rgba(20, 12, 45, 0.88);
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.win-overlay.visible {
    opacity: 1;
    pointer-events: all;
}

.win-modal {
    background: white;
    border-radius: 20px;
    padding: 40px 52px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    box-shadow: 0 8px 48px rgba(0, 0, 0, 0.45);
    animation: winPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes winPop {
    from { transform: scale(0.55); opacity: 0; }
    to   { transform: scale(1);    opacity: 1; }
}

.win-trophy-token {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: 5px solid rgba(0, 0, 0, 0.12);
    margin-bottom: 4px;
}

.win-trophy-token.p1 { background: #ffd700; }
.win-trophy-token.p2 { background: #42b3f5; }
.win-trophy-token.p3 { background: #ff7043; }

.win-label {
    font-size: 12px;
    letter-spacing: 5px;
    text-transform: uppercase;
    color: #bbb;
    font-weight: bold;
}

.win-player-name {
    font-size: 28px;
    font-weight: 900;
    background: linear-gradient(135deg, #667eea, #764ba2);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 4px;
}

.btn-play-again {
    padding: 12px 32px;
    font-size: 16px;
    font-weight: bold;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
    margin-top: 4px;
}

.btn-play-again:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(102, 126, 234, 0.5);
}

.btn-play-again:active {
    transform: translateY(0);
}
