/* Import the Google Sans font */
@import url('https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500&display=swap');

/* --- THEME & ANIMATIONS --- */
:root {
    --md-sys-color-primary: #A8C7FA;
    --md-sys-color-surface-container: #1F2328;
    --md-sys-color-surface-container-high: #3A3E42;
    --md-sys-color-on-surface: #E3E2E6;
    --md-sys-color-on-surface-variant: #C4C6CF;
    --md-sys-color-outline: #45474a;
    --md-sys-color-background: #1B1B1F;
    --md-sys-color-error: #F2B8B5;
    --font-primary: 'Google Sans', sans-serif;
    --ripple-color: rgba(255, 255, 255, 0.1);

    /* NEW: A more expressive M3 easing curve */
    --ease-standard: cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes fadeIn-Up {
    from {
        opacity: 0;
        /* Start slightly further down for a more noticeable animation */
        transform: translateY(24px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes ripple-effect {
    to {
        transform: scale(4);
        opacity: 0;
    }
}

/* --- GENERAL STYLES --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-primary);
    background-color: var(--md-sys-color-background);
    color: var(--md-sys-color-on-surface);
    -webkit-tap-highlight-color: transparent;
}

.container {
    padding: 16px;
    max-width: 600px;
    margin: 0 auto;
    transition: filter 0.5s var(--ease-standard);
    position: relative;
}

a {
    color: inherit;
    text-decoration: none;
}

button {
    background: none;
    border: none;
    padding: 0;
    color: inherit;
    font: inherit;
    cursor: pointer;
}

/* --- HELPER CLASSES --- */
.hidden {
    display: none !important;
}

body.icons-filled .material-symbols-outlined {
    font-variation-settings: 'FILL' 1;
}

body.settings-open .container {
    filter: blur(10px) brightness(0.8);
}

/* --- PAGE LOAD ANIMATIONS --- */
.anim-load > .container > * {
    opacity: 0;
    /* CHANGED: Increased duration and added expressive easing */
    animation: fadeIn-Up 0.6s var(--ease-standard) forwards;
}

/* Staggered delays for a more fluid cascade */
.anim-load .logo-container   { animation-delay: 0.1s; }
.anim-load .search-section   { animation-delay: 0.18s; }
.anim-load .action-buttons   { animation-delay: 0.26s; }
.anim-load .links-section    { animation-delay: 0.34s; }

/* --- RIPPLE EFFECT & INTERACTIVE SCALE --- */
.action-btn,
.link-card-content,
.fab,
#settings-close-btn,
.radio-row,
.switch-row {
    position: relative;
    overflow: hidden;
    transition: transform 0.2s ease-out;
}

.ripple {
    position: absolute;
    border-radius: 50%;
    background-color: var(--ripple-color);
    transform: scale(0);
    animation: ripple-effect 0.6s linear;
}

.action-btn:active,
.link-card-content:active,
.fab:active,
#settings-close-btn:active,
.radio-row:active,
.switch-row:active {
    transform: scale(0.96);
}

/* --- UI ELEMENT STYLES --- */
.logo-container {
    text-align: center;
    padding-top: 6vh;
    padding-bottom: 28px;
}

#google-logo-img {
    height: 55px;
}

.search-section {
    margin-bottom: 16px;
}

#search-form {
    display: flex;
    align-items: center;
    background-color: var(--md-sys-color-surface-container);
    border-radius: 28px;
    height: 56px;
    border: 1px solid var(--md-sys-color-outline);
    padding: 0 16px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

#search-form:focus-within {
    border-color: var(--md-sys-color-primary);
    box-shadow: 0 0 0 1px var(--md-sys-color-primary);
}

#search-input {
    flex-grow: 1;
    border: none;
    background: transparent;
    outline: none;
    font-size: 1rem;
    color: var(--md-sys-color-on-surface);
    padding-left: 12px;
    font-family: inherit;
}

.pre-icon-img {
    width: 20px;
    height: 20px;
}

.post-icon {
    font-size: 24px;
    color: var(--md-sys-color-on-surface-variant);
    margin-left: 8px;
}

.action-buttons {
    display: flex;
    justify-content: center;
    gap: 12px;
    margin-bottom: 32px;
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--md-sys-color-surface-container);
    border-radius: 99px;
    height: 48px;
    transition: background-color 0.2s ease, opacity 0.3s ease, transform 0.2s ease-out;
    flex-grow: 1;
    width: 0;
}

.action-btn .material-symbols-outlined {
    font-size: 24px;
    color: var(--md-sys-color-on-surface-variant);
}

/* --- FAVORITES GRID & EDIT MODE STYLES --- */
.links-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.link-card {
    display: block;
    position: relative;
}

.link-card-content {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    background-color: var(--md-sys-color-surface-container);
    border-radius: 999px;
    padding: 8px;
    transition: background-color 0.2s ease, transform 0.2s ease-out;
    cursor: pointer;
    /* THE FIX: Makes it feel like a link */
}

.icon-container {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
    flex-shrink: 0;
    overflow: hidden;
}

.icon-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.link-card span {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.delete-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: transparent;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    margin-left: auto;
    padding: 4px;
    flex-shrink: 0;
    transform: scale(0);
    transition: transform 0.2s ease, background-color 0.2s ease;
    cursor: pointer;
}

.delete-btn .material-symbols-outlined {
    font-size: 20px;
    color: var(--md-sys-color-on-surface-variant);
}

.delete-btn:hover {
    background-color: var(--ripple-color);
}

body.edit-mode .link-card {
    animation: wiggle 1s infinite;
}

body.edit-mode .link-card-content {
    cursor: default;
}

/* In edit mode, the pill isn't a link */
body.edit-mode .delete-btn {
    transform: scale(1);
}

@keyframes wiggle {

    0%,
    100% {
        transform: rotate(-1deg);
    }

    50% {
        transform: rotate(1deg);
    }
}

/* --- Edit Mode Red Overlay --- */
.container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;

    /* Subtle red using your error color variable with low opacity */
    background-color: rgba(255, 0, 0, 0.2); 
    border-radius: 28px; /* Match the panel's rounding */

    /* Animation */
    opacity: 0;
    transition: opacity 0.3s ease-out;

    /* Crucial: This lets you click on the favorites underneath */
    pointer-events: none; 

    z-index: 1; /* Ensures it sits on top of the content */
}

body.edit-mode .container::before {
    opacity: 1;
}

/* --- Drag-and-Drop Reordering Styles --- */
.sortable-ghost {
    opacity: 0.4;
    background-color: var(--md-sys-color-primary) !important;
}

.sortable-chosen .link-card-content {
    /* Optional: Add a subtle effect to the item being dragged */
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}

.add-favorite-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--md-sys-color-surface-container-high);
    background-color: transparent;
    border-radius: 999px;
    min-height: 54px;
    color: var(--md-sys-color-on-surface-variant);
    transition: all 0.2s ease-out;
    cursor: pointer;
}

.add-favorite-btn:hover {
    background-color: var(--md-sys-color-surface-container);
    border-style: solid;
}

.add-favorite-btn .material-symbols-outlined {
    font-size: 24px;
}

/* --- Voice Search Listening Animation --- */
.action-btn.listening .material-symbols-outlined {
    /* Pulses the icon with the primary color */
    animation: pulse 1.5s infinite ease-out;
}

@keyframes pulse {
    0% {
        transform: scale(1);
        color: var(--md-sys-color-on-surface-variant);
    }
    50% {
        transform: scale(1.1);
        color: var(--md-sys-color-primary);
    }
    100% {
        transform: scale(1);
        color: var(--md-sys-color-on-surface-variant);
    }
}

/* --- FLOATING ACTION BUTTONS (FAB) STYLES --- */
.fab-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    gap: 16px;
    z-index: 1000;
}

.fab {
    width: 56px;
    height: 56px;
    background-color: var(--md-sys-color-surface-container-high);
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    transition: all 0.2s ease-out;
}

.fab .material-symbols-outlined {
    color: var(--md-sys-color-primary);
}

#edit-favorites-fab.active {
    background-color: var(--md-sys-color-primary);
}

#edit-favorites-fab.active .material-symbols-outlined {
    color: var(--md-sys-color-background);
}

/* --- SETTINGS PANEL STYLES --- */
#settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.2);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease;
}

body.settings-open #settings-overlay {
    opacity: 1;
    pointer-events: auto;
}

#settings-panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: rgba(30, 30, 35, 0.7);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    border-top-left-radius: 28px;
    border-top-right-radius: 28px;
    z-index: 1002;
    padding: 8px 16px 32px;
    max-height: 80vh;
    overflow-y: auto;
    transform: translateY(100%);
        transition: transform 0.5s var(--ease-standard);
    }

body.settings-open #settings-panel {
    transform: translateY(0);
}

.drag-handle {
    width: 32px;
    height: 4px;
    background-color: var(--md-sys-color-outline);
    border-radius: 2px;
    margin: 0 auto 16px;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding: 0 8px;
}

.settings-header h2 {
    margin: 0;
    font-weight: 500;
}

#settings-close-btn {
    padding: 8px;
    border-radius: 50%;
}

.settings-group {
    border: none;
    padding: 0 8px;
    margin-bottom: 16px;
}

.settings-group legend {
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--md-sys-color-primary);
    padding-bottom: 8px;
}
/* --- Polished M3 Setting Rows --- */

/* Base style for all interactive rows in settings */
.radio-row,
.switch-row {
    display: flex;
    align-items: center;
    padding: 8px;
    border-radius: 16px;
    transition: background-color 0.2s ease;
    cursor: pointer;
    justify-content: space-between;
}

.radio-row:active,
.switch-row:active {
    background-color: var(--ripple-color);
}

.radio-row>label,
.switch-row>label {
    font-weight: 500;
}

/* --- NEW Expressive Toggle Button (from your image) --- */
.switch {
    position: relative;
    display: inline-block;
    width: 120px;
    /* A fixed width that matches the style you want */
    height: 42px;
    flex-shrink: 0;
    /* Prevents the toggle from shrinking */
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: transparent;
    /* OFF state is transparent */
    border: 2px solid var(--md-sys-color-surface-container-high);
    /* Outlined when OFF */
    transition: all .3s cubic-bezier(0.2, 0.8, 0.2, 1);
    border-radius: 999px;
    /* Pill shape */
    display: flex;
    align-items: center;
    padding: 0 5px;
    /* Padding for the icon container */
}

.slider:before {
    content: "";
    /* No icon in OFF state */
    height: 32px;
    width: 32px;
    background-color: var(--md-sys-color-surface-container-high);
    /* Gray circle when OFF */
    transition: all .3s cubic-bezier(0.2, 0.8, 0.2, 1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: transparent;
}

/* --- CHECKED/ON STATE for the new Toggle Button --- */
input:checked+.slider {
    background-color: var(--md-sys-color-primary);
    /* Blue background when ON */
    border-color: var(--md-sys-color-primary);
}

input:checked+.slider:before {
    background-color: var(--md-sys-color-background);
    /* Dark circle for the icon */
    content: 'done';
    /* The checkmark icon */
    font-family: 'Material Symbols Outlined';
    font-weight: 500;
    font-size: 20px;
    color: var(--md-sys-color-on-surface);
    /* White checkmark to match your image */
}

.switch-row {
    justify-content: space-between;
}

.switch {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 32px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--md-sys-color-surface-container-high);
    transition: .4s;
    border-radius: 34px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 24px;
    width: 24px;
    left: 4px;
    bottom: 4px;
    background-color: var(--md-sys-color-on-surface-variant);
    transition: .4s cubic-bezier(0.2, 0.8, 0.2, 1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

input:checked+.slider {
    background-color: var(--md-sys-color-primary);
}

input:checked+.slider:before {
    transform: translateX(20px);
    background-color: var(--md-sys-color-background);
    content: 'done';
    font-family: 'Material Symbols Outlined';
    font-weight: 500;
    font-size: 16px;
    color: var(--md-sys-color-primary);
}