/* ============================================================
   ClashOS Phase 2 — Premium UI Stylesheet
   Auth modal · Toasts · Account switcher · History · Settings
   Supercell-grade design system
   ============================================================ */

/* ══════════════════════════════════════════════════════════════
   DESIGN TOKENS
   ══════════════════════════════════════════════════════════════ */

:root {
    --co-gold: var(--gold-primary);
    --co-gold-dim: var(--gold-dim);
    --co-gold-glow: var(--gold-glow);
    --co-bg-deep: var(--bg-deep);
    --co-bg-card: var(--bg-surface);
    --co-bg-glass: var(--panel-bg);
    --co-border: var(--panel-border);
    --co-border-bright: rgba(255, 255, 255, 0.15);
    --co-text: var(--text-primary);
    --co-text-dim: var(--text-secondary);
    --co-danger: var(--red-slacker);
    --co-success: var(--green-accent);
    --co-warn: var(--gold-light);
    --co-info: var(--blue-accent);
    --co-radius: var(--radius-lg);
    --co-radius-sm: var(--radius-sm);
    --co-shadow: var(--shadow-heavy);
    --co-transition: var(--duration-normal) var(--ease-out);
}

body.modal-open {
    overflow: hidden;
}


/* ══════════════════════════════════════════════════════════════
   TOAST SYSTEM
   ══════════════════════════════════════════════════════════════ */

.co-toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 100000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.co-toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 18px;
    border-radius: var(--co-radius-sm);
    background: var(--co-bg-card);
    border: 1px solid var(--co-border);
    color: var(--co-text);
    font-size: 14px;
    font-family: 'Supercell-Magic', 'Inter', sans-serif;
    box-shadow: var(--co-shadow);
    pointer-events: auto;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    transform: translateX(120%);
    opacity: 0;
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
    max-width: 360px;
}

.co-toast--enter {
    transform: translateX(0);
    opacity: 1;
}

.co-toast--exit {
    transform: translateX(120%);
    opacity: 0;
}

.co-toast--success {
    border-color: rgba(34, 197, 94, 0.4);
}

.co-toast--error {
    border-color: rgba(239, 68, 68, 0.4);
}

.co-toast--warn {
    border-color: rgba(245, 158, 11, 0.4);
}

.co-toast--info {
    border-color: rgba(96, 165, 250, 0.4);
}

.co-toast__icon {
    font-size: 18px;
    flex-shrink: 0;
}

.co-toast__msg {
    flex: 1;
    line-height: 1.4;
}

.co-toast__close {
    background: none;
    border: none;
    color: var(--co-text-dim);
    font-size: 20px;
    cursor: pointer;
    padding: 0 0 0 8px;
    line-height: 1;
}


/* ══════════════════════════════════════════════════════════════
   AUTH MODAL
   ══════════════════════════════════════════════════════════════ */

.co-auth-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(8, 6, 18, 0.75);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: none;
    place-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.co-auth-overlay.active {
    display: grid;
    opacity: 1;
    animation: coFadeIn 0.3s ease forwards;
}

.co-auth-overlay.closing {
    animation: coFadeOut 0.28s ease forwards;
}

@keyframes coFadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes coFadeOut {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

/* ── Card ──────────────────────────────────────────────────── */

.co-auth-card {
    position: relative;
    width: 92vw;
    max-width: 420px;
    padding: 36px 32px 32px;
    background: linear-gradient(165deg, rgba(30, 25, 65, 0.95), rgba(16, 14, 35, 0.98));
    border: 1px solid var(--co-border-bright);
    border-radius: 20px;
    box-shadow:
        0 0 80px rgba(251, 191, 36, 0.08),
        0 20px 60px rgba(0, 0, 0, 0.6),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
    transform: scale(0.9) translateY(20px);
    animation: coCardIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    overflow: hidden;
}

.co-auth-overlay.closing .co-auth-card {
    animation: coCardOut 0.25s ease forwards;
}

@keyframes coCardIn {
    to {
        transform: scale(1) translateY(0);
    }
}

@keyframes coCardOut {
    to {
        transform: scale(0.92) translateY(15px);
        opacity: 0;
    }
}

/* Top gold line */
.co-auth-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 20%;
    right: 20%;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--co-gold), transparent);
    border-radius: 0 0 3px 3px;
}

/* ── Close button ──────────────────────────────────────────── */

.co-auth-close {
    position: absolute;
    top: 14px;
    right: 16px;
    background: none;
    border: none;
    color: var(--co-text-dim);
    font-size: 24px;
    cursor: pointer;
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    transition: var(--co-transition);
}

.co-auth-close:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--co-text);
}

/* ── Logo ──────────────────────────────────────────────────── */

.co-auth-logo {
    text-align: center;
    margin-bottom: 24px;
}

.co-auth-logo__icon {
    display: block;
    font-size: 44px;
    margin-bottom: 8px;
    filter: drop-shadow(0 4px 12px rgba(251, 191, 36, 0.3));
    animation: coIconPulse 3s ease-in-out infinite;
}

@keyframes coIconPulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.06);
    }
}

.co-auth-logo__text {
    font-family: 'Supercell-Magic', 'Inter', sans-serif;
    font-size: 20px;
    color: var(--co-gold);
    letter-spacing: 0.5px;
    text-shadow: 0 2px 8px rgba(251, 191, 36, 0.25);
}

/* ── Tabs ──────────────────────────────────────────────────── */

.co-auth-tabs {
    display: flex;
    border-radius: var(--co-radius-sm);
    background: rgba(0, 0, 0, 0.25);
    padding: 4px;
    margin-bottom: 22px;
    gap: 4px;
}

.co-auth-tab {
    flex: 1;
    padding: 10px 0;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--co-text-dim);
    font-family: 'Supercell-Magic', 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0.6px;
    cursor: pointer;
    transition: var(--co-transition);
}

.co-auth-tab.active {
    background: linear-gradient(135deg, var(--co-gold), var(--co-gold-dim));
    color: #1a1632;
    box-shadow: 0 4px 14px rgba(251, 191, 36, 0.3);
}

.co-auth-tab:not(.active):hover {
    color: var(--co-text);
    background: rgba(255, 255, 255, 0.05);
}

/* ── Forms ─────────────────────────────────────────────────── */

.co-auth-form {
    display: none;
}

.co-auth-form.active {
    display: block;
    animation: coFormIn 0.3s ease;
}

@keyframes coFormIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ── Error ─────────────────────────────────────────────────── */

.co-auth-error {
    padding: 10px 14px;
    border-radius: var(--co-radius-sm);
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #fca5a5;
    font-size: 13px;
    margin-bottom: 16px;
    display: none;
    animation: coShakeLight 0.4s ease;
}

.co-auth-error.visible {
    display: block;
}

@keyframes coShakeLight {

    0%,
    100% {
        transform: translateX(0);
    }

    20% {
        transform: translateX(-6px);
    }

    40% {
        transform: translateX(5px);
    }

    60% {
        transform: translateX(-4px);
    }

    80% {
        transform: translateX(3px);
    }
}

/* ── Fields ────────────────────────────────────────────────── */

.co-auth-field {
    margin-bottom: 16px;
}

.co-auth-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 1.2px;
    text-transform: uppercase;
    color: var(--co-text-dim);
    margin-bottom: 6px;
}

.co-auth-input-wrap {
    position: relative;
}

.co-auth-input {
    width: 100%;
    padding: 13px 44px 13px 16px;
    border-radius: var(--co-radius-sm);
    border: 1px solid var(--co-border);
    background: rgba(0, 0, 0, 0.3);
    color: var(--co-text);
    font-size: 15px;
    font-family: inherit;
    outline: none;
    transition: var(--co-transition);
    box-sizing: border-box;
}

.co-auth-input:focus {
    border-color: var(--co-gold);
    box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.12);
}

.co-auth-input::placeholder {
    color: rgba(255, 255, 255, 0.2);
}

/* Password eye toggle */
.co-pass-toggle {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--co-text-dim);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    transition: var(--co-transition);
}

.co-pass-toggle:hover {
    color: var(--co-text);
    background: rgba(255, 255, 255, 0.06);
}

/* ── Submit Button ─────────────────────────────────────────── */

.co-auth-submit {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: var(--co-radius-sm);
    background: linear-gradient(135deg, #fbbf24, #f59e0b, #d97706);
    color: #1a1632;
    font-family: 'Supercell-Magic', 'Inter', sans-serif;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: var(--co-transition);
    box-shadow: 0 4px 20px rgba(251, 191, 36, 0.25);
    margin-top: 6px;
    position: relative;
    overflow: hidden;
}

.co-auth-submit:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 28px rgba(251, 191, 36, 0.4);
}

.co-auth-submit:active:not(:disabled) {
    transform: translateY(0);
}

.co-auth-submit:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.co-auth-submit.loading {
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.6), rgba(245, 158, 11, 0.6));
}

/* Spinner inside button */
.co-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid rgba(26, 22, 50, 0.3);
    border-top-color: #1a1632;
    border-radius: 50%;
    animation: coSpin 0.6s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

@keyframes coSpin {
    to {
        transform: rotate(360deg);
    }
}

/* ── Shake & Glow Animations ──────────────────────────────── */

.co-auth-card.shake {
    animation: coShake 0.5s cubic-bezier(0.36, 0.07, 0.19, 0.97);
}

@keyframes coShake {

    0%,
    100% {
        transform: translateX(0) scale(1);
    }

    15% {
        transform: translateX(-10px) scale(1);
    }

    30% {
        transform: translateX(8px) scale(1);
    }

    45% {
        transform: translateX(-6px) scale(1);
    }

    60% {
        transform: translateX(4px) scale(1);
    }

    75% {
        transform: translateX(-2px) scale(1);
    }
}

.co-auth-card.success-glow {
    border-color: var(--co-success) !important;
    box-shadow:
        0 0 40px rgba(34, 197, 94, 0.3),
        0 0 80px rgba(34, 197, 94, 0.15),
        inset 0 0 30px rgba(34, 197, 94, 0.05) !important;
}

/* Particles */
.co-auth-particle {
    position: absolute;
    width: 6px;
    height: 6px;
    background: var(--co-gold);
    border-radius: 50%;
    pointer-events: none;
    animation: coParticle 1s ease-out forwards;
    animation-delay: var(--delay, 0s);
    box-shadow: 0 0 6px var(--co-gold-glow);
}

@keyframes coParticle {
    0% {
        transform: translate(0, 0) scale(1);
        opacity: 1;
    }

    100% {
        transform: translate(var(--x, 0), var(--y, -100px)) scale(0);
        opacity: 0;
    }
}


/* ══════════════════════════════════════════════════════════════
   AUTH HEADER BAR (inside Progress view)
   ══════════════════════════════════════════════════════════════ */

.co-auth-bar {
    display: flex;
    align-items: center;
    gap: 8px;
}

.co-signin-btn {
    padding: 8px 18px;
    border: 1px solid var(--co-border-bright);
    border-radius: 24px;
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.15), rgba(251, 191, 36, 0.05));
    color: var(--co-gold);
    font-family: 'Supercell-Magic', 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.5px;
    cursor: pointer;
    transition: var(--co-transition);
    white-space: nowrap;
}

.co-signin-btn:hover {
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.25), rgba(251, 191, 36, 0.1));
    box-shadow: 0 0 16px rgba(251, 191, 36, 0.15);
}

/* User area (when logged in) */
.co-user-area {
    display: none;
    align-items: center;
    gap: 8px;
    position: relative;
    cursor: pointer;
}

.co-user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--co-gold), var(--co-gold-dim));
    display: grid;
    place-items: center;
    font-size: 16px;
    color: #1a1632;
    box-shadow: 0 0 12px var(--co-gold-glow);
    transition: var(--co-transition);
}

.co-user-avatar:hover {
    transform: scale(1.08);
    box-shadow: 0 0 20px var(--co-gold-glow);
}

.co-user-name {
    font-size: 13px;
    color: var(--co-text);
    font-weight: 600;
}

/* ── User Dropdown ─────────────────────────────────────────── */

.co-user-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    min-width: 200px;
    background: var(--co-bg-card);
    border: 1px solid var(--co-border-bright);
    border-radius: var(--co-radius);
    box-shadow: var(--co-shadow);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 6px;
    z-index: 500;
    display: none;
    opacity: 0;
    transform: translateY(-6px) scale(0.96);
    transition: var(--co-transition);
}

.co-user-dropdown.active {
    display: block;
    opacity: 1;
    transform: translateY(0) scale(1);
    animation: coDDIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

@keyframes coDDIn {
    from {
        opacity: 0;
        transform: translateY(-6px) scale(0.96);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.co-dd-item {
    padding: 10px 14px;
    border-radius: var(--co-radius-sm);
    font-size: 13px;
    color: var(--co-text);
    cursor: pointer;
    transition: var(--co-transition);
    display: flex;
    align-items: center;
    gap: 8px;
}

.co-dd-item:hover {
    background: rgba(251, 191, 36, 0.08);
}

.co-dd-item.danger {
    color: var(--co-danger);
}

.co-dd-item.danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

.co-dd-divider {
    height: 1px;
    background: var(--co-border);
    margin: 4px 8px;
}


/* ══════════════════════════════════════════════════════════════
   ACCOUNT SWITCHER
   ══════════════════════════════════════════════════════════════ */

.co-accounts-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 6px;
}

.co-quick-save {
    display: none;
    padding: 7px 16px;
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: 24px;
    background: rgba(34, 197, 94, 0.12);
    color: var(--co-success);
    font-family: 'Supercell-Magic', 'Inter', sans-serif;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--co-transition);
    white-space: nowrap;
}

.co-quick-save.show {
    display: inline-flex;
    animation: coFadeSlideUp 0.3s ease;
}

.co-quick-save:hover {
    background: rgba(34, 197, 94, 0.2);
    box-shadow: 0 0 12px rgba(34, 197, 94, 0.15);
}

@keyframes coFadeSlideUp {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Account dropdown toggle */
.co-acc-toggle {
    padding: 7px 16px;
    border: 1px solid var(--co-border);
    border-radius: 24px;
    background: rgba(251, 191, 36, 0.06);
    color: var(--co-text-dim);
    font-family: 'Supercell-Magic', 'Inter', sans-serif;
    font-size: 11px;
    cursor: pointer;
    transition: var(--co-transition);
    display: none;
    white-space: nowrap;
}

.co-acc-toggle:hover {
    background: rgba(251, 191, 36, 0.12);
    color: var(--co-text);
}

/* Dropdown panel */
.co-acc-dropdown {
    position: relative;
}

.co-acc-panel {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    min-width: 280px;
    max-width: 350px;
    max-height: 300px;
    overflow-y: auto;
    background: var(--co-bg-card);
    border: 1px solid var(--co-border-bright);
    border-radius: var(--co-radius);
    box-shadow: var(--co-shadow);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    z-index: 450;
    padding: 6px;
}

.co-acc-panel.active {
    display: block;
    animation: coDDIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* Empty state */
.co-acc-empty {
    padding: 24px 16px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    color: var(--co-text-dim);
    font-size: 13px;
}

.co-acc-empty__icon {
    font-size: 28px;
    opacity: 0.5;
}

.co-acc-empty__sub {
    font-size: 11px;
    opacity: 0.6;
}

/* Account items */
.co-acc-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--co-radius-sm);
    cursor: pointer;
    transition: var(--co-transition);
    border: 1px solid transparent;
}

.co-acc-item:hover {
    background: rgba(251, 191, 36, 0.06);
}

.co-acc-item.selected {
    background: rgba(251, 191, 36, 0.1);
    border-color: var(--co-border-bright);
}

.co-acc-item__info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.co-acc-item__name {
    font-size: 13px;
    font-weight: 600;
    color: var(--co-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.co-acc-item__tag {
    font-size: 11px;
    color: var(--co-text-dim);
    font-family: monospace;
}

.co-acc-item__th {
    padding: 3px 8px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--co-gold), var(--co-gold-dim));
    color: #1a1632;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.co-acc-item__del {
    background: none;
    border: none;
    color: var(--co-text-dim);
    font-size: 14px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 4px;
    transition: var(--co-transition);
    opacity: 0;
}

.co-acc-item:hover .co-acc-item__del {
    opacity: 1;
}

.co-acc-item__del:hover {
    color: var(--co-danger);
    background: rgba(239, 68, 68, 0.1);
}


/* ══════════════════════════════════════════════════════════════
   HISTORY SECTION
   ══════════════════════════════════════════════════════════════ */

#pi-history-section {
    display: none;
    margin-top: 16px;
    padding: 20px;
    background: var(--co-bg-glass);
    border: 1px solid var(--co-border);
    border-radius: var(--co-radius);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

#pi-history-section.visible {
    display: block;
    animation: coFadeSlideUp 0.4s ease;
}

.co-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 16px;
}

.co-history-title {
    font-family: 'Supercell-Magic', 'Inter', sans-serif;
    font-size: 15px;
    color: var(--co-gold);
    letter-spacing: 0.3px;
}

.co-history-filters {
    display: flex;
    gap: 4px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 6px;
    padding: 3px;
}

.co-hf-chip {
    padding: 5px 14px;
    border: none;
    border-radius: 5px;
    background: transparent;
    color: var(--co-text-dim);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--co-transition);
}

.co-hf-chip.active {
    background: var(--co-gold);
    color: #1a1632;
    box-shadow: 0 2px 8px rgba(251, 191, 36, 0.25);
}

.co-hf-chip:not(.active):hover {
    color: var(--co-text);
    background: rgba(255, 255, 255, 0.05);
}

/* Charts grid */
.co-history-charts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.co-chart-card {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--co-border);
    border-radius: var(--co-radius-sm);
    padding: 12px;
}

.co-chart-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--co-text-dim);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 8px;
}

.co-chart-svg {
    width: 100%;
    height: auto;
}

.co-chart-line {
    animation: coLineIn 1s ease forwards;
    stroke-dasharray: 1000;
    stroke-dashoffset: 1000;
}

@keyframes coLineIn {
    to {
        stroke-dashoffset: 0;
    }
}

.co-chart-fill {
    animation: coFillIn 1.2s ease forwards;
    opacity: 0;
}

@keyframes coFillIn {
    to {
        opacity: 1;
    }
}

.co-chart-dot {
    animation: coDotPulse 2s ease-in-out infinite;
}

@keyframes coDotPulse {

    0%,
    100% {
        r: 4;
    }

    50% {
        r: 5.5;
    }
}

/* Empty state */
.co-history-empty {
    padding: 32px 16px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    color: var(--co-text-dim);
}

.co-history-empty__icon {
    font-size: 36px;
    opacity: 0.4;
}

.co-history-empty__text {
    font-size: 14px;
    font-weight: 600;
    color: var(--co-text);
}

.co-history-empty__sub {
    font-size: 12px;
    opacity: 0.6;
}


/* ══════════════════════════════════════════════════════════════
   SETTINGS MODAL
   ══════════════════════════════════════════════════════════════ */

.co-settings-overlay {
    position: fixed;
    inset: 0;
    z-index: 9998;
    background: rgba(8, 6, 18, 0.6);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: none;
    place-items: center;
}

.co-settings-overlay.active {
    display: grid;
    animation: coFadeIn 0.25s ease;
}

.co-settings-card {
    position: relative;
    width: 90vw;
    max-width: 380px;
    padding: 28px 24px 24px;
    background: linear-gradient(165deg, rgba(30, 25, 65, 0.95), rgba(16, 14, 35, 0.98));
    border: 1px solid var(--co-border-bright);
    border-radius: var(--co-radius);
    box-shadow: var(--co-shadow);
    animation: coCardIn 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.co-settings-title {
    font-family: 'Supercell-Magic', 'Inter', sans-serif;
    font-size: 16px;
    color: var(--co-gold);
    margin-bottom: 20px;
}

.co-settings-close {
    position: absolute;
    top: 12px;
    right: 14px;
    background: none;
    border: none;
    color: var(--co-text-dim);
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}

.co-settings-close:hover {
    color: var(--co-text);
    background: rgba(255, 255, 255, 0.06);
}

.co-settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0;
    border-bottom: 1px solid var(--co-border);
}

.co-settings-row:last-of-type {
    border-bottom: none;
}

.co-settings-label {
    font-size: 14px;
    color: var(--co-text);
    font-weight: 600;
}

.co-settings-sublabel {
    font-size: 11px;
    color: var(--co-text-dim);
    margin-top: 2px;
}

/* Toggle switch */
.co-toggle {
    width: 44px;
    height: 24px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.1);
    cursor: pointer;
    position: relative;
    transition: var(--co-transition);
    flex-shrink: 0;
}

.co-toggle::after {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--co-text-dim);
    top: 3px;
    left: 3px;
    transition: var(--co-transition);
}

.co-toggle.on {
    background: linear-gradient(135deg, var(--co-gold), var(--co-gold-dim));
}

.co-toggle.on::after {
    left: 23px;
    background: #1a1632;
}

.co-settings-select {
    padding: 7px 12px;
    border-radius: 6px;
    border: 1px solid var(--co-border);
    background: rgba(0, 0, 0, 0.3);
    color: var(--co-text);
    font-size: 13px;
    outline: none;
}

.co-settings-save {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: var(--co-radius-sm);
    background: linear-gradient(135deg, var(--co-gold), var(--co-gold-dim));
    color: #1a1632;
    font-family: 'Supercell-Magic', 'Inter', sans-serif;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    margin-top: 16px;
    transition: var(--co-transition);
}

.co-settings-save:hover {
    box-shadow: 0 4px 16px rgba(251, 191, 36, 0.3);
    transform: translateY(-1px);
}


/* ══════════════════════════════════════════════════════════════
   MOBILE RESPONSIVE
   ══════════════════════════════════════════════════════════════ */

@media (max-width: 640px) {
    .co-auth-card {
        padding: 28px 20px 24px;
        border-radius: 16px;
    }

    .co-auth-logo__icon {
        font-size: 36px;
    }

    .co-auth-logo__text {
        font-size: 17px;
    }

    .co-auth-tab {
        font-size: 12px;
        padding: 9px 0;
    }

    .co-auth-input {
        font-size: 16px;
        /* prevent zoom on iOS */
    }

    .co-toast-container {
        top: 10px;
        right: 10px;
        left: 10px;
    }

    .co-toast {
        max-width: 100%;
        font-size: 13px;
        padding: 10px 14px;
    }

    .co-history-charts {
        grid-template-columns: 1fr;
    }

    .co-acc-panel {
        min-width: 240px;
        max-width: calc(100vw - 40px);
    }

    .co-user-dropdown {
        right: -10px;
        min-width: 180px;
    }
}


/* ══════════════════════════════════════════════════════════════
   FEATURE GATING — Guest Lock Overlay
   ══════════════════════════════════════════════════════════════ */

/* Container must be position: relative for the overlay */
[data-gate] {
    position: relative;
}

/* Lock overlay on gated sections */
.co-gate-lock {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    background: rgba(14, 12, 29, 0.7);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    border-radius: inherit;
    opacity: 0;
    animation: coGateFadeIn 0.4s ease forwards;
    cursor: pointer;
}

@keyframes coGateFadeIn {
    to {
        opacity: 1;
    }
}

.co-gate-lock__inner {
    text-align: center;
    padding: 20px;
}

.co-gate-lock__icon {
    font-size: 28px;
    display: block;
    margin-bottom: 8px;
    filter: drop-shadow(0 2px 8px rgba(251, 191, 36, 0.3));
}

.co-gate-lock__text {
    font-size: 13px;
    color: var(--co-text-dim);
    margin-bottom: 12px;
    display: block;
}

.co-gate-lock__cta {
    padding: 8px 22px;
    border: 1px solid var(--co-border-bright);
    border-radius: 24px;
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.2), rgba(251, 191, 36, 0.08));
    color: var(--co-gold);
    font-family: 'Supercell-Magic', 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--co-transition);
    letter-spacing: 0.4px;
}

.co-gate-lock__cta:hover {
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.35), rgba(251, 191, 36, 0.15));
    box-shadow: 0 0 20px rgba(251, 191, 36, 0.2);
    transform: translateY(-1px);
}

/* Blurred teaser content behind lock */
[data-gate].co-gated>*:not(.co-gate-lock) {
    filter: blur(5px);
    pointer-events: none;
    user-select: none;
}

/* Remove gate when logged in */
[data-gate].co-unlocked .co-gate-lock {
    display: none;
}

[data-gate].co-unlocked>* {
    filter: none !important;
    pointer-events: auto !important;
    user-select: auto !important;
}


/* ══════════════════════════════════════════════════════════════
   GUEST BANNER — "Sign in to save villages..."
   ══════════════════════════════════════════════════════════════ */

.co-guest-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 10px 20px;
    margin: 8px 0 12px;
    border-radius: var(--co-radius-sm);
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.08), rgba(251, 191, 36, 0.02));
    border: 1px solid rgba(251, 191, 36, 0.12);
    font-size: 13px;
    color: var(--co-text-dim);
    animation: coFadeSlideUp 0.4s ease;
}

.co-guest-banner.hidden {
    display: none;
}

.co-guest-banner__icon {
    font-size: 16px;
}

.co-guest-banner__text {
    flex: 1;
}

.co-guest-banner__text strong {
    color: var(--co-gold);
    font-weight: 600;
}

.co-guest-banner__cta {
    padding: 6px 16px;
    border: 1px solid var(--co-border-bright);
    border-radius: 20px;
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.15), rgba(251, 191, 36, 0.05));
    color: var(--co-gold);
    font-size: 11px;
    font-weight: 600;
    font-family: 'Supercell-Magic', 'Inter', sans-serif;
    cursor: pointer;
    transition: var(--co-transition);
    white-space: nowrap;
}

.co-guest-banner__cta:hover {
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.3), rgba(251, 191, 36, 0.12));
    box-shadow: 0 0 14px rgba(251, 191, 36, 0.15);
}


/* ══════════════════════════════════════════════════════════════
   SAVE VILLAGE CTA — Post-scan conversion card
   ══════════════════════════════════════════════════════════════ */

.co-save-cta {
    display: none;
    align-items: center;
    gap: 14px;
    padding: 16px 20px;
    margin: 12px 0;
    border-radius: var(--co-radius);
    background: linear-gradient(165deg, rgba(34, 197, 94, 0.08), rgba(34, 197, 94, 0.02));
    border: 1px solid rgba(34, 197, 94, 0.2);
    position: relative;
    overflow: hidden;
    animation: coFadeSlideUp 0.5s ease;
}

.co-save-cta.visible {
    display: flex;
}

/* Animated shimmer border */
.co-save-cta::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--co-success), transparent);
    animation: coShimmer 3s ease-in-out infinite;
}

@keyframes coShimmer {
    0% {
        left: -100%;
    }

    100% {
        left: 100%;
    }
}

.co-save-cta__icon {
    font-size: 24px;
    flex-shrink: 0;
}

.co-save-cta__body {
    flex: 1;
}

.co-save-cta__title {
    font-size: 14px;
    font-weight: 700;
    color: var(--co-text);
    margin-bottom: 2px;
}

.co-save-cta__sub {
    font-size: 12px;
    color: var(--co-text-dim);
}

.co-save-cta__btn {
    padding: 9px 20px;
    border: 1px solid rgba(34, 197, 94, 0.35);
    border-radius: 24px;
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.2), rgba(34, 197, 94, 0.08));
    color: var(--co-success);
    font-family: 'Supercell-Magic', 'Inter', sans-serif;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: var(--co-transition);
    white-space: nowrap;
    letter-spacing: 0.3px;
}

.co-save-cta__btn:hover {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.35), rgba(34, 197, 94, 0.15));
    box-shadow: 0 0 18px rgba(34, 197, 94, 0.2);
    transform: translateY(-1px);
}

/* Hide when logged in */
.co-save-cta.co-auth-hide {
    display: none !important;
}

/* Mobile responsive */
@media (max-width: 600px) {
    .co-save-cta {
        flex-direction: column;
        text-align: center;
        gap: 10px;
    }

    .co-guest-banner {
        flex-direction: column;
        text-align: center;
        gap: 8px;
    }
}