:root {
    --bg: #060612;
    --surface: #0F0F22;
    --card: #14142A;
    --border: rgba(255,255,255,0.08);
    --primary: #6366F1;
    --secondary: #06B6D4;
    --accent: #F59E0B;
    --success: #10B981;
    --danger: #EF4444;
    --text: #F1F5F9;
    --muted: #94A3B8;
    --nav-height: 70px;
    --top-height: 65px;
    --vit-height: 50px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Plus Jakarta Sans', sans-serif;
}

body {
    background-color: var(--bg);
    color: var(--text);
    overflow-x: hidden;
    overscroll-behavior-y: none;
    -webkit-tap-highlight-color: transparent;
}

/* Utilities */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--muted); }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-sm { font-size: 0.85rem; }
.text-lg { font-size: 1.25rem; }
.text-huge { font-size: 2.5rem; font-weight: 800; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.py-1 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-gap { display: flex; gap: 0.5rem; }
.flex-col { display: flex; flex-direction: column; }
.gap-2 { gap: 1rem; }
.flex-1 { flex: 1; }
.flex-2 { flex: 2; }
.border-bottom { border-bottom: 1px solid var(--border); }

/* Glassmorphism */
.glass-card {
    background: rgba(20, 20, 42, 0.6);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1rem;
}
.glass-bar {
    background: rgba(15, 15, 34, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border);
}

/* Typography */
.gradient-text {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 800;
}

/* Buttons */
.btn {
    border: none;
    border-radius: 12px;
    padding: 0.75rem 1.25rem;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}
.btn:active { transform: scale(0.96); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-large { padding: 1rem 1.5rem; font-size: 1.1rem; }
.btn-block { width: 100%; }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.85rem; border-radius: 8px;}
.btn-primary { background: linear-gradient(135deg, var(--primary), #818cf8); box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3); }
.btn-secondary { background: var(--surface); border: 1px solid var(--border); color: var(--text); }
.btn-success { background: var(--success); }
.btn-danger { background: var(--danger); }

/* Inputs */
input, select {
    width: 100%;
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.8rem 1rem;
    border-radius: 10px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}
input:focus, select:focus { border-color: var(--primary); }
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.5rem; color: var(--muted); font-size: 0.9rem; }

/* Screens */
.screen {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    display: none;
    flex-direction: column;
    padding: 1rem;
    overflow-y: auto;
}
.screen.active {
    display: flex;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* Screen 1: Lobby */
.lobby-header { text-align: center; margin: 2rem 0; }
.lobby-header h1 { font-size: 2.5rem; font-weight: 800; background: linear-gradient(to right, var(--primary), var(--secondary)); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.avatar-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.5rem; }
.avatar-item { font-size: 2rem; background: var(--surface); border: 2px solid transparent; border-radius: 12px; text-align: center; padding: 0.5rem; cursor: pointer; transition: 0.2s; }
.avatar-item.selected { border-color: var(--primary); background: rgba(99, 102, 241, 0.2); transform: scale(1.1); }
.profession-grid { display: grid; grid-template-columns: 1fr; gap: 0.75rem; max-height: 250px; overflow-y: auto; padding-right: 0.5rem; }
.prof-card { display: flex; align-items: center; background: var(--surface); border-radius: 12px; padding: 0.75rem; border: 1px solid var(--border); border-left: 4px solid var(--muted); cursor: pointer; transition: 0.2s; }
.prof-card.selected { background: rgba(255,255,255,0.05); }
.prof-icon { font-size: 1.5rem; margin-right: 1rem; width: 40px; height: 40px; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.prof-info h4 { margin: 0; }
.prof-info p { margin: 0; font-size: 0.75rem; color: var(--muted); }

/* Screen 2: Waiting */
.waiting-header { text-align: center; padding: 2rem 1rem; margin-top: 2rem; }
.waiting-header h2 { font-size: 3rem; letter-spacing: 4px; margin: 1rem 0; }
.player-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 1rem; margin-top: 1rem; }
.player-item { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 1rem; text-align: center; display: flex; flex-direction: column; align-items: center; position: relative; }
.player-item .avatar { font-size: 2.5rem; margin-bottom: 0.5rem; }
.player-item .ready-indicator { position: absolute; top: 10px; right: 10px; width: 12px; height: 12px; border-radius: 50%; background: var(--danger); }
.player-item.is-ready .ready-indicator { background: var(--success); box-shadow: 0 0 10px var(--success); }
.waiting-action { margin-top: auto; padding: 1rem 0; }

/* Screen 3: Game Layout */
#screen-game { padding: 0; display: none; }
#screen-game.active { display: block; }
#game-topbar { position: fixed; top: 0; left: 0; right: 0; height: var(--top-height); display: flex; justify-content: space-between; align-items: center; padding: 0 1rem; z-index: 100; border-bottom-left-radius: 16px; border-bottom-right-radius: 16px; }
.player-info-mini { display: flex; align-items: center; gap: 0.75rem; }
.avatar-mini { font-size: 1.5rem; background: var(--surface); padding: 0.25rem; border-radius: 50%; }
.badge-role { font-size: 0.65rem; padding: 0.2rem 0.5rem; border-radius: 4px; font-weight: 700; text-transform: uppercase; }
.game-info-mini { text-align: right; }
.balance-display { font-weight: 800; color: var(--success); font-size: 1.1rem; }
.timer-display { font-size: 0.8rem; color: var(--danger); font-weight: 700; }

#vitality-panel { position: fixed; top: calc(var(--top-height) + 5px); left: 2%; right: 2%; width: 96%; height: var(--vit-height); border-radius: 12px; display: flex; justify-content: space-around; align-items: center; padding: 0 0.5rem; z-index: 99; }
.vitality-item { display: flex; align-items: center; gap: 4px; width: 23%; }
.vitality-item .icon { font-size: 1rem; }
.bar-bg { flex: 1; height: 6px; background: rgba(255,255,255,0.1); border-radius: 3px; overflow: hidden; }
.bar-fill { height: 100%; transition: width 0.3s ease, background-color 0.3s ease; }
.bg-success { background-color: var(--success); }
.bg-warning { background-color: var(--accent); }
.bg-danger { background-color: var(--danger); }
.vitality-item .val { font-size: 0.7rem; font-weight: 700; min-width: 20px; text-align: right; }

#game-content { position: absolute; top: calc(var(--top-height) + var(--vit-height) + 15px); bottom: var(--nav-height); left: 0; right: 0; overflow-y: auto; padding: 0 1rem 1rem 1rem; }

/* Tabs */
.tab-content { display: none; animation: slideUp 0.3s ease; }
.tab-content.active { display: block; }

/* Bottom Nav */
#bottom-nav { position: fixed; bottom: 0; left: 0; right: 0; height: var(--nav-height); display: flex; justify-content: space-around; align-items: center; padding-bottom: env(safe-area-inset-bottom); border-top-left-radius: 20px; border-top-right-radius: 20px; z-index: 100; }
.nav-item { background: transparent; border: none; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; cursor: pointer; transition: 0.2s; width: 20%; }
.nav-item .icon { font-size: 1.4rem; transition: transform 0.2s; }
.nav-item .label { font-size: 0.65rem; font-weight: 600; }
.nav-item.active { color: var(--primary); }
.nav-item.active .icon { transform: translateY(-3px) scale(1.1); }

/* Beranda */
.stats-mini { display: flex; justify-content: space-between; padding: 1rem; margin-bottom: 1rem; }
.stat-box { text-align: center; }
.stat-box span { font-size: 0.7rem; color: var(--muted); display: block; margin-bottom: 4px; }
.quick-actions { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; overflow-x: auto; padding-bottom: 0.5rem; scrollbar-width: none; }
.quick-actions::-webkit-scrollbar { display: none; }
.quick-actions .btn { white-space: nowrap; flex: 0 0 auto; }
.feed-list { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.5rem; }
.feed-item { background: var(--surface); padding: 0.75rem; border-radius: 10px; border-left: 4px solid var(--border); display: flex; gap: 0.75rem; align-items: flex-start; font-size: 0.85rem; }
.feed-item .time { font-size: 0.7rem; color: var(--muted); display: block; margin-top: 4px; }
.feed-type-positive { border-left-color: var(--success); }
.feed-type-negative { border-left-color: var(--danger); }
.feed-type-info { border-left-color: var(--primary); }
.feed-type-special { border-left-color: var(--accent); background: rgba(245, 158, 11, 0.05); }
.event-banner { background: linear-gradient(45deg, rgba(99,102,241,0.2), rgba(245,158,11,0.2)); border-color: var(--accent); margin-bottom: 1rem; }

/* Market */
.market-header { position: sticky; top: 0; background: var(--bg); z-index: 10; padding-bottom: 1rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); }
.category-filters { display: flex; gap: 0.5rem; overflow-x: auto; margin-top: 0.5rem; padding-bottom: 0.5rem; scrollbar-width: none; }
.category-filters::-webkit-scrollbar { display: none; }
.cat-btn { background: var(--surface); border: 1px solid var(--border); color: var(--text); padding: 0.4rem 0.8rem; border-radius: 20px; font-size: 0.8rem; white-space: nowrap; cursor: pointer; }
.cat-btn.active { background: var(--primary); border-color: var(--primary); font-weight: 600; }
.market-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem; }
.market-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 0.75rem; display: flex; flex-direction: column; }
.market-card .icon-large { font-size: 2.5rem; text-align: center; margin-bottom: 0.5rem; background: rgba(255,255,255,0.05); border-radius: 8px; padding: 0.5rem; }
.market-card .title { font-size: 0.9rem; font-weight: 600; margin-bottom: 0.2rem; }
.market-card .seller { font-size: 0.7rem; color: var(--muted); margin-bottom: 0.5rem; }
.market-card .price { font-weight: 800; color: var(--success); font-size: 1rem; margin-bottom: 0.5rem; }
.market-card .stock { font-size: 0.7rem; background: rgba(255,255,255,0.1); padding: 2px 6px; border-radius: 4px; display: inline-block; align-self: flex-start; margin-bottom: 0.5rem; }
.market-card .btn { margin-top: auto; padding: 0.5rem; font-size: 0.85rem; }

/* Modals */
.modal { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.8); backdrop-filter: blur(5px); z-index: 1000; display: none; justify-content: center; align-items: center; padding: 1rem; }
.modal.active { display: flex; animation: fadeIn 0.2s ease; }
.modal-content { width: 100%; max-width: 400px; padding: 1.5rem; animation: slideUp 0.3s ease; }
.qris-visual { background: #fff; padding: 1rem; border-radius: 12px; margin: 1rem auto; width: 180px; height: 180px; position: relative; }
.qr-grid { width: 100%; height: 100%; display: grid; grid-template-columns: repeat(8, 1fr); grid-template-rows: repeat(8, 1fr); gap: 2px; }
.qr-cell { background: #000; border-radius: 2px; }
.qr-cell.empty { background: transparent; }

/* Toasts */
#toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 2000; display: flex; flex-direction: column; gap: 0.5rem; pointer-events: none; }
.toast { background: var(--surface); color: var(--text); padding: 0.75rem 1rem; border-radius: 8px; border-left: 4px solid var(--primary); box-shadow: 0 4px 12px rgba(0,0,0,0.5); display: flex; align-items: center; gap: 0.5rem; animation: slideInRight 0.3s ease, fadeOut 0.3s ease 2.7s forwards; min-width: 250px; pointer-events: auto; }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--accent); }
@keyframes slideInRight { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

/* Profile & Score */
.avatar-large { font-size: 4rem; background: var(--surface); width: 80px; height: 80px; border-radius: 50%; display: flex; align-items: center; justify-content: center; margin: 0 auto; border: 2px solid var(--primary); }
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.stat-item { background: rgba(255,255,255,0.03); padding: 0.75rem; border-radius: 8px; display: flex; flex-direction: column; align-items: center; }

/* End Screen */
.confetti-bg { position: absolute; top:0; left:0; right:0; bottom:0; background-image: radial-gradient(#F59E0B 2px, transparent 2px), radial-gradient(#6366F1 2px, transparent 2px), radial-gradient(#10B981 2px, transparent 2px); background-size: 40px 40px, 50px 50px, 30px 30px; background-position: 0 0, 20px 20px, 15px 15px; opacity: 0.3; animation: confettiFall 20s linear infinite; pointer-events: none; }
@keyframes confettiFall { from { background-position: 0 0, 20px 20px, 15px 15px; } to { background-position: 0 400px, 20px 420px, 15px 415px; } }
.leaderboard-list { display: flex; flex-direction: column; gap: 0.5rem; max-height: 40vh; overflow-y: auto; }
.lb-item { display: flex; align-items: center; background: var(--surface); padding: 0.75rem; border-radius: 8px; border: 1px solid var(--border); }
.lb-rank { font-size: 1.2rem; font-weight: 800; width: 30px; text-align: center; margin-right: 0.5rem; }
.lb-item:nth-child(1) .lb-rank { color: #FFD700; }
.lb-item:nth-child(2) .lb-rank { color: #C0C0C0; }
.lb-item:nth-child(3) .lb-rank { color: #CD7F32; }
.lb-score { margin-left: auto; font-weight: 700; color: var(--primary); }

/* Emulate safe area for notched devices */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    #bottom-nav { padding-bottom: calc(0.5rem + env(safe-area-inset-bottom)); height: calc(var(--nav-height) + env(safe-area-inset-bottom) - 0.5rem); }
}

/* Profession bonus badge in lobby */
.prof-bonus {
    font-size: 0.72rem !important;
    color: var(--success) !important;
    margin-top: 0.2rem !important;
    font-weight: 600;
}

/* Score breakdown items */
.score-breakdown { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; margin-top: 0.75rem; }
.score-item { background: rgba(99,102,241,0.1); border: 1px solid rgba(99,102,241,0.2); border-radius: 8px; padding: 0.5rem; text-align: center; }
.score-item .score-val { font-size: 1.2rem; font-weight: 800; color: var(--primary); }
.score-item .score-label { font-size: 0.68rem; color: var(--muted); margin-top: 0.1rem; }
