:root {
    --bg: #f5f5f5;
    --bg-elev: #ffffff;
    --bg-elev-2: #f9fafb;
    --bg-subtle: #f3f4f6;
    --text: #111827;
    --text-secondary: #333333;
    --text-muted: #6b7280;
    --text-subtle: #9ca3af;
    --border: #e5e7eb;
    --border-soft: #f3f4f6;
    --border-strong: #d1d5db;
    --accent: #5b21b6;
    --accent-hover: #4c1d95;
    --accent-strong: #6d28d9;
    --accent-light: #8b5cf6;
    --accent-soft: #f5f3ff;
    --accent-soft-2: #ddd6fe;
    --accent-on: #ffffff;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.03);
    --shadow-card: 0 1px 4px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08);
    --shadow-nav: 0 8px 16px -8px rgba(0, 0, 0, 0.12);
    --success-bg: #d1fae5;
    --success-text: #065f46;
    --success-border: #a7f3d0;
    --error-bg: #fee2e2;
    --error-text: #991b1b;
    --error-border: #fca5a5;
    --warning-bg: #fffbeb;
    --warning-text: #92400e;
    --warning-border: #fde68a;
    --danger-strong: #b91c1c;
    --danger: #dc2626;
    --positive-bg: #d1fae5;
    --positive-text: #047857;
    --logout-hover-bg: #fecaca;
}

[data-theme="dark"] {
    --bg: #0a0a0f;
    --bg-elev: #16161d;
    --bg-elev-2: #1c1c25;
    --bg-subtle: #22222e;
    --text: #f3f4f6;
    --text-secondary: #e5e7eb;
    --text-muted: #9ca3af;
    --text-subtle: #6b7280;
    --border: #2a2a36;
    --border-soft: #1f1f29;
    --border-strong: #3a3a48;
    --accent: #a78bfa;
    --accent-hover: #c4b5fd;
    --accent-strong: #8b5cf6;
    --accent-light: #c4b5fd;
    --accent-soft: rgba(167, 139, 250, 0.12);
    --accent-soft-2: rgba(167, 139, 250, 0.28);
    --accent-on: #0a0a0f;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-card: 0 1px 4px rgba(0, 0, 0, 0.5);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.45), 0 2px 4px -1px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.55);
    --shadow-nav: 0 8px 16px -8px rgba(0, 0, 0, 0.7);
    --success-bg: rgba(16, 185, 129, 0.14);
    --success-text: #6ee7b7;
    --success-border: rgba(16, 185, 129, 0.35);
    --error-bg: rgba(239, 68, 68, 0.14);
    --error-text: #fca5a5;
    --error-border: rgba(239, 68, 68, 0.35);
    --warning-bg: rgba(245, 158, 11, 0.12);
    --warning-text: #fcd34d;
    --warning-border: rgba(245, 158, 11, 0.35);
    --danger-strong: #ef4444;
    --danger: #ef4444;
    --positive-bg: rgba(16, 185, 129, 0.18);
    --positive-text: #6ee7b7;
    --logout-hover-bg: rgba(239, 68, 68, 0.22);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    background: var(--bg);
    transition: background-color 0.25s ease;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: transparent;
    color: var(--text-secondary);
    min-height: 100vh;
    transition: color 0.25s ease;
}

body > header,
body > main {
    position: relative;
    z-index: 1;
}

body > header {
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    height: 56px;
    transition: background-color 0.25s ease, border-color 0.25s ease;
}

body > header .logo {
    display: inline-flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: 1.6rem;
    letter-spacing: -0.01em;
    color: var(--accent);
    text-decoration: none;
}

body > header .logo img {
    width: 40px;
    height: 40px;
}

nav {
    display: flex;
    align-items: stretch;
    gap: 4px;
}

nav a {
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0 14px;
    transition: color 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    line-height: 1;
    position: relative;
    color: var(--text-muted);
}

nav a::after {
    content: "";
    position: absolute;
    left: 14px;
    right: 14px;
    bottom: 0;
    height: 2px;
    background: transparent;
    border-radius: 2px 2px 0 0;
    transition: background 0.18s ease;
}

nav a:hover {
    color: var(--accent);
}

nav a:hover::after {
    background: var(--accent-soft-2);
}

nav a.is-active {
    color: var(--accent);
}

nav a.is-active::after {
    background: var(--accent);
}

nav a.nav-logout {
    color: var(--text-subtle);
    margin-left: 8px;
    border-left: 1px solid var(--border);
}

nav a.nav-logout:hover {
    color: var(--danger-strong);
}

nav a.nav-logout:hover::after {
    background: var(--logout-hover-bg);
}

nav a.nav-logout::after {
    left: 22px;
}

.nav-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: 0;
    padding: 8px;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 6px;
}

.nav-toggle:hover { color: var(--accent); background: var(--bg-subtle); }

.theme-toggle {
    --thumb-size: 22px;
    --track-w: 52px;
    --track-h: 28px;
    align-self: center;
    width: var(--track-w);
    height: var(--track-h);
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    background: linear-gradient(135deg, #fde68a, #fdba74);
    position: relative;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
    transition: background 0.35s ease, border-color 0.25s ease, box-shadow 0.25s ease;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.06);
    margin: 0 6px;
}

.theme-toggle:hover {
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.08), 0 0 0 4px var(--accent-soft);
}

.theme-toggle:focus-visible {
    outline: none;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.08), 0 0 0 3px var(--accent-soft-2);
}

[data-theme="dark"] .theme-toggle {
    background: linear-gradient(135deg, #1e1b4b, #312e81);
    border-color: rgba(167, 139, 250, 0.4);
}

.theme-toggle .theme-icon {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 13px;
    height: 13px;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.theme-toggle .theme-icon-sun {
    left: 7px;
    color: #f59e0b;
    opacity: 1;
}

.theme-toggle .theme-icon-moon {
    right: 7px;
    color: #c7d2fe;
    opacity: 0.55;
}

[data-theme="dark"] .theme-toggle .theme-icon-sun { opacity: 0.45; }
[data-theme="dark"] .theme-toggle .theme-icon-moon { opacity: 1; }

.theme-toggle-thumb {
    position: absolute;
    top: 50%;
    left: 2px;
    width: var(--thumb-size);
    height: var(--thumb-size);
    border-radius: 50%;
    background: #ffffff;
    transform: translateY(-50%);
    transition: transform 0.32s cubic-bezier(0.4, 0.0, 0.2, 1), background 0.25s ease, box-shadow 0.25s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25), 0 1px 1px rgba(0, 0, 0, 0.15);
    pointer-events: none;
}

[data-theme="dark"] .theme-toggle-thumb {
    transform: translate(calc(var(--track-w) - var(--thumb-size) - 6px), -50%);
    background: #f9fafb;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.6);
}

@media (max-width: 720px) {
    body > header {
        padding: 0 16px;
        position: relative;
        flex-wrap: wrap;
    }

    .nav-toggle { display: inline-flex; }

    nav {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        background: var(--bg-elev);
        border-bottom: 1px solid var(--border);
        box-shadow: var(--shadow-nav);
        padding: 8px 0;
        gap: 0;
        z-index: 10;
    }

    nav.is-open { display: flex; }

    nav a {
        padding: 12px 20px;
        font-size: 0.95rem;
    }

    nav a::after { display: none; }

    nav a.is-active {
        background: var(--accent-soft);
        box-shadow: inset 3px 0 0 var(--accent);
    }

    nav a.nav-logout {
        margin-left: 0;
        border-left: 0;
        border-top: 1px solid var(--border);
        margin-top: 4px;
        padding-top: 14px;
    }

    .theme-toggle {
        margin: 10px 20px;
        align-self: flex-start;
    }
}

main { max-width: 860px; margin: 32px auto; padding: 0 16px; }

.flash {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 0.9rem;
}

.flash-success { background: var(--success-bg); color: var(--success-text); border: 1px solid var(--success-border); }
.flash-error   { background: var(--error-bg); color: var(--error-text); border: 1px solid var(--error-border); }

/* === Ambient background scene === */
.bg-scene {
    position: fixed;
    inset: 0;
    z-index: -1;
    overflow: hidden;
    pointer-events: none;
    contain: strict;
}

.bg-aurora {
    position: absolute;
    border-radius: 50%;
    filter: blur(130px);
    will-change: transform;
    transform: translate3d(0, 0, 0);
}

.bg-aurora-1 {
    width: 720px;
    height: 720px;
    top: -260px;
    left: -220px;
    background: radial-gradient(circle, #c4b5fd, transparent 65%);
    opacity: 0.55;
    animation: aurora-drift-1 34s ease-in-out infinite;
}

.bg-aurora-2 {
    width: 620px;
    height: 620px;
    bottom: -220px;
    right: -160px;
    background: radial-gradient(circle, #fbcfe8, transparent 65%);
    opacity: 0.45;
    animation: aurora-drift-2 42s ease-in-out infinite;
}

[data-theme="dark"] .bg-aurora-1 {
    background: radial-gradient(circle, #7c3aed, transparent 65%);
    opacity: 0.4;
}

[data-theme="dark"] .bg-aurora-2 {
    background: radial-gradient(circle, #a78bfa, transparent 65%);
    opacity: 0.32;
}

.bg-scene::after {
    content: "";
    position: absolute;
    inset: 0;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/></filter><rect width='240' height='240' filter='url(%23n)'/></svg>");
    opacity: 0.05;
    mix-blend-mode: overlay;
    pointer-events: none;
}

[data-theme="dark"] .bg-scene::after {
    opacity: 0.08;
}

@keyframes aurora-drift-1 {
    0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
    50%      { transform: translate3d(60px, 40px, 0) scale(1.06); }
}

@keyframes aurora-drift-2 {
    0%, 100% { transform: translate3d(0, 0, 0) scale(1); }
    50%      { transform: translate3d(-50px, -40px, 0) scale(1.08); }
}

@media (max-width: 720px) {
    .bg-aurora   { filter: blur(90px); }
    .bg-aurora-1 { width: 480px; height: 480px; }
    .bg-aurora-2 { width: 420px; height: 420px; }
}

@media (prefers-reduced-motion: reduce) {
    .bg-aurora { animation: none; }
}
