:root {
    --bg: #f4efe5;
    --surface: rgba(255, 251, 243, 0.86);
    --surface-strong: #fffaf0;
    --border: rgba(74, 55, 25, 0.16);
    --text: #2f2416;
    --muted: #6e5d47;
    --accent: #9f3f19;
    --accent-soft: #f2d7bb;
    --tag-bg: #efe1c8;
    --shadow: 0 20px 50px rgba(89, 60, 22, 0.12);
    --radius-lg: 24px;
    --radius-md: 16px;
    --max-width: 1040px;
}

* {
    box-sizing: border-box;
}

html {
    color-scheme: light;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Georgia, "Times New Roman", serif;
    color: var(--text);
    background:
        radial-gradient(
            circle at top left,
            rgba(255, 255, 255, 0.9),
            transparent 30%
        ),
        radial-gradient(
            circle at top right,
            rgba(228, 211, 180, 0.9),
            transparent 28%
        ),
        linear-gradient(180deg, #f8f4ed 0%, var(--bg) 48%, #eadfc9 100%);
}

button,
input,
label {
    font: inherit;
}

.shell {
    width: min(calc(100% - 2rem), var(--max-width));
    margin: 0 auto;
    padding: 3rem 0 4rem;
}

.hero {
    padding: 0.5rem 0 1.75rem;
}

.eyebrow {
    margin: 0 0 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    font-size: 0.8rem;
    color: var(--accent);
}

.dictionary-switcher {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
    margin-bottom: 1rem;
}

.dictionary-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.4rem;
    padding: 0.55rem 0.9rem;
    border: 1px solid rgba(74, 55, 25, 0.16);
    border-radius: 999px;
    background: rgba(255, 251, 243, 0.8);
    color: var(--text);
    text-decoration: none;
    transition:
        transform 180ms ease,
        border-color 180ms ease,
        background 180ms ease;
}

.dictionary-link:hover {
    transform: translateY(-1px);
    border-color: rgba(159, 63, 25, 0.32);
    background: #fffdf8;
}

.dictionary-link.current {
    border-color: rgba(159, 63, 25, 0.38);
    background: var(--accent-soft);
    color: #6d2a10;
    font-weight: 700;
}

.hero h1 {
    margin: 0;
    font-size: clamp(2.3rem, 5vw, 4.5rem);
    line-height: 0.95;
}

.lede {
    max-width: 48rem;
    margin: 1rem 0 0;
    font-size: 1.05rem;
    line-height: 1.6;
    color: var(--muted);
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
}

.controls {
    display: grid;
    gap: 1rem;
    padding: 1.25rem;
}

.search-form {
    display: grid;
    gap: 1rem;
}

.search-box {
    display: grid;
    gap: 0.5rem;
    position: relative;
}

.search-box label {
    font-size: 0.95rem;
    color: var(--muted);
}

.search-box input {
    width: 100%;
    min-height: 3.4rem;
    padding: 0.9rem 1rem;
    border: 1px solid rgba(74, 55, 25, 0.2);
    border-radius: var(--radius-md);
    background: rgba(255, 252, 247, 0.95);
    color: var(--text);
    transition:
        border-color 180ms ease,
        transform 180ms ease,
        box-shadow 180ms ease;
}

.search-box input:focus {
    outline: none;
    border-color: rgba(159, 63, 25, 0.55);
    box-shadow: 0 0 0 4px rgba(159, 63, 25, 0.1);
    transform: translateY(-1px);
}

.autocomplete-list {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    z-index: 100;
    margin: 0;
    padding: 0.25rem 0;
    list-style: none;
    background: var(--surface-strong);
    border: 1px solid rgba(74, 55, 25, 0.2);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow);
    max-height: 18rem;
    overflow-y: auto;
}

.autocomplete-option {
    padding: 0.55rem 1rem;
    cursor: pointer;
    transition: background 100ms ease;
}

.autocomplete-option:hover,
.autocomplete-option.is-active {
    background: var(--accent-soft);
    color: var(--accent);
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.actions button,
.file-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.8rem;
    padding: 0.7rem 1rem;
    border: 1px solid rgba(74, 55, 25, 0.18);
    border-radius: 999px;
    background: var(--surface-strong);
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
    transition:
        transform 180ms ease,
        border-color 180ms ease,
        background 180ms ease;
}

.actions button:hover,
.file-button:hover {
    transform: translateY(-1px);
    border-color: rgba(159, 63, 25, 0.35);
    background: #fffdf8;
}

.status {
    margin: 0;
    min-height: 1.5rem;
    color: var(--muted);
}

.results-panel {
    margin-top: 1.25rem;
    padding: 1.25rem;
}

.results-meta {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 0.75rem;
    align-items: baseline;
    margin-bottom: 1rem;
}

.results-meta p {
    margin: 0;
}

.hint {
    color: var(--muted);
}

.results {
    display: grid;
    gap: 1rem;
}

.entry-card {
    padding: 1.1rem;
    border: 1px solid var(--border);
    border-radius: 20px;
    background:
        linear-gradient(
            135deg,
            rgba(255, 255, 255, 0.68),
            rgba(255, 247, 235, 0.94)
        ),
        var(--surface-strong);
    animation: rise-in 260ms ease both;
}

.entry-header {
    margin-bottom: 0.85rem;
}

.entry-title {
    margin: 0;
    font-size: clamp(1.5rem, 2vw, 2rem);
}

.entry-subtitle {
    margin: 0.25rem 0 0;
    color: var(--muted);
}

.sense-list {
    display: grid;
    gap: 0.9rem;
    margin: 0;
    padding-left: 1.35rem;
}

.sense-item {
    position: relative;
    padding: 0 2.3rem 0 0.2rem;
    scroll-margin-top: 1.25rem;
}

.sense-item:target {
    background: rgba(159, 63, 25, 0.08);
    border-radius: 14px;
    padding: 0.75rem 2.8rem 0.75rem 0.95rem;
}

.sense-permalink {
    position: absolute;
    top: 0.05rem;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 1.85rem;
    min-height: 1.85rem;
    border-radius: 999px;
    color: var(--muted);
    text-decoration: none;
    border: 1px solid transparent;
    background: rgba(255, 251, 243, 0.88);
    opacity: 0.3;
    transition:
        opacity 180ms ease,
        color 180ms ease,
        border-color 180ms ease,
        background 180ms ease;
}

.sense-item:hover .sense-permalink,
.sense-item:focus-within .sense-permalink,
.sense-item:target .sense-permalink {
    opacity: 1;
}

.sense-permalink:hover {
    color: var(--accent);
    border-color: rgba(159, 63, 25, 0.18);
    background: rgba(255, 248, 239, 0.96);
}

.sense-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 0.45rem;
}

.tag {
    display: inline-flex;
    align-items: center;
    min-height: 1.9rem;
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    background: var(--tag-bg);
    color: #5d4322;
    font-size: 0.9rem;
}

.sense-source {
    margin: 0 0 0.4rem;
    color: var(--muted);
    font-style: italic;
}

.sense-glosses {
    display: grid;
    gap: 0.3rem;
    margin: 0;
    padding-left: 1rem;
}

.sense-glosses li {
    line-height: 1.55;
}

.gloss-line {
    position: relative;
    padding-right: 1.8rem;
    scroll-margin-top: 1.25rem;
}

.gloss-line:target {
    background: rgba(159, 63, 25, 0.08);
    border-radius: 10px;
    padding: 0.2rem 1.8rem 0.2rem 0.35rem;
}

.gloss-permalink {
    position: absolute;
    top: 0.1rem;
    right: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.4rem;
    min-height: 1.4rem;
    border-radius: 999px;
    color: var(--muted);
    text-decoration: none;
    background: rgba(255, 251, 243, 0.8);
    opacity: 0;
    transition:
        opacity 180ms ease,
        color 180ms ease,
        background 180ms ease;
}

.gloss-line:hover .gloss-permalink,
.gloss-line:focus-within .gloss-permalink,
.gloss-line:target .gloss-permalink {
    opacity: 0.9;
}

.gloss-permalink:hover {
    color: var(--accent);
    background: rgba(255, 248, 239, 0.96);
}

.gloss-link {
    color: inherit;
    text-decoration-line: underline;
    text-decoration-style: dotted;
    text-decoration-thickness: 0.8px;
    text-decoration-color: rgba(110, 93, 71, 0.28);
    text-underline-offset: 0.12em;
    transition:
        color 180ms ease,
        text-decoration-color 180ms ease,
        background 180ms ease;
}

.gloss-link:hover,
.gloss-link:focus-visible {
    color: inherit;
    text-decoration-style: solid;
    text-decoration-color: rgba(159, 63, 25, 0.55);
    background: rgba(159, 63, 25, 0.06);
    border-radius: 0.2rem;
}

.gloss-link-same {
    text-decoration-color: rgba(46, 83, 142, 0.28);
}

.gloss-link-same:hover,
.gloss-link-same:focus-visible {
    text-decoration-color: rgba(46, 83, 142, 0.55);
    background: rgba(46, 83, 142, 0.06);
}

.gloss-note,
.gloss-label,
.gloss-grammar,
.gloss-marker {
    display: inline-block;
    margin-right: 0.28rem;
    padding: 0.04rem 0.42rem;
    border-radius: 999px;
    white-space: nowrap;
}

.gloss-note {
    background: rgba(110, 93, 71, 0.12);
    color: #5f4e3b;
}

.gloss-label {
    background: rgba(34, 110, 93, 0.14);
    color: #1c6656;
}

.gloss-grammar {
    background: rgba(159, 63, 25, 0.12);
    color: #8e3a18;
    font-weight: 600;
}

.gloss-marker {
    background: rgba(46, 83, 142, 0.12);
    color: #30507f;
    font-weight: 600;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    align-items: center;
    justify-content: center;
    padding-top: 0.5rem;
}

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.5rem;
    min-height: 2.5rem;
    padding: 0.55rem 0.8rem;
    border: 1px solid rgba(74, 55, 25, 0.18);
    border-radius: 999px;
    background: rgba(255, 251, 243, 0.92);
    color: var(--text);
    text-decoration: none;
}

.page-link.current {
    border-color: rgba(159, 63, 25, 0.4);
    background: var(--accent-soft);
    color: #6d2a10;
    font-weight: 700;
}

.empty-state {
    padding: 1.75rem 1rem;
    border: 1px dashed rgba(74, 55, 25, 0.24);
    border-radius: var(--radius-md);
    text-align: center;
    color: var(--muted);
    background: rgba(255, 251, 243, 0.6);
}

code {
    padding: 0.1rem 0.35rem;
    border-radius: 6px;
    background: rgba(74, 55, 25, 0.08);
}

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

@media (max-width: 720px) {
    .shell {
        width: min(calc(100% - 1rem), var(--max-width));
        padding-top: 1.5rem;
    }

    .controls,
    .results-panel {
        padding: 1rem;
    }

    .results-meta {
        align-items: flex-start;
    }

    .sense-item {
        padding-right: 1.9rem;
    }

    .sense-item:target {
        padding-right: 2.4rem;
    }

    .sense-permalink {
        opacity: 1;
    }

    .gloss-permalink {
        opacity: 0.65;
    }
}
