:root {
    --bg: #0e1014;
    --panel: #141820;
    --panel2: #1a1f29;
    --stroke: #2a3140;
    --text: #e8ecf6;
    --muted: #9aa5bb;
    --good: #7af0aa;
    --warn: #ffd778;
    --cap: #ffbf72;
    --acc: #78aaff;
    --acc2: #ff8c6e;
    --dark: #4a3f3a;
    --light: #cfc3aa;
    --danger: #ff6b8b;
    --success: #4cd964;
    --menu-bg: rgba(14, 16, 20, 0.95);
    --glass: rgba(255, 255, 255, 0.08);
    --glow: rgba(120, 170, 255, 0.3);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    margin: 0;
    background: radial-gradient(1200px 900px at 30% -10%, rgba(120,170,255,.18), transparent 55%),
                radial-gradient(900px 700px at 90% 10%, rgba(255,140,110,.14), transparent 55%),
                var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
    height: 100vh;
    overflow: hidden;
}

/* Screen shake effect */
@keyframes screenShake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.shake {
    animation: screenShake 0.5s cubic-bezier(.36,.07,.19,.97) both;
}

/* Menu System */
.menu-screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--menu-bg);
    backdrop-filter: blur(10px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    padding: 20px;
    transition: opacity 0.5s ease;
}

.menu-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.menu-screen h1 {
    font-size: 4.5rem;
    margin-bottom: 10px;
    text-align: center;
    background: linear-gradient(to right, #ffd778, #78aaff, #7af0aa);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0 0 30px rgba(120, 170, 255, 0.3);
    letter-spacing: 1px;
}

.menu-screen h1 .g-strong {
    font-weight: 900;
    font-size: 5rem;
    color: #ffd778;
    text-shadow: 0 0 20px rgba(255, 215, 120, 0.5);
}

.menu-screen .subtitle {
    font-size: 1.2rem;
    color: var(--muted);
    margin-bottom: 60px;
    text-align: center;
    max-width: 600px;
    line-height: 1.5;
}

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 20px;
    width: 100%;
    max-width: 300px;
    margin: 30px 0;
}

.menu-btn {
    padding: 18px 30px;
    border: none;
    border-radius: 16px;
    font-size: 1.3rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.menu-btn-primary {
    background: linear-gradient(135deg, #78aaff, #4d8eff);
    color: white;
    box-shadow: 0 10px 20px rgba(120, 170, 255, 0.3);
}

.menu-btn-primary:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 30px rgba(120, 170, 255, 0.4);
}

.menu-btn-secondary {
    background: var(--glass);
    color: var(--text);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.menu-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
    transform: translateY(-3px);
}

/* Modal Windows */
.modal {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(5px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal.active {
    opacity: 1;
    pointer-events: all;
}

.modal-content {
    background: var(--panel);
    border-radius: 20px;
    padding: 30px;
    max-width: 800px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    border: 1px solid var(--glass);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    position: relative;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modal-title {
    font-size: 1.8rem;
    color: var(--text);
}

.close-modal {
    background: transparent;
    border: none;
    color: var(--muted);
    font-size: 1.5rem;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.close-modal:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
}

/* Rules Modal */
.rules-list {
    display: grid;
    gap: 15px;
    margin-bottom: 30px;
}

.rule-item {
    display: flex;
    gap: 15px;
    padding: 15px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    border-left: 4px solid var(--acc);
}

.rule-icon {
    color: var(--acc);
    font-size: 1.2rem;
    margin-top: 2px;
}

.rule-text h4 {
    margin-bottom: 5px;
    color: var(--text);
}

.rule-text p {
    color: var(--muted);
    line-height: 1.5;
}

/* Credits Modal */
.credits-list {
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.credit-item {
    display: flex;
    gap: 20px;
    align-items: center;
    padding: 20px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 16px;
}

.credit-avatar {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    font-weight: bold;
    flex-shrink: 0;
}

.avatar-salaj {
    background: linear-gradient(135deg, #78aaff, #4d8eff);
}

.avatar-ariba {
    background: linear-gradient(135deg, #ff8c6e, #ff6b8b);
}

.avatar-arhit {
    background: linear-gradient(135deg, #7af0aa, #4cd964);
}

.credit-info h3 {
    font-size: 1.5rem;
    margin-bottom: 5px;
    color: var(--text);
}

.credit-info p {
    color: var(--muted);
    margin-bottom: 8px;
}

/* Game Container */
.game-container {
    width: 100%;
    height: 100%;
    overflow: hidden;
    position: relative;
}

.game-ui {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Top Bar */
.topbar {
    background: linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.04));
    border: 1px solid var(--glass);
    border-radius: 18px;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,.35);
    margin: 10px 15px 0 15px;
    flex-shrink: 0;
}

.title {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.title h1 {
    margin: 0;
    font-size: 18px;
    letter-spacing: .3px;
}

.title .sub {
    font-size: 12px;
    color: var(--muted);
}

.chips {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.chip {
    display: flex;
    gap: 8px;
    align-items: center;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(255,255,255,.05);
    border: 1px solid rgba(255,255,255,.08);
    color: var(--text);
    font-size: 12px;
    transition: all 0.3s ease;
}

.chip.pulse {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 215, 120, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(255, 215, 120, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 215, 120, 0); }
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.dot.acc { background: var(--acc); }
.dot.cap { background: var(--cap); }
.dot.warn { background: var(--warn); }
.dot.good { background: var(--good); }
.dot.danger { background: var(--danger); }

/* Main Game Area */
.main-game-area {
    display: flex;
    flex: 1;
    padding: 15px;
    gap: 15px;
    min-height: 0;
    overflow: hidden;
}

/* Board Area */
.board-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.boardCard {
    background: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.02));
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 18px;
    padding: 14px;
    box-shadow: 0 10px 30px rgba(0,0,0,.35);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.canvasWrap {
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,.08);
    background: var(--panel2);
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 0;
}

#cv {
    display: block;
    max-width: 100%;
    max-height: 100%;
    aspect-ratio: 1/1;
    cursor: pointer;
    object-fit: contain;
}

/* Side Panel */
.side {
    background: linear-gradient(180deg, rgba(255,255,255,.06), rgba(255,255,255,.02));
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 18px;
    padding: 14px;
    box-shadow: 0 10px 30px rgba(0,0,0,.35);
    width: 320px;
    max-height: 100%;
    overflow-y: auto;
    flex-shrink: 0;
}

/* For mobile, side panel becomes bottom panel */
@media (max-width: 1024px) {
    .main-game-area {
        flex-direction: column;
    }
    
    .side {
        width: 100%;
        max-height: 300px;
        order: 2;
    }
    
    .board-area {
        order: 1;
    }
    
    .menu-screen h1 {
        font-size: 3rem;
    }
    
    .menu-screen h1 .g-strong {
        font-size: 3.5rem;
    }
    
    .menu-buttons {
        max-width: 250px;
    }
    
    .modal-content {
        padding: 20px;
        width: 95%;
    }
}

@media (max-width: 768px) {
    .topbar {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .chips {
        width: 100%;
        justify-content: flex-start;
    }
    
    .menu-screen h1 {
        font-size: 2.5rem;
    }
    
    .menu-screen h1 .g-strong {
        font-size: 3rem;
    }
    
    .menu-screen .subtitle {
        font-size: 1rem;
        margin-bottom: 40px;
    }
    
    .credit-item {
        flex-direction: column;
        text-align: center;
    }
    
    .credit-avatar {
        width: 60px;
        height: 60px;
        font-size: 1.5rem;
    }
}

.section {
    padding: 12px;
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 14px;
    background: rgba(0,0,0,.18);
    margin-bottom: 12px;
}

.section h2 {
    margin: 0 0 10px 0;
    font-size: 13px;
    color: var(--text);
    letter-spacing: .3px;
}

.row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    margin: 8px 0;
    font-size: 13px;
}

.label {
    color: var(--muted);
}

.value {
    color: var(--text);
    font-weight: 600;
}

.btns {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

button {
    appearance: none;
    border: 1px solid rgba(255,255,255,.12);
    background: rgba(255,255,255,.06);
    color: var(--text);
    padding: 10px 12px;
    border-radius: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: transform .08s ease, background .2s ease, border-color .2s ease;
    font-size: 13px;
}

button:hover {
    background: rgba(255,255,255,.09);
    border-color: rgba(255,255,255,.18);
}

button:active {
    transform: scale(.98);
}

button.primary {
    background: rgba(120,170,255,.18);
    border-color: rgba(120,170,255,.35);
}

button.danger {
    background: rgba(255,140,110,.16);
    border-color: rgba(255,140,110,.35);
}

.hint {
    font-size: 12px;
    color: var(--muted);
    line-height: 1.45;
}

.statusLine {
    font-size: 12px;
    color: var(--muted);
    padding: 8px 0;
}

.statusLine strong {
    color: var(--text);
}

/* Back to menu button */
.back-to-menu {
    position: absolute;
    top: 85px;
    left: 30px;
    z-index: 100;
}

.back-btn {
    padding: 10px 16px;
    background: var(--glass);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text);
    border-radius: 12px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 8px;
}

.back-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

/* Game Winner Overlay */
.game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(5px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

.game-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.winner-message {
    background: var(--panel);
    border-radius: 20px;
    padding: 40px;
    max-width: 500px;
    width: 90%;
    text-align: center;
    border: 1px solid var(--glass);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.winner-message h2 {
    font-size: 3rem;
    margin-bottom: 20px;
    background: linear-gradient(to right, #ffd778, #78aaff);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.winner-message p {
    color: var(--muted);
    margin-bottom: 30px;
    font-size: 1.1rem;
    line-height: 1.5;
}

/* Sound controls */
.sound-controls {
    position: absolute;
    bottom: 20px;
    right: 20px;
    z-index: 100;
    display: flex;
    gap: 10px;
}

.sound-btn {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: var(--glass);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.2rem;
    transition: all 0.3s;
}

.sound-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    transform: scale(1.1);
}