:root {
    --bg: #f8f9fa;
    --surface: #fff;
    --surface-2: #f1f3f4;
    --border: #dadce0;
    --border-strong: #c0c4c9;
    --text: #202124;
    --text-secondary: #5f6368;
    --text-tertiary: #80868b;
    --accent: #1a73e8;
    --accent-hover: #1557b0;
    --accent-light: #e8f0fe;
    --accent-glow: rgba(26, 115, 232, .12);
    --success: #188038;
    --warning: #f9ab00;
    --error: #d93025;
    --noun: #1a73e8;
    --verb: #e37400;
    --adj: #188038;
    --adv: #c5221f;
    --noun-bg: #e8f0fe;
    --verb-bg: #fef7e0;
    --adj-bg: #e6f4ea;
    --adv-bg: #fce8e6;
    --shadow-sm: 0 1px 2px 0 rgba(60, 64, 67, .3), 0 1px 3px 1px rgba(60, 64, 67, .15);
    --shadow-md: 0 1px 3px 0 rgba(60, 64, 67, .3), 0 4px 8px 3px rgba(60, 64, 67, .15);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-full: 24px
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Roboto', system-ui, sans-serif;
    min-height: 100vh;
    line-height: 1.5
}

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .05)
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.35rem;
    font-weight: 500;
    color: var(--text)
}

.brand .logo {
    width: 36px;
    height: 36px;
    background: linear-gradient(135deg, #1a73e8, #34a853);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff
}

.brand span.sub {
    font-size: .85rem;
    color: var(--text-secondary);
    font-weight: 400;
    margin-left: 4px
}

.main {
    max-width: 1280px;
    margin: 0 auto;
    padding: 20px 16px 60px
}

.content-row {
    display: flex;
    gap: 16px;
    align-items: flex-start
}

.main-column {
    flex: 1;
    min-width: 0
}

.dict-sidebar {
    width: 0;
    max-width: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-width .28s cubic-bezier(.4, 0, .2, 1), opacity .2s ease;
    flex-shrink: 0;
    pointer-events: none
}

.dict-sidebar.open {
    width: 340px;
    max-width: 340px;
    opacity: 1;
    pointer-events: auto
}

.dict-sidebar-inner {
    width: 340px;
    min-width: 340px;
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    max-height: calc(100vh - 140px);
    display: flex;
    flex-direction: column;
    overflow: hidden
}

.dict-sidebar-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 12px
}

.dict-sidebar-header .header-left {
    flex: 1;
    min-width: 0
}

.dict-sidebar-header .dict-title {
    font-size: 1.35rem;
    font-weight: 500;
    color: var(--text);
    word-break: break-word
}

.dict-sidebar-header .dict-subtitle {
    font-size: .85rem;
    color: var(--text-secondary);
    margin-top: 2px
}

.dict-sidebar-header .header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0
}

.close-sidebar,
.header-speak {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.15rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s
}

.close-sidebar:hover,
.header-speak:hover {
    background: rgba(0, 0, 0, .07);
    color: var(--text)
}

.header-speak.speaking {
    background: var(--success);
    color: #fff
}

.dict-sidebar-body {
    padding: 8px 0 16px;
    overflow-y: auto;
    flex: 1
}

.dict-section {
    padding: 8px 16px 4px
}

.dict-section-title {
    font-size: .8rem;
    font-weight: 500;
    color: var(--accent);
    margin-bottom: 6px;
    padding: 4px 0
}

.dict-entry-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(0, 0, 0, .04)
}

.dict-entry-row:last-child {
    border-bottom: none
}

.dict-entry-main {
    flex: 1;
    min-width: 0
}

.dict-entry-word {
    font-size: 1.05rem;
    font-weight: 500;
    color: var(--text);
    font-family: monospace
}

.dict-entry-word .alt {
    display: block;
    font-size: .85rem;
    font-weight: 400;
    color: var(--text-secondary);
    margin-top: 1px
}

.dict-entry-meta {
    font-size: .8rem;
    color: var(--text-secondary);
    margin-top: 3px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px
}

.dict-entry-meta span {
    background: var(--surface-2);
    padding: 1px 8px;
    border-radius: 4px
}

.dict-entry-speak {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    flex-shrink: 0
}

.dict-entry-speak:hover {
    background: var(--accent-light);
    color: var(--accent)
}

.dict-toggle-btn {
    display: none;
    align-items: center;
    gap: 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    padding: 8px 18px;
    font-size: .875rem;
    font-weight: 500;
    color: var(--accent);
    cursor: pointer;
    margin: 0 auto 16px;
    box-shadow: var(--shadow-sm)
}

.dict-toggle-btn.visible {
    display: inline-flex
}

.dict-toggle-btn .badge {
    background: var(--accent);
    color: #fff;
    font-size: .7rem;
    padding: 2px 8px;
    border-radius: 10px;
    font-weight: 600
}

@media(max-width:960px) {
    .content-row {
        flex-direction: column
    }

    .dict-sidebar {
        width: 100% !important;
        max-width: 100% !important;
        max-height: 0;
        opacity: 0;
        overflow: hidden;
        transition: max-height .35s ease, opacity .25s ease;
        margin-top: 0;
        pointer-events: none
    }

    .dict-sidebar.open {
        max-height: 2000px;
        opacity: 1;
        margin-top: 12px;
        pointer-events: auto
    }

    .dict-sidebar-inner {
        width: 100%;
        min-width: 0;
        max-height: none
    }
}

.lang-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-bottom: 20px;
    flex-wrap: wrap
}

.lang-select-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.lang-select-label {
    font-size: .72rem;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.lang-select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    min-width: 190px;
    padding: 10px 40px 10px 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    font-size: .95rem;
    font-weight: 600;
    cursor: pointer;
    transition: border-color .2s, box-shadow .2s, background-color .2s;
}

.lang-select:hover {
    border-color: var(--accent);
    background: var(--surface-2);
}

.lang-select:focus-visible {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.lang-select-wrap::after {
    content: "";
    position: absolute;
    right: 17px;
    top: 50%;
    width: 7px;
    height: 7px;
    border-right: 2px solid var(--text-secondary);
    border-bottom: 2px solid var(--text-secondary);
    transform: translateY(-70%) rotate(45deg);
    pointer-events: none;
}

.manual-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--accent);
    font-size: .875rem;
    font-weight: 500;
    text-decoration: none;
    padding: 8px 16px;
    border-radius: var(--radius-full);
    margin-left: 8px
}

.manual-link:hover {
    background: var(--accent-light)
}

.translator {
    position: relative;
    background: var(--surface);
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    overflow: hidden;
    margin-bottom: 24px
}

.search-btn:disabled {
    opacity: .55;
    cursor: wait
}

.translator-panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    min-height: 220px
}

@media(max-width:768px) {
    .translator-panels {
        grid-template-columns: 1fr
    }
}

.panel {
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    position: relative
}

.panel-input {
    border-right: 1px solid var(--border)
}

@media(max-width:768px) {
    .panel-input {
        border-right: none;
        border-bottom: 1px solid var(--border)
    }
}

.panel-label {
    font-size: .8rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: .5px
}

.panel textarea,
.panel .output-area {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    font-family: inherit;
    font-size: 1.25rem;
    line-height: 1.5;
    color: var(--text);
    background: transparent;
    width: 100%;
    min-height: 120px
}

.panel textarea::placeholder {
    color: var(--text-tertiary)
}

.panel-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border)
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem
}

.icon-btn:hover {
    background: var(--surface-2);
    color: var(--text)
}

.icon-btn:disabled {
    opacity: .4;
    cursor: not-allowed
}

.search-btn {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-full);
    padding: 10px 28px;
    font-size: .95rem;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-left: auto
}

.search-btn:hover {
    background: var(--accent-hover)
}

.result-placeholder {
    color: var(--text-tertiary);
    text-align: center;
    padding: 40px 20px;
    font-size: 1rem
}

.result-placeholder .icon {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 12px;
    opacity: .6
}

.no-results {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 20px
}

.no-results .icon {
    font-size: 2.5rem;
    display: block;
    margin-bottom: 10px
}

.loader {
    display: none;
    width: 28px;
    height: 28px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    margin: 24px auto
}

@keyframes spin {
    to {
        transform: rotate(360deg)
    }
}

@keyframes pulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(24, 128, 56, .4)
    }

    50% {
        box-shadow: 0 0 0 8px rgba(24, 128, 56, 0)
    }
}

.speak-btn.speaking {
    background: var(--success) !important;
    border-color: var(--success) !important;
    color: #fff !important;
    animation: pulse 1s ease-in-out infinite
}

.status-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 16px;
    font-size: .8rem;
    color: var(--text-tertiary)
}

.status-bar .dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--success);
    animation: pulse-dot 1.6s ease-in-out infinite
}

@keyframes pulse-dot {

    0%,
    100% {
        opacity: 1
    }

    50% {
        opacity: .35
    }
}

.gloss-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
    font-size: .875rem
}

.gloss-table th,
.gloss-table td {
    text-align: left;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary)
}

.gloss-table th {
    font-weight: 500;
    color: var(--text);
    background: var(--surface-2)
}

.gloss-table td:nth-child(2) {
    color: var(--text);
    font-family: monospace;
    font-weight: 500
}

.sent-notes {
    margin-top: 14px;
    font-size: .85rem;
    color: #b06000;
    background: #fef7e0;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    border-left: 4px solid var(--warning)
}

.tip {
    text-align: center;
    margin-top: 20px;
    font-size: .8rem;
    color: var(--text-tertiary)
}

.result-entry {
    padding: 16px 18px;
    margin-bottom: 12px;
    border-radius: var(--radius);
    border-left: 4px solid var(--accent);
    background: var(--surface-2)
}

.result-entry .result-word-row {
    display: flex;
    align-items: center;
    gap: 14px;
    margin: 4px 0 8px
}

.result-entry .result-word {
    font-size: 1.5rem;
    font-weight: 500;
    color: var(--text);
    font-family: monospace;
    flex: 1
}

.result-entry .result-details {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 6px
}

.result-entry .result-details span {
    font-size: .875rem;
    background: rgba(0, 0, 0, .04);
    border-left: 3px solid var(--border-strong);
    padding: 3px 12px;
    color: var(--text-secondary);
    border-radius: 0 6px 6px 0
}

/* ===== 语系树按钮 ===== */
.tree-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    padding: 8px 16px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.tree-btn:hover {
    background: var(--surface-2);
    border-color: var(--accent);
    color: var(--accent);
}

/* ===== 模态框 ===== */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
}

.modal-overlay.open {
    display: flex;
}

.modal-content {
    background: #fff;
    border-radius: 16px;
    width: 90%;
    max-width: 600px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    background: #f8f9fa;
}

.modal-header h2 {
    font-size: 1.4rem;
    color: var(--text);
    margin: 0;
    line-height: 1.4;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
}

.close-btn:hover {
    color: var(--error);
}

/* ===== 语系树（ECharts） ===== */
.modal-content.tree-modal-content {
    max-width: 1180px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.tree-body {
    flex: 1 1 auto;
    min-height: 0;
    padding: 14px 18px 18px;
    overflow: auto;
}

.tree-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    padding: 0 2px 10px;
    font-size: .78rem;
    color: var(--text-secondary);
}

.tree-legend .legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.tree-legend .legend-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    box-shadow: 0 0 0 3px rgba(0, 0, 0, .03);
}

.legend-dot.active { background: #10b981; }
.legend-dot.endangered { background: #f59e0b; }
.legend-dot.extinct { background: #9ca3af; }

.tree-hint {
    margin-left: auto;
    opacity: .72;
}

.tree-note {
    margin: 0 2px 12px;
    font-size: .78rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.tree-families {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr);
    gap: 16px;
    align-items: stretch;
}

.tree-family {
    display: flex;
    flex-direction: column;
    min-width: 0;
    padding: 12px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .03);
}

.tree-family-header {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px;
    padding: 2px 4px 10px;
}

.tree-family-header h3 {
    margin: 0;
    font-size: .95rem;
    font-weight: 600;
    color: var(--text);
}

.tree-family-header span {
    font-size: .72rem;
    color: var(--text-secondary);
}

.tree-family .tree-chart {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 300px;
}

.tree-families > .tree-loading,
.tree-families > .tree-error {
    grid-column: 1 / -1;
}

.tree-chart {
    width: 100%;
    height: 360px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background:
        radial-gradient(circle at 12% 18%, rgba(99, 102, 241, .10), transparent 45%),
        radial-gradient(circle at 88% 82%, rgba(16, 185, 129, .08), transparent 42%),
        linear-gradient(180deg, #fbfcff 0%, #f6f8ff 100%);
}

.tree-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    height: 100%;
    min-height: 280px;
    color: var(--text-secondary);
    font-size: .9rem;
}

.tree-loading::before {
    content: "";
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid var(--border-strong);
    border-top-color: var(--accent);
    animation: tree-spin .8s linear infinite;
}

@keyframes tree-spin {
    to { transform: rotate(360deg); }
}

.tree-error {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    min-height: 280px;
    padding: 24px;
    text-align: center;
    color: var(--text-secondary);
    font-size: .9rem;
    line-height: 1.7;
}

@media (max-width: 1200px) {
    .modal-content.tree-modal-content {
        max-width: 860px;
    }

    .tree-families {
        grid-template-columns: 1fr;
    }

    .tree-chart {
        height: 340px;
    }
}

/* 语系树已改为 ECharts 渲染（见 js/family-tree.js） */






