/* Material Design 3 Palette & Expressive System Tokens */
:root {
    /* Dynamic variables (Light Mode Default) */
    --md-sys-color-primary: #1a73e8;
    --md-sys-color-on-primary: #ffffff;
    --md-sys-color-primary-container: #e8f0fe;
    --md-sys-color-on-primary-container: #174ea6;

    --md-sys-color-surface: #f6f8fc;
    --md-sys-color-surface-container-lowest: #ffffff;
    --md-sys-color-surface-container-low: #f1f4f9;
    --md-sys-color-surface-container: #ebf0f7;
    --md-sys-color-surface-container-high: #e3e9f2;
    --md-sys-color-surface-container-highest: #dae2ed;

    --md-sys-color-on-surface: #1f2328;
    --md-sys-color-on-surface-variant: #545b66;
    --md-sys-color-outline: #858d99;
    --md-sys-color-outline-variant: #d8e1ed;

    /* Base Material Shapes & Motion Tokens */
    --md-shape-corner-full: 9999px;
    --md-shape-corner-extra-large: 28px;
    --md-shape-corner-large: 16px;
    --md-shape-corner-medium: 12px;
    --md-shape-corner-small: 8px;

    --transition-fast: 0.15s cubic-bezier(0.2, 0, 0, 1);
    --transition-medium: 0.25s cubic-bezier(0.2, 0, 0, 1);
    --transition-spring: 0.4s cubic-bezier(0.34, 1.2, 0.64, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    user-select: none;
    -webkit-user-select: none;
}

html, body {
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
}

a, a * {
    text-decoration: none;
}

img {
    border: none;
    outline: none;
}

button, input {
    font-family: inherit;
}

body {
    font-family: 'Google Sans', 'Noto Sans SC', system-ui, -apple-system, sans-serif;
    background-color: var(--md-sys-color-surface);
    color: var(--md-sys-color-on-surface);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    transition: background-color var(--transition-medium), color var(--transition-medium);
}

/* 全屏同色覆盖块样式 */
#app-cover {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--md-sys-color-surface);
    z-index: 99999;
    pointer-events: none;
    animation: coverFadeOut 0.5s cubic-bezier(0.2, 0, 0, 1) forwards;
}

@keyframes coverFadeOut {
    0% {
        opacity: 1;
    }
    20% {
        /* 显示 0.1s (0.5s * 20% = 0.1s) */
        opacity: 1;
    }
    100% {
        opacity: 0;
        visibility: hidden;
    }
}

.material-symbols-rounded {
    font-family: 'Material Symbols Rounded';
    font-weight: normal;
    font-style: normal;
    font-size: 24px;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    display: inline-block;
    white-space: nowrap;
    word-wrap: normal;
    direction: ltr;
    -webkit-font-smoothing: antialiased;
}

/* Header Navigation Bar */
header {
    width: 100%;
    max-width: 100%;
    padding: 16px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: -0.2px;
    color: var(--md-sys-color-on-surface);
    background: var(--md-sys-color-surface-container);
    padding: 8px 18px;
    border-radius: var(--md-shape-corner-full);
    transition: background var(--transition-medium);
    max-width: calc(100% - 60px);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.icon-btn {
    width: 44px;
    height: 44px;
    border-radius: var(--md-shape-corner-full);
    border: none;
    background: var(--md-sys-color-surface-container);
    color: var(--md-sys-color-on-surface);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition-fast);
    outline: none;
    flex-shrink: 0;
}

.icon-btn:hover {
    background: var(--md-sys-color-surface-container-high);
}

.icon-btn:active {
    background: var(--md-sys-color-surface-container-highest);
}

/* Main Section Container */
main {
    width: 100%;
    max-width: 760px;
    padding: 0 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: -20px;
}

/* Clock & Greeting Card */
.time-greeting-container {
    text-align: center;
    margin-bottom: 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.digital-clock {
    font-size: clamp(48px, 12vw, 68px);
    font-weight: 700;
    letter-spacing: -1.5px;
    line-height: 1.1;
    color: var(--md-sys-color-on-surface);
    font-feature-settings: "tnum";
    font-variant-numeric: tabular-nums;
    word-break: break-all;
}

.date-display {
    font-size: clamp(13px, 3.5vw, 15px);
    color: var(--md-sys-color-on-surface-variant);
    margin-top: 6px;
    font-weight: 500;
}

.greeting-badge {
    margin-top: 14px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    background-color: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    border-radius: var(--md-shape-corner-full);
    font-size: 14px;
    font-weight: 500;
    transition: background-color var(--transition-medium), color var(--transition-medium);
    animation: fadeIn 0.6s ease-out;
    max-width: 100%;
}

.greeting-badge span:last-child {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Material You Search Bar (Tonal Surface Container) */
.search-container {
    width: 100%;
    position: relative;
    margin-bottom: 36px;
}

.search-bar {
    width: 100%;
    min-height: 60px;
    background: var(--md-sys-color-surface-container-low);
    border-radius: var(--md-shape-corner-full);
    display: flex;
    align-items: center;
    padding: 0 8px 0 16px;
    transition: all var(--transition-medium);
    border: 1px solid var(--md-sys-color-outline-variant);
}

.search-bar:focus-within {
    background: var(--md-sys-color-surface-container-lowest);
    border-color: var(--md-sys-color-primary);
}

.engine-selector {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 6px 10px;
    border-radius: var(--md-shape-corner-full);
    background: var(--md-sys-color-surface-container);
    color: var(--md-sys-color-on-surface);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    margin-right: 8px;
    flex-shrink: 0;
    transition: background var(--transition-fast), color var(--transition-fast);
}

.engine-selector:hover {
    background: var(--md-sys-color-surface-container-high);
}

.search-input {
    flex: 1;
    min-width: 0;
    height: 100%;
    border: none;
    background: transparent;
    outline: none;
    font-family: inherit;
    font-size: 16px;
    color: var(--md-sys-color-on-surface);
    user-select: text;
    -webkit-user-select: text;
}

.search-input::placeholder {
    color: var(--md-sys-color-outline);
}

.search-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.search-btn {
    width: 44px;
    height: 44px;
    border-radius: var(--md-shape-corner-full);
    border: none;
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: opacity var(--transition-fast), background-color var(--transition-medium);
}

.search-btn:hover {
    opacity: 0.9;
}

/* Search Engine Dropdown Menu */
.engine-menu {
    position: absolute;
    top: 68px;
    left: 0;
    background: var(--md-sys-color-surface-container-lowest);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-shape-corner-large);
    padding: 6px;
    display: none;
    flex-direction: column;
    gap: 2px;
    z-index: 100;
    min-width: 140px;
}

.engine-menu.active {
    display: flex;
    animation: slideDown 0.15s cubic-bezier(0.2, 0, 0, 1);
}

.engine-item {
    display: flex;
    align-items: center;
    padding: 10px 16px;
    border-radius: var(--md-shape-corner-medium);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
    transition: background var(--transition-fast);
}

.engine-item:hover {
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}

/* Shortcuts Section (Fluid Grid Layout) */
.shortcuts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 16px;
    width: 100%;
}

.shortcut-card {
    background: var(--md-sys-color-surface-container-low);
    border-radius: var(--md-shape-corner-extra-large);
    padding: 18px 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--md-sys-color-on-surface);
    transition: background var(--transition-fast), transform var(--transition-fast);
    position: relative;
    min-width: 0;
}

.shortcut-card:hover {
    background: var(--md-sys-color-surface-container);
}

.shortcut-card.dragging {
    opacity: 0.4;
    transform: scale(0.95);
}

.shortcut-card.touch-dragging {
    opacity: 0.8;
    position: fixed;
    z-index: 3000;
    pointer-events: none;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    transition: none;
    background: var(--md-sys-color-surface-container-high);
}

.shortcut-card.drag-over {
    border: 2px solid var(--md-sys-color-primary);
    background: var(--md-sys-color-primary-container);
}

.shortcut-icon-wrapper {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    flex-shrink: 0;
}

.shortcut-icon-wrapper img {
    width: 32px;
    height: 32px;
    object-fit: contain;
    border-radius: var(--md-shape-corner-small);
}

.shortcut-icon-fallback {
    width: 32px;
    height: 32px;
    border-radius: var(--md-shape-corner-small);
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
}

.shortcut-title {
    font-size: 13px;
    font-weight: 500;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    padding: 0 2px;
}

.add-shortcut-card {
    border: 2px dashed var(--md-sys-color-outline-variant);
    background: transparent;
    cursor: pointer;
}

.add-shortcut-card:hover {
    border-color: var(--md-sys-color-primary);
    background: var(--md-sys-color-surface-container-low);
}

/* Material Context Menu for Shortcuts */
.context-menu {
    position: fixed;
    background: var(--md-sys-color-surface-container-lowest);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-shape-corner-large);
    padding: 6px;
    display: none;
    flex-direction: column;
    gap: 2px;
    z-index: 2000;
    min-width: 140px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.context-menu.active {
    display: flex;
    animation: slideDown 0.12s cubic-bezier(0.2, 0, 0, 1);
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-radius: var(--md-shape-corner-medium);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
    transition: background var(--transition-fast);
}

.context-menu-item:hover {
    background: var(--md-sys-color-surface-container-high);
}

.context-menu-item.danger {
    color: #d93025;
}

.context-menu-item.danger:hover {
    background: #fce8e6;
}

[data-theme="dark"] .context-menu-item.danger:hover {
    background: #410e0b;
}

/* Footer Links Area */
.footer-container {
    padding: 24px 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 36px;
    opacity: 0.35;
    transition: opacity var(--transition-fast);
}

.footer-container:hover {
    opacity: 0.9;
}

.footer-link {
    font-size: 13px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
    text-decoration: none;
    cursor: pointer;
    transition: color var(--transition-fast);
}

.footer-link:hover {
    color: var(--md-sys-color-primary);
}

/* Material You Toast Notification Bubble */
.toast {
    position: fixed;
    bottom: 48px;
    left: 50%;
    transform: translateX(-50%) translateY(16px);
    background: var(--md-sys-color-surface-container-high);
    color: var(--md-sys-color-on-surface);
    padding: 10px 20px;
    border-radius: var(--md-shape-corner-full);
    font-size: 14px;
    font-weight: 500;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
    border: 1px solid var(--md-sys-color-outline-variant);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity var(--transition-fast), transform var(--transition-fast), visibility var(--transition-fast), background-color var(--transition-medium), color var(--transition-medium);
    z-index: 3000;
}

[data-theme="dark"] .toast {
    background: var(--md-sys-color-surface-container-high);
    color: var(--md-sys-color-on-surface);
    border: 1px solid var(--md-sys-color-outline-variant);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.toast.show {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

/* Material You Tinted Modal Dialog */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background: rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(2px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    padding: 16px;
    transition: opacity var(--transition-fast);
}

.modal-overlay.active {
    display: flex;
    opacity: 1;
}

.modal-card {
    background: var(--md-sys-color-surface-container-lowest);
    border: 1px solid var(--md-sys-color-outline-variant);
    color: var(--md-sys-color-on-surface);
    width: 100%;
    max-width: 400px;
    border-radius: var(--md-shape-corner-extra-large);
    padding: 24px;
    transform: scale(0.95);
    transition: transform var(--transition-fast), background-color var(--transition-medium);
    max-height: 90vh;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.modal-card::-webkit-scrollbar {
    display: none;
}

.modal-overlay.active .modal-card {
    transform: scale(1);
}

.modal-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 18px;
}

.form-group label {
    font-size: 12px;
    font-weight: 500;
    color: var(--md-sys-color-primary);
}

.form-input {
    width: 100%;
    height: 48px;
    border-radius: var(--md-shape-corner-medium);
    border: 1px solid var(--md-sys-color-outline-variant);
    background: var(--md-sys-color-surface-container-low);
    color: var(--md-sys-color-on-surface);
    padding: 0 14px;
    font-size: 15px;
    outline: none;
    transition: border-color var(--transition-fast), background var(--transition-fast);
}

.form-input:focus {
    background: var(--md-sys-color-surface-container-lowest);
    border-color: var(--md-sys-color-primary);
    border-width: 2px;
}

/* Segmented Buttons for Theme, Engine & Target Selectors */
.theme-options, .lang-options {
    display: flex;
    gap: 8px;
    margin-top: 4px;
    width: 100%;
}

.engine-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-top: 4px;
    width: 100%;
}

.theme-chip, .target-chip, .engine-chip, .lang-chip {
    font-family: inherit;
    flex: 1;
    min-width: 0;
    height: 40px;
    border-radius: var(--md-shape-corner-medium);
    border: 1px solid var(--md-sys-color-outline-variant);
    background: var(--md-sys-color-surface-container-low);
    color: var(--md-sys-color-on-surface);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    padding: 0 6px;
}

.theme-chip span:last-child, .target-chip span:last-child, .engine-chip span:last-child, .lang-chip span:last-child {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.theme-chip:hover, .target-chip:hover, .engine-chip:hover, .lang-chip:hover {
    background: var(--md-sys-color-surface-container);
}

.theme-chip.active, .target-chip.active, .engine-chip.active, .lang-chip.active {
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    border-color: var(--md-sys-color-primary);
}

.theme-chip .material-symbols-rounded, .target-chip .material-symbols-rounded, .engine-chip .material-symbols-rounded, .lang-chip .material-symbols-rounded {
    font-size: 18px;
    flex-shrink: 0;
}

/* Custom Color Picker Options */
.color-palette-container {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 6px;
    width: 100%;
    flex-wrap: wrap;
}

.color-palette-options {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.color-dot {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform var(--transition-fast);
    flex-shrink: 0;
}

.color-dot:hover {
    transform: scale(1.1);
}

.color-dot.active {
    border-color: var(--md-sys-color-on-surface);
}

.custom-color-wrapper {
    position: relative;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--md-sys-color-surface-container-high);
    border: 1px solid var(--md-sys-color-outline-variant);
    cursor: pointer;
    transition: transform var(--transition-fast);
    flex-shrink: 0;
}

.custom-color-wrapper:hover {
    transform: scale(1.1);
}

.custom-color-input {
    position: absolute;
    top: -10px;
    left: -10px;
    width: 60px;
    height: 60px;
    border: none;
    cursor: pointer;
    opacity: 0;
}

.hex-input-wrapper {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--md-sys-color-surface-container-low);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-shape-corner-medium);
    padding: 0 10px;
    height: 34px;
    flex: 1;
    min-width: 100px;
}

.hex-input-prefix {
    font-size: 13px;
    font-weight: 700;
    color: var(--md-sys-color-outline);
}

.hex-input {
    width: 100%;
    border: none;
    background: transparent;
    font-family: monospace;
    font-size: 13px;
    font-weight: 500;
    color: var(--md-sys-color-on-surface);
    outline: none;
    text-transform: uppercase;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
}

.btn {
    height: 40px;
    padding: 0 20px;
    border-radius: var(--md-shape-corner-full);
    font-size: 14px;
    font-weight: 500;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all var(--transition-fast);
}

.btn-text {
    background: transparent;
    color: var(--md-sys-color-primary);
}

.btn-text:hover {
    background: var(--md-sys-color-surface-container);
}

.btn-filled {
    background: var(--md-sys-color-primary);
    color: var(--md-sys-color-on-primary);
}

.btn-filled:hover {
    opacity: 0.9;
}

/* Mobile Breakpoints (< 480px) */
@media (max-width: 480px) {
    header {
        padding: 12px 16px;
    }

    main {
        margin-top: 0;
        padding: 0 12px;
    }

    .time-greeting-container {
        margin-bottom: 20px;
    }

    .search-container {
        margin-bottom: 24px;
    }

    .search-bar {
        height: 52px;
        min-height: 52px;
        padding: 0 6px 0 12px;
    }

    .engine-selector {
        padding: 4px 8px;
        font-size: 13px;
        margin-right: 4px;
    }

    .search-input {
        font-size: 15px;
    }

    .search-btn {
        width: 40px;
        height: 40px;
    }

    .shortcuts-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
    }

    .shortcut-card {
        padding: 12px 4px;
        border-radius: 20px;
    }

    .shortcut-icon-wrapper,
    .shortcut-icon-wrapper img,
    .shortcut-icon-fallback {
        width: 36px;
        height: 36px;
    }

    .shortcut-title {
        font-size: 11px;
    }

    .footer-container {
        gap: 20px;
        padding: 16px;
    }

    .footer-link {
        font-size: 12px;
    }

    .modal-card {
        padding: 18px;
    }

    .engine-options {
        grid-template-columns: repeat(2, 1fr);
    }

    .hex-input-wrapper {
        width: 100%;
    }
}

/* Keyframes */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

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