:root {
    /* Refined Modern Palette */
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-alt: #334155;
    --accent: #10b981;
    /* Emerald */
    --accent-glow: rgba(16, 185, 129, 0.2);
    --secondary: #3b82f6;
    /* Blue */
    --danger: #ef4444;
    --warning: #f59e0b;
    --text: #f8fafc;
    --text-dim: #94a3b8;
    --border: rgba(255, 255, 255, 0.06);
    --radius-lg: 16px;
    --radius-md: 10px;
}

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

body {
    font-family: 'IBM Plex Sans Arabic', sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
    overflow-x: hidden;
}

#app {
    max-width: 1100px;
    margin: 0 auto;
    padding-bottom: 40px;
    padding-top: 140px; /* Further increased to ensure no overlap and better breathing room */
    padding-right: 15px;
    padding-left: 15px;
}

/* ============================
   TYPOGRAPHY
   ============================ */
h1,
h2,
h3 {
    font-weight: 700;
}

.logo {
    font-size: 22px;
    text-align: center;
    padding: 25px 0;
    font-weight: 700;
    letter-spacing: 0px;
}

.logo span {
    color: var(--accent);
}

/* ============================
   FORMS & SELECTS (Premium Redesign)
   ============================ */
.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-dim);
    text-transform: uppercase;
    margin-bottom: 10px;
    letter-spacing: 0px;
}

select,
input {
    width: 100%;
    padding: 14px 18px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    appearance: none;
}

select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%2310b981' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 15px center;
    padding-left: 45px;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

select:focus,
input:focus {
    border-color: var(--accent);
    background: var(--surface-alt);
    box-shadow: 0 0 0 4px var(--accent-glow);
}

select option {
    background: #1e293b;
    color: var(--text);
    padding: 15px;
}

/* ============================
   BUTTONS (Modern & Consistent)
   ============================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid transparent;
    font-family: inherit;
    gap: 10px;
    outline: none;
    min-width: 130px;
}

.btn.primary {
    background: var(--accent);
    color: #064e3b;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.2);
}

.btn.secondary {
    background: var(--surface-alt);
    color: var(--text);
    border-color: var(--border);
}

.btn.danger {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.2);
}

.btn.outline {
    background: transparent;
    border-color: var(--border);
    color: var(--text);
}

.btn:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}

.btn:active {
    transform: scale(0.97);
}

/* Small buttons for cards */
.mac-btn {
    min-width: 80px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
    transition: 0.2s;
    font-size: 14px;
    text-decoration: none;
    padding: 0 15px;
}

.mac-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

/* ============================
   CARDS (Consistent Layout)
   ============================ */
#tables-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 20px;
    padding: 15px;
}

.mini-arena-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    transition: 0.3s;
}

.mini-arena-card:hover {
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.mac-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.mac-title {
    font-weight: 800;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.mac-badge {
    font-size: 11px;
    background: var(--surface-alt);
    padding: 2px 8px;
    border-radius: 20px;
    color: var(--text-dim);
}

.mac-body {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    gap: 10px;
}

.mac-player {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    text-align: center;
}

.mp-avatar {
    width: 60px;
    height: 60px;
    border-radius: 16px;
    object-fit: cover;
    background: var(--surface-alt);
}

.mp-name {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
    height: 32px;
    overflow: hidden;
}

.mp-score-ball {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #fff;
    color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 900;
    box-shadow: inset -2px -2px 4px rgba(0, 0, 0, 0.3), 0 4px 8px rgba(0, 0, 0, 0.2);
}

.mac-vs {
    color: var(--warning);
    font-weight: 950;
    font-size: 18px;
    opacity: 0.6;
}

.mac-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.timer-label {
    font-size: 13px;
    font-weight: 700;
    color: var(--accent);
}

/* ============================
   FORMS
   ============================ */
.setup-card {
    background: var(--surface);
    margin: 20px 15px;
    padding: 25px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 800;
    color: var(--text-dim);
    text-transform: uppercase;
    margin-bottom: 8px;
}

select,
input {
    width: 100%;
    padding: 12px 15px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: 0.2s;
}

select:focus,
input:focus {
    border-color: var(--accent);
}

/* ============================
   MODALS
   ============================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-overlay.hidden {
    display: none;
}

.modal-box {
    background: var(--surface);
    width: 100%;
    max-width: 400px;
    max-height: 90vh;
    border-radius: 24px;
    padding: 30px;
    border: 1px solid var(--border);
    overflow-y: auto;
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.5);
}

.modal-box h3 {
    margin-bottom: 10px;
    text-align: center;
}

/* ============================
   TOP BAR
   ============================ */
.app-topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: rgba(15, 23, 42, 0.98);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 1500;
    display: flex;
    flex-direction: column;
    padding: 0;
    box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
}

.app-topbar-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 17px;
    font-weight: 700;
    color: var(--text);
}

.app-topbar-badge {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0px;
    background: linear-gradient(135deg, var(--accent), #059669);
    color: #064e3b;
    padding: 2px 8px;
    border-radius: 20px;
}

/* ============================
   FOOTER
   ============================ */
.app-footer {
    display: block;
    text-align: center;
    font-size: 10px;
    color: var(--text-dim);
    font-weight: 700;
    letter-spacing: 0.5px;
    opacity: 0.7;
    padding: 30px 0;
    margin-top: 20px;
}

.app-footer a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 900;
    pointer-events: auto;
}

.app-footer a:hover {
    text-shadow: 0 0 10px var(--accent-glow);
}

/* ============================
   STATIC FOOTER NAV (Premium)
   ============================ */
/* ============================
   FLOATING BOTTOM NAV (Premium)
   ============================ */
/* ============================
   MAIN TOP NAVIGATION (Integrated)
   ============================ */
.main-nav {
    display: flex;
    justify-content: flex-start; /* Aligns items to the right in RTL */
    align-items: center;
    gap: 15px;
    width: 100%;
    margin: 0 auto;
    padding: 5px 20px;
    direction: rtl;
    overflow-x: auto;
    scrollbar-width: none;
}
.main-nav::-webkit-scrollbar { display: none; }

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--text-dim);
    transition: all 0.3s ease;
    padding: 10px 15px;
    opacity: 0.6;
    flex-shrink: 0;
}

.nav-icon {
    font-size: 24px;
    margin-bottom: 5px;
    transition: 0.3s;
}

.nav-label {
    font-size: 14px;
    font-weight: 800;
    text-align: center;
    white-space: nowrap;
    margin-top: 2px;
}

.nav-item:hover {
    color: #fff;
    opacity: 1;
}

.nav-item.active {
    color: var(--accent);
    opacity: 1;
    position: relative;
}

.nav-item.active .nav-icon {
    transform: scale(1.1);
    filter: drop-shadow(0 0 10px var(--accent-glow));
}

.nav-item.active::after {
    content: '';
    position: absolute;
    bottom: 2px;
    width: 20px;
    height: 3px;
    background: var(--accent);
    border-radius: 10px;
    box-shadow: 0 0 10px var(--accent-glow);
}

.nav-item.locked {
    opacity: 0.2;
    filter: grayscale(1);
}

/* ============================
   SCREEN & PAGE HEADER
   ============================ */
.screen {
    padding-top: 10px;
}

.screen-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 20px 15px 20px;
    margin-bottom: 5px;
}

.screen-header h2 {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--text);
}

@media (max-width: 600px) {
    #tables-list {
        grid-template-columns: 1fr;
    }
}

/* Premium Toggle Switch */
.premium-toggle { display: flex; align-items: center; justify-content: space-between; padding: 15px 20px; background: rgba(255, 255, 255, 0.05); border-radius: 14px; cursor: pointer; transition: all 0.3s ease; border: 1px solid rgba(255, 255, 255, 0.05); }
.premium-toggle:active { transform: scale(0.98); }
.premium-toggle span { font-weight: 700; color: #fff; }
.switch { position: relative; display: inline-block; width: 46px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #334155; transition: .4s; border-radius: 24px; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .4s; border-radius: 50%; }
input:checked + .slider { background-color: var(--accent); }
input:checked + .slider:before { transform: translateX(22px); }

/* Option Selector Grid */
.option-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 10px; }
.option-item {
    background: rgba(255,255,255,0.03); border: 1px solid var(--border);
    padding: 15px; border-radius: 12px; text-align: center; cursor: pointer;
    transition: all 0.3s ease; display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.option-item i { font-size: 20px; opacity: 0.7; }
.option-item span { font-size: 13px; font-weight: 700; color: #fff; }
.option-item.active {
    background: rgba(16, 185, 129, 0.1); border-color: var(--accent); scale: 1.02;
    box-shadow: 0 5px 15px rgba(16, 185, 129, 0.2);
}
.option-item.active i { color: var(--accent); opacity: 1; }

/* Glassmorphism Option Cards */
.cast-options { display: flex; gap: 15px; margin-top: 15px; }
.cast-option-card { flex: 1; position: relative; background: rgba(255, 255, 255, 0.02); border: 1px solid rgba(255, 255, 255, 0.06); border-radius: 20px; padding: 22px 10px; text-align: center; cursor: pointer; transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275); overflow: hidden; }
.cast-option-card .icon-box { width: 48px; height: 48px; background: rgba(255, 255, 255, 0.04); border-radius: 14px; display: flex; align-items: center; justify-content: center; margin: 0 auto 12px; font-size: 22px; transition: 0.4s; }
.cast-option-card .label { font-size: 13px; font-weight: 800; color: var(--text-dim); transition: 0.4s; }
.cast-option-card.active { border-color: var(--accent); background: rgba(16, 185, 129, 0.08); transform: translateY(-4px); box-shadow: 0 12px 24px rgba(0,0,0,0.4), 0 0 15px var(--accent-glow); }
.cast-option-card.active .icon-box { background: var(--accent); transform: scale(1.05); }
.cast-option-card.active .label { color: #fff; }
