/* ---- Global Enhancements ---- */
* {
    -webkit-tap-highlight-color: transparent;
}

body {
    transition: background-color 0.2s ease-out, color 0.2s ease-out;
    overscroll-behavior-y: contain;
}

/* ---- Smooth Scrolling ---- */
html {
    scroll-behavior: smooth;
}

/* ---- Dark Mode Variables & Overrides ---- */
body.dark {
    background-color: #0f172a !important;
    color: #f8fafc;
}

body.dark .bg-slate-50 {
    background-color: #0f172a;
}

body.dark .text-slate-900 {
    color: #f8fafc;
}

body.dark .text-slate-500 {
    color: #94a3b8;
}

body.dark .text-slate-400 {
    color: #cbd5e1;
}

body.dark .bg-white {
    background-color: #1e293b;
    color: #f8fafc;
    border-color: #334155;
}

/* Force Light Mode styles for key elements when not dark */
body:not(.dark) .bg-white,
body:not(.dark) nav,
body:not(.dark) .mood-card,
body:not(.dark) .stat-card,
body:not(.dark) .rec-box,
body:not(.dark) #recommendation-panel .bg-white {
    background-color: #ffffff !important;
    background-image: none !important;
    border-color: #e2e8f0;
    color: #0f172a !important;
}

body:not(.dark) .text-slate-900 {
    color: #0f172a !important;
}

body:not(.dark) .text-slate-800 {
    color: #1e293b !important;
}

body.dark .bg-slate-100 {
    background-color: #334155;
    color: white;
}

body.dark input {
    color: white;
}

body.dark input::placeholder {
    color: #94a3b8;
}

body.dark nav {
    background-color: rgba(15, 23, 42, 0.8);
    border-color: rgba(255, 255, 255, 0.1);
}

body.dark .mood-card {
    background-color: #1e293b;
    border-color: #334155;
    color: #f8fafc;
}

body.dark .mood-card:hover {
    border-color: #6366f1;
    background-color: #334155;
}

body.dark .recommendation-card {
    background-color: rgba(30, 41, 59, 0.9);
    border-color: #334155;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

body.dark .rec-box {
    background-color: rgba(15, 23, 42, 0.5);
    border-color: #334155;
}

body.dark .rec-box h4 {
    filter: brightness(1.2);
}

body.dark .rec-box p {
    color: #cbd5e1;
}

body.dark #rec-emoji {
    background-color: #334155;
    border-color: #475569;
}

body.dark .btn-secondary {
    background-color: transparent;
    border-color: #475569;
    color: #f8fafc;
}

body.dark .btn-secondary:hover {
    background-color: #334155;
}

body.dark .btn-ghost {
    background-color: #334155;
    color: #cbd5e1;
}

body.dark .btn-ghost:hover {
    background-color: #475569;
}

body.dark .stat-card {
    background-color: #1e293b;
    border-bottom-width: 4px;
}

body.dark .stat-card p {
    color: #f8fafc;
}

body.dark .stat-card h6 {
    color: #94a3b8;
}

body.dark .timer-mode-btn.active {
    background-color: #334155;
    color: #818cf8;
}

body.dark #timer-display {
    color: #f8fafc;
}

/* ---- Focus States for Accessibility ---- */
button:focus-visible,
input:focus-visible,
[tabindex]:focus-visible {
    outline: 2px solid #4f46e5;
    outline-offset: 2px;
}

body.dark button:focus-visible,
body.dark input:focus-visible,
body.dark [tabindex]:focus-visible {
    outline-color: #818cf8;
}

/* ---- Mobile Nav ---- */
.mobile-nav-btn.active {
    color: #4f46e5;
    background-color: rgba(79, 70, 229, 0.1);
}

.mobile-nav-btn:not(.active) {
    color: #94a3b8;
}

body.dark .mobile-nav-btn.active {
    color: #818cf8;
    background-color: rgba(129, 140, 248, 0.1);
}

body.dark .mobile-nav-btn:not(.active) {
    color: #475569;
}

.safe-area-bottom {
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
}

/* ---- Animations ---- */
.section-content {
    animation: fadeIn 0.6s ease-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

/* ---- Nav Buttons ---- */
.nav-btn {
    padding: 0.6rem 1.2rem;
    border-radius: 0.8rem;
    font-size: 0.85rem;
    font-weight: 700;
    color: #64748b;
    transition: all 0.3s ease;
}

.nav-btn.active {
    background: white;
    color: #4f46e5;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}

body.dark .nav-btn.active {
    background: #334155;
    color: #818cf8;
}

/* ---- Mood Cards ---- */
.mood-card {
    background: white;
    border: 1px solid #f1f5f9;
    border-radius: 1.5rem;
    padding: 1.5rem 1rem;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.05);
    cursor: pointer;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.mood-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 20px 40px -15px rgba(79, 70, 229, 0.15);
    border-color: #e2e8f0;
}

.mood-card:active {
    transform: translateY(-4px);
}

.mood-card.selected {
    background: #4f46e5;
    color: white !important;
    border-color: #4f46e5;
    transform: scale(1.05);
}

.mood-card.selected span {
    color: white;
}

body.dark .mood-card.selected {
    background: #6366f1;
    border-color: #6366f1;
}

/* ---- Recommendation Boxes ---- */
.rec-box {
    padding: 1.25rem;
    border-radius: 1.5rem;
    border: 1px solid transparent;
    transition: transform 0.3s ease;
}

.rec-box:hover {
    transform: scale(1.02);
}

.rec-box h4 {
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 0.5rem;
}

.rec-box p {
    font-weight: 600;
    color: #334155;
    line-height: 1.6;
    font-size: 0.9rem;
}

@media (max-width: 640px) {
    .rec-box {
        padding: 1rem;
    }
    
    .rec-box h4 {
        font-size: 0.7rem;
    }
    
    .rec-box p {
        font-size: 0.85rem;
    }
}

/* ---- UI Elements ---- */
.quote-card {
    background: linear-gradient(135deg, #4f46e5, #9333ea);
    padding: 1.5rem;
    border-radius: 2rem;
    color: white;
    text-align: center;
    position: relative;
    box-shadow: 0 20px 50px -15px rgba(79, 70, 229, 0.4);
    cursor: pointer;
    transition: transform 0.3s ease;
    overflow: hidden;
}

.quote-card:hover {
    transform: scale(1.02);
}

.quote-card:active {
    transform: scale(0.98);
}

.card-quote {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 0 1rem;
    min-height: 100px;
}

@media (min-width: 640px) {
    .quote-card {
        padding: 1rem 0.5rem;
    }
    
    .card-quote {
        flex-direction: row;
        justify-content: space-between;
        padding: 0 1.5rem;
    }
}

.btn-primary {
    background: #1e293b;
    color: white;
    padding: 0.875rem 1.5rem;
    border-radius: 1.2rem;
    font-weight: 700;
    transition: all 0.3s ease;
    flex: 1 1 auto;
    min-width: 120px;
    cursor: pointer;
    border: none;
}

.btn-primary:hover {
    background: #0f172a;
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
}

.btn-primary:active {
    transform: translateY(0);
}

body.dark .btn-primary {
    background: #4f46e5;
}

body.dark .btn-primary:hover {
    background: #4338ca;
}

.btn-secondary {
    background: white;
    border: 2px solid #e2e8f0;
    padding: 0.875rem 1.5rem;
    border-radius: 1.2rem;
    font-weight: 700;
    transition: all 0.3s ease;
    flex: 1 1 auto;
    min-width: 120px;
    cursor: pointer;
}

.btn-secondary:hover {
    background: #f8fafc;
    border-color: #cbd5e1;
}

.btn-secondary:active {
    transform: scale(0.98);
}

.btn-ghost {
    background: #f1f5f9;
    padding: 0.875rem 1.25rem;
    border-radius: 1.2rem;
    font-weight: 700;
    color: #64748b;
    transition: all 0.3s ease;
    cursor: pointer;
    border: none;
}

.btn-ghost:hover {
    background: #e2e8f0;
}

.btn-ghost:active {
    transform: scale(0.98);
}

/* ---- Timer Custom ---- */
.timer-mode-btn {
    padding: 0.6rem 1.5rem;
    border-radius: 0.9rem;
    font-weight: 700;
    font-size: 0.8rem;
    color: #94a3b8;
    transition: all 0.3s ease;
    cursor: pointer;
    border: none;
    background: transparent;
}

.timer-mode-btn.active {
    background: white;
    color: #4f46e5;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}

body.dark .timer-mode-btn {
    color: #64748b;
}

body.dark .timer-mode-btn:hover {
    color: #94a3b8;
}

/* ---- Dashboard ---- */
.stat-card {
    background: white;
    padding: 1.25rem;
    border-radius: 1.5rem;
    border-bottom: 4px solid;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    transition: transform 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
}

.stat-card h6 {
    color: #94a3b8;
    font-size: 0.7rem;
    text-transform: uppercase;
    font-weight: 800;
    margin-bottom: 0.5rem;
    letter-spacing: 0.05em;
}

.stat-card p {
    font-size: 1.75rem;
    font-weight: 900;
    color: #1e293b;
}

@media (max-width: 640px) {
    .stat-card {
        padding: 1rem;
    }
    
    .stat-card p {
        font-size: 1.5rem;
    }
}

/* ---- Toast ---- */
#toast {
    transform: translateX(100%);
    opacity: 0;
    transition: all 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    pointer-events: none;
}

#toast.show {
    transform: translateX(0);
    opacity: 1;
    pointer-events: auto;
}

/* ---- Scroll Margin for Sticky Nav ---- */
.scroll-mt-24 {
    scroll-margin-top: 7rem;
}

/* ---- Loading State for Charts ---- */
canvas {
    opacity: 1;
    transition: opacity 0.3s ease;
}

canvas.loading {
    opacity: 0.5;
}

/* ---- Improved Link Styles ---- */
a {
    color: #4f46e5;
    text-decoration: none;
    transition: color 0.2s ease;
}

a:hover {
    color: #4338ca;
}

body.dark a {
    color: #818cf8;
}

body.dark a:hover {
    color: #a5b4fc;
}

/* ---- Log List Items ---- */
#mood-log-list > div {
    transition: all 0.2s ease;
}

#mood-log-list > div:hover {
    transform: translateX(4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

body.dark #mood-log-list > div {
    background-color: rgba(30, 41, 59, 0.5) !important;
    border-color: #334155 !important;
}

body.dark #mood-log-list > div:hover {
    background-color: rgba(30, 41, 59, 0.8) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* ---- Custom Scrollbar ---- */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

body.dark ::-webkit-scrollbar-thumb {
    background: #475569;
}

body.dark ::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* ---- Responsive Typography ---- */
@media (max-width: 640px) {
    html {
        font-size: 15px;
    }
}

/* ---- Prevent Text Selection on Buttons ---- */
button {
    user-select: none;
    -webkit-user-select: none;
}

/* ---- Performance Optimization ---- */
.recommendation-card,
.mood-card,
.stat-card {
    will-change: transform;
}

/* ---- Auth Overlay Improvements ---- */
#auth-overlay > div {
    animation: slideUp 0.3s ease-out;
}

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

body.dark #auth-overlay > div {
    background-color: #1e293b;
    border: 1px solid #334155;
}

/* ---- Sound Widget ---- */
#sound-widget button:first-child {
    will-change: transform;
}

#sound-menu {
    animation: fadeInUp 0.2s ease-out;
}

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