:root {
    --bg-start: #eef4ff;
    --bg-end: #fdf4e8;
    --text-primary: #1b2430;
    --text-secondary: #5a6676;
    --panel-bg: rgba(255, 255, 255, 0.78);
    --panel-border: rgba(255, 255, 255, 0.95);
    --panel-shadow: 0 24px 70px rgba(35, 57, 91, 0.16);
    --input-bg: rgba(255, 255, 255, 0.9);
    --input-border: #d6deea;
    --accent: #0d8f6f;
    --accent-hover: #08785d;
    --chip-bg: #ecf3ff;
    --chip-text: #2b3f57;
    --card-bg: rgba(255, 255, 255, 0.92);
    --card-shadow: 0 8px 24px rgba(23, 39, 66, 0.12);
    --modal-overlay: rgba(16, 22, 32, 0.48);
    --danger: #d54242;
    --danger-hover: #b83232;
    --ring: rgba(13, 143, 111, 0.3);
}

[data-theme="dark"] {
    --bg-start: #101722;
    --bg-end: #13283a;
    --text-primary: #ecf3ff;
    --text-secondary: #a3b3ca;
    --panel-bg: rgba(19, 31, 46, 0.72);
    --panel-border: rgba(255, 255, 255, 0.1);
    --panel-shadow: 0 24px 70px rgba(0, 0, 0, 0.45);
    --input-bg: rgba(18, 31, 47, 0.95);
    --input-border: #324154;
    --accent: #45b88f;
    --accent-hover: #35a781;
    --chip-bg: #203347;
    --chip-text: #d5e2f6;
    --card-bg: rgba(21, 35, 53, 0.9);
    --card-shadow: 0 14px 28px rgba(2, 8, 18, 0.5);
    --modal-overlay: rgba(2, 8, 18, 0.72);
    --danger: #f16666;
    --danger-hover: #e65050;
    --ring: rgba(69, 184, 143, 0.34);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    padding: 20px;
    font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
    color: var(--text-primary);
    background: linear-gradient(145deg, var(--bg-start), var(--bg-end));
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    overflow-x: hidden;
}

.bg-orb {
    position: fixed;
    border-radius: 999px;
    filter: blur(8px);
    pointer-events: none;
    z-index: 0;
}

.bg-orb-1 {
    width: 320px;
    height: 320px;
    top: -90px;
    right: -70px;
    background: rgba(56, 150, 255, 0.24);
    animation: floatY 9s ease-in-out infinite;
}

.bg-orb-2 {
    width: 260px;
    height: 260px;
    bottom: -80px;
    left: -70px;
    background: rgba(250, 168, 60, 0.22);
    animation: floatY 11s ease-in-out infinite reverse;
}

.app-shell {
    width: min(780px, 100%);
    margin: 0 auto;
    padding: 32px 28px 28px;
    border: 0;
    border-radius: 0;
    background: transparent;
    backdrop-filter: none;
    box-shadow: none;
    position: relative;
    z-index: 1;
}

.site-header {
    position: relative;
    margin-bottom: 24px;
    text-align: center;
}

.site-title {
    margin: 0;
    font-family: "Manrope", "Noto Sans SC", sans-serif;
    font-size: clamp(2rem, 5vw, 3rem);
    line-height: 1.08;
    letter-spacing: 0.02em;
}

.poem {
    margin: 12px auto 0;
    max-width: 680px;
    color: var(--text-secondary);
    font-size: 0.95rem;
    min-height: 1.4em;
}

.icon-button {
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--chip-text);
    cursor: pointer;
    transition: transform 0.2s ease, color 0.2s ease;
}

.icon-button:hover {
    transform: translateY(-1px);
}

.icon-button:active {
    transform: translateY(0);
}

.theme-toggle {
    position: fixed !important;
    top: 14px !important;
    right: 14px !important;
    z-index: 50 !important;
    width: 44px;
    height: 44px;
    font-size: 1rem;
    box-shadow: none;
}

.control-button {
    background: var(--input-bg);
}

.theme-toggle,
#lock-toggle {
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
}

.search-area {
    margin-bottom: 26px;
}

.search-box {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 10px;
    border: 0;
    border-radius: 999px;
    padding: 8px 10px;
    background: var(--input-bg);
    box-shadow: none;
}

.engine-button {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 0;
    background: transparent;
    cursor: pointer;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.engine-button img {
    width: 24px;
    height: 24px;
    object-fit: contain;
}

.search-input {
    flex: 1;
    min-width: 0;
    border: 0;
    outline: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
}

.search-input::placeholder {
    color: var(--text-secondary);
}

.search-submit {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
}

.search-box:focus-within {
    box-shadow: 0 0 0 2px var(--ring);
}

.search-area .search-input:focus-visible,
.search-area .engine-button:focus-visible,
.search-area .search-submit:focus-visible {
    box-shadow: none;
}

.engine-icons-below-box {
    margin-top: 12px;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 10px;
    opacity: 0;
    visibility: hidden;
    max-height: 0;
    overflow: hidden;
    transition: opacity 0.25s ease, max-height 0.25s ease, visibility 0.25s ease;
}

.engine-icons-below-box.visible {
    opacity: 1;
    visibility: visible;
    max-height: 80px;
}

.engine-option {
    border: 0;
    border-radius: 12px;
    height: 40px;
    background: var(--input-bg);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0.68;
    transition: opacity 0.2s ease, transform 0.2s ease, border-color 0.2s ease;
}

.engine-option img {
    width: 20px;
    height: 20px;
    object-fit: contain;
}

.engine-option:hover,
.engine-option.active {
    opacity: 1;
    transform: translateY(-1px);
    border-color: var(--accent);
}

.controls-area {
    position: static;
    right: auto;
    bottom: auto;
    z-index: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.control-button {
    width: 44px;
    height: 44px;
    border-radius: 999px;
    font-size: 1rem;
    box-shadow: none;
}

#add-link-icon {
    position: fixed !important;
    right: 14px !important;
    bottom: 62px !important;
    z-index: 49 !important;
}

#lock-toggle {
    position: fixed !important;
    right: 14px !important;
    bottom: 14px !important;
    z-index: 50 !important;
}

.links-section {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 10px;
}

.link-item {
    position: relative;
    border: 0;
    border-radius: 14px;
    padding: 10px 8px;
    background: var(--card-bg);
    box-shadow: none;
    color: var(--text-primary);
    text-decoration: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    min-height: 88px;
    transition: transform 0.22s ease, box-shadow 0.22s ease;
}

.link-item:hover {
    transform: translateY(-3px);
    box-shadow: none;
}

.link-item.is-draggable {
    cursor: grab;
}

.link-item.is-draggable:active {
    cursor: grabbing;
}

.link-item.dragging {
    opacity: 0.55;
    transform: scale(0.98);
}

.link-item.drag-over {
    outline: 2px dashed var(--accent);
    outline-offset: 2px;
}

.link-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: transparent;
    color: var(--chip-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    overflow: hidden;
}

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

.link-text {
    max-width: 100%;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.82rem;
    color: var(--text-secondary);
}

.link-action {
    position: absolute;
    top: -7px;
    width: 20px;
    height: 20px;
    border: 0;
    border-radius: 50%;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.68rem;
    cursor: pointer;
    opacity: 0;
    transform: scale(0.94);
    transition: opacity 0.18s ease, transform 0.18s ease;
}

.link-item:hover .link-action,
.link-item:focus-within .link-action {
    opacity: 1;
    transform: scale(1);
}

.edit-link-btn {
    right: 16px;
    background: #2f73e0;
}

.edit-link-btn:hover {
    background: #255fc0;
}

.delete-link-btn {
    right: -5px;
    background: var(--danger);
}

.delete-link-btn:hover {
    background: var(--danger-hover);
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--modal-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 30;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.22s ease, visibility 0.22s ease;
}

.modal-overlay.visible {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    width: min(430px, 100%);
    border: 1px solid var(--panel-border);
    background: var(--panel-bg);
    backdrop-filter: blur(8px);
    border-radius: 18px;
    padding: 20px;
    box-shadow: var(--panel-shadow);
}

.modal-content h2 {
    margin: 0 0 14px;
    font-size: 1.25rem;
}

.modal-content label {
    display: block;
    margin: 8px 0 5px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.modal-content input {
    width: 100%;
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    padding: 10px 12px;
}

.modal-buttons {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}

.modal-buttons button {
    border: 0;
    border-radius: 10px;
    padding: 9px 14px;
    font-size: 0.92rem;
    cursor: pointer;
}

.primary-btn {
    background: var(--accent);
    color: #fff;
}

.primary-btn:hover {
    background: var(--accent-hover);
}

.secondary-btn {
    background: var(--chip-bg);
    color: var(--chip-text);
}

.secondary-btn:hover {
    filter: brightness(0.96);
}

.data-tools {
    margin: 10px auto 0;
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

.tool-btn {
    border: 0;
    border-radius: 999px;
    background: var(--input-bg);
    color: var(--chip-text);
    font-size: 0.82rem;
    height: 32px;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    transition: transform 0.2s ease, filter 0.2s ease;
}

.tool-btn:hover {
    transform: translateY(-1px);
    filter: brightness(0.98);
}

.tool-btn.danger {
    color: var(--danger);
}

.site-footer {
    width: min(780px, 100%);
    margin-top: 14px;
    padding-top: 14px;
    padding-bottom: 4px;
    color: var(--text-secondary);
    font-size: 0.82rem;
    text-align: center;
    position: relative;
    z-index: 1;
}

.notfound-shell {
    width: min(600px, 100%);
    margin: auto;
    padding: 36px 26px;
    border-radius: 24px;
    border: 1px solid var(--panel-border);
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    box-shadow: var(--panel-shadow);
    text-align: center;
    position: relative;
    z-index: 1;
}

.notfound-shell h1 {
    margin: 0 0 6px;
    font-size: clamp(2.4rem, 8vw, 4rem);
    font-family: "Manrope", "Noto Sans SC", sans-serif;
}

.notfound-shell p {
    margin: 0 0 20px;
    color: var(--text-secondary);
}

.notfound-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
}

.notfound-actions a {
    text-decoration: none;
}

.notfound-actions .primary-btn,
.notfound-actions .secondary-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.is-hidden {
    display: none !important;
}

:focus-visible {
    outline: 0;
    box-shadow: 0 0 0 3px var(--ring);
}

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

@media (max-width: 768px) {
    body {
        padding: 16px 14px;
        min-height: 100vh;
        justify-content: center;
    }

    .app-shell {
        padding: 24px 10px 14px;
        border-radius: 0;
        width: 100%;
    }

    .theme-toggle {
        top: 10px !important;
        right: 10px !important;
        width: 40px;
        height: 40px;
    }

    .links-section {
        grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
        gap: 9px;
    }

    .link-item {
        min-height: 84px;
    }

    .control-button {
        width: 40px;
        height: 40px;
    }

    #add-link-icon {
        right: 10px !important;
        bottom: 56px !important;
    }

    #lock-toggle {
        right: 10px !important;
        bottom: 10px !important;
    }

    .engine-icons-below-box {
        grid-template-columns: repeat(5, minmax(0, 1fr));
        gap: 8px;
    }

    .site-footer {
        width: 100%;
        padding-bottom: 2px;
    }

    .data-tools {
        gap: 6px;
    }

    .tool-btn {
        height: 30px;
        padding: 0 10px;
        font-size: 0.78rem;
    }
}
