/* --- NEO-BIOLOGY V3: HIGH-TECH DARK THEME --- */
:root {
    --bg0: #060f0b;
    --bg1: #0a1f14;
    --bg2: #0e2d1d;
    --card: rgba(14, 38, 24, 0.88);
    --card2: rgba(16, 44, 28, 0.75);
    --text: #e8fff2;
    --muted: #9cc4ab;
    --line: rgba(46, 242, 154, 0.12);
    --accent: #2ef29a;
    --accent2: #41c8e5;
    --accent3: #7bed9f;
    --danger: #ff6b81;
    --warn: #ffd166;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
    --glow: 0 0 20px rgba(46, 242, 154, 0.15);
    --radius: 18px;
    --radius2: 14px;
    --radius3: 12px;
    --focus: 0 0 0 3px rgba(46, 242, 154, 0.25);
    --font: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font);
    color: var(--text);
    background: var(--bg0);
    background: radial-gradient(ellipse 600px 800px at 10% 20%, rgba(46, 242, 154, 0.08), transparent 60%), radial-gradient(ellipse 500px 700px at 85% 15%, rgba(65, 200, 229, 0.07), transparent 55%), var(--bg0);
    background-attachment: fixed;
    height: 100vh;
    overflow: hidden;
    /* Prevent body scroll, use app scroll */
    -webkit-tap-highlight-color: transparent;
}

#app {
    max-width: 600px;
    margin: 0 auto;
    position: relative;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ─── TopBar ─── */
.topbar {
    position: sticky;
    top: 0;
    z-index: 1000;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    background: rgba(6, 15, 11, 0.85);
    border-bottom: 1px solid var(--line);
    padding: 15px 20px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    box-shadow: var(--glow);
}

.brand h1 {
    font-size: 18px;
    font-weight: 800;
    background: linear-gradient(to right, #FFF, var(--accent3));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ─── Content / Tabs ─── */
.content,
.tab-content {
    padding: 15px 15px 40px;
    /* Reduced padding since we will use spacer */
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    display: flex;
    flex-direction: column;
}

/* Guaranteed space at bottom for floating nav */
.tab-content::after {
    content: '';
    display: block;
    min-height: 250px;
    /* Large spacer */
    width: 100%;
    flex-shrink: 0;
}

.tab-content.hidden {
    display: none !important;
}

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 15px;
    backdrop-filter: blur(10px);
}

.section-title {
    font-size: 16px;
    font-weight: 800;
    margin-bottom: 15px;
    color: var(--accent);
    display: flex;
    align-items: center;
    gap: 10px;
}

/* ─── Buttons ─── */
.btn {
    width: 100%;
    padding: 14px;
    border-radius: var(--radius2);
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(46, 242, 154, 0.1);
    color: var(--text);
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.btn.primary {
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    color: #062012;
    border: none;
    box-shadow: var(--glow);
}

.btn:active {
    transform: scale(0.97);
}

/* ─── List Items ─── */
.item {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--line);
    padding: 15px;
    border-radius: var(--radius3);
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: 0.2s;
}

.item:hover {
    background: rgba(46, 242, 154, 0.05);
    border-color: var(--accent);
}

.item-info h3 {
    font-size: 14.5px;
    margin-bottom: 4px;
}

.item-info p {
    font-size: 12px;
    color: var(--muted);
}

.item-actions {
    display: flex;
    gap: 12px;
}

/* ─── Rating System ─── */
.rating-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px 15px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 14px;
    margin-bottom: 8px;
    border: 1px solid transparent;
}

.rank-num {
    width: 32px;
    height: 32px;
    min-width: 32px;
    /* Prevent shrink */
    flex-shrink: 0;
    /* Prevent oval shape on long names */
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    background: rgba(255, 255, 255, 0.1);
    font-size: 13px;
}

/* Top 3 Styles */
.rank-1 {
    background: linear-gradient(135deg, #FFD700, #FFA500);
    color: #000;
    border: 1px solid #FFD700;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.3);
}

.rank-2 {
    background: linear-gradient(135deg, #C0C0C0, #808080);
    color: #000;
    border: 1px solid #C0C0C0;
}

.rank-3 {
    background: linear-gradient(135deg, #CD7F32, #8B4513);
    color: #000;
    border: 1px solid #CD7F32;
}

.rating-score {
    margin-left: auto;
    font-weight: 800;
    color: var(--accent);
    font-size: 14px;
}

/* ─── OMR Answer Sheet ─── */
.answer-sheet {
    background: rgba(255, 255, 255, 0.02);
    padding: 10px;
    border-radius: var(--radius2);
    border: 1px solid var(--line);
    margin-bottom: 20px;
}

.sheet-table {
    width: 100%;
    border-collapse: collapse;
}

.sheet-row td {
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    text-align: center;
}

.row-num {
    font-weight: 800;
    color: var(--muted);
    font-size: 12px;
}

.bubble-btn {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.2);
    background: transparent;
    cursor: pointer;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.bubble-btn::after {
    content: '';
    width: 0;
    height: 0;
    border-radius: 50%;
    background: var(--accent2);
    transition: 0.2s;
}

.bubble-btn.selected {
    border-color: var(--accent2);
}

.bubble-btn.selected::after {
    width: 16px;
    height: 16px;
}

/* ─── Forms / Admin ─── */
.field {
    margin-bottom: 15px;
}

.field label {
    display: block;
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 6px;
    font-weight: 600;
}

.control {
    width: 100%;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: rgba(0, 0, 0, 0.3);
    color: #FFF;
    outline: none;
    transition: 0.3s;
}

.control:focus {
    border-color: var(--accent);
    box-shadow: var(--focus);
}

/* Toggle Switch */
.switch-container {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(46, 242, 154, 0.05);
    padding: 12px;
    border-radius: 12px;
    border: 1px solid var(--line);
    margin-bottom: 15px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    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: #333;
    transition: .4s;
    border-radius: 20px;
}

.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(20px);
}

/* Closed Savol Styling */
.closed-savol-header {
    display: flex;
    justify-content: space-between;
    padding: 15px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 12px 12px 0 0;
    margin-top: 15px;
    border: 1px solid var(--line);
    border-bottom: none;
}

.closed-input-box {
    display: flex;
    gap: 12px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--line);
    border-top: none;
}

.closed-idx {
    font-weight: 700;
    color: var(--muted);
}

.closed-input-wrapper {
    flex: 1;
    position: relative;
}

.closed-input-wrapper input {
    width: 100%;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.05);
    padding: 10px;
    border-radius: 8px;
    color: #FFF;
    outline: none;
}

.closed-icons {
    position: absolute;
    right: 10px;
    top: 8px;
    font-size: 14px;
    opacity: 0.5;
}

/* ─── Bottom Nav ─── */
.bottomNav {
    position: fixed;
    bottom: 25px;
    left: 50%;
    transform: translateX(-50%);
    width: 85%;
    max-width: 380px;
    z-index: 1000;
    backdrop-filter: blur(25px) saturate(180%);
    -webkit-backdrop-filter: blur(25px) saturate(180%);
    background: rgba(10, 31, 20, 0.78);
    border: 1px solid rgba(46, 242, 154, 0.22);
    border-radius: 35px;
    padding: 12px 10px;
    display: flex;
    justify-content: space-around;
    box-shadow: 0 15px 50px rgba(0, 0, 0, 0.8), inset 0 0 10px rgba(46, 242, 154, 0.05);
}

.navbtn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--muted);
    cursor: pointer;
    transition: 0.2s;
    font-size: 11px;
    font-weight: 700;
}

.navbtn.active {
    color: var(--accent);
}

.navbtn .icon {
    font-size: 20px;
    transition: 0.2s;
}

.navbtn:active {
    transform: scale(0.9);
}

/* --- Segmented Control (Filters) --- */
.segmented {
    display: flex;
    background: rgba(255, 255, 255, 0.05);
    padding: 4px;
    border-radius: 12px;
    border: 1px solid var(--line);
    margin-bottom: 15px;
}

.seg-item {
    flex: 1;
    text-align: center;
    padding: 8px;
    border-radius: 9px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    color: var(--muted);
    transition: 0.2s;
}

.seg-item.active {
    background: var(--accent);
    color: #000;
    box-shadow: var(--glow);
}

.num-chip {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
    background: rgba(46, 242, 154, 0.15);
    border: 1px solid rgba(46, 242, 154, 0.3);
    color: var(--accent);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.num-chip.wrong {
    background: rgba(255, 107, 129, 0.15);
    border: 1px solid rgba(255, 107, 129, 0.3);
    color: var(--danger);
}

/* --- Modals/Utility --- */
.hidden {
    display: none !important;
}

.loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--bg0);
    display: flex;
    align-items: center;
    justify-content: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--bg2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s infinite linear;
}

@keyframes spin {
    100% {
        transform: rotate(360deg);
    }
}

/* --- Test Rating Screen --- */
.rating-header {
    display: flex;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}

.rating-header h2 {
    font-size: 18px;
    margin: 0;
}

.overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(12px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal {
    background: var(--bg1);
    border-radius: 28px;
    width: 100%;
    max-width: 500px;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.9);
    animation: modalBounce 0.4s cubic-bezier(0.3, 0, 0.2, 1.5);
    border: 1px solid rgba(46, 242, 154, 0.25);
}

@keyframes modalBounce {
    from {
        transform: scale(0.85);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

/* Scrollbar for modal */
.modal::-webkit-scrollbar {
    width: 4px;
}

.modal::-webkit-scrollbar-thumb {
    background: var(--line);
    border-radius: 4px;
}

/* --- Chat System --- */
#tab-chat {
    height: 100vh;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

#tab-chat::after {
    display: none;
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 15px;
    padding-bottom: 180px;
    /* Space for fixed input-bar and bottom nav */
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius);
}

.chat-input-bar {
    position: fixed;
    bottom: 110px;
    left: 15px;
    right: 15px;
    display: flex;
    gap: 10px;
    background: var(--bg2);
    padding: 10px;
    border-radius: 20px;
    border: 1px solid var(--line);
    z-index: 900;
}

.chat-msg-del {
    position: absolute;
    top: -8px;
    right: -8px;
    font-size: 14px;
    opacity: 0.9;
    padding: 4px;
    cursor: pointer;
    z-index: 100;
    color: #ff3b30;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 50%;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.chat-msg-del:hover {
    opacity: 1;
    transform: scale(1.1);
}

#chat-input {
    flex: 1;
    background: transparent;
    border: none;
    color: #fff;
    outline: none;
    padding: 5px 10px;
}

#chat-send {
    width: auto;
    padding: 8px 15px;
    border-radius: 15px;
}

.chat-msg {
    max-width: 80%;
    padding: 10px 15px;
    border-radius: 18px;
    position: relative;
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    border: 1px solid var(--line);
}

.chat-msg.me {
    align-self: flex-end;
    background: var(--accent);
    color: #000;
    border: none;
}

.chat-msg-user {
    font-size: 11px;
    font-weight: 800;
    margin-bottom: 3px;
    opacity: 0.7;
}

.chat-msg-text {
    font-size: 14px;
    line-height: 1.4;
}

.chat-msg-time {
    font-size: 9px;
    margin-top: 5px;
    text-align: right;
    opacity: 0.5;
}

.solving-header {
    margin-bottom: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.solving-header h2 {
    margin: 0;
}

.timer-display {
    background: var(--danger);
    color: #fff;
    padding: 5px 12px;
    border-radius: 10px;
    font-weight: 800;
    font-family: monospace;
    font-size: 18px;
}

/* --- Duel / Challenge System --- */
.duel-header {
    background: rgba(255, 255, 255, 0.05);
    padding: 15px;
    border-radius: 15px;
    margin-bottom: 20px;
    border: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.player-score {
    text-align: center;
}

.player-score .label {
    font-size: 12px;
    opacity: 0.6;
}

.score-me {
    font-size: 24px;
    font-weight: 900;
    color: var(--accent);
}

.score-opp {
    font-size: 24px;
    font-weight: 900;
    color: var(--danger);
}

.vs-text {
    font-size: 20px;
    font-weight: 900;
    opacity: 0.3;
}

.timer-bar {
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    overflow: hidden;
    margin-bottom: 25px;
    border: 1px solid var(--line);
}

.timer-fill {
    height: 100%;
    width: 100%;
    background: var(--accent);
    transition: width 1s linear;
}

.ch-question-card {
    margin-bottom: 20px;
    text-align: center;
    min-height: 120px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.badge {
    position: absolute;
    top: 5px;
    right: 20%;
    background: var(--danger);
    color: #fff;
    font-size: 10px;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    padding: 0 4px;
    border: 2px solid var(--bg0);
    z-index: 10;
}