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

[hidden] {
    display: none !important;
}

button {
    cursor: pointer;
    font-family: inherit;
    font-size: inherit;
}

input,
select {
    font-family: inherit;
    font-size: inherit;
}

:root {
    --bg-top: #eef4f8;
    --bg-bottom: #d8e6ed;
    --panel: rgba(255, 255, 255, 0.92);
    --panel-strong: #ffffff;
    --border: #cad8e0;
    --border-strong: #a4bcc8;
    --text-main: #16303b;
    --text-sub: #59707a;
    --accent: #1f6f8b;
    --accent-strong: #144f64;
    --accent-soft: #e8f3f8;
    --success-soft: #ecf8f1;
    --success-border: rgba(31, 117, 71, 0.16);
    --success-text: #1f7547;
    --loading-soft: #eef5fb;
    --loading-border: rgba(31, 111, 139, 0.16);
    --error: #b00020;
    --shadow: 0 20px 44px rgba(24, 52, 64, 0.12);
}

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

body {
    margin: 0;
    padding: 24px 20px 32px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text-main);
    background:
        radial-gradient(circle at top left, rgba(255, 255, 255, 0.92), transparent 30%),
        linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

#head {
    max-width: 920px;
    margin: 0 auto 18px;
    padding: 24px;
    border: 1px solid var(--border);
    border-radius: 0;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 252, 253, 0.93));
    box-shadow: var(--shadow);
}

#extend {
    max-width: 920px;
    min-height: calc(100vh - 270px);
    margin: 0 auto;
    padding: 20px 24px 28px;
    border: 1px solid var(--border);
    border-radius: 0;
    background: var(--panel);
    box-shadow: var(--shadow);
    overflow: scroll;
}

.search-title {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.search-title-copy {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    text-align: center;
}

#pageTitle {
    font-size: clamp(1.5rem, 2vw, 2rem);
    font-weight: 800;
    letter-spacing: 0.01em;
}

.search-subtitle {
    color: var(--text-sub);
    font-size: 0.92rem;
    max-width: 680px;
    line-height: 1.6;
}

#controls {
    display: flex;
    justify-content: center;
    margin-top: 18px;
}

.controls-main {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.search-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    width: min(336px, 100%);
}

.actions-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px 12px;
    width: 100%;
}

.search-options-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    width: min(560px, 100%);
}

.utility-button {
    color: var(--text-sub);
    border-color: rgba(31, 111, 139, 0.18);
    background: rgba(255, 255, 255, 0.82);
}

#text {
    width: 100%;
    min-height: 48px;
    padding: 0 16px;
    border: 1px solid var(--border-strong);
    border-radius: 0;
    background: var(--panel-strong);
    box-shadow: inset 0 1px 2px rgba(18, 43, 53, 0.05);
}

select {
    min-height: 40px;
    padding: 0 12px;
    border: 1px solid var(--border-strong);
    border-radius: 0;
    background: var(--panel-strong);
}

#text:focus,
select:focus,
#loadMore:focus,
.action-button:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(31, 111, 139, 0.15);
}

#status {
    margin-top: 16px;
    padding: 12px 14px;
    font-size: 0.95rem;
    color: var(--text-sub);
    border: 1px solid transparent;
    border-radius: 0;
    background: rgba(232, 243, 248, 0.88);
}

#status.loading {
    color: var(--accent-strong);
    border-color: var(--loading-border);
    background: var(--loading-soft);
}

#status.success {
    color: var(--success-text);
    border-color: var(--success-border);
    background: var(--success-soft);
}

#status.error {
    color: var(--error);
    font-weight: 600;
    border-color: rgba(176, 0, 32, 0.14);
    background: rgba(255, 237, 241, 0.94);
}

#searchMeta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 12px;
}

#headerMenus {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.header-menu {
    position: relative;
}

.header-menu-toggle,
.meta-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding: 0 10px;
    border: 1px solid rgba(31, 111, 139, 0.18);
    border-radius: 0;
    background: rgba(255, 255, 255, 0.82);
    color: var(--accent-strong);
    font-size: 0.84rem;
    font-weight: 700;
}

.meta-chip-loading {
    color: var(--accent-strong);
    border-color: var(--loading-border);
    background: var(--loading-soft);
}

.header-menu-toggle {
    min-width: 88px;
}

.header-menu-panel {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    width: min(420px, calc(100vw - 40px));
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 0;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 18px 38px rgba(24, 52, 64, 0.16);
}

.quick-panel {
    padding: 14px 16px;
    border: 1px solid var(--border);
    border-radius: 0;
    background: rgba(255, 255, 255, 0.72);
}

.quick-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.quick-title {
    font-size: 0.9rem;
    font-weight: 800;
    color: var(--text-main);
}

.quick-clear,
.quick-remove {
    min-height: 28px;
    padding: 0 10px;
    border: 1px solid rgba(31, 111, 139, 0.18);
    border-radius: 0;
    background: rgba(255, 255, 255, 0.82);
    color: var(--text-sub);
    font-size: 0.76rem;
    font-weight: 700;
}

.quick-entry {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.quick-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.quick-chip {
    min-height: 32px;
    padding: 0 12px;
    border: 1px solid rgba(31, 111, 139, 0.18);
    border-radius: 0;
    background: rgba(232, 243, 248, 0.8);
    color: var(--accent-strong);
    font-size: 0.84rem;
    font-weight: 700;
}

.quick-empty {
    margin-top: 10px;
    color: var(--text-sub);
    font-size: 0.88rem;
}

.help-list {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 7px 14px;
    margin: 10px 0 0;
    padding: 0;
}

.help-list dt {
    font-size: 0.84rem;
    font-weight: 800;
    color: var(--accent-strong);
    white-space: nowrap;
    align-self: baseline;
}

.help-list dd {
    margin: 0;
    font-size: 0.84rem;
    color: var(--text-sub);
    line-height: 1.55;
    align-self: baseline;
}

.control-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    color: var(--text-sub);
    font-size: 0.92rem;
}

.regex-toggle {
    min-height: 38px;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    color: var(--accent-strong);
    font-weight: 700;
}

.inline-select {
    min-height: 38px;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    color: var(--accent-strong);
    font-weight: 700;
}

.inline-select select {
    min-height: 30px;
    border: none;
    background: transparent;
    box-shadow: none;
    padding: 0 4px 0 0;
}

.regex-toggle input {
    margin: 0;
}

.action-button {
    min-height: 44px;
    padding: 0 16px;
    border: 1px solid transparent;
    border-radius: 0;
    font-weight: 700;
    transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
}

#btnS,
#btnY,
#loadMore {
    color: var(--accent-strong);
    border-color: rgba(31, 111, 139, 0.22);
    background: var(--accent-soft);
}


#loadMoreWrap {
    margin-top: 18px;
    text-align: center;
}

.results-list {
    display: flex;
    flex-direction: column;
}

.result-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 16px 10px;
    border-top: 1px solid rgba(164, 188, 200, 0.28);
}

.result-top {
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    gap: 10px;
}

.result-item:first-child .result-card {
    border-top: none;
}

.result-item:hover .result-card {
    background: rgba(232, 243, 248, 0.5);
}

.result-item-simple {
    border-top: 1px solid rgba(164, 188, 200, 0.22);
}

.result-simple-row {
    display: flex;
    align-items: flex-start;
    gap: 6px;
}

.result-simple-body {
    flex: 1 1 auto;
    min-width: 0;
}

.result-item:first-child {
    border-top: none;
}

.result-link {
    display: inline-block;
    flex: 1 1 auto;
    min-width: 0;
    color: var(--accent-strong);
    font-weight: 700;
    text-decoration: none;
}

.result-link:hover {
    text-decoration: underline;
}

.result-link-simple {
    display: block;
    flex: 1 1 auto;
    min-width: 0;
    padding: 10px 6px;
    font-weight: 600;
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
    line-height: 1.45;
}

.result-item-simple:hover {
    background: rgba(232, 243, 248, 0.36);
}

.result-reading-simple {
    margin: 0 6px 10px;
    font-size: 0.86rem;
    line-height: 1.35;
}

.result-reading {
    margin-left: 44px;
    font-size: 0.93rem;
    color: var(--text-sub);
    letter-spacing: 0.01em;
}

.favorite-action {
    min-width: 34px;
    min-height: 34px;
    padding: 0;
    border: none;
    background: transparent;
    color: #d19a00;
    font-size: 1.6rem;
    line-height: 1;
    box-shadow: none;
    flex-shrink: 0;
    align-self: flex-start;
    cursor: pointer;
}

.favorite-action-simple {
    min-width: 28px;
    min-height: 28px;
    font-size: 1.2rem;
    margin-top: 6px;
}

mark {
    padding: 0 0.15em;
    border-radius: 0;
    background: rgba(255, 222, 89, 0.55);
    color: inherit;
}

.result-empty {
    text-align: center;
    padding: 40px 20px;
    border: 1px dashed rgba(164, 188, 200, 0.6);
    border-radius: 0;
    background: rgba(255, 255, 255, 0.6);
}

.empty-title {
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--text-main);
}

.empty-subtitle {
    margin-top: 8px;
    color: var(--text-sub);
    line-height: 1.7;
}

#results {
    user-select: none;
    -moz-user-select: none;
    -webkit-user-select: none;
    -ms-user-select: none;
}

@media (max-width: 900px) {
    body {
        padding: 16px 14px 24px;
    }

    .search-subtitle {
        max-width: none;
    }

    .search-title {
        flex-direction: column;
        align-items: stretch;
    }

    #headerMenus {
        position: static;
        width: 100%;
    }

    .header-menu {
        flex: 1 1 0;
    }

    .header-menu-toggle {
        width: 100%;
    }

    .header-menu-panel {
        width: 100%;
        right: auto;
        left: 0;
    }
}

@media (max-width: 640px) {
    #head,
    #extend {
        padding-left: 16px;
        padding-right: 16px;
        border-radius: 0;
    }

    .search-row {
        grid-template-columns: 1fr;
    }

    .actions-row {
        display: grid;
    }

    .search-options-row {
        width: 100%;
    }

    .action-button,
    #loadMore,
    #text,
    select {
        width: 100%;
    }

    .control-label {
        width: 100%;
        justify-content: space-between;
    }

    .regex-toggle {
        justify-content: flex-start;
    }
}
