:root {
    --card-size: 80px;
    --radius: 18px;
    --gap: 30px;
    --row-count: 8;
    --page-width: calc(var(--row-count) * (var(--card-size) + var(--gap)) - var(--gap));
}

body {
    margin: 0; padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    min-height: 100vh;
    overflow: hidden;
    display: flex; flex-direction: column; align-items: center;
    box-sizing: border-box;
    visibility: hidden;
    animation: fallback-visible 0s 3s forwards;
    transition: color 0.3s ease;
    color: #333;
}

@keyframes fallback-visible {
    to { visibility: visible; }
}

body.dark-mode {
    color: #fff;
}
body.dark-mode .page-title,
body.dark-mode .bookmark-title {
    text-shadow: 0 1px 3px rgba(0,0,0,0.9);
}
body.dark-mode #user-icon-svg {
    fill: #fff;
}

.background-layer {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -1;
    background-color: #e4d0e5;
    background-image:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 320' preserveAspectRatio='none'%3E%3Cpath fill='rgba(255,255,255,0.4)' d='M0,0L48,26.7C96,53,192,107,288,122.7C384,139,480,117,576,106.7C672,96,768,96,864,112C960,128,1056,160,1152,160C1248,160,1344,128,1392,112L1440,96L1440,0L1392,0C1344,0,1248,0,1152,0C1056,0,960,0,864,0C768,0,672,0,576,0C480,0,384,0,288,0C192,0,96,0,48,0L0,0Z'%3E%3C/path%3E%3C/svg%3E"),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1440 320' preserveAspectRatio='none'%3E%3Cpath fill='rgba(255,255,255,0.2)' d='M0,192L48,197.3C96,203,192,213,288,229.3C384,245,480,267,576,250.7C672,235,768,181,864,181.3C960,181,1056,235,1152,234.7C1248,235,1344,181,1392,154.7L1440,128L1440,320L1392,320C1344,320,1248,320,1152,320C1056,320,960,320,864,320C768,320,672,320,576,320C480,320,384,320,288,320C192,320,96,320,48,320L0,320Z'%3E%3C/path%3E%3C/svg%3E"),
        linear-gradient(180deg, rgba(255,255,255,0.3) 0%, rgba(255,255,255,0) 100%);
    background-position: top center, bottom center, center;
    background-repeat: no-repeat;
    background-size: 100% 50%, 100% 50%, cover;
    transition: background-color 0.5s ease;
}

.background-layer.bg-pattern-aurora {
    background-image:
        linear-gradient(126deg,
            rgba(255, 190, 151, 0.34) 0%,
            rgba(255, 229, 198, 0.08) 18%,
            transparent 34%),
        linear-gradient(28deg,
            transparent 23%,
            rgba(77, 210, 187, 0.34) 38%,
            rgba(255, 255, 255, 0.14) 47%,
            transparent 59%),
        linear-gradient(148deg,
            transparent 44%,
            rgba(166, 112, 218, 0.24) 56%,
            rgba(82, 168, 230, 0.30) 68%,
            transparent 83%),
        linear-gradient(180deg,
            rgba(255, 255, 255, 0.24),
            rgba(255, 255, 255, 0.04) 48%,
            rgba(255, 255, 255, 0.18));
    background-position: 32% 18%, 46% 42%, 58% 58%, center !important;
    background-size: 138% 138%, 128% 128%, 132% 132%, cover !important;
    background-blend-mode: screen, screen, screen, normal;
    overflow: hidden;
    isolation: isolate;
}

.background-layer.bg-pattern-aurora::before,
.background-layer.bg-pattern-aurora::after,
.background-layer.bg-pattern-flow::before,
.background-layer.bg-pattern-flow::after,
.background-layer.bg-pattern-lines-d::before,
.background-layer.bg-pattern-lines-d::after {
    content: "";
    position: absolute;
    pointer-events: none;
}

.background-layer.bg-pattern-aurora::before {
    inset: -22%;
    background:
        repeating-linear-gradient(118deg,
            transparent 0 8%,
            rgba(255, 255, 255, 0.12) 9%,
            rgba(87, 216, 190, 0.14) 12%,
            transparent 17% 25%);
    transform: rotate(-7deg) scale(1.08);
    filter: blur(16px);
    opacity: 0.82;
    mix-blend-mode: soft-light;
    animation: aurora-drift 18s ease-in-out infinite alternate;
}

.background-layer.bg-pattern-aurora::after {
    inset: -10%;
    background:
        repeating-linear-gradient(0deg,
            rgba(255, 255, 255, 0.035) 0 1px,
            transparent 1px 5px);
    opacity: 0.65;
    mix-blend-mode: overlay;
}

@keyframes aurora-drift {
    from {
        background-position: 0 28%;
        transform: translate3d(-3%, -2%, 0) rotate(-7deg) scale(1.08);
    }
    to {
        background-position: 18% 62%;
        transform: translate3d(4%, 3%, 0) rotate(-4deg) scale(1.13);
    }
}

.background-layer.bg-pattern-flow {
    background-image:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 760'%3E%3Cg fill='none' stroke-linecap='round'%3E%3Cpath d='M-120 690C130 465 280 780 525 535S900 185 1320 315' stroke='rgba(255,255,255,0.48)' stroke-width='18'/%3E%3Cpath d='M-130 640C115 420 285 725 525 480S905 145 1325 265' stroke='rgba(255,255,255,0.30)' stroke-width='8'/%3E%3Cpath d='M-120 755C145 515 300 830 555 585S925 245 1325 375' stroke='rgba(255,255,255,0.24)' stroke-width='6'/%3E%3Cpath d='M-110 575C135 375 300 660 535 425S925 105 1320 210' stroke='rgba(255,255,255,0.18)' stroke-width='3'/%3E%3Cpath d='M-125 515C115 325 315 600 555 365S935 55 1325 155' stroke='rgba(255,255,255,0.14)' stroke-width='2'/%3E%3C/g%3E%3C/svg%3E"),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 760'%3E%3Cg fill='none' stroke-linecap='round'%3E%3Cpath d='M-120 115C170 335 325 35 600 235S955 565 1320 475' stroke='rgba(38,75,112,0.16)' stroke-width='13'/%3E%3Cpath d='M-120 65C185 285 345-20 615 185S975 515 1325 425' stroke='rgba(38,75,112,0.10)' stroke-width='5'/%3E%3Cpath d='M-125 170C155 385 325 80 585 285S940 615 1325 535' stroke='rgba(255,255,255,0.14)' stroke-width='4'/%3E%3C/g%3E%3C/svg%3E"),
        linear-gradient(118deg,
            rgba(255, 255, 255, 0.22),
            transparent 32%,
            rgba(255, 255, 255, 0.08) 64%,
            rgba(255, 255, 255, 0.26));
    background-position: center, center, center !important;
    background-size: cover, cover, cover !important;
    background-repeat: no-repeat !important;
    overflow: hidden;
    isolation: isolate;
}

.background-layer.bg-pattern-flow::before {
    inset: -8%;
    background:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 760'%3E%3Cg fill='none' stroke='rgba(255,255,255,0.16)' stroke-width='2'%3E%3Cpath d='M-80 365C215 145 365 625 685 380S1035 75 1290 215'/%3E%3Cpath d='M-80 415C215 195 365 675 685 430S1035 125 1290 265'/%3E%3Cpath d='M-80 465C215 245 365 725 685 480S1035 175 1290 315'/%3E%3Cpath d='M-80 515C215 295 365 775 685 530S1035 225 1290 365'/%3E%3C/g%3E%3C/svg%3E");
    background-size: 1440px 900px;
    opacity: 0.72;
    mix-blend-mode: soft-light;
    animation: flow-current 16s linear infinite;
}

.background-layer.bg-pattern-flow::after {
    inset: 0;
    background:
        linear-gradient(90deg,
            rgba(255, 255, 255, 0.08),
            transparent 18%,
            transparent 78%,
            rgba(255, 255, 255, 0.12)),
        repeating-linear-gradient(90deg,
            transparent 0 95px,
            rgba(255, 255, 255, 0.055) 96px,
            transparent 97px 192px);
    opacity: 0.85;
}

@keyframes flow-current {
    from { background-position: 0 24%; }
    to { background-position: -420px -155px; }
}

.background-layer.bg-pattern-lines-d {
    background-image:
        linear-gradient(124deg,
            transparent 0 55%,
            rgba(218, 116, 101, 0.22) 55% 63%,
            transparent 63% 73%,
            rgba(28, 147, 153, 0.18) 73% 81%,
            transparent 81%),
        linear-gradient(32deg,
            rgba(255, 255, 255, 0.12) 0 1px,
            transparent 1px 72px),
        repeating-linear-gradient(32deg,
            rgba(255, 255, 255, 0.16) 0 1px,
            transparent 1px 72px),
        linear-gradient(180deg,
            rgba(255, 255, 255, 0.18),
            transparent 38%,
            rgba(0, 0, 0, 0.055));
    background-position: center, 0 0, 36px 36px, center !important;
    background-size: cover, 144px 144px, 144px 144px, cover !important;
    overflow: hidden;
    isolation: isolate;
}

.background-layer.bg-pattern-lines-d::before {
    inset: -30%;
    background:
        repeating-linear-gradient(90deg,
            transparent 0 128px,
            rgba(255, 255, 255, 0.17) 129px 130px,
            transparent 131px 256px);
    transform: translate3d(-4%, -3%, 0);
    opacity: 0.88;
    animation: lines-shift 14s ease-in-out infinite alternate;
}

.background-layer.bg-pattern-lines-d::after {
    inset: -18%;
    background:
        repeating-linear-gradient(0deg,
            transparent 0 46px,
            rgba(18, 48, 58, 0.07) 47px,
            transparent 48px 92px);
    transform: translate3d(2%, 2%, 0);
    opacity: 0.8;
}

@keyframes lines-shift {
    from {
        background-position: 0 0;
        transform: translate3d(-4%, -3%, 0) skewX(-2deg);
    }
    to {
        background-position: 86px 22px;
        transform: translate3d(3%, 2%, 0) skewX(-2deg);
    }
}

@media (max-width: 768px) {
    .background-layer.bg-pattern-aurora {
        background-image:
            linear-gradient(126deg,
                rgba(255, 173, 146, 0.56) 0%,
                rgba(255, 222, 205, 0.20) 22%,
                transparent 43%),
            linear-gradient(27deg,
                transparent 18%,
                rgba(57, 204, 181, 0.54) 37%,
                rgba(255, 255, 255, 0.28) 47%,
                transparent 65%),
            linear-gradient(148deg,
                transparent 39%,
                rgba(157, 109, 219, 0.48) 56%,
                rgba(72, 160, 228, 0.44) 70%,
                transparent 87%),
            linear-gradient(180deg,
                rgba(255, 255, 255, 0.2),
                rgba(255, 255, 255, 0.03) 50%,
                rgba(255, 255, 255, 0.14));
        background-position: 0 0, 100% 38%, 68% 100%, center !important;
        background-size: 175% 118%, 168% 112%, 174% 122%, cover !important;
    }

    .background-layer.bg-pattern-aurora::before {
        inset: -16%;
        background:
            linear-gradient(116deg,
                transparent 4%,
                rgba(255, 157, 184, 0.42) 17%,
                rgba(255, 236, 214, 0.18) 28%,
                transparent 40%),
            linear-gradient(28deg,
                transparent 18%,
                rgba(51, 205, 177, 0.46) 36%,
                rgba(255, 255, 255, 0.32) 46%,
                transparent 61%),
            linear-gradient(148deg,
                transparent 37%,
                rgba(164, 104, 222, 0.42) 55%,
                rgba(68, 159, 230, 0.40) 71%,
                transparent 88%);
        filter: blur(18px) saturate(1.18);
        mix-blend-mode: normal;
        opacity: 0.74;
    }

    .background-layer.bg-pattern-flow {
        background-size: cover, cover, cover !important;
    }

    .background-layer.bg-pattern-flow::before {
        background-size: 1080px 680px;
        opacity: 0.62;
    }

    .background-layer.bg-pattern-lines-d {
        background-size: cover, 118px 118px, 118px 118px, cover !important;
    }

    .background-layer.bg-pattern-lines-d::after {
        opacity: 0.62;
    }
}

@media (prefers-reduced-motion: reduce) {
    .background-layer.bg-pattern-aurora::before,
    .background-layer.bg-pattern-flow::before,
    .background-layer.bg-pattern-lines-d::before {
        animation: none;
    }
}

.container {
    width: 100%; height: 100vh;
    display: flex; flex-direction: column; justify-content: flex-start;
    padding-top: 6vh; padding-bottom: 84px; box-sizing: border-box;
}

.hidden { display: none !important; }

.toast-container {
    position: fixed; top: 20px; left: 50%; transform: translateX(-50%);
    z-index: 9999; display: flex; flex-direction: column; gap: 10px;
    pointer-events: none; width: 90%; max-width: 400px;
}
.toast {
    background: rgba(0, 0, 0, 0.85); color: white; padding: 12px 24px;
    border-radius: 30px; font-size: 14px; font-weight: 500;
    backdrop-filter: blur(10px); box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    text-align: center; opacity: 0; transform: translateY(-20px) scale(0.9);
    transition: opacity 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    pointer-events: auto;
}
.toast.visible { opacity: 1; transform: translateY(0) scale(1); }
.toast.success { background: rgba(52, 199, 89, 0.9); }
.toast.error { background: rgba(255, 59, 48, 0.9); }

.sync-status {
    position: fixed;
    top: 20px;
    left: 20px;
    background: rgba(255, 255, 255, 0.9);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    color: #333;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 9000;
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 6px;
}
.sync-status.visible { opacity: 1; transform: translateY(0); }
.sync-status.saving { color: #007AFF; }
.sync-status.saved { color: #34C759; }
.sync-status.error { color: #FF3B30; }
body.dark-mode .sync-status { background: rgba(30, 30, 30, 0.9); color: #fff; box-shadow: 0 2px 10px rgba(0,0,0,0.3); }
