body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    background: #f8f9fa;
    color: #333;
    display: flex;
    flex-direction: column;
    line-height: 1.6;
}

header {
    background: #007acc;
    color: #fff;
    padding: 1rem 0;
    text-align: center;
}

main {
    flex: 1;
    max-width: 800px;
    margin: 1rem auto;
    padding: 0 1rem;
    width: 100%;
}

footer {
    color: #666;
    padding: 1rem;
    text-align: center;
}

footer p {
    margin: 0;
}

.settings-panel {
    margin-bottom: 1rem;
    padding: 1rem;
    background: #fff;
    border: 1px solid #d8e2ea;
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0, 60, 100, 0.08);
}

.settings-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #005fa3;
    cursor: pointer;
    font-weight: bold;
    list-style: none;
}

.settings-toggle::-webkit-details-marker {
    display: none;
}

.settings-icon {
    width: 1.35rem;
    height: 1.35rem;
    fill: currentColor;
    transition: transform 0.25s ease;
}

.settings-panel[open] .settings-icon,
.settings-toggle:hover .settings-icon {
    transform: rotate(45deg);
}

.settings-content {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-end;
    margin-top: 1rem;
}

.setting-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.setting-group label {
    color: #444;
    font-size: 0.95rem;
    font-weight: bold;
}

.setting-group input,
.setting-group select {
    border: 1px solid #b8c8d6;
    border-radius: 4px;
    font-size: 1rem;
    padding: 0.45rem 0.55rem;
}

.db-explorer-control select {
    min-width: 10rem;
}

.secondary-button {
    background: #6c757d;
}

.secondary-button:hover {
    background: #555f66;
}

#flashcard-section {
    text-align: center;
    margin-top: 1rem;
}

#flashcard {
    border: 2px solid #007acc;
    border-radius: 5px;
    padding: 2rem;
    background: #fff;
    min-height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: bold;
    position: relative;
}

#card-content.answer-visible {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    width: 100%;
}

.card-front-word {
    font-size: 1.5rem;
    font-weight: bold;
}

.study-age-badge {
    background: #e8f3fb;
    border: 1px solid #b8d8ef;
    border-radius: 999px;
    bottom: 0.45rem;
    color: #005fa3;
    display: inline-flex;
    font-size: 0.8rem;
    font-weight: bold;
    line-height: 1;
    padding: 0.35rem 0.65rem;
    position: absolute;
    right: 0.45rem;
    width: fit-content;
}

.card-line {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    width: 100%;
}

.card-word {
    font-size: 1.5rem;
    font-weight: bold;
}

.card-meaning {
    font-size: 1.1rem;
    font-weight: normal;
}

#controls {
    margin-top: 1rem;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 0.45rem;
}

.search-result-box {
    background: #fff;
    border: 1px solid #c9d7e3;
    border-radius: 5px;
    margin-top: 1rem;
    padding: 1rem;
    text-align: left;
}

.search-result-title {
    color: #005fa3;
    font-size: 0.9rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
}

#searchResultContent {
    color: #444;
    font-size: 0.95rem;
    font-weight: normal;
}

#searchResultContent ol {
    margin: 0;
    padding-left: 1.25rem;
}

#searchResultContent li + li {
    margin-top: 0.5rem;
}

.definition-heading {
    align-items: center;
    display: inline-flex;
    gap: 0.35rem;
    margin-bottom: 0.5rem;
}

.definition-phonetic {
    color: #666;
    font-size: 0.9rem;
}

.definition-part {
    color: #005fa3;
    font-weight: bold;
}

.definition-example {
    color: #666;
    font-size: 0.9rem;
    font-style: italic;
    margin-top: 0.2rem;
}

.example-text {
    align-items: center;
    color: #444;
    display: inline-flex;
    font-size: 1rem;
    font-style: italic;
    gap: 0.35rem;
    margin: 0;
}

#searchResultContent a {
    color: #005fa3;
    font-weight: bold;
    text-decoration: none;
}

#searchResultContent a:hover {
    text-decoration: underline;
}

#searchResultContent p {
    margin: 0.2rem 0 0;
}

.translation-text {
    direction: rtl;
    font-size: 1.1rem;
    line-height: 1.9;
    text-align: right;
    white-space: pre-line;
}

.search-result-empty {
    margin: 0;
}

.table-page {
    max-width: 1200px;
}

.table-status {
    color: #555;
    font-weight: bold;
    margin-bottom: 0.75rem;
}

.table-filter-bar {
    align-items: center;
    background: #fff;
    border: 1px solid #d8e2ea;
    border-radius: 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    margin-bottom: 0.75rem;
    padding: 0.75rem;
}

.table-filter-bar label {
    color: #444;
    font-weight: bold;
}

.table-filter-bar input,
.table-filter-bar select {
    border: 1px solid #b8c8d6;
    border-radius: 4px;
    font-size: 1rem;
    padding: 0.45rem 0.55rem;
}

.table-filter-bar input {
    min-width: 16rem;
}

.table-scroll {
    background: #fff;
    border: 1px solid #d8e2ea;
    border-radius: 8px;
    overflow: auto;
}

.db-table {
    border-collapse: collapse;
    font-size: 0.9rem;
    min-width: 100%;
    text-align: left;
}

.db-table th,
.db-table td {
    border-bottom: 1px solid #e4edf3;
    padding: 0.55rem 0.7rem;
    vertical-align: top;
}

.db-table th {
    background: #e8f3fb;
    color: #005fa3;
    cursor: pointer;
    position: sticky;
    top: 0;
    white-space: nowrap;
}

.db-table th:hover {
    background: #d9edf9;
}

.db-table tbody tr:hover {
    background: #f6fbff;
}

.db-table td {
    cursor: pointer;
}

.db-table td:hover {
    background: #edf7ff;
}

.sortable-header:focus {
    outline: 2px solid #007acc;
    outline-offset: -2px;
}

.db-table td:focus {
    outline: 2px solid #007acc;
    outline-offset: -2px;
}

.table-sort-button {
    align-items: center;
    background: transparent;
    color: inherit;
    display: inline-flex;
    font: inherit;
    font-weight: bold;
    gap: 0.35rem;
    padding: 0;
    text-align: left;
}

.table-sort-button:hover {
    background: transparent;
    color: #003f6f;
    text-decoration: underline;
}

.table-sort-button[data-direction="asc"]::after {
    content: "▲";
    font-size: 0.7rem;
}

.table-sort-button[data-direction="desc"]::after {
    content: "▼";
    font-size: 0.7rem;
}

.db-table td {
    max-width: 28rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.db-table td {
    position: relative;
}

.table-cell-text {
    display: inline;
}

button {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    background: #007acc;
    color: #fff;
    cursor: pointer;
    font-size: 1rem;
}

button:hover {
    background: #005fa3;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

.icon-button {
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
    background: transparent;
    color: #007acc;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
    transform: translateY(0.3rem);
}

.inline-speaker-button {
    flex: 0 0 auto;
    width: 2rem;
    height: 2rem;
    transform: none;
}

.icon-button:hover {
    background: rgba(0, 122, 204, 0.1);
    color: #005fa3;
    transform: translateY(0.15rem);
}

.inline-speaker-button:hover {
    transform: none;
}

.speaker-icon {
    width: 1.35rem;
    height: 1.35rem;
    fill: currentColor;
}

.speaker-wave {
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    opacity: 0.75;
    transform-origin: 13px 12px;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.icon-button:hover .speaker-wave-inner {
    opacity: 1;
    transform: scaleX(1.12);
}

.icon-button:hover .speaker-wave-outer {
    opacity: 1;
    transform: scaleX(1.22);
}

.hidden {
    display: none;
}

@media (max-width: 700px) {
    body {
        line-height: 1.45;
    }

    header {
        padding: 0.85rem 1rem;
    }

    header h1 {
        font-size: 1.45rem;
        margin: 0;
    }

    header p {
        font-size: 0.95rem;
        margin: 0.35rem 0 0;
    }

    main,
    .table-page {
        box-sizing: border-box;
        margin: 0.75rem auto;
        max-width: 100%;
        padding: 0 0.75rem;
    }

    .settings-panel {
        padding: 0.85rem;
    }

    .settings-content,
    .setting-group,
    .table-filter-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .setting-group input,
    .setting-group select,
    .setting-group button,
    .table-filter-bar input,
    .table-filter-bar select {
        box-sizing: border-box;
        min-width: 0;
        width: 100%;
    }

    #flashcard {
        box-sizing: border-box;
        min-height: 180px;
        padding: 1.4rem 1rem 2.7rem;
        width: 100%;
    }

    .card-front-word,
    .card-word {
        font-size: 1.3rem;
        line-height: 1.35;
    }

    .card-meaning {
        font-size: 1rem;
        line-height: 1.45;
    }

    .card-line {
        align-items: center;
        flex-wrap: wrap;
        line-height: 1.35;
    }

    #controls {
        align-items: stretch;
        flex-direction: column;
    }

    #controls > button,
    #answerActions,
    #answerActions button {
        box-sizing: border-box;
        width: 100%;
    }

    #answerActions {
        display: grid;
        gap: 0.45rem;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    #answerActions.hidden {
        display: none;
    }

    #answerActions button {
        min-height: 2.6rem;
        padding-left: 0.45rem;
        padding-right: 0.45rem;
    }

    #speakCard.icon-button {
        align-self: flex-end;
        width: 2.75rem;
    }

    .search-result-box {
        padding: 0.85rem;
    }

    .example-text {
        align-items: flex-start;
        line-height: 1.5;
    }

    .table-filter-bar {
        padding: 0.65rem;
    }

    .table-scroll {
        max-height: 70vh;
    }

    .db-table {
        font-size: 0.82rem;
    }

    .db-table th,
    .db-table td {
        padding: 0.45rem 0.55rem;
    }

    .db-table td {
        max-width: 16rem;
    }

    footer {
        font-size: 0.9rem;
        padding: 0.8rem;
    }
}

@media (max-width: 420px) {
    #answerActions {
        grid-template-columns: 1fr;
    }

    button {
        font-size: 0.95rem;
    }

    .study-age-badge {
        bottom: 0.35rem;
        right: 0.35rem;
    }
}
