/* DreamQuests — Core Styles */

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-body);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100dvh;
    overflow-x: hidden;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* Starfield canvas */
#starfield {
    position: fixed;
    inset: 0;
    z-index: var(--z-starfield);
    pointer-events: none;
}

[data-theme="light"] #starfield {
    opacity: 0.15;
}

/* App container */
#app {
    position: relative;
    z-index: var(--z-content);
    min-height: 100dvh;
}

/* ========== Loading Screen ========== */
.loading-screen {
    position: fixed;
    inset: 0;
    z-index: var(--z-loading);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    transition: opacity 0.6s ease, visibility 0.6s ease;
}

.loading-screen.fade-out {
    opacity: 0;
    visibility: hidden;
}

.loading-logo {
    width: 100px;
    height: 100px;
    animation: float 3s ease-in-out infinite;
}

.logo-svg {
    width: 100%;
    height: 100%;
    filter: drop-shadow(0 0 20px var(--accent-glow));
}

.loading-title {
    font-family: var(--font-display);
    font-size: 2rem;
    font-weight: 600;
    color: var(--accent-lighter);
    margin-top: var(--space-lg);
    letter-spacing: 0.1em;
}

.loading-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: var(--space-sm);
    font-weight: 300;
}

.loading-spinner {
    margin-top: var(--space-xl);
}

.spinner-ring {
    width: 32px;
    height: 32px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* ========== Page Layout ========== */
.page {
    padding: calc(var(--navbar-height) + var(--space-lg)) var(--space-md) calc(var(--bottom-nav-height) + var(--space-xl));
    max-width: var(--max-width);
    margin: 0 auto;
    animation: fadeIn 0.3s ease;
}

.page-header {
    margin-bottom: var(--space-xl);
}

.page-title {
    font-family: var(--font-display);
    font-size: 1.6rem;
    font-weight: 600;
    color: var(--accent-lighter);
    letter-spacing: 0.04em;
}

.page-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: var(--space-xs);
}

/* ========== Navbar ========== */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--navbar-height);
    padding: 0 var(--space-md);
    padding-top: var(--safe-area-top);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--bg-overlay);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-light);
    z-index: var(--z-navbar);
}

.navbar-brand {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    text-decoration: none;
    cursor: pointer;
}

.navbar-brand svg {
    width: 32px;
    height: 32px;
}

.navbar-brand-text {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--accent-lighter);
    letter-spacing: 0.06em;
}

.navbar-actions {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.desktop-nav-link {
    display: none;
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    padding: 6px 12px;
    border-radius: var(--radius-md);
    transition: color var(--transition-fast), background var(--transition-fast);
}

.desktop-nav-link:hover {
    color: var(--accent-light);
    background: var(--accent-subtle);
}

.desktop-nav-link.active {
    color: var(--accent-light);
}

@media (min-width: 768px) {
    .desktop-nav-link {
        display: block;
    }
}

/* ========== Bottom Navigation (Mobile) ========== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    padding-bottom: var(--safe-area-bottom);
    display: flex;
    align-items: center;
    justify-content: space-around;
    background: var(--bg-overlay);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-light);
    z-index: var(--z-navbar);
}

.bottom-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    flex: 1;
    min-width: 0;
    padding: var(--space-xs) 0;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.6rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    transition: color var(--transition-fast);
    cursor: pointer;
    background: none;
    border: none;
}

.bottom-nav-item svg {
    width: 22px;
    height: 22px;
    transition: transform var(--transition-fast);
}

.bottom-nav-item.active,
.bottom-nav-item:hover {
    color: var(--accent-light);
}

.bottom-nav-item.active svg {
    transform: scale(1.1);
    filter: drop-shadow(0 0 6px var(--accent-glow));
}

/* New dream FAB in bottom nav */
.bottom-nav-fab {
    width: 48px;
    height: 48px;
    min-width: 48px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: -20px;
    box-shadow: var(--shadow-glow), var(--shadow-md);
    cursor: pointer;
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
    flex: 0 0 auto;
}

.bottom-nav-fab:hover {
    transform: scale(1.08);
    box-shadow: var(--shadow-glow), var(--shadow-lg);
}

.bottom-nav-fab svg {
    width: 24px;
    height: 24px;
}

/* ========== Buttons ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    white-space: nowrap;
    line-height: 1.4;
}

.btn svg {
    width: 18px;
    height: 18px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: white;
    box-shadow: var(--shadow-glow-sm);
}

.btn-primary:hover {
    box-shadow: var(--shadow-glow);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--glass-bg);
    color: var(--accent-light);
    border: 1px solid var(--glass-border);
}

.btn-secondary:hover {
    background: var(--accent-subtle);
    border-color: var(--accent);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px 12px;
}

.btn-ghost:hover {
    color: var(--accent-light);
    background: var(--accent-subtle);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.25);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.8rem;
}

.btn-lg {
    padding: 14px 28px;
    font-size: 1rem;
}

.btn-block {
    width: 100%;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-full);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    color: var(--text-secondary);
}

.btn-icon:hover {
    color: var(--accent-light);
    border-color: var(--accent);
    background: var(--accent-subtle);
}

/* ========== Form Elements ========== */
.form-group {
    margin-bottom: var(--space-lg);
}

.form-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
    letter-spacing: 0.02em;
}

.form-input,
.form-textarea,
.form-select {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.95rem;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    outline: none;
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--text-muted);
}

.form-textarea {
    resize: vertical;
    min-height: 120px;
    line-height: 1.7;
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b6590' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.form-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: var(--space-xs);
}

.form-error {
    font-size: 0.78rem;
    color: #ef4444;
    margin-top: var(--space-xs);
}

/* Checkbox / toggle */
.form-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    cursor: pointer;
}

.form-toggle input[type="checkbox"] {
    appearance: none;
    width: 44px;
    height: 24px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    position: relative;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.form-toggle input[type="checkbox"]::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: var(--text-secondary);
    border-radius: 50%;
    transition: transform var(--transition-fast), background var(--transition-fast);
}

.form-toggle input[type="checkbox"]:checked {
    background: var(--accent);
    border-color: var(--accent);
}

.form-toggle input[type="checkbox"]:checked::after {
    transform: translateX(20px);
    background: white;
}

/* ========== Cards ========== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: all var(--transition-base);
}

.card:hover {
    background: var(--bg-card-hover);
    border-color: var(--glass-border);
    box-shadow: var(--shadow-md);
}

.card-glass {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
}

/* ========== Tags ========== */
.tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--accent-subtle);
    color: var(--accent-light);
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
    border: 1px solid var(--glass-border);
}

.tag-remove {
    cursor: pointer;
    opacity: 0.6;
    transition: opacity var(--transition-fast);
    background: none;
    border: none;
    color: inherit;
    font-size: 1rem;
    line-height: 1;
    padding: 0;
}

.tag-remove:hover {
    opacity: 1;
}

/* ========== Mood Badge ========== */
.mood-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 600;
}

/* ========== Empty State ========== */
.empty-state {
    text-align: center;
    padding: var(--space-3xl) var(--space-md);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: var(--space-md);
    opacity: 0.6;
}

.empty-state-title {
    font-family: var(--font-display);
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

.empty-state-text {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: var(--space-lg);
}

/* ========== Modal ========== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: var(--z-modal);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
    animation: fadeIn 0.2s ease;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: var(--space-xl);
    max-width: 440px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

.modal-title {
    font-family: var(--font-display);
    font-size: 1.2rem;
    color: var(--accent-lighter);
    margin-bottom: var(--space-lg);
}

.modal-actions {
    display: flex;
    gap: var(--space-sm);
    justify-content: flex-end;
    margin-top: var(--space-xl);
}

/* ========== Skeleton Loading ========== */
.skeleton {
    background: linear-gradient(90deg, var(--bg-tertiary) 25%, var(--bg-card) 50%, var(--bg-tertiary) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-md);
}

.skeleton-text {
    height: 14px;
    margin-bottom: 8px;
}

.skeleton-text:last-child {
    width: 60%;
}

.skeleton-title {
    height: 20px;
    width: 70%;
    margin-bottom: 12px;
}

.skeleton-card {
    height: 120px;
    margin-bottom: var(--space-md);
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--accent);
}

/* ========== Animations ========== */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

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

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 0 10px var(--accent-glow); }
    50% { box-shadow: 0 0 25px var(--accent-glow); }
}

@keyframes staggerIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Stagger children */
.stagger-in > * {
    animation: staggerIn 0.4s ease both;
}
.stagger-in > *:nth-child(1) { animation-delay: 0.05s; }
.stagger-in > *:nth-child(2) { animation-delay: 0.1s; }
.stagger-in > *:nth-child(3) { animation-delay: 0.15s; }
.stagger-in > *:nth-child(4) { animation-delay: 0.2s; }
.stagger-in > *:nth-child(5) { animation-delay: 0.25s; }
.stagger-in > *:nth-child(6) { animation-delay: 0.3s; }
.stagger-in > *:nth-child(7) { animation-delay: 0.35s; }
.stagger-in > *:nth-child(8) { animation-delay: 0.4s; }

/* ========== Utilities ========== */
.text-center { text-align: center; }
.text-accent { color: var(--accent-light); }
.text-muted { color: var(--text-muted); }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.hidden { display: none !important; }
.relative { position: relative; }

/* ========== Responsive ========== */
@media (min-width: 768px) {
    .page {
        padding-top: calc(var(--navbar-height) + var(--space-xl));
        padding-bottom: var(--space-xl);
        padding-left: var(--space-xl);
        padding-right: var(--space-xl);
    }

    .bottom-nav {
        display: none;
    }

    .page-title {
        font-size: 2rem;
    }
}

/* ========== Auth Pages ========== */
.auth-page {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
}

.auth-container {
    width: 100%;
    max-width: 400px;
    animation: slideUp 0.5s ease;
}

.auth-header {
    text-align: center;
    margin-bottom: var(--space-2xl);
}

.auth-header .logo-svg {
    width: 80px;
    height: 80px;
    margin-bottom: var(--space-md);
}

.auth-header h1 {
    font-family: var(--font-display);
    font-size: 1.8rem;
    color: var(--accent-lighter);
    letter-spacing: 0.08em;
}

.auth-header p {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: var(--space-xs);
}

.auth-form .card {
    padding: var(--space-xl);
}

.auth-footer {
    text-align: center;
    margin-top: var(--space-lg);
    font-size: 0.85rem;
    color: var(--text-muted);
}

.auth-footer a {
    color: var(--accent-light);
    text-decoration: none;
    font-weight: 600;
}

.auth-footer a:hover {
    text-decoration: underline;
}

.auth-divider {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    margin: var(--space-lg) 0;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}
