:root {
    color-scheme: light dark;
    --ink: #1c1a17; --ink-soft: #4a4540; --ink-faint: #8a837a;
    --paper: #f7f3ee; --paper-card: #fdfaf6; --paper-inset: #f0ebe3;
    --vermilion: #c0392b; --vermilion-light: #f5e6e4;
    --indigo: #2c3e6b; --indigo-light: #e8ecf5;
    --gold: #8b6914; --gold-light: #f5eed8;
    --border: #d6cfc5; --border-light: #e8e2d8;
}

@media (prefers-color-scheme: dark) {
    :root {
        --ink: #e8e2d8; --ink-soft: #a8a095; --ink-faint: #7a736a;
        --paper: #1c1a17; --paper-card: #25221e; --paper-inset: #141210;
        --vermilion: #d94b3a; --vermilion-light: #3a1c18;
        --indigo: #6b84c4; --indigo-light: #1e2638;
        --gold: #c2a153; --gold-light: #302612;
        --border: #4a4540; --border-light: #36322d;
    }
    body {
        background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Crect width='60' height='60' fill='%231c1a17'/%3E%3Crect x='0' y='29.5' width='60' height='1' fill='%2336322d' opacity='0.5'/%3E%3Crect x='29.5' y='0' width='1' height='60' fill='%2336322d' opacity='0.5'/%3E%3C/svg%3E");
    }
    input[type="text"] { color: var(--ink); }
    button:disabled { background: var(--ink-soft); }
    .annotation-link {
        color: #8cb4ff;
        border-bottom-color: rgba(140, 180, 255, 0.4);
    }
    .annotation-link:hover {
        color: var(--gold);
        border-bottom-color: var(--gold);
    }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
    font-family: "Noto Serif TC", "PingFang TC", "STSong", serif; background-color: var(--paper);
    color: var(--ink); max-width: 820px; margin: 0 auto; padding: 32px 24px; line-height: 1.8;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' xmlns='http://www.w3.org/2000/svg'%3E%3Crect width='60' height='60' fill='%23f7f3ee'/%3E%3Crect x='0' y='29.5' width='60' height='1' fill='%23e8e2d8' opacity='0.5'/%3E%3Crect x='29.5' y='0' width='1' height='60' fill='%23e8e2d8' opacity='0.5'/%3E%3C/svg%3E");
    min-height: 100vh;
}
.page-header { text-align: center; margin-bottom: 36px; padding-bottom: 24px; border-bottom: 1px solid var(--border); }
.page-header::after { content: ''; display: block; width: 60px; height: 2px; background: var(--vermilion); margin: 12px auto 0; }
.page-header h1 { font-size: 26px; font-weight: 500; letter-spacing: 0.15em; color: var(--indigo); }
.page-header h1 a { color: inherit; text-decoration: none; transition: color 0.2s; }
.page-header h1 a:hover { color: var(--vermilion); }
.search-container { position: sticky; top: env(safe-area-inset-top, 0); background: var(--paper); padding: 12px 0 16px; z-index: 100; margin-bottom: 12px; }
@supports (backdrop-filter: blur(8px)) {
    .search-container { background: color-mix(in srgb, var(--paper) 94%, transparent); backdrop-filter: blur(8px); }
}
.search-box { display: flex; border: 1.5px solid var(--border); border-radius: 4px; overflow: hidden; background: var(--paper-card); box-shadow: 0 2px 12px rgba(0,0,0,0.06); transition: border-color 0.2s, box-shadow 0.2s; }
.search-box:focus-within { border-color: var(--indigo); box-shadow: 0 2px 16px rgba(44,62,107,0.12); }
.search-options { display: flex; gap: 10px; margin-top: 14px; justify-content: center; flex-wrap: wrap; }
.radio-label { cursor: pointer; display: inline-flex; }
.radio-label input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}
.radio-btn { padding: 6px 18px; font-size: 13px; font-weight: 500; border: 1.5px solid var(--border); border-radius: 20px; color: var(--ink-soft); transition: all 0.2s ease; background: var(--paper-card); letter-spacing: 0.05em; }
.radio-label:hover .radio-btn { border-color: var(--indigo-light); color: var(--indigo); }
.radio-label input:checked + .radio-btn { background: var(--indigo); color: #fff; border-color: var(--indigo); box-shadow: 0 2px 8px rgba(44,62,107,0.2); }
.radio-label input:focus-visible + .radio-btn { outline: 2px solid var(--indigo); outline-offset: 2px; }

input[type="text"] { flex: 1; padding: 13px 16px; font-size: 15px; font-family: inherit; border: none; background: transparent; outline: none; min-width: 0; }
input[type="text"]::placeholder { color: var(--ink-faint); }
button { padding: 12px 20px; font-size: 14px; font-family: inherit; letter-spacing: 0.1em; cursor: pointer; background: var(--indigo); color: #fff; border: none; transition: background 0.2s, transform 0.1s; white-space: nowrap; }
button:active { transform: scale(0.97); }
button:hover { background: #1e2b4e; }
button:disabled { cursor: not-allowed; opacity: 0.7; }
button:focus-visible, a:focus-visible, select:focus-visible {
    outline: 2px solid var(--vermilion);
    outline-offset: 2px;
}

#updateBar {
    display: none; align-items: center; justify-content: space-between; gap: 12px;
    margin-bottom: 20px; padding: 10px 16px;
    background: var(--indigo-light); color: var(--indigo);
    border: 1px solid rgba(44,62,107,0.2); border-radius: 4px;
    font-size: 13.5px; letter-spacing: 0.05em;
    animation: fadeUp 0.3s ease both;
}
#updateBar .update-actions { display: flex; gap: 8px; flex-shrink: 0; }
#updateBar .btn-reload { padding: 4px 14px; font-size: 12px; font-family: inherit; background: var(--indigo); color: #fff; border: none; border-radius: 3px; cursor: pointer; letter-spacing: 0.08em; transition: background 0.2s; }
#updateBar .btn-reload:hover { background: #1e2b4e; }
#updateBar .btn-dismiss { padding: 4px 10px; font-size: 12px; font-family: inherit; background: transparent; color: var(--indigo); border: 1px solid var(--indigo); border-radius: 3px; cursor: pointer; }
#updateBar .btn-dismiss:hover { background: rgba(44,62,107,0.08); }

#extraStatus { text-align: center; font-size: 13px; color: var(--gold); margin-bottom: 24px; display: none; }
#regexError {
    display: none;
    text-align: center;
    margin-bottom: 16px;
    padding: 10px 16px;
    background: var(--vermilion-light);
    color: var(--vermilion);
    border: 1px solid rgba(192,57,43,0.2);
    border-radius: 4px;
    font-size: 13.5px;
    letter-spacing: 0.05em;
}
.result-card { background: var(--paper-card); margin-bottom: 28px; border-radius: 4px; border: 1px solid var(--border); box-shadow: 0 3px 20px rgba(0,0,0,0.05); overflow: hidden; animation: fadeUp 0.35s ease both; transition: box-shadow 0.25s ease, transform 0.2s ease; content-visibility: auto; contain-intrinsic-size: 260px; }
.result-card:hover {
    box-shadow: 0 6px 28px rgba(0,0,0,0.1);
    transform: translateY(-2px);
}
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.char-banner { background: var(--indigo); color: #fff; padding: 20px 28px; display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.char-glyph-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; flex-shrink: 0; }
.char-glyph { font-size: 64px; font-weight: 700; line-height: 1; color: #fff; text-shadow: 0 2px 8px rgba(0,0,0,0.3); user-select: text; }
.zi-link { font-size: 11px; color: rgba(255,255,255,0.5); text-decoration: none; letter-spacing: 0.06em; border-bottom: 1px dashed rgba(255,255,255,0.3); transition: color 0.2s, border-color 0.2s; white-space: nowrap; }
.zi-link:hover { color: #f0c27f; border-bottom-color: #f0c27f; }
.char-phonetics { flex: 1 1 240px; min-width: 0; }
.phonetic-row { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; flex-wrap: wrap; }
.phonetic-label { font-size: 11px; color: rgba(255,255,255,0.55); letter-spacing: 0.08em; width: 28px; flex-shrink: 0; }
.phonetic-value { font-family: "Noto Sans Mono", monospace; font-size: 18px; color: #f0c27f; letter-spacing: 0.05em; word-break: break-all; }
.pinyin-value { font-family: "Noto Sans Mono", monospace; font-size: 14px; color: rgba(255,255,255,0.75); letter-spacing: 0.05em; word-break: break-all; }
.char-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.tag { display: inline-flex; align-items: center; min-height: 24px; padding: 2px 10px; border-radius: 2px; font-family: inherit; font-size: 11px; line-height: 1.5; letter-spacing: 0.06em; background: rgba(255,255,255,0.15); color: rgba(255,255,255,0.85); border: 1px solid rgba(255,255,255,0.25); white-space: nowrap; }
.xiesheng-tag { background: rgba(240, 194, 127, 0.2); color: #f0c27f; border-color: rgba(240, 194, 127, 0.4); cursor: pointer; transition: all 0.2s; }
.xiesheng-tag:hover { background: rgba(240, 194, 127, 0.4); transform: translateY(-1px); }
.xiesheng-tag:focus-visible { outline-color: #f0c27f; }
.card-body { padding: 18px 24px; }
.section { margin-bottom: 16px; }
.section:last-child { margin-bottom: 0; }
.section-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.section-label { font-size: 11px; font-weight: 700; letter-spacing: 0.12em; color: var(--ink-faint); text-transform: uppercase; }
.section-note { font-size: 12px; color: var(--ink-faint); margin-left: 4px; }
.section-divider { height: 1px; background: var(--border-light); margin: 16px 0; }
.empty-meaning { color: var(--ink-faint); font-size: 14px; font-style: italic; }
.meanings-list { list-style: none; }
.meanings-list li { display: flex; gap: 12px; align-items: flex-start; margin-bottom: 8px; font-size: 14.5px; line-height: 1.9; color: var(--ink); }
.sense-num {
    min-width: 20px;
    height: 20px;
    background: var(--vermilion);
    color: #fff;
    border-radius: 50%;
    font-size: 11px;
    font-family: "Noto Sans Mono", monospace;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-top: 4px;
}
.text-block { background: var(--paper-inset); border: 1px solid var(--border-light); border-left: 3px solid var(--border); border-radius: 0 3px 3px 0; padding: 10px 14px; font-size: 13.5px; line-height: 1.9; color: var(--ink-soft); white-space: pre-wrap; word-break: break-word; }
.text-block.annotation { border-left-color: var(--gold); background: var(--gold-light); color: var(--ink); }
.no-result { text-align: center; padding: 48px 0; color: var(--ink-faint); font-size: 15px; letter-spacing: 0.05em; }
.no-result span { font-size: 0.9em; }
.pagination-bar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    margin: 0 0 20px; padding: 12px 14px;
    background: var(--paper-card); border: 1px solid var(--border); border-radius: 4px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.04); color: var(--ink-soft);
    font-size: 13px; letter-spacing: 0.04em; flex-wrap: wrap;
}
.pagination-bar.bottom { margin: 8px 0 0; }
.pagination-summary { color: var(--ink-soft); }
.pagination-controls { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.pagination-controls button,
.pagination-size select {
    font-family: inherit; font-size: 12px; letter-spacing: 0.04em; border-radius: 4px;
    border: 1px solid var(--border); background: var(--paper-card); color: var(--ink-soft);
}
.pagination-controls button { padding: 5px 9px; cursor: pointer; transition: color 0.2s, border-color 0.2s, background 0.2s; }
.pagination-controls button:hover:not(:disabled) { border-color: var(--indigo); color: var(--indigo); background: var(--indigo-light); }
.pagination-controls button:disabled { background: var(--paper-inset); color: var(--ink-faint); border-color: var(--border-light); cursor: not-allowed; opacity: 0.75; }
.pagination-controls button[aria-current="page"] { background: var(--indigo); color: #fff; border-color: var(--indigo); cursor: default; }
.pagination-ellipsis { padding: 0 2px; color: var(--ink-faint); }
.pagination-size { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.pagination-size select { padding: 4px 24px 4px 8px; cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.copy-btn {
    background: transparent; border: none; cursor: pointer;
    font-size: 14px; padding: 4px 6px; border-radius: 4px; transition: background 0.2s; color: inherit;
    display: inline-flex; align-items: center; justify-content: center;
}
.copy-btn:hover { background: rgba(255,255,255,0.15); }
.export-btn {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.3);
    color: rgba(255,255,255,0.85);
    cursor: pointer;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 4px;
    margin-left: auto;
    transition: all 0.2s;
    letter-spacing: 0.05em;
    white-space: nowrap;
}
.export-btn:hover {
    background: rgba(255,255,255,0.15);
    color: #fff;
    border-color: #fff;
}
.exporting .export-btn { display: none; }
.exporting .char-phonetics { flex: 1 0 auto; min-width: max-content; }
.exporting .char-tags { flex-wrap: nowrap !important; }

.annotation-link {
    color: #2b5e9e;
    text-decoration: none;
    border-bottom: 1px dotted rgba(43, 94, 158, 0.4);
    transition: color 0.2s, border-color 0.2s;
    word-break: break-all;
}
.annotation-link:hover {
    color: var(--vermilion);
    border-bottom-color: var(--vermilion);
}


@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
    .result-card:hover { transform: none; }
}

@media (max-width: 640px) {
    body { padding: 16px 12px; }
    .page-header { margin-bottom: 20px; padding-bottom: 16px; }
    .page-header h1 { font-size: 22px; letter-spacing: 0.1em; }
    .search-container { padding: 8px 0 12px; }
    .search-box { border-radius: 3px; }
    input[type="text"] { padding: 10px 12px; font-size: 14px; }
    button { padding: 10px 16px; font-size: 13px; }
    .search-options { gap: 6px; margin-top: 10px; }
    .radio-btn { padding: 4px 12px; font-size: 12px; border-radius: 16px; }

    .char-banner { padding: 14px 18px; gap: 12px; }
    .char-glyph { font-size: 48px; }
    .phonetic-value { font-size: 16px; }
    .pinyin-value { font-size: 13px; }
    .export-btn { margin-left: 0; margin-top: 8px; width: 100%; text-align: center; }

    .card-body { padding: 12px 16px; }
    .meanings-list li { font-size: 13.5px; gap: 8px; }
    .sense-num { min-width: 18px; height: 18px; font-size: 10px; margin-top: 3px; }
    .text-block { padding: 8px 10px; font-size: 12.5px; }

    .no-result { padding: 36px 0; font-size: 14px; }
    .pagination-bar { align-items: stretch; flex-direction: column; gap: 10px; padding: 10px 12px; }
    .pagination-controls { justify-content: center; }
    .pagination-controls button { padding: 5px 8px; }
    .pagination-size { justify-content: center; }
    #updateBar { flex-direction: column; align-items: flex-start; gap: 8px; padding: 8px 12px; }
}

@media (max-width: 380px) {
    .page-header h1 { font-size: 20px; }
    .char-glyph { font-size: 40px; }
    .phonetic-value { font-size: 14px; }
    .pinyin-value { font-size: 12px; }
    .search-options { gap: 4px; }
    .radio-btn { padding: 3px 10px; font-size: 11px; }
}
