:root {
    --bg: #0b0f14;
    --panel: #141b24;
    --accent: #f1c40f;
    --text: #e6edf3;
    --muted: #8b97a7;
    --felt: #0a6b3a;
    --rail: #3a1f0b;
    --rail-hi: #7a4220;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: radial-gradient(1200px 600px at 50% 20%, #1a2533 0%, var(--bg) 60%);
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
    min-height: 100vh;
    user-select: none;
}

.wrap {
    max-width: 900px;
    margin: 0 auto;
    padding: 18px 12px 32px;
}

/* ── HUD ── */
.hud {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: nowrap;
    background: var(--panel);
    border: 1px solid #1f2a38;
    border-radius: 10px;
    padding: 10px 14px;
    margin-bottom: 10px;
    box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
}

.hud-player-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    padding: 6px 10px;
    border-radius: 8px;
    min-width: 130px;
    transition: box-shadow 0.3s ease, border-color 0.3s ease;
}
.player-block {
    background: rgba(52, 152, 219, 0.15);
    border: 2px solid rgba(52, 152, 219, 0.35);
}
.ai-block {
    background: rgba(231, 76, 60, 0.13);
    border: 2px solid rgba(231, 76, 60, 0.3);
}
.hud-player-block.active-turn {
    box-shadow: 0 0 14px 3px rgba(255, 255, 255, 0.6);
    border-color: rgba(255, 255, 255, 0.9);
}
.player-block.active-turn {
    box-shadow: 0 0 14px 3px rgba(52, 152, 219, 0.9);
    border-color: #3498db;
}
.ai-block.active-turn {
    box-shadow: 0 0 14px 3px rgba(231, 76, 60, 0.9);
    border-color: #e74c3c;
}
.hud-player-label {
    font-size: 12px;
    font-weight: bold;
    letter-spacing: 1px;
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 5px;
}
.hud-group {
    font-size: 11px;
    font-weight: 600;
    color: var(--accent);
    min-height: 16px;
}
.hud-potted {
    display: flex;
    gap: 3px;
    flex-wrap: nowrap;
    justify-content: center;
    align-items: center;
}

/* Empty slot */
.mini-ball-slot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.04);
    flex-shrink: 0;
    transition: all 0.2s ease;
}

/* Filled slot */
.mini-ball-slot.filled {
    border: 1px solid rgba(255,255,255,0.35);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 8px;
    font-weight: bold;
    color: #fff;
    text-shadow: 0 0 2px #000;
    animation: ball-pop 0.2s ease-out;
}
.mini-ball-slot.filled.stripe {
    background: linear-gradient(180deg, #fff 25%, var(--ball-color) 25%, var(--ball-color) 75%, #fff 75%) !important;
}
@keyframes ball-pop {
    from { transform: scale(0.4); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}

.hud-center-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex: 1;
}

.hud-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}
.hud-item .label {
    color: var(--muted);
    font-size: 12px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-weight: 700;
}
.hud-item.power {
    width: 100%;
    min-width: 160px;
}

.bar {
    flex: 1;
    height: 12px;
    background: #0a1018;
    border: 1px solid #2a384a;
    border-radius: 6px;
    overflow: hidden;
    min-width: 120px;
}
#powerFill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #2ecc71 0%, #f1c40f 60%, #e74c3c 100%);
    transition: width 40ms linear;
}

/* Turn indicator */
#turnIndicator {
    font-size: 12px;
    font-weight: bold;
    padding: 3px 12px;
    border-radius: 10px;
    letter-spacing: 0.5px;
    transition: all 0.3s ease;
    white-space: nowrap;
}
.turn-player {
    background: rgba(52, 152, 219, 0.25);
    color: #5dade2;
    border: 1px solid rgba(52, 152, 219, 0.5);
}
.turn-ai {
    background: rgba(231, 76, 60, 0.22);
    color: #e74c3c;
    border: 1px solid rgba(231, 76, 60, 0.5);
    animation: ai-pulse 0.9s ease-in-out infinite alternate;
}
@keyframes ai-pulse {
    from { opacity: 0.75; }
    to   { opacity: 1; box-shadow: 0 0 8px rgba(231,76,60,0.5); }
}

.ball-in-hand-indicator {
    font-size: 12px;
    font-weight: bold;
    color: #2ecc71;
    padding: 3px 10px;
    background: rgba(46,204,113,0.15);
    border: 1px solid rgba(46,204,113,0.4);
    border-radius: 8px;
    animation: bih-pulse 1s ease-in-out infinite alternate;
}
@keyframes bih-pulse {
    from { opacity: 0.7; }
    to { opacity: 1; box-shadow: 0 0 10px rgba(46,204,113,0.4); }
}

.hud-btns {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-left: 4px;
}

.btn {
    background: #1f2a38;
    color: var(--text);
    border: 1px solid #2a384a;
    border-radius: 6px;
    padding: 6px 12px;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, transform 0.05s;
}
.btn:hover { background: #27374b; }
.btn:active { transform: translateY(1px); }

canvas#table {
    display: block;
    width: 100%;
    height: auto;
    max-width: 860px;
    margin: 0 auto;
    background: #000;
    border-radius: 14px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    cursor: crosshair;
}

.controls {
    margin-top: 12px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
    background: var(--panel);
    border: 1px solid #1f2a38;
    border-radius: 10px;
    padding: 10px 14px;
}
.controls strong { color: var(--text); }
.controls em { color: var(--accent); }

#message {
    margin: 8px 0 0;
    color: var(--text);
    min-height: 1.2em;
}

/* ── Modals ── */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    z-index: 2000;
    justify-content: center;
    align-items: center;
}
.modal-overlay.active { display: flex; }

.modal-box {
    background: linear-gradient(135deg, #0a0f1e 0%, #16213e 100%);
    border: 3px solid #f1c40f;
    border-radius: 30px;
    padding: 30px 40px;
    text-align: center;
    box-shadow: 0 0 60px rgba(241,196,15,0.4);
    animation: modalPop 0.25s ease-out;
    min-width: 340px;
    max-width: 95vw;
    position: relative;
    font-family: system-ui, sans-serif;
}
@keyframes modalPop {
    from { transform: scale(0.8); opacity: 0; }
    to   { transform: scale(1);   opacity: 1; }
}
.modal-box h2 {
    font-size: 28px;
    color: #f1c40f;
    text-shadow: 0 0 10px #f1c40f;
    margin: 0 0 18px;
    letter-spacing: 3px;
}
.modal-icon { font-size: 56px; margin-bottom: 6px; }
.modal-score-line {
    font-size: 18px; color: #ffdd88;
    margin: 8px 0;
    text-shadow: 0 0 6px #ffaa44;
}
.btn-row {
    display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 14px;
}
.modal-btn {
    background: linear-gradient(90deg, #f1c40f, #d4a00a);
    border: none; color: #1a1a2e;
    font-size: 16px; font-weight: bold;
    padding: 10px 24px; border-radius: 40px;
    cursor: pointer; transition: all 0.2s;
    font-family: inherit;
    margin: 5px 4px 0;
}
.modal-btn:hover { transform: scale(1.04); box-shadow: 0 0 16px rgba(241,196,15,0.7); }
.modal-btn.danger { background: linear-gradient(90deg, #e94560, #c72a48); color: #fff; }
.modal-btn.danger:hover { box-shadow: 0 0 16px rgba(233,69,96,0.7); }

/* ── Stars & card wrap ── */
.hud-card-wrap {
    display: flex;
    align-items: flex-start;
    gap: 4px;
}
.hud-stars {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-top: 4px;
    min-width: 18px;
    font-size: 14px;
    line-height: 1;
}

/* ── Icon buttons (mute + rules) ── */
.hud-icon-btns {
    display: flex;
    gap: 4px;
}
.btn-icon {
    padding: 6px 7px;
    min-width: 0;
    font-size: 13px;
    font-weight: bold;
}

/* ── Rules modal ── */
.modal-box--rules {
    max-width: 480px;
    text-align: left;
}
.modal-box--rules h2 {
    text-align: center;
}
.rules-text p {
    color: #e0d8c0;
    font-size: 14px;
    margin: 8px 0;
    line-height: 1.55;
}
.rules-text strong { color: var(--text); }
.rules-text em { color: var(--accent); }