:root {
    /* Theme Colors: Achromatic Theme */
    --bg-main: #212121;
    --bg-card: #282828;
    --text-primary: #e0e0e0; /* Light gray for main text */
    --text-highlight: #c5c5c5; /* Medium-light gray for emphasis */
    --text-secondary: #909090; /* Medium gray for secondary text */
    --accent-color: #ffffff; /* Pure white for hover/active */
    --border-color: #383838;
    --hover-bg: rgba(255, 255, 255, 0.08);
}

html {
    overflow: hidden;
}


body {
    width: 350px;
    max-height: 500px;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-size: 14px;
    overflow-y: auto;
    -ms-overflow-style: none;  /* IE and Edge */
}

body::-webkit-scrollbar {
    display: none; /* Chrome, Safari, Opera */
}

a {
    color: unset;
    text-decoration: none;
    cursor: unset;
}

rt {
    user-select: none;
    font-size: 0.65em;
}

.sticky-header {
    position: sticky;
    top: 0;
    background-color: var(--bg-main);
    z-index: 100;
    padding: 10px 10px 0 10px;
}

.content-area {
    padding: 0 10px 10px 10px;
}

.lang-toggle-container {
    display: flex;
    align-items: center;
    gap: 4px;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
    color: var(--text-secondary);
}
.lang-toggle-container::-webkit-scrollbar {
    display: none;
}

.lang-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 4px 8px;
    border-radius: 12px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all 0.2s;
}

.lang-separator {
    color: var(--border-color);
    user-select: none;
}

.lang-btn.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    font-weight: bold;
}

.lang-btn:hover:not(.active) {
    color: var(--text-primary);
}

.search-container {
    display: flex;
    gap: 10px; /* gap for settings button */
    width: 100%;
    margin: 8px 0;
}

.search-input-wrapper {
    display: flex;
    flex-grow: 1;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: transparent;
    overflow: hidden;
    transition: border-color 0.2s;
}

#search-input {
    flex-grow: 1;
    padding: 5px 8px;
    border: none;
    background-color: transparent;
    color: var(--text-primary);
    font-size: 1em;
}

#search-input:focus {
    outline: none;
}

.btn-search-group {
    background-color: transparent;
    color: var(--text-secondary);
    border: none;
    border-left: 1px solid var(--border-color); /* vertical divider */
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-search-group:hover {
    color: var(--text-primary);
    background-color: var(--hover-bg);
}

.main-search {
    padding: 0 15px;
}

.btn-translate {
    padding: 0 7px;
}

.btn-popout {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.btn-popout:hover {
    color: var(--text-primary);
    background-color: var(--hover-bg);
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 1px 3px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background-color 0.2s;
}

.icon-btn:hover {
    color: var(--accent-color);
}

.search-history-container {
    display: flex;
    align-items: center;
    gap: 6px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
}
.search-history-container::-webkit-scrollbar {
    display: none;
}

body.has-autocomplete {
    min-height: 310px;
}

body.has-autocomplete .search-input-wrapper {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-bottom-color: transparent;
}

.search-input-group {
    position: relative;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.autocomplete-container {
    position: absolute;
    top: calc(100% - 1px);
    left: 0;
    right: 0;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 0 0 4px 4px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
    max-height: 220px;
    overflow-y: auto;
    z-index: 1000;
}

.autocomplete-container::-webkit-scrollbar {
    width: 4px;
}
.autocomplete-container::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 2px;
}

.ac-item {
    padding: 5px 8px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    transition: background-color 0.12s ease;
    display: flex;
    align-items: center;
    white-space: nowrap;
    overflow: hidden;
    gap: 6px;
    font-size: 0.9em;
}

.ac-item:last-child {
    border-bottom: none;
}

.ac-item:hover,
.ac-item.selected {
    background-color: var(--hover-bg);
}

.ac-word {
    color: var(--text-primary);
    flex-shrink: 0;
}

.ac-subtitle {
    font-size: 0.85em;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.ac-meaning {
    font-size: 0.85em;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-grow: 1;
}

.ac-divider {
    border-top: 1px solid var(--border-color);
    margin-top: 2px;
    padding-top: 5px;
}

.history-chip {
    display: inline-flex;
    align-items: center;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 2px 6px;
    font-size: 0.85em;
    color: var(--text-secondary);
    transition: background 0.2s, color 0.2s;
}

.history-chip:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.history-word {
    cursor: pointer;
    margin-right: 4px;
}

.history-remove {
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 0.9em;
    padding-left: 4px;
    border-left: 1px solid var(--border-color);
}
.history-remove:hover {
    color: #ff5252;
}

.section-title {
    font-size: 1.2em;
    color: var(--text-primary);
    font-weight: bold;
    margin: 10px 0 5px 5px;
}

.entry-card, .example-card {
    background: var(--bg-card);
    border-radius: 4px;
    padding: 5px 8px;
    margin-bottom: 6px;
    border: none;
}

.entry-header {
    display: flex;
    align-items: center;
    gap: 5px;
}

.entry-header.clickable {
    cursor: pointer;
}

.entry-header.clickable:hover .entry-title {
    color: var(--accent-color);
}

.entry-title {
    font-size: 1.2em;
    font-weight: bold;
    color: var(--text-primary);
    transition: color 0.2s;
}

.entry-origin-lang {
    font-size: 0.9em;
    font-weight: normal;
    color: var(--text-highlight);
    margin-left: 4px;
}

.entry-origin-lang strong {
    font-weight: normal;
    color: var(--text-primary);
}

.entry-ipa {
    color: var(--text-secondary);
    font-size: 0.9em;
}

.entry-ipa strong {
    font-weight: normal;
    color: inherit;
}

.entry-summaries {
    margin: 5px 0 0 0;
    color: var(--text-primary);
    font-size: 0.9em;
}

.summary-pos {
    color: var(--text-secondary);
    margin-top: 5px;
}

.summary-pos:first-child {
    margin-top: 0;
}

.summary-item {
    margin-top: 5px;
    padding-left: 5px;
}

.entry-detail-container {
    margin-top: 10px;
    border-top: 1px dashed var(--border-color);
}

.detail-mean-block:first-child {
    margin-top: 10px;
}

.detail-mean-block {
    margin-top: 5px;
}

.detail-mean-text {
    margin: 0 0 8px 0;
    color: var(--text-highlight);
}

.detail-example-wrapper {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    margin-bottom: 5px;
    padding: 5px 8px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 4px;
}

.example-toggle-container {
    width: 24px;
    flex-shrink: 0;
    display: flex;
    justify-content: flex-start;
    padding-top: 2px;
}

.example-content-container {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.detail-example-origin {
    color: var(--text-primary);
}

.detail-example-trans {
    color: var(--text-secondary);
    font-size: 0.9em;
}

.btn-toggle-examples {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

hr {
    border: 0;
    border-top: 1px solid var(--border-color);
    margin: 15px 0;
}

/* Prevent HR at the very bottom */
.result-section:last-child hr {
    display: none;
}

#search-results {
}

/* --- Settings UI --- */
.btn-settings {
    padding: 0 5px;
    background-color: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.btn-settings:hover {
    color: var(--text-primary);
    background-color: var(--hover-bg);
    border-color: var(--border-color);
}

#settings-view {
    margin-top: 6px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
}

body.has-history #settings-view {
    margin-top: 5px;
    padding-top: 5px;
    border-top: none;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.settings-title {
    margin: 0;
    font-size: 1.1em;
    color: var(--text-primary);
}

.btn-reset {
    padding: 4px 8px;
    background-color: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85em;
    transition: all 0.2s;
}

.btn-reset:hover {
    color: #ff5252;
    border-color: #ff5252;
    background-color: rgba(255, 82, 82, 0.1);
}

.settings-group {
    margin-bottom: 15px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
}

.settings-group-col {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
}

.settings-group label {
    font-size: 0.9em;
    color: var(--text-highlight);
    font-weight: bold;
    white-space: nowrap;
}

.settings-input {
    width: 140px;
    padding: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 4px;
    font-family: inherit;
    accent-color: var(--text-secondary);
}

.settings-textarea {
    width: 100%;
    resize: vertical;
    box-sizing: border-box;
    font-size: 0.9em;
}

.dict-sort-list {
    list-style: none;
    padding: 0;
    margin: 0;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: var(--bg-card);
}

.dict-sort-item {
    display: flex;
    align-items: center;
    padding: 8px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-card);
    cursor: grab;
}

.dict-sort-item:last-child {
    border-bottom: none;
}

.dict-sort-item.dragging {
    opacity: 0.5;
    background: var(--hover-bg);
}

.dict-sort-handle {
    color: var(--text-secondary);
    margin-right: 10px;
    cursor: grab;
}

.dict-sort-label {
    flex-grow: 1;
    font-size: 0.95em;
    user-select: none;
}

.dict-sort-toggle {
    cursor: pointer;
    accent-color: var(--text-secondary);
}

.settings-contact {
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
    font-size: 0.9em;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.settings-link {
    color: #5c9df5;
    text-decoration: underline;
    cursor: pointer;
    transition: color 0.2s;
}

.settings-link:hover {
    color: #8cbcfc;
}

/* --- Light Theme --- */
:root[data-theme="light"] {
    --bg-main: #f5f5f5;
    --bg-card: #ffffff;
    --text-primary: #333333;
    --text-highlight: #555555;
    --text-secondary: #777777;
    --accent-color: #000000;
    --border-color: #dddddd;
    --hover-bg: rgba(0, 0, 0, 0.05);
}