:root {
    color-scheme: dark;
    --bg: #12141c;
    --bg-alt: #1b1e29;
    --card: #212433;
    --border: #2f3346;
    --text: #e7e9f2;
    --text-dim: #9198b3;
    --accent: #5b8cff;
    --accent-dim: #34406b;
    --good: #3fcf7f;
    --warn: #f2b84b;
    --danger: #f2555a;
    --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

#app { min-height: 100%; display: flex; flex-direction: column; }

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: 0.95rem;
    background: var(--accent-dim);
    color: var(--text);
    transition: background 0.15s ease;
}
button:hover { background: #3d4a78; }
button.primary { background: var(--accent); color: #08101f; font-weight: 600; }
button.primary:hover { background: #7aa2ff; }
button.danger { background: var(--danger); color: #2a0506; font-weight: 600; }
button.ghost { background: transparent; border: 1px solid var(--border); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.icon-btn {
    background: transparent;
    padding: 6px 10px;
    font-size: 1.1rem;
    line-height: 1;
}

input, textarea, select {
    font-family: inherit;
    font-size: 1rem;
    background: var(--bg-alt);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: var(--radius);
    padding: 10px 12px;
    width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); }
label { display: block; font-size: 0.85rem; color: var(--text-dim); margin: 12px 0 4px; }
label:first-child { margin-top: 0; }

.topbar {
    position: sticky; top: 0; z-index: 5;
    display: flex; align-items: center; gap: 10px;
    padding: 12px 16px;
    background: rgba(18, 20, 28, 0.92);
    backdrop-filter: blur(6px);
    border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 1.1rem; margin: 0; flex: 1; }
.topbar .back { font-size: 1.3rem; }

.view { flex: 1; padding: 12px 16px 32px; max-width: 780px; width: 100%; margin: 0 auto; }

.auth-view { display: flex; align-items: center; justify-content: center; min-height: 100%; padding: 24px; }
.auth-card { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 28px; width: 100%; max-width: 380px; }
.auth-card h1 { text-align: center; margin-top: 0; }
.auth-card .switch { text-align: center; margin-top: 16px; color: var(--text-dim); font-size: 0.9rem; }
.auth-card .switch a { color: var(--accent); cursor: pointer; }
.error-text { color: var(--danger); font-size: 0.88rem; margin-top: 10px; min-height: 1.2em; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; align-items: center; }
.toolbar input[type="search"] { flex: 1; min-width: 140px; }
.toolbar .spacer { flex: 1; }

.project-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    display: flex; gap: 12px; align-items: center;
    margin-bottom: 10px;
    cursor: pointer;
}
.project-card:hover { border-color: var(--accent-dim); }
.project-cover { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; background: var(--bg-alt); flex-shrink: 0; }
.project-info { flex: 1; min-width: 0; }
.project-info h3 { margin: 0 0 4px; font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-meta { color: var(--text-dim); font-size: 0.82rem; }
.progress-bar { height: 6px; border-radius: 4px; background: var(--bg-alt); margin-top: 6px; overflow: hidden; }
.progress-bar > div { height: 100%; background: var(--good); }
.pct { font-weight: 700; font-size: 1rem; width: 46px; text-align: right; flex-shrink: 0; }

.empty-state { text-align: center; color: var(--text-dim); padding: 40px 16px; }

.fab {
    position: fixed; right: 20px; bottom: max(20px, env(safe-area-inset-bottom));
    width: 56px; height: 56px; border-radius: 50%;
    font-size: 1.6rem; background: var(--accent); color: #08101f;
    box-shadow: 0 6px 18px rgba(0,0,0,0.4);
    z-index: 6;
}

.project-header { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 16px; }
.project-header .project-cover { width: 84px; height: 84px; }
.project-header .project-title { flex: 1; }
.project-header h2 { margin: 0 0 4px; }
.stat-row { display: flex; gap: 16px; color: var(--text-dim); font-size: 0.85rem; flex-wrap: wrap; }

.group-heading { margin: 18px 0 8px; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-dim); }

.trophy-row {
    display: flex; align-items: center; gap: 10px;
    background: var(--card); border: 1px solid var(--border); border-radius: 10px;
    padding: 10px 12px; margin-bottom: 8px;
}
.trophy-row.completed { opacity: 0.65; }
.trophy-check {
    width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--border);
    background: transparent; flex-shrink: 0; display: flex; align-items: center; justify-content: center; padding: 0;
}
.trophy-row.completed .trophy-check { background: var(--good); border-color: var(--good); color: #06210f; }
.trophy-main { flex: 1; min-width: 0; }
.trophy-main .name { font-weight: 600; }
.trophy-main .desc { color: var(--text-dim); font-size: 0.85rem; }
.rank-badge { font-size: 0.7rem; padding: 2px 8px; border-radius: 20px; background: var(--bg-alt); color: var(--text-dim); text-transform: capitalize; }
.rank-badge.platinum { background: #6b5bd6; color: #fff; }
.rank-badge.gold { background: #a9852b; color: #fff; }
.rank-badge.silver { background: #7c8291; color: #fff; }
.rank-badge.bronze { background: #8a5533; color: #fff; }
.counter { display: flex; align-items: center; gap: 6px; }
.counter button { padding: 4px 10px; }
.fav-btn.active { color: var(--warn); }

.card-section { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
.card-section h3 { margin-top: 0; }
.settings-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; }

.modal-backdrop {
    position: fixed; inset: 0; background: rgba(0,0,0,0.6);
    display: flex; align-items: flex-end; justify-content: center; z-index: 20;
}
.modal {
    background: var(--bg); border: 1px solid var(--border);
    width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto;
    border-radius: 16px 16px 0 0; padding: 0;
}
.modal-header { display: flex; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg); }
.modal-title { flex: 1; margin: 0; font-size: 1.05rem; }
.modal-body { padding: 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.search-result { display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 8px; cursor: pointer; }
.search-result:hover { background: var(--bg-alt); }
.search-result img { width: 40px; height: 40px; object-fit: cover; border-radius: 6px; background: var(--bg-alt); }

.toast {
    position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
    background: #2a2e40; border: 1px solid var(--border); color: var(--text);
    padding: 10px 18px; border-radius: 10px; font-size: 0.9rem; z-index: 50;
    max-width: 90vw;
}
.toast.error { border-color: var(--danger); color: #ffb3b3; }

@media (min-width: 640px) {
    .view { padding: 24px 24px 48px; }
    .project-card { padding: 14px; }
}
