/* ========== RESET & BASE ========== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    overflow: hidden;
    background: #0a0a1a;
    font-family: 'Rajdhani', sans-serif;
    color: #fff;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* ========== CANVAS ========== */
#game-canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    touch-action: none;
}

/* ========== LOADING SCREEN ========== */
#loading-screen {
    position: fixed;
    inset: 0;
    background: #0a0a1a;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    transition: opacity 0.6s ease;
}

#loading-screen.hidden {
    opacity: 0;
    pointer-events: none;
}

.loader p {
    margin-top: 20px;
    font-size: 1.1rem;
    color: rgba(255, 255, 255, 0.5);
    letter-spacing: 2px;
}

.spinner {
    width: 48px;
    height: 48px;
    border: 3px solid rgba(255, 255, 255, 0.08);
    border-top-color: #7c4dff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========== UI OVERLAY ========== */
#ui-overlay {
    position: fixed;
    inset: 0;
    z-index: 10;
    pointer-events: none;
}

.screen {
    display: none;
    position: absolute;
    inset: 0;
}

.screen.active {
    display: flex;
}

/* ========== MAIN MENU ========== */
#main-menu {
    background: rgba(10, 10, 26, 0.88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    align-items: center;
    justify-content: center;
    pointer-events: all;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.menu-content {
    text-align: center;
    padding: 40px 24px;
    max-width: 480px;
    width: 100%;
    margin: auto;
}

.game-title {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(2rem, 6vw, 3.8rem);
    font-weight: 900;
    letter-spacing: 3px;
    line-height: 1.15;
    background: linear-gradient(135deg, #7c4dff 0%, #448aff 50%, #40c4ff 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 6px;
    filter: drop-shadow(0 0 30px rgba(124, 77, 255, 0.25));
}

.subtitle {
    font-size: clamp(0.85rem, 2.5vw, 1.3rem);
    color: rgba(255, 255, 255, 0.4);
    letter-spacing: 8px;
    text-transform: uppercase;
    margin-bottom: 48px;
    font-weight: 300;
}

/* ========== BUTTONS ========== */
.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: center;
}

.btn {
    font-family: 'Rajdhani', sans-serif;
    font-size: 1.15rem;
    font-weight: 600;
    padding: 13px 36px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.25s ease;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 230px;
    justify-content: center;
    letter-spacing: 1px;
    outline: none;
}

.btn:active {
    transform: scale(0.97) !important;
}

.btn-primary {
    background: linear-gradient(135deg, #7c4dff, #536dfe);
    color: #fff;
    box-shadow: 0 4px 24px rgba(124, 77, 255, 0.35);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 32px rgba(124, 77, 255, 0.55);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.07);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.15);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.12);
    transform: translateY(-2px);
}

.btn-small {
    padding: 7px 18px;
    font-size: 1rem;
    min-width: auto;
    background: rgba(255, 255, 255, 0.06);
    color: rgba(255, 255, 255, 0.55);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
}

.btn-small.active {
    background: linear-gradient(135deg, #7c4dff, #536dfe);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 2px 12px rgba(124, 77, 255, 0.3);
}

.btn-small:hover:not(.active) {
    background: rgba(255, 255, 255, 0.1);
}

.btn-start {
    margin-top: 20px;
}

.btn-icon {
    font-size: 1.3rem;
}

.btn-icon-only {
    width: 44px;
    height: 44px;
    min-width: auto;
    padding: 0;
    font-size: 1.35rem;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon-only:hover {
    background: rgba(255, 255, 255, 0.15);
}

.floating-theme-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 50;
    pointer-events: all;
    background: rgba(255, 255, 255, 0.1);
}

/* ========== DIFFICULTY SELECT ========== */
#difficulty-select {
    margin-top: 28px;
    transition: all 0.3s ease;
}

#difficulty-select.hidden {
    display: none;
}

.diff-label {
    color: rgba(255, 255, 255, 0.5);
    margin-bottom: 12px;
    font-size: 1.05rem;
    letter-spacing: 1px;
}

.difficulty-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

/* ========== NAME INPUTS ========== */
.name-input-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    margin-bottom: 14px;
}

.name-input-row label {
    font-size: 0.88rem;
    color: rgba(255, 255, 255, 0.45);
    letter-spacing: 1px;
}

.name-input {
    font-family: 'Rajdhani', sans-serif;
    font-size: 16px; /* explicitly 16px prevents iOS zoom issue */
    font-weight: 500;
    padding: 8px 16px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    text-align: center;
    outline: none;
    width: 200px;
    transition: border-color 0.2s;
}

.name-input:focus {
    border-color: rgba(124, 77, 255, 0.5);
}

.name-input::placeholder {
    color: rgba(255, 255, 255, 0.25);
}

#two-player-config {
    margin-top: 24px;
    transition: all 0.3s ease;
}

#two-player-config.hidden {
    display: none;
}

/* ========== SCORE BADGES ========== */
.player-score {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.8rem;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.08);
    padding: 2px 8px;
    border-radius: 6px;
    min-width: 26px;
    text-align: center;
    color: rgba(255, 255, 255, 0.7);
}

.result-score {
    font-size: 1.15rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.55);
    margin-bottom: 28px;
    letter-spacing: 1px;
}

.rules-hint {
    margin-top: 36px;
    padding: 14px 20px;
    border-radius: 10px;
    background: rgba(124, 77, 255, 0.08);
    border: 1px solid rgba(124, 77, 255, 0.15);
}

.rules-hint p {
    font-size: 0.92rem;
    color: rgba(255, 255, 255, 0.45);
    line-height: 1.5;
}

/* ========== GAME HUD ========== */
#game-hud {
    pointer-events: none;
    flex-direction: column;
    justify-content: space-between;
    padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

#game-hud.active {
    display: flex;
}

.hud-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(10, 10, 26, 0.75);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: 14px;
    padding: 10px 20px;
    pointer-events: all;
    border: 1px solid rgba(255, 255, 255, 0.06);
    gap: 8px;
}

.player-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    border-radius: 10px;
    transition: all 0.3s ease;
    opacity: 0.4;
    flex-shrink: 0;
}

.player-indicator.active {
    opacity: 1;
    background: rgba(255, 255, 255, 0.06);
}

.player-symbol {
    font-size: 1.5rem;
    font-weight: 900;
    line-height: 1;
}

.x-sym { color: #448aff; }
.o-sym { color: #ff5252; }

.player-name {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.75);
    white-space: nowrap;
}

.game-status {
    font-size: 1rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.85);
    text-align: center;
    letter-spacing: 0.5px;
    flex: 1;
    min-width: 0;
}

.hud-info {
    text-align: center;
    pointer-events: none;
    margin-top: 8px;
    font-size: 0.88rem;
    color: rgba(255, 255, 255, 0.35);
    letter-spacing: 0.5px;
    min-height: 22px;
}

.hud-bottom {
    display: flex;
    justify-content: center;
    gap: 10px;
    pointer-events: all;
}

/* ========== RESULT SCREEN ========== */
#result-screen {
    background: rgba(10, 10, 26, 0.88);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    align-items: center;
    justify-content: center;
    pointer-events: all;
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.result-content {
    text-align: center;
    padding: 40px 28px;
}

.result-icon {
    font-size: 4rem;
    margin-bottom: 16px;
    line-height: 1;
}

#result-text {
    font-family: 'Orbitron', sans-serif;
    font-size: clamp(1.6rem, 5vw, 2.8rem);
    font-weight: 700;
    margin-bottom: 12px;
    letter-spacing: 2px;
}

#result-text.x-win {
    background: linear-gradient(135deg, #448aff, #40c4ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

#result-text.o-win {
    background: linear-gradient(135deg, #ff5252, #ff8a80);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

#result-text.draw {
    background: linear-gradient(135deg, #b0bec5, #78909c);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.result-sub {
    font-size: 1rem;
    color: rgba(255, 255, 255, 0.4);
    margin-bottom: 36px;
}

.result-buttons {
    display: flex;
    gap: 14px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ========== INFO MODAL ========== */
.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: rgba(6, 6, 18, 0.88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal-card {
    background: rgba(22, 22, 48, 0.95);
    border: 1px solid rgba(124, 77, 255, 0.2);
    border-radius: 18px;
    padding: 32px 28px 28px;
    max-width: 520px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 8px 48px rgba(0, 0, 0, 0.5);
}

.modal-card::-webkit-scrollbar {
    width: 6px;
}

.modal-card::-webkit-scrollbar-thumb {
    background: rgba(124, 77, 255, 0.3);
    border-radius: 3px;
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    font-size: 1.8rem;
    cursor: pointer;
    line-height: 1;
    transition: color 0.2s;
}

.modal-close:hover {
    color: #fff;
}

.modal-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 20px;
    background: linear-gradient(135deg, #7c4dff, #40c4ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.modal-body {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.rule-section h3 {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: 4px;
    color: rgba(255, 255, 255, 0.9);
}

.rule-section p {
    font-size: 0.92rem;
    color: rgba(255, 255, 255, 0.55);
    line-height: 1.55;
}

.rule-section p strong {
    color: rgba(255, 255, 255, 0.85);
}

.x-color { color: #448aff !important; }
.o-color { color: #ff5252 !important; }
.hl-color { color: #00e676 !important; }

/* ========== LIGHT THEME ========== */
body.light-theme {
    background: #e9eaef;
    color: #1a1a2e;
}

.light-theme #loading-screen {
    background: #e9eaef;
}

.light-theme .loader p {
    color: rgba(26, 26, 46, 0.7);
}

.light-theme .spinner {
    border-color: rgba(26, 26, 46, 0.1);
    border-top-color: #7c4dff;
}

.light-theme #main-menu {
    background: rgba(233, 234, 239, 0.88);
}

.light-theme .subtitle {
    color: rgba(26, 26, 46, 0.6);
}

.light-theme .btn-secondary {
    background: rgba(26, 26, 46, 0.05);
    color: #1a1a2e;
    border-color: rgba(26, 26, 46, 0.15);
}

.light-theme .btn-secondary:hover {
    background: rgba(26, 26, 46, 0.1);
}

.light-theme .btn-small {
    background: rgba(26, 26, 46, 0.05);
    color: rgba(26, 26, 46, 0.7);
    border-color: rgba(26, 26, 46, 0.1);
}

.light-theme .btn-small.active {
    color: #fff;
}

.light-theme .btn-small:hover:not(.active) {
    background: rgba(26, 26, 46, 0.1);
}

.light-theme .diff-label,
.light-theme .name-input-row label {
    color: rgba(26, 26, 46, 0.6);
}

.light-theme .name-input {
    background: #fff;
    color: #1a1a2e;
    border-color: rgba(26, 26, 46, 0.2);
}

.light-theme .name-input::placeholder {
    color: rgba(26, 26, 46, 0.3);
}

.light-theme .rules-hint {
    background: rgba(124, 77, 255, 0.1);
    border-color: rgba(124, 77, 255, 0.2);
}

.light-theme .rules-hint p {
    color: rgba(26, 26, 46, 0.7);
}

.light-theme .hud-top {
    background: rgba(245, 245, 245, 0.85);
    border-color: rgba(26, 26, 46, 0.1);
}

.light-theme .player-name {
    color: rgba(26, 26, 46, 0.8);
}

.light-theme .game-status {
    color: #1a1a2e;
}

.light-theme .player-indicator.active {
    background: rgba(26, 26, 46, 0.08);
}

.light-theme .player-score {
    background: rgba(26, 26, 46, 0.1);
    color: #1a1a2e;
}

.light-theme .hud-info {
    color: rgba(26, 26, 46, 0.6);
    font-weight: 500;
}

.light-theme .btn-icon-only {
    background: rgba(255, 255, 255, 0.8);
    color: #1a1a2e;
    border-color: rgba(26, 26, 46, 0.1);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.light-theme .btn-icon-only:hover {
    background: #fff;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.light-theme #result-screen {
    background: rgba(233, 234, 239, 0.92);
}

.light-theme .result-sub {
    color: rgba(26, 26, 46, 0.6);
}

.light-theme .result-score {
    color: #1a1a2e;
}

.light-theme .modal-overlay {
    background: rgba(233, 234, 239, 0.9);
}

.light-theme .modal-card {
    background: #fff;
    border-color: rgba(124, 77, 255, 0.2);
    box-shadow: 0 8px 48px rgba(0, 0, 0, 0.15);
}

.light-theme .modal-close {
    color: rgba(26, 26, 46, 0.5);
}

.light-theme .modal-close:hover {
    color: #1a1a2e;
}

.light-theme .rule-section h3 {
    color: #1a1a2e;
}

.light-theme .rule-section p {
    color: rgba(26, 26, 46, 0.7);
}

.light-theme .rule-section p strong {
    color: #1a1a2e;
}

/* ========== ONLINE LOBBY ========== */
#online-lobby {
    margin-top: 24px;
    transition: all 0.3s ease;
}

#online-lobby.hidden {
    display: none;
}

.online-lobby-buttons {
    display: flex;
    flex-direction: column;
    gap: 14px;
    align-items: center;
    margin-top: 16px;
}

.join-room-row {
    display: flex;
    gap: 8px;
    align-items: center;
    width: 100%;
    max-width: 280px;
}

.room-code-input {
    flex: 1;
    font-family: 'Orbitron', monospace;
    font-size: 16px;
    letter-spacing: 4px;
    text-align: center;
    text-transform: uppercase;
}

.btn-join {
    min-width: 70px !important;
    height: 42px;
}

.online-error {
    color: #ff5252;
    font-size: 0.88rem;
    margin-top: 10px;
    text-align: center;
}

.online-error.hidden {
    display: none;
}

/* ========== WAITING ROOM ========== */
#waiting-room {
    margin-top: 24px;
    transition: all 0.3s ease;
}

#waiting-room.hidden {
    display: none;
}

.waiting-content {
    text-align: center;
}

.room-code-display {
    margin-bottom: 24px;
}

.room-code-label {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.45);
    letter-spacing: 2px;
    margin-bottom: 8px;
    text-transform: uppercase;
}

.room-code-value {
    font-family: 'Orbitron', monospace;
    font-size: clamp(2rem, 6vw, 3rem);
    font-weight: 900;
    letter-spacing: 10px;
    background: linear-gradient(135deg, #7c4dff 0%, #448aff 50%, #40c4ff 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 12px;
}

.waiting-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.waiting-spinner p {
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.95rem;
    letter-spacing: 1px;
}

/* ========== CHAT PANEL ========== */
.chat-panel {
    position: fixed;
    right: -360px;
    top: 0;
    width: 340px;
    max-width: 85vw;
    height: 100%;
    background: rgba(14, 14, 30, 0.95);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 60;
    display: flex;
    flex-direction: column;
    transition: right 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.3);
}

.chat-panel.open {
    right: 0;
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.chat-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: 1px;
}

.chat-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    font-size: 1.6rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.chat-close:hover {
    color: #fff;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(124, 77, 255, 0.3);
    border-radius: 2px;
}

.chat-msg {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 0.88rem;
    line-height: 1.4;
    word-break: break-word;
}

.chat-msg.sent {
    align-self: flex-end;
    background: linear-gradient(135deg, #7c4dff, #536dfe);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-msg.received {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.85);
    border-bottom-left-radius: 4px;
}

.chat-msg .msg-sender {
    font-size: 0.72rem;
    opacity: 0.6;
    display: block;
    margin-bottom: 2px;
    font-weight: 600;
}

.chat-msg.system {
    align-self: center;
    background: rgba(124, 77, 255, 0.15);
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.78rem;
    padding: 4px 12px;
    border-radius: 20px;
    max-width: 90%;
    text-align: center;
}

.chat-input-row {
    display: flex;
    gap: 6px;
    padding: 10px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    font-family: 'Rajdhani', sans-serif;
    font-size: 16px;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.06);
    color: #fff;
    outline: none;
}

.chat-input:focus {
    border-color: rgba(124, 77, 255, 0.5);
}

.chat-send {
    min-width: 40px !important;
    padding: 6px !important;
    font-size: 1.1rem !important;
}

.chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #ff5252;
    font-size: 0.6rem;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

/* ========== VIDEO CALL OVERLAY (draggable) ========== */
.video-overlay {
    position: fixed;
    inset: 0;
    z-index: 55;
    pointer-events: none;
}

.video-overlay.hidden {
    display: none;
}

.video-container {
    position: absolute;
    top: 80px;
    left: 16px;
    width: 340px;
    background: rgba(14, 14, 30, 0.95);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid rgba(124, 77, 255, 0.35);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    pointer-events: all;
    z-index: 56;
    user-select: none;
    transition: box-shadow 0.2s;
}

.video-container:hover {
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
}

.video-drag-handle {
    padding: 8px 14px;
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.6);
    cursor: grab;
    background: rgba(124, 77, 255, 0.12);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    gap: 6px;
}

.video-drag-handle:active {
    cursor: grabbing;
}

.video-streams {
    display: flex;
    gap: 4px;
    padding: 8px;
}

.video-remote-wrap {
    position: relative;
    flex: 1;
    height: 140px;
    border-radius: 10px;
    overflow: hidden;
    background: #000;
    border: 1px solid rgba(124, 77, 255, 0.3);
}

.video-remote-wrap video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.video-label {
    position: absolute;
    bottom: 4px;
    left: 6px;
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.7);
    background: rgba(0, 0, 0, 0.55);
    padding: 2px 6px;
    border-radius: 4px;
}

.video-local-wrap {
    width: 100px;
    height: 140px;
    border-radius: 10px;
    overflow: hidden;
    background: #111;
    border: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0;
}

.video-local-wrap video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

.video-controls {
    display: flex;
    gap: 8px;
    justify-content: center;
    padding: 8px 8px 10px;
}

.vc-btn {
    width: 40px !important;
    height: 40px !important;
    font-size: 1.1rem !important;
    border-radius: 50% !important;
}

.vc-btn.muted {
    background: rgba(255, 82, 82, 0.3) !important;
    border-color: rgba(255, 82, 82, 0.5) !important;
}

.vc-end {
    background: rgba(255, 82, 82, 0.3) !important;
    border-color: rgba(255, 82, 82, 0.5) !important;
}

.vc-end:hover {
    background: rgba(255, 82, 82, 0.5) !important;
}

/* ========== INCOMING CALL MODAL ========== */
.incoming-call-card {
    animation: callPulse 1.5s ease-in-out infinite;
}

@keyframes callPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(124, 77, 255, 0.4); }
    50% { box-shadow: 0 0 0 14px rgba(124, 77, 255, 0); }
}

.incoming-call-icon {
    font-size: 2.8rem;
    margin-bottom: 10px;
    animation: callRing 0.6s ease-in-out infinite alternate;
}

@keyframes callRing {
    from { transform: rotate(-12deg); }
    to { transform: rotate(12deg); }
}

.call-accept-btn {
    background: linear-gradient(135deg, #00c853, #00e676) !important;
    border: none !important;
    color: #fff !important;
}

.call-decline-btn {
    background: rgba(255, 82, 82, 0.25) !important;
    border-color: rgba(255, 82, 82, 0.5) !important;
    color: #ff5252 !important;
}

/* ========== RESET CONFIRM MODAL ========== */
.modal-card-small {
    max-width: 340px;
    text-align: center;
}

.modal-card-small p {
    color: rgba(255, 255, 255, 0.65);
    margin-bottom: 20px;
    font-size: 0.95rem;
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.modal-actions .btn {
    min-width: 100px;
}

/* ========== CONNECTION TOAST ========== */
.connection-toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(14, 14, 30, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(124, 77, 255, 0.3);
    border-radius: 12px;
    padding: 10px 24px;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.85);
    z-index: 200;
    pointer-events: none;
    transition: opacity 0.4s ease, transform 0.4s ease;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

.connection-toast.hidden {
    opacity: 0;
    transform: translateX(-50%) translateY(-20px);
    pointer-events: none;
}

.connection-toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.connection-toast.error {
    border-color: rgba(255, 82, 82, 0.5);
}

.connection-toast.success {
    border-color: rgba(0, 230, 118, 0.5);
}

/* ========== LIGHT THEME (new components) ========== */
.light-theme .chat-panel {
    background: rgba(245, 245, 250, 0.96);
    border-left-color: rgba(26, 26, 46, 0.1);
}

.light-theme .chat-header {
    border-bottom-color: rgba(26, 26, 46, 0.1);
}

.light-theme .chat-title {
    color: #1a1a2e;
}

.light-theme .chat-close {
    color: rgba(26, 26, 46, 0.5);
}

.light-theme .chat-close:hover {
    color: #1a1a2e;
}

.light-theme .chat-msg.received {
    background: rgba(26, 26, 46, 0.06);
    color: #1a1a2e;
}

.light-theme .chat-msg.system {
    background: rgba(124, 77, 255, 0.08);
    color: rgba(26, 26, 46, 0.5);
}

.light-theme .chat-input-row {
    border-top-color: rgba(26, 26, 46, 0.1);
}

.light-theme .chat-input {
    background: #fff;
    color: #1a1a2e;
    border-color: rgba(26, 26, 46, 0.15);
}

.light-theme .room-code-label {
    color: rgba(26, 26, 46, 0.5);
}

.light-theme .waiting-spinner p {
    color: rgba(26, 26, 46, 0.5);
}

.light-theme .online-error {
    color: #d32f2f;
}

.light-theme .connection-toast {
    background: rgba(255, 255, 255, 0.95);
    color: #1a1a2e;
    border-color: rgba(124, 77, 255, 0.3);
}

.light-theme .modal-card-small p {
    color: rgba(26, 26, 46, 0.65);
}

.light-theme .video-container {
    background: rgba(245, 245, 250, 0.96);
    border-color: rgba(124, 77, 255, 0.25);
}

.light-theme .video-drag-handle {
    color: rgba(26, 26, 46, 0.6);
    background: rgba(124, 77, 255, 0.08);
    border-bottom-color: rgba(26, 26, 46, 0.08);
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  
    
    .game-title {
        font-size: clamp(2.2rem, 8vw, 3.5rem);
    }

    .menu-content {
        padding: 24px 16px;
    }

    .subtitle {
        letter-spacing: 5px;
        margin-bottom: 32px;
    }

    .btn {
        font-size: 1.05rem;
        padding: 12px 28px;
        min-width: 200px;
    }

    .hud-top {
        padding: 8px 12px;
        border-radius: 12px;
    }

    .player-name {
        max-width: 80px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .player-indicator {
        padding: 5px 10px;
    }

    .game-status {
        font-size: 0.95rem;
    }

    .modal-card {
        padding: 24px 20px;
        max-height: 85vh;
    }
}

@media (max-width: 480px) {
     .difficulty-buttons .btn{
    min-width: 50px !important;
   }
    .subtitle {
        letter-spacing: 3px;
        margin-bottom: 24px;
    }

    .hud-top {
        padding: 6px 8px;
        gap: 6px;
    }

    .player-indicator {
        flex-direction: column;
        gap: 2px;
        min-width: 65px;
        padding: 4px;
        border-radius: 8px;
    }

    .player-symbol {
        font-size: 1.3rem;
        margin-bottom: -2px;
    }

    .player-name {
        font-size: 0.75rem;
        max-width: 60px;
    }
    
    .player-score {
        position: absolute;
        top: -6px;
        right: -6px;
        font-size: 0.7rem;
        padding: 2px 5px;
        min-width: 20px;
        background: rgba(124, 77, 255, 0.9);
        border-radius: 10px;
        color: #fff;
    }

    #player-o .player-score {
        background: rgba(255, 82, 82, 0.9);
    }
    
    .player-indicator { position: relative; }

    .game-status {
        font-size: 0.85rem;
        line-height: 1.2;
    }

    .btn {
        min-width: 100%;
        padding: 12px 16px;
        font-size: 1rem;
    }

    .btn-icon-only {
        width: 42px;
        height: 42px;
        min-width: auto;
        font-size: 1.25rem;
    }

    .rules-hint {
        margin-top: 24px;
        padding: 10px 14px;
    }

    .rules-hint p {
        font-size: 0.82rem;
    }
    
    #game-hud {
        padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
    }
    
    .name-input {
        width: 100%;
    }
    
    #result-text {
        font-size: 2.2rem;
    }
    
    /* Chat mobile */
    .chat-panel {
        width: 100%;
        max-width: 100vw;
        right: -100%;
    }
    
    /* Video mobile */
    .video-container {
        width: 260px;
        left: 8px;
        top: 70px;
    }
    
    .video-streams {
        padding: 6px;
    }
    
    .video-remote-wrap {
        height: 100px;
    }
    
    .video-local-wrap {
        width: 75px;
        height: 100px;
    }
    
    .vc-btn {
        width: 36px !important;
        height: 36px !important;
        font-size: 0.95rem !important;
    }
    
    /* Online lobby mobile */
    .join-room-row {
        flex-direction: column;
        max-width: 100%;
    }
    
    .btn-join {
        min-width: 100% !important;
    }
}

@media (max-width: 360px) {
    .player-name { display: none; }
}

@media (max-height: 500px) {
    .subtitle {
        margin-bottom: 16px;
    }

    .rules-hint {
        display: none;
    }

    #difficulty-select {
        margin-top: 14px;
    }
    
    .game-title {
        font-size: 2rem;
    }
}
