/* =========================================================
   POOL MASTERS — BI-A 8 BI
   Neon Hall Glassmorphism · 2 người chơi luân phiên
   ========================================================= */

:root {
    --font-display: 'Baloo 2', 'Nunito', system-ui, sans-serif;
    --font-main: 'Nunito', system-ui, sans-serif;

    --bg-dark: #070914;
    --card-bg: rgba(15, 23, 42, 0.78);
    --card-border: rgba(255, 255, 255, 0.12);

    --neon-blue: #00f0ff;
    --neon-green: #39ff14;
    --neon-yellow: #ffd700;
    --neon-red: #ff3366;

    --p1: #ff6b3d;
    --p2: #3da5ff;
    --felt: #0f7a49;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-main);
    background-color: var(--bg-dark);
    color: #fff;
    min-height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.bg-hall-glow {
    position: fixed;
    inset: 0;
    z-index: -1;
    background:
        radial-gradient(circle at 15% 20%, rgba(255, 107, 61, 0.18), transparent 45%),
        radial-gradient(circle at 85% 20%, rgba(61, 165, 255, 0.18), transparent 45%),
        radial-gradient(circle at 50% 105%, rgba(15, 122, 73, 0.28), transparent 55%),
        linear-gradient(160deg, #050714 0%, #0c1122 60%, #111a2e 100%);
    background-size: 180% 180%;
    animation: hallPulse 18s ease-in-out infinite alternate;
}

@keyframes hallPulse {
    0% { background-position: 0% 50%; }
    100% { background-position: 100% 50%; }
}

.app-wrapper {
    width: 100%;
    max-width: 1340px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 10px 14px 14px;
    gap: 10px;
}

/* ---------------- Navigation ---------------- */
.unified-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 18px;
    padding: 9px 16px;
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.45);
    flex-shrink: 0;
}

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

.brand-icon {
    font-size: 1.7rem;
    filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.35));
}

.brand-title {
    font-family: var(--font-display);
    font-size: 1.45rem;
    font-weight: 800;
    letter-spacing: 1px;
    white-space: nowrap;
    background: linear-gradient(135deg, var(--p1), var(--neon-yellow), var(--p2));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.btn {
    font-family: var(--font-display);
    font-size: 0.92rem;
    font-weight: 700;
    padding: 8px 15px;
    border-radius: 13px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(255, 255, 255, 0.07);
    color: #e2e8f0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
    transition: all 0.2s ease;
    white-space: nowrap;
}

.btn:hover {
    background: rgba(255, 255, 255, 0.14);
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.35);
}

.btn-home {
    background: linear-gradient(135deg, rgba(157, 78, 221, 0.35), rgba(0, 240, 255, 0.25));
    border-color: rgba(157, 78, 221, 0.5);
    color: #fff;
}

.btn-toggle.active {
    background: linear-gradient(135deg, rgba(57, 255, 20, 0.22), rgba(0, 240, 255, 0.18));
    border-color: rgba(57, 255, 20, 0.55);
    color: #b9ffb0;
    box-shadow: 0 0 16px rgba(57, 255, 20, 0.25);
}

.btn.muted { opacity: 0.55; }

/* ---------------- Player bar ---------------- */
.players-bar {
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    gap: 10px;
    flex-shrink: 0;
}

.player-panel {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 11px;
    background: rgba(6, 10, 24, 0.7);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 8px 14px;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    transition: all 0.3s ease;
    opacity: 0.55;
    min-width: 0;
}

.player-panel.active { opacity: 1; }
.panel-p1.active { border-color: var(--p1); box-shadow: 0 0 26px rgba(255, 107, 61, 0.4); }
.panel-p2.active { border-color: var(--p2); box-shadow: 0 0 26px rgba(61, 165, 255, 0.4); }

.p-avatar { font-size: 1.9rem; line-height: 1; flex-shrink: 0; }

.p-body { flex: 1; min-width: 0; }
.align-right { text-align: right; }

.p-name {
    font-family: var(--font-display);
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.p-group {
    font-size: 0.78rem;
    font-weight: 700;
    color: #94a3b8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.p-group.solid { color: #ffd98a; }
.p-group.stripe { color: #9fd8ff; }

/* Hàng bi còn lại */
.p-balls {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    max-width: 58%;
    justify-content: flex-end;
}

/* Ảnh bi 3D do game.js tô sẵn (cùng bộ tô với bi trên bàn) */
.mini-ball {
    width: 26px;
    height: 26px;
    background-size: contain;
    background-repeat: no-repeat;
    background-position: center;
    filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.55));
    flex-shrink: 0;
}

.mini-ball.done { opacity: 0.2; filter: grayscale(1); }

.turn-indicator {
    flex: 0 0 auto;
    text-align: center;
    background: rgba(6, 10, 24, 0.78);
    border: 1px solid rgba(255, 215, 0, 0.35);
    border-radius: 16px;
    padding: 7px 22px;
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    display: grid;
    place-content: center;
}

.turn-text {
    font-family: var(--font-display);
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--neon-yellow);
    white-space: nowrap;
}

.turn-sub {
    font-size: 0.75rem;
    color: #94a3b8;
    white-space: nowrap;
    margin-top: 1px;
}

/* ---------------- Viewport ---------------- */
.game-viewport {
    position: relative;
    flex: 1;
    min-height: 0;
    border-radius: 22px;
    overflow: hidden;
    border: 1px solid var(--card-border);
    box-shadow: 0 18px 60px rgba(0, 0, 0, 0.6);
    background: #0a0e1c;
}

#game-canvas {
    display: block;
    width: 100%;
    height: 100%;
    touch-action: none;
    cursor: crosshair;
}

.hud-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 16px;
}

.toast {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 800;
    padding: 10px 26px;
    border-radius: 16px;
    background: rgba(6, 10, 24, 0.9);
    border: 1px solid var(--card-border);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    animation: toastIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.4);
    text-align: center;
    max-width: 90%;
}

.toast.hidden { display: none; }
.toast.good { border-color: rgba(57, 255, 20, 0.6); color: #b9ffb0; box-shadow: 0 0 30px rgba(57, 255, 20, 0.3); }
.toast.bad { border-color: rgba(255, 51, 102, 0.6); color: #ffb3c4; box-shadow: 0 0 30px rgba(255, 51, 102, 0.3); }
.toast.info { border-color: rgba(255, 215, 0, 0.6); color: #ffe89a; }

@keyframes toastIn {
    from { opacity: 0; transform: translateY(-14px) scale(0.9); }
    to { opacity: 1; transform: none; }
}

/* ---------------- Screens ---------------- */
.screen {
    position: absolute;
    inset: 0;
    background: rgba(4, 7, 18, 0.88);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    z-index: 20;
    overflow-y: auto;
}

.screen.hidden { display: none; }

.panel {
    width: 100%;
    max-width: 720px;
    background: rgba(13, 19, 38, 0.92);
    border: 1px solid var(--card-border);
    border-radius: 24px;
    padding: 24px 28px 28px;
    text-align: center;
    box-shadow: 0 20px 70px rgba(0, 0, 0, 0.65);
    animation: panelIn 0.35s cubic-bezier(0.175, 0.885, 0.32, 1.28);
}

.panel-small { max-width: 460px; }

@keyframes panelIn {
    from { opacity: 0; transform: translateY(22px) scale(0.95); }
    to { opacity: 1; transform: none; }
}

.panel-emoji { font-size: 2.8rem; margin-bottom: 4px; }

.panel-title {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 800;
    letter-spacing: 1px;
    background: linear-gradient(135deg, var(--p1), var(--neon-yellow), var(--p2));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 6px;
}

.panel-desc {
    color: #cbd5e1;
    font-size: 0.98rem;
    line-height: 1.55;
    margin-bottom: 16px;
}

.rules-grid {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.rule-box {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    border-radius: 18px;
    padding: 12px;
}

.rule-p1 { border-color: rgba(255, 107, 61, 0.5); }
.rule-p2 { border-color: rgba(61, 165, 255, 0.5); }
.rule-avatar { font-size: 2rem; }

.rule-name {
    font-family: var(--font-display);
    font-weight: 800;
    margin: 3px 0 4px;
}

.rule-note { font-size: 0.8rem; color: #94a3b8; }

.vs-badge {
    font-family: var(--font-display);
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--neon-yellow);
}

.howto {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 18px;
    text-align: left;
}

.howto-item {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 11px;
    padding: 8px 13px;
    font-size: 0.92rem;
    color: #e2e8f0;
}

.step {
    font-family: var(--font-display);
    font-weight: 800;
    width: 23px;
    height: 23px;
    flex-shrink: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--p1), var(--neon-yellow));
    color: #16100a;
    display: grid;
    place-items: center;
    font-size: 0.82rem;
}

.rule-list {
    display: flex;
    flex-direction: column;
    gap: 9px;
    text-align: left;
    margin-bottom: 20px;
}

.rule-line {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    padding: 10px 15px;
    font-size: 0.93rem;
    line-height: 1.5;
    color: #e2e8f0;
}

.chip {
    font-weight: 800;
    padding: 1px 8px;
    border-radius: 8px;
    font-size: 0.85rem;
}

.chip-solid { background: rgba(255, 215, 0, 0.2); color: #ffd98a; }
.chip-stripe { background: rgba(61, 165, 255, 0.2); color: #9fd8ff; }

.big-btn {
    font-family: var(--font-display);
    font-size: 1.2rem;
    font-weight: 800;
    padding: 13px 36px;
    border-radius: 17px;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, var(--p1), var(--neon-yellow));
    color: #16100a;
    box-shadow: 0 8px 26px rgba(255, 107, 61, 0.45);
    display: inline-flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    transition: all 0.22s ease;
}

.big-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 12px 34px rgba(255, 107, 61, 0.7);
}

.btn-ghost {
    background: rgba(255, 255, 255, 0.08);
    color: #e2e8f0;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: none;
}

.over-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ---------------- Responsive ---------------- */
@media (max-width: 980px) {
    .brand-title { font-size: 1.1rem; }
    .btn span { display: none; }
    .btn { padding: 8px 12px; }
    .p-name { font-size: 0.8rem; }
    .p-group { font-size: 0.68rem; }
    .p-avatar { font-size: 1.4rem; }
    .turn-text { font-size: 0.88rem; }
    .turn-sub { display: none; }
    .turn-indicator { padding: 6px 12px; }
    .mini-ball { width: 21px; height: 21px; }
    .panel { padding: 18px 16px 22px; }
    .panel-title { font-size: 1.5rem; }
    .rules-grid { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
    .app-wrapper { padding: 6px 6px 8px; }
    .p-balls { display: none; }
    .players-bar { gap: 6px; }
    .player-panel { padding: 6px 9px; gap: 7px; }
}
