:root {
    --bg-dark: #0f172a;
    --bg-gradient: radial-gradient(circle at center, #1e1b4b, #020617 80%);
    --glass-bg: rgba(255, 255, 255, 0.04);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 15px 35px 0 rgba(0, 0, 0, 0.5);
    --primary: #4f46e5;
    --primary-glow: #6366f1;
    --success: #10b981;
    --danger: #f43f5e;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --dropdown-bg: rgba(15, 23, 42, 0.85);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Poppins', sans-serif;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overscroll-behavior: none;
}

body {
    background: var(--bg-gradient);
    color: var(--text-main);
    min-height: 100vh;
    min-height: 100dvh;
    width: 100vw;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 12px;
    overflow: hidden;
}

/* Full Overlay Loader */
.full-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--bg-dark); z-index: 10000;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
    opacity: 0; pointer-events: none; transition: opacity 0.3s ease;
}
.full-overlay.active { opacity: 1; pointer-events: auto; }
.loader-spinner {
    width: 50px; height: 50px; border: 4px solid rgba(255,255,255,0.1);
    border-top: 4px solid var(--primary-glow); border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* Base Glassmorphism & 3D Elements */
.app-wrapper {
    position: relative;
    width: 100%;
    max-width: 440px;
    height: 100%;
    max-height: 850px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.glass {
    background: var(--glass-bg); backdrop-filter: blur(16px) saturate(180%);
    -webkit-backdrop-filter: blur(16px) saturate(180%);
    border: 1px solid var(--glass-border); box-shadow: var(--glass-shadow);
    border-radius: 35px;
}

.glass-inner {
    background: rgba(0, 0, 0, 0.3); border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 20px; padding: 18px; box-shadow: inset 0 4px 15px rgba(0,0,0,0.4);
}

.3d-box { box-shadow: 0 8px 0 rgba(0,0,0,0.3), inset 0 2px 10px rgba(255,255,255,0.05); }

/* Screens */
.screen {
    width: 100%; height: 100%; position: absolute; display: flex; flex-direction: column;
    padding: 22px; opacity: 0; pointer-events: none;
    transform: scale(0.95); transition: all 0.3s ease;
    overflow-y: auto; overflow-x: hidden;
}
.screen::-webkit-scrollbar { width: 4px; }
.screen::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 10px; }
.screen.active { opacity: 1; pointer-events: auto; transform: scale(1); z-index: 2;}

/* Panels */
.panel { display: none; flex-direction: column; flex: 1; animation: fadeIn 0.3s ease; padding-bottom: 10px; min-width: 0;}
.panel.active { display: flex; }

/* Typography */
.logo-3d {
    font-size: clamp(2rem, 8vw, 2.8rem); font-weight: 800; text-align: center; margin: 15px 0 30px 0;
    background: linear-gradient(to bottom right, #a855f7, #3b82f6);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 4px 10px rgba(99, 102, 241, 0.5));
    flex-shrink: 0;
}

.glow-text { text-shadow: 0 0 15px rgba(255,255,255,0.3); }
.success-text { color: var(--success); text-shadow: 0 0 10px rgba(16, 185, 129, 0.4); }
.danger-text { color: var(--danger); text-shadow: 0 0 10px rgba(244, 63, 94, 0.4); }
.muted { color: var(--text-muted); font-size: 0.85rem; }

/* Buttons & Inputs */
.btn {
    display: flex; justify-content: center; align-items: center; padding: 16px;
    border-radius: 18px; font-weight: 700; cursor: pointer; text-transform: uppercase;
    letter-spacing: 1px; transition: all 0.15s ease; flex-shrink: 0;
    text-align: center; word-break: break-word;
}

.3d-btn { box-shadow: 0 6px 0 rgba(0,0,0,0.5), 0 12px 25px rgba(0,0,0,0.4), inset 0 2px 5px rgba(255,255,255,0.2); }
.3d-btn:active { transform: translateY(6px); box-shadow: 0 0 0 rgba(0,0,0,0.5), 0 2px 5px rgba(0,0,0,0.4), inset 0 2px 5px rgba(255,255,255,0.2); }

.primary { background: linear-gradient(135deg, var(--primary), #3b82f6); }
.success { background: linear-gradient(135deg, #059669, #10b981); }
.danger { background: linear-gradient(135deg, #be123c, #f43f5e); }
.small { padding: 8px 16px; font-size: 0.8rem; border-radius: 12px; box-shadow: 0 4px 0 rgba(0,0,0,0.5); margin-top: 0; flex-shrink: 0;}
.small:active { transform: translateY(4px); box-shadow: 0 0 0 rgba(0,0,0,0.5); }

/* Max Buttons & Layouts */
.flex-between { display: flex; justify-content: space-between; align-items: center; width: 100%; margin: 15px 0; gap: 10px;}
.btn-max {
    background: rgba(99, 102, 241, 0.15); border: 1px solid var(--primary);
    color: var(--primary-glow); padding: 8px 15px; border-radius: 10px;
    cursor: pointer; font-weight: 700; font-size: 0.85rem; transition: 0.2s;
    flex-shrink: 0; white-space: nowrap;
}
.btn-max:active { transform: scale(0.95); background: var(--primary); color: white;}

input {
    width: 100%; padding: 16px; border-radius: 15px; border: 2px solid transparent;
    background: rgba(0,0,0,0.4); color: white; font-size: 1.05rem; font-weight: 600;
    box-shadow: inset 0 3px 6px rgba(0,0,0,0.5); outline: none; transition: 0.3s;
    min-width: 0;
}
input:focus { border-color: var(--primary); background: rgba(0,0,0,0.6); }
input::placeholder { color: var(--text-muted); }

/* Auth Slider */
.auth-slider { position: relative; flex: 1; overflow: hidden; min-height: 320px;}
.auth-panel {
    position: absolute; width: 100%; height: 100%; display: flex; flex-direction: column; gap: 18px;
    transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    opacity: 0; transform: translateX(120%); pointer-events: none;
}
.auth-panel.active-panel { opacity: 1; transform: translateX(0); pointer-events: auto; }
.auth-panel.slide-left { transform: translateX(-120%); }
.switch-text { text-align: center; font-size: 0.9rem; color: var(--text-muted); margin-top: 8px; }
.switch-text span { color: var(--primary-glow); font-weight: 700; cursor: pointer; }

/* Custom Dropdown (still used for signup wallet address) */
.custom-dropdown { position: relative; width: 100%; margin-bottom: 5px; min-width: 0;}
.dropdown-selected {
    background: rgba(0,0,0,0.4); padding: 16px; border-radius: 15px;
    cursor: pointer; font-weight: 600; border: 2px solid transparent;
    display: flex; justify-content: space-between; align-items: center; box-shadow: inset 0 3px 6px rgba(0,0,0,0.5);
    gap: 10px; overflow: hidden;
}
.dropdown-selected::after { content: '▼'; font-size: 0.8rem; color: var(--primary-glow); flex-shrink: 0;}
.custom-dropdown.open .dropdown-selected { border-color: var(--primary); }
.dropdown-options {
    position: absolute; top: 105%; left: 0; width: 100%; background: var(--dropdown-bg);
    backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border: 1px solid var(--glass-border);
    border-radius: 15px; max-height: 200px; overflow-y: auto; opacity: 0; visibility: hidden; transform: translateY(-10px);
    transition: 0.3s; z-index: 100; box-shadow: var(--glass-shadow);
}
.custom-dropdown.open .dropdown-options { opacity: 1; visibility: visible; transform: translateY(0); }
.dropdown-options div { padding: 15px; cursor: pointer; border-bottom: 1px solid rgba(255,255,255,0.05); font-weight: 600; overflow-wrap: break-word;}
.dropdown-options div:hover { background: rgba(255,255,255,0.1); }
.dropdown-options div:last-child { border-bottom: none; }
.dropdown-options::-webkit-scrollbar { width: 6px; }
.dropdown-options::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 10px; }

/* Main App Layout */
.header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; flex-shrink: 0;}
.user-info { display: flex; justify-content: space-between; width: 100%; align-items: center; gap: 10px;}
.user-id { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
#display-user {
    font-size: 1.05rem; font-weight: 700; background: rgba(0,0,0,0.4); padding: 5px 12px;
    border-radius: 8px; border-left: 3px solid var(--primary);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%;
}
.address-text {
    font-size: 0.72rem; color: var(--text-muted); margin-top: 5px; margin-left: 5px;
    font-family: monospace; letter-spacing: 0.5px; white-space: nowrap;
}

.balance-card { margin-bottom: 16px; display: flex; flex-direction: column; gap: 8px; flex-shrink: 0;}
.balance-row { display: flex; justify-content: space-between; align-items: center; font-size: 1.15rem; font-weight: bold; gap: 10px;}
.balance-row strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;}
.balance-row:first-child { font-size: 1.3rem; }
.small-bal { font-size: 0.88rem; color: var(--text-muted); border-top: 1px solid rgba(255,255,255,0.08); padding-top: 7px; margin-top: 2px; }
.small-bal strong { font-size: 0.95rem; }
.pnl-positive { color: var(--success) !important; }
.pnl-negative { color: var(--danger) !important; }

/* Navigation Tabs */
.3d-tabs {
    display: flex; gap: 8px; margin-bottom: 12px; background: rgba(0,0,0,0.2);
    padding: 7px; border-radius: 20px; box-shadow: inset 0 3px 10px rgba(0,0,0,0.3); flex-shrink: 0;
}
.3d-tabs .tab {
    flex: 1; text-align: center; padding: 11px 4px; border-radius: 14px;
    font-weight: 700; cursor: pointer; transition: 0.3s; color: var(--text-muted);
    font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.3d-tabs .tab.active {
    background: var(--primary); color: white;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.5), inset 0 2px 5px rgba(255,255,255,0.2);
}

/* Action sub-tabs */
.action-tabs { display: flex; gap: 10px; flex: 1; margin: 0; min-width: 0;}
.action-tab { flex: 1; text-align: center; padding: 10px; background: rgba(0,0,0,0.4); border-radius: 12px; cursor: pointer; transition: 0.3s; font-size: 0.9rem; font-weight: 600;}
.action-tab.active { background: rgba(255,255,255,0.1); border: 1px solid var(--glass-border); box-shadow: 0 4px 10px rgba(0,0,0,0.3); color: var(--primary-glow);}
.action-tab.buy-active.active { color: var(--success); }
.action-tab.sell-active.active { color: var(--danger); }

/* ===== Coin List Cards (Market / Portfolio / Bank) ===== */
.coin-list { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; flex: 1; padding-bottom: 10px; min-height: 0;}
.coin-list::-webkit-scrollbar { width: 4px; }
.coin-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 10px; }

.section-label { font-size: 0.85rem; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 10px; flex-shrink: 0;}

.coin-card {
    background: rgba(0,0,0,0.3); border: 1px solid rgba(255,255,255,0.06);
    border-radius: 18px; padding: 14px 16px; display: flex; align-items: center; gap: 12px;
    cursor: pointer; transition: 0.2s; box-shadow: inset 0 2px 8px rgba(0,0,0,0.3);
    flex-shrink: 0;
}
.coin-card:active { transform: scale(0.98); background: rgba(0,0,0,0.45); }

.coin-icon {
    width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-weight: 800; font-size: 0.85rem; color: white;
    background: linear-gradient(135deg, var(--primary), #3b82f6);
    box-shadow: 0 4px 10px rgba(0,0,0,0.4);
}

.coin-card-info { display: flex; flex-direction: column; min-width: 0; flex: 1; gap: 2px;}
.coin-card-symbol { font-weight: 700; font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}
.coin-card-sub { font-size: 0.78rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}

.coin-card-values { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex-shrink: 0; text-align: right;}
.coin-card-primary { font-weight: 700; font-size: 0.98rem; white-space: nowrap; }
.coin-card-secondary { font-size: 0.76rem; color: var(--text-muted); white-space: nowrap; }

.coin-card-chevron { color: var(--primary-glow); font-size: 1.1rem; flex-shrink: 0; }

.empty-state {
    text-align: center; color: var(--text-muted); font-size: 0.9rem;
    padding: 30px 15px; line-height: 1.5;
}
.hidden { display: none !important; }

/* Trade / Bank Modals */
.trade-modal-box { gap: 14px; border-color: var(--glass-border); box-shadow: var(--glass-shadow); }
.trade-modal-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.trade-modal-coin { display: flex; align-items: center; gap: 12px; min-width: 0; }
.trade-modal-coin h3 { font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px;}
.modal-close {
    width: 32px; height: 32px; border-radius: 50%; background: rgba(255,255,255,0.06);
    display: flex; align-items: center; justify-content: center; cursor: pointer;
    flex-shrink: 0; font-size: 0.9rem; color: var(--text-muted);
}
.modal-close:active { background: rgba(255,255,255,0.15); }

.price-ticker { text-align: center; margin: 12px 0; padding: 18px;}
.pulse { display: inline-block; font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 2px; animation: pulse 2s infinite; margin-bottom: 5px;}
@keyframes pulse { 0% { opacity: 0.4; } 50% { opacity: 1; } 100% { opacity: 0.4; } }
#live-price { font-size: clamp(1.6rem, 7vw, 2.2rem); font-weight: 800; word-break: break-word;}

.trade-inputs { display: flex; align-items: flex-end; gap: 10px; margin-bottom: 5px; }
.trade-inputs.single-input { justify-content: center; }
.input-group { flex: 1; display: flex; flex-direction: column; gap: 5px; position: relative; min-width: 0;}
.input-group label { font-size: 0.78rem; color: var(--text-muted); padding-left: 5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;}
.swap-icon { font-size: 1.4rem; color: var(--primary-glow); margin-bottom: 14px; font-weight: bold; flex-shrink: 0;}

.fee-info { display: flex; flex-direction: column; gap: 8px; margin: 15px 0; font-size: 0.88rem; }
.fee-row { display: flex; justify-content: space-between; color: var(--text-muted); gap: 10px;}
.fee-row span:last-child { text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;}
.fee-row.highlight { color: white; font-weight: 700; border-top: 1px solid rgba(255,255,255,0.1); padding-top: 8px; margin-top: 4px; font-size: 1rem;}

/* Bank Specific */
.bank-header { text-align: center; margin-bottom: 0; flex-shrink: 0;}
.bank-header h3 { font-size: 1.15rem; margin-bottom: 5px; }

.bank-card-rate {
    font-size: 0.72rem; background: rgba(16, 185, 129, 0.12); color: var(--success);
    padding: 3px 9px; border-radius: 8px; display: inline-block; margin-top: 3px; white-space: nowrap;
}

/* Admin Panel */
.admin-scroll { display: flex; flex-direction: column; gap: 15px; padding-bottom: 20px;}
.admin-section { display: flex; flex-direction: column; gap: 10px; }
.admin-section h3 { font-size: 1rem; color: var(--primary-glow); border-bottom: 1px solid rgba(255,255,255,0.1); padding-bottom: 8px;}
.admin-input-row { display: flex; justify-content: space-between; align-items: center; gap: 12px;}
.admin-input-row label { font-size: 0.85rem; flex: 1; min-width: 0;}
.admin-input-row input { flex: 1; padding: 10px; font-size: 0.95rem; text-align: right; min-width: 0;}
.treasury-item { display: flex; justify-content: space-between; border-bottom: 1px dashed rgba(255,255,255,0.1); padding: 8px 0; font-family: monospace; font-size: 1rem; gap: 10px;}
.treasury-item:last-child { border: none; }
.treasury-item span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-header .user-info { flex-wrap: wrap; }
.admin-header .glow-text.danger-text { font-size: 0.95rem; overflow-wrap: break-word; }

/* Modal overlays */
.modal-overlay {
    position: fixed; top:0; left:0; width:100%; height:100%;
    background: rgba(0,0,0,0.8); backdrop-filter: blur(10px);
    z-index: 1000; display: flex; justify-content: center; align-items: center;
    opacity: 1; transition: 0.3s; padding: 20px;
}
.modal-overlay.hidden { opacity: 0; pointer-events: none; }
.glass-modal {
    background: rgba(15, 23, 42, 0.9); padding: 26px; border-radius: 25px;
    border: 1px solid var(--glass-border); box-shadow: var(--glass-shadow);
    width: 100%; max-width: 350px; display: flex; flex-direction: column; gap: 16px;
    max-height: 90vh; overflow-y: auto;
}
.glass-modal::-webkit-scrollbar { width: 4px; }
.glass-modal::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 10px; }
#admin-prompt .glass-modal { border-color: var(--danger); box-shadow: 0 0 30px rgba(244, 63, 94, 0.3); }
#admin-prompt .glass-modal h3 { text-align: center; color: var(--danger); text-transform: uppercase; font-size: 1.05rem; }

/* Toasts */
#toast-container {
    position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 9999;
    display: flex; flex-direction: column; gap: 12px; width: 90%; max-width: 380px; pointer-events: none;
}
.toast {
    background: var(--dropdown-bg); backdrop-filter: blur(12px);
    border-left: 6px solid var(--primary); padding: 16px 22px;
    border-radius: 12px; color: white; font-weight: 600; font-size: 0.92rem; box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    animation: slideDown 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards, fadeOut 0.3s forwards 3s;
    word-break: break-word;
}
.toast.error { border-left-color: var(--danger); box-shadow: 0 10px 25px rgba(244, 63, 94, 0.3);}
.toast.success { border-left-color: var(--success); box-shadow: 0 10px 25px rgba(16, 185, 129, 0.3);}
@keyframes slideDown { from { transform: translateY(-40px) scale(0.9); opacity: 0; } to { transform: translateY(0) scale(1); opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; transform: translateY(-15px) scale(0.9); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* Small phone safeguard - tighten spacing so nothing gets clipped */
@media (max-height: 700px) {
    .screen { padding: 16px; }
    .logo-3d { margin: 8px 0 20px 0; }
    .balance-card, .3d-tabs { margin-bottom: 10px; }
    .coin-card { padding: 11px 14px; }
}

@media (max-width: 360px) {
    #live-price { font-size: 1.5rem; }
    .btn { padding: 14px; font-size: 0.9rem; }
    .3d-tabs .tab { font-size: 0.78rem; padding: 10px 2px; }
}