:root {
    --wdm-bg: #1a1a2e;
    --wdm-panel: #16213e;
    --wdm-accent: #e94560; 
    --wdm-primary: #0f3460;
    --wdm-green: #2ecc71; 
    --wdm-text: #ffffff;
    --wdm-text-muted: #8d93ab;
    --wdm-btn-bg: #2a2a40;
    --wdm-btn-active: #4a4e69;
}

#wdm-app {
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--wdm-bg);
    color: var(--wdm-text);
    width: 100%;
    min-height: 100vh; 
    margin: 0 auto;
    position: relative;
    box-sizing: border-box;
    display: flex; 
    flex-direction: column;
}

#wdm-app * { box-sizing: border-box; }

.hidden { display: none !important; }
.wdm-screen { width: 100%; height: 100%; display: flex; flex-direction: column; flex-grow: 1; }

/* Setup Screen */
#wdm-setup {
    justify-content: center; align-items: center;
    background: radial-gradient(circle at center, #1f2a48 0%, #1a1a2e 100%);
    overflow-y: auto; padding: 20px;
}
.wdm-setup-card {
    background: var(--wdm-panel); padding: 40px; border-radius: 20px;
    width: 90%; max-width: 500px; box-shadow: 0 10px 40px rgba(0,0,0,0.5); text-align: center;
}
.wdm-logo { margin: 0 0 30px 0; font-size: 32px; text-transform: uppercase; letter-spacing: 2px; }
.wdm-step { margin-bottom: 25px; text-align: left; }
.wdm-step label { display: block; margin-bottom: 10px; color: var(--wdm-text-muted); font-size: 14px; text-transform: uppercase; font-weight: bold; }
.wdm-mode-selector { display: flex; gap: 10px; }
.wdm-mode-btn {
    flex: 1; background: var(--wdm-btn-bg); border: 2px solid transparent; border-radius: 10px; padding: 15px 10px;
    color: var(--wdm-text); cursor: pointer; transition: all 0.2s;
    display: flex; flex-direction: column; align-items: center;
}
.wdm-mode-btn.active { background: rgba(46, 204, 113, 0.15); border-color: var(--wdm-green); color: var(--wdm-green); }
.mode-title { font-weight: 800; font-size: 18px; display: block; }
.mode-desc { font-size: 11px; opacity: 0.7; margin-top: 4px; }
.wdm-player-input-row { display: flex; gap: 10px; }
#wdm-new-player { flex: 1; background: rgba(0,0,0,0.3); border: 1px solid #333; padding: 12px; border-radius: 8px; color: white; font-size: 16px; }
#wdm-add-player-btn { background: var(--wdm-primary); border: none; color: white; border-radius: 8px; width: 50px; font-size: 20px; cursor: pointer; }
#wdm-player-list { list-style: none; padding: 0; margin-top: 15px; max-height: 150px; overflow-y: auto; }
#wdm-player-list li { background: rgba(255,255,255,0.05); padding: 10px 15px; margin-bottom: 5px; border-radius: 6px; display: flex; justify-content: space-between; align-items: center; }
.wdm-actions-footer { margin-top: 30px; display: flex; flex-direction: column; gap: 15px; }
.wdm-btn.primary { background: var(--wdm-green); color: #1a1a2e; font-weight: 900; padding: 18px; border: none; border-radius: 12px; font-size: 20px; text-transform: uppercase; letter-spacing: 1px; cursor: pointer; }
.wdm-btn.secondary { background: #333; color: white; font-weight: bold; padding: 15px; border: none; border-radius: 12px; font-size: 16px; cursor: pointer; }
.wdm-btn.text-only { background: none; border: none; color: var(--wdm-text-muted); text-decoration: underline; cursor: pointer; }


/* --- GAME SCREEN --- */
.wdm-game-layout { display: flex; height: 100%; overflow: hidden; }

/* Sidebar */
.wdm-sidebar {
    width: 35%; min-width: 320px;
    background: #121826; border-right: 1px solid #333;
    display: flex; flex-direction: column; padding: 20px; min-height: 0; z-index: 10;
}
.wdm-header-bar { display: flex; justify-content: space-between; margin-bottom: 10px; color: var(--wdm-text-muted); font-size: 14px; }
.wdm-btn.small-text { background: none; border: none; color: inherit; cursor: pointer; padding: 0; }
.wdm-active-player-panel {
    text-align: center; background: var(--wdm-panel); padding: 15px; border-radius: 15px; margin-bottom: 15px;
    border: 1px solid #333; box-shadow: inset 0 0 20px rgba(0,0,0,0.5); flex-shrink: 0;
}
.wdm-active-label { font-size: 11px; letter-spacing: 2px; color: var(--wdm-green); font-weight: bold; display: block; margin-bottom: 2px; }
#wdm-active-player-name { margin: 0 0 5px 0; font-size: 22px; font-weight: 600; color: white; }
.wdm-big-score { font-size: 55px; font-weight: 900; line-height: 1; color: white; margin-bottom: 10px; }

.wdm-stats-row { display: flex; justify-content: center; gap: 15px; padding-top: 10px; border-top: 1px solid rgba(255,255,255,0.1); }
.wdm-stat-item { display: flex; flex-direction: column; align-items: center; }
.wdm-stat-item .label { font-size: 10px; color: var(--wdm-text-muted); font-weight: bold; }
.wdm-stat-item .value { font-size: 18px; font-weight: bold; color: #ccc; }

.wdm-checkout-box { background: rgba(233, 69, 96, 0.15); border: 1px solid var(--wdm-accent); padding: 5px 10px; border-radius: 6px; display: flex; flex-direction: column; }
.wdm-checkout-box.hidden { display: none; }
.wdm-checkout-box .label { color: var(--wdm-accent); font-size: 9px; font-weight: bold; letter-spacing: 1px; }
.wdm-checkout-box .value { color: white; font-weight: bold; font-size: 14px; }


.wdm-turn-display {
    display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px;
    background: #151525; padding: 10px 15px; border-radius: 12px; flex-shrink: 0;
}
.wdm-darts-monitor { display: flex; gap: 10px; }
.wdm-dart-slot {
    width: 40px; height: 40px; background: #0f121a; border: 2px solid #333; border-radius: 8px;
    display: flex; align-items: center; justify-content: center; font-weight: bold; color: var(--wdm-text-muted); font-size: 14px;
}
.wdm-dart-slot.filled { border-color: var(--wdm-green); color: white; background: rgba(46, 204, 113, 0.1); }
.wdm-turn-sum { text-align: right; color: var(--wdm-text-muted); font-size: 12px; }
.wdm-turn-sum strong { display: block; font-size: 20px; color: var(--wdm-green); }

.wdm-mini-scoreboard { flex: 1; overflow-y: auto; min-height: 0; margin-bottom: 10px; }
.wdm-player-row { display: flex; justify-content: space-between; padding: 10px; border-bottom: 1px solid rgba(255,255,255,0.05); color: var(--wdm-text-muted); }
.wdm-player-row.active { background: rgba(255,255,255,0.05); color: white; border-left: 4px solid var(--wdm-green); }

/* Buttons in sidebar */
.wdm-sidebar-actions {
    display: flex; gap: 10px; flex-shrink: 0; 
    height: 90px; /* Increased height for better button sizing */
}
.wdm-undo-group {
    display: flex; flex-direction: column; gap: 5px; 
    flex: 0 0 100px; /* Increased width for undo buttons */
}
.wdm-action-btn { 
    border: none; border-radius: 8px; font-weight: bold; cursor: pointer; transition: background 0.2s;
    padding: 8px; /* Added padding for better touch target */
}
.wdm-action-btn.undo-throw { 
    background: #333; color: #fff; flex: 1; 
    font-size: 12px; /* Increased font size */
    text-transform: uppercase; 
}
.wdm-action-btn.undo-round { 
    background: #4a1c1c; color: #ffadad; flex: 1; 
    font-size: 12px; /* Increased font size */
    text-transform: uppercase; 
}
.wdm-action-btn.undo-throw:hover, .wdm-action-btn.undo-round:hover { opacity: 0.8; }

.wdm-action-btn.next { 
    flex: 1; background: var(--wdm-green); color: #1a1a2e; 
    font-size: 22px; /* Slightly larger font for main action */
    text-transform: uppercase; height: 100%; 
}
.wdm-action-btn.next:hover { background: #27ae60; }

/* Dartboard Area */
.wdm-main-control {
    width: 65%;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: #252836; 
    position: relative;
    padding: 10px;
}
#wdm-dartboard-container { width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; }
svg#dartboard { max-width: 95%; max-height: 95%; width: 100%; height: 100%; display: block; filter: drop-shadow(0 0 20px rgba(0,0,0,0.5)); }

/* SVG Styles */
.wdm-sector { cursor: pointer; transition: opacity 0.1s; }
.wdm-sector:hover { opacity: 0.8; }
.wdm-sector:active { opacity: 0.6; }
.fill-black { fill: #111; }
.fill-white { fill: #e0e0e0; }
.fill-red { fill: #d63031; }
.fill-green { fill: #00b894; }
.stroke-wire { stroke: #d1ccc0; stroke-width: 1.5; fill: none; pointer-events: none; }
.sector-text { font-family: sans-serif; font-weight: bold; fill: #fff; font-size: 18px; pointer-events: none; }
.wdm-instruction-overlay { position: absolute; bottom: 10px; left: 0; right: 0; text-align: center; color: rgba(255,255,255,0.3); font-size: 12px; pointer-events: none; }


/* --- GAME OVER SCREEN --- */
#wdm-game-over { justify-content: center; align-items: center; background: radial-gradient(circle at center, #1f2a48 0%, #000 100%); }
.wdm-winner-card { text-align: center; background: var(--wdm-panel); padding: 40px; border-radius: 20px; border: 2px solid var(--wdm-green); box-shadow: 0 0 50px rgba(46, 204, 113, 0.2); animation: popIn 0.5s ease; }
@keyframes popIn { 0% { transform: scale(0.8); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.wdm-winner-card h1 { color: var(--wdm-green); font-size: 32px; margin: 0 0 10px 0; letter-spacing: 2px; }
.wdm-winner-trophy { font-size: 60px; margin: 10px 0; }
.wdm-winner-card h2 { font-size: 40px; margin: 10px 0 20px 0; color: white; }
.wdm-winner-stats { display: flex; gap: 20px; justify-content: center; margin-bottom: 30px; }
.stat-box { background: rgba(255,255,255,0.05); padding: 10px 20px; border-radius: 8px; min-width: 100px; }
.stat-box span { display: block; font-size: 11px; text-transform: uppercase; color: #888; }
.stat-box strong { font-size: 24px; color: white; }
.wdm-game-over-actions { display: flex; flex-direction: column; gap: 10px; }


/* --- STATS OVERLAY FIX --- */
.wdm-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.95);
    z-index: 99999;
    display: flex; align-items: center; justify-content: center;
    overflow-y: auto; padding: 20px;
}
.wdm-overlay-card {
    background: var(--wdm-panel);
    width: 90%; max-width: 900px;
    border-radius: 20px; padding: 30px;
    position: relative; border: 1px solid #444;
    display: flex; flex-direction: column; gap: 20px;
}
.wdm-close-btn { position: absolute; top: 15px; right: 20px; background: none; border: none; color: white; font-size: 30px; cursor: pointer; }
.wdm-overlay-card h2 { margin-top: 0; text-align: center; }

.wdm-stats-dashboard { display: flex; gap: 20px; }
.wdm-kpi { flex: 1; background: rgba(255,255,255,0.05); padding: 20px; border-radius: 12px; text-align: center; }
.wdm-kpi.highlight { background: rgba(46, 204, 113, 0.1); border: 1px solid var(--wdm-green); }
.wdm-kpi h3 { margin: 0 0 10px 0; font-size: 12px; text-transform: uppercase; color: var(--wdm-text-muted); }
.wdm-kpi-val { font-size: 28px; font-weight: 800; color: white; }

.wdm-charts-container { display: flex; gap: 20px; flex-wrap: wrap; }
.wdm-chart-wrapper { flex: 1; min-width: 300px; background: rgba(0,0,0,0.3); padding: 15px; border-radius: 12px; }
.wdm-chart-wrapper h4 { text-align: center; margin-top: 0; color: #aaa; font-size: 14px; }
canvas { width: 100% !important; height: 250px !important; }

/* Media Queries */
@media (max-width: 900px) {
    .wdm-game-layout { flex-direction: column-reverse; overflow-y: auto; }
    .wdm-sidebar { width: 100%; height: auto; min-width: unset; flex-shrink: 0; border-top: 1px solid #333; }
    .wdm-main-control { width: 100%; height: 50vh; flex-shrink: 0; }
    #wdm-dartboard-container { padding: 10px; }
    .wdm-mini-scoreboard { display: none; }
    .wdm-active-player-panel { display: flex; justify-content: space-between; align-items: center; padding: 10px; text-align: left; }
    .wdm-player-header { flex: 1; }
    .wdm-big-score { font-size: 32px; margin: 0; text-align: right; }
    .wdm-stats-row { display: none; }
    .wdm-charts-container { flex-direction: column; }
}