:root {
    --color-bg: #f3f1ec;
    --color-surface: rgba(255, 255, 255, 0.88);
    --color-surface-solid: #ffffff;
    --color-text: #23211d;
    --color-text-muted: #5c584f;
    --color-border: rgba(35, 33, 29, 0.12);
    --color-accent: #b1502e;
    --color-accent-hover: #953f22;
    --color-accent-contrast: #ffffff;
    --color-danger: #b3261e;
    --color-success: #2e7d4f;
    --scrim: rgba(20, 18, 14, 0.45);
    --shadow: 0 10px 30px rgba(20, 18, 14, 0.18);
    --radius: 14px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

:root[data-theme="dark"] {
    --color-bg: #1b1a17;
    --color-surface: rgba(27, 25, 22, 0.82);
    --color-surface-solid: #24221e;
    --color-text: #f2efe9;
    --color-text-muted: #c9c3b6;
    --color-border: rgba(242, 239, 233, 0.14);
    --color-accent: #e2764f;
    --color-accent-hover: #ef8a63;
    --color-accent-contrast: #1b1a17;
    --scrim: rgba(10, 9, 7, 0.6);
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --color-bg: #1b1a17;
        --color-surface: rgba(27, 25, 22, 0.82);
        --color-surface-solid: #24221e;
        --color-text: #f2efe9;
        --color-text-muted: #c9c3b6;
        --color-border: rgba(242, 239, 233, 0.14);
        --color-accent: #e2764f;
        --color-accent-hover: #ef8a63;
        --color-accent-contrast: #1b1a17;
        --scrim: rgba(10, 9, 7, 0.6);
        --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body {
    font-family: var(--font);
    color: var(--color-text);
    background-color: var(--color-bg);
    background-image: linear-gradient(var(--scrim), var(--scrim)), url('../images/background.jpg');
    background-repeat: no-repeat;
    background-position: center center;
    background-attachment: fixed;
    background-size: cover;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

a { color: var(--color-accent); }
a:hover { color: var(--color-accent-hover); }

.wrap {
    width: 100%;
    max-width: 880px;
    margin: 0 auto;
    padding: 0 16px;
}

.wrap-wide { max-width: 1180px; }

.home-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
    align-items: start;
    width: 100vw;
    margin-left: calc(50% - 50vw);
    margin-right: calc(50% - 50vw);
    padding: 0 24px;
    box-sizing: border-box;
}

@media (min-width: 1100px) {
    .home-layout { grid-template-columns: 1fr 640px 1fr; padding: 0 32px; }
}

.home-main { width: 100%; order: 1; }
.home-side { width: 100%; }
.quote-of-day { order: 2; }
.word-of-day { order: 3; }

@media (min-width: 1100px) {
    .quote-of-day { order: 1; }
    .home-main { order: 2; }
    .word-of-day { order: 3; }
}

.home-side.card, .home-main.card { margin-bottom: 0; }

header.site-header {
    padding: 18px 0;
}

.site-header .wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.brand {
    color: var(--color-accent-contrast, #fff);
    font-weight: 700;
    font-size: 1.15rem;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand, .site-header nav a, .background-toggle, .theme-toggle {
    color: #fff;
    text-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

.site-header nav {
    display: flex;
    gap: 16px;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
}

.site-header nav a { text-decoration: none; font-size: 0.95rem; }
.site-header nav a:hover { text-decoration: underline; }

.background-toggle,
.theme-toggle {
    background: rgba(255,255,255,0.15);
    border: 1px solid rgba(255,255,255,0.35);
    border-radius: 999px;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 0.9rem;
}

@media (max-width: 639px) {
    .site-header .wrap {
        flex-direction: column;
        justify-content: center;
    }

    .site-header .brand {
        justify-content: center;
        text-align: center;
    }

    /* 6 columns: 3 links in row 1, 2 centered links in row 2, toggles in row 3 */
    .site-header nav {
        display: grid;
        grid-template-columns: repeat(6, max-content);
        justify-content: center;
        gap: 12px 7px;
        width: 100%;
    }

    .site-header nav a {
        grid-column: span 2;
        justify-self: center;
        white-space: nowrap;
        font-size: 0.85rem;
    }

    .site-header nav a:nth-of-type(4) { grid-column: 2 / span 2; }
    .site-header nav a:nth-of-type(5) { grid-column: 4 / span 2; }

    .background-toggle {
        grid-column: 2 / span 2;
        grid-row: 3;
        justify-self: center;
    }

    .theme-toggle {
        grid-column: 4 / span 2;
        grid-row: 3;
        justify-self: center;
    }
}

.background-toggle:hover,
.background-toggle[aria-pressed="true"],
.theme-toggle:hover {
    background: rgba(255,255,255,0.3);
}

main {
    flex: 1;
    padding: 24px 0 60px;
    opacity: 1;
    visibility: visible;
    transition: opacity 250ms ease, visibility 250ms ease;
}

body.background-view main {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

@media (prefers-reduced-motion: reduce) {
    main { transition: none; }
}

.card {
    background: var(--color-surface);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
    margin-bottom: 24px;
}

.card-narrow { max-width: 640px; margin-left: auto; margin-right: auto; }

.hero { text-align: center; padding: 40px 28px; }
.hero h1 { margin: 0 0 8px; font-size: clamp(1.6rem, 4vw, 2rem); }
.hero p.lead { color: var(--color-text-muted); margin: 0; }

.search-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-top: 24px;
}

@media (min-width: 640px) {
    .search-grid { grid-template-columns: 1fr 1fr; }
}

.field { position: relative; text-align: left; }
.field label {
    display: block;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    margin-bottom: 6px;
}

.field input[type="text"], .field input[type="email"], .field select, .field textarea {
    width: 100%;
    padding: 12px 14px;
    border-radius: 10px;
    border: 1px solid var(--color-border);
    background: var(--color-surface-solid);
    color: var(--color-text);
    font-size: 1rem;
}

.field input:focus, .field select:focus, .field textarea:focus {
    outline: 2px solid var(--color-accent);
    outline-offset: 1px;
}

.autocomplete-list {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    background: var(--color-surface-solid);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    box-shadow: var(--shadow);
    max-height: 320px;
    overflow-y: auto;
    z-index: 20;
    display: none;
}

.autocomplete-list.open { display: block; }

.autocomplete-list button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px 14px;
    background: none;
    border: none;
    color: var(--color-text);
    cursor: pointer;
    font-size: 0.95rem;
}

.autocomplete-list button:hover,
.autocomplete-list button.active {
    background: var(--color-accent);
    color: var(--color-accent-contrast);
}

.autocomplete-list .pos-tag { color: var(--color-text-muted); font-size: 0.8rem; }
.autocomplete-list button:hover .pos-tag,
.autocomplete-list button.active .pos-tag { color: inherit; opacity: 0.85; }

.btn {
    display: inline-block;
    background: var(--color-accent);
    color: var(--color-accent-contrast);
    border: none;
    padding: 11px 20px;
    border-radius: 10px;
    font-size: 0.95rem;
    cursor: pointer;
    text-decoration: none;
    font-weight: 600;
}

.btn:hover { background: var(--color-accent-hover); color: var(--color-accent-contrast); }
.btn.secondary { background: transparent; color: var(--color-text); border: 1px solid var(--color-border); }
.btn.danger { background: var(--color-danger); }
.btn.small { padding: 6px 12px; font-size: 0.85rem; }

.card.quote-of-day,
.card.word-of-day {
    background: transparent;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    border: none;
    box-shadow: none;
    color: #fff;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
}

.quote-of-day strong,
.word-of-day strong { color: #fff; }

.word-of-day .pos-tag { color: rgba(255, 255, 255, 0.85); }

.quote-of-day cite { display: block; color: rgba(255, 255, 255, 0.85); margin-top: 6px; font-style: normal; }
.quote-of-day p.explanation { margin-top: 14px; color: rgba(255, 255, 255, 0.85); }

.quote-of-day p.quote-category { margin: 14px 0 0; font-size: 0.85rem; color: rgba(255, 255, 255, 0.85); }
.quote-of-day p.permalink,
.word-of-day p.permalink { margin: 16px 0 0; font-size: 0.8rem; }
.quote-of-day p.permalink a,
.word-of-day p.permalink a { color: #fff; }

.section-title {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 14px;
}

.section-title h2 { margin: 0; font-size: 1.2rem; }
.section-title a { font-size: 0.9rem; }

.category-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 999px;
    background: var(--color-surface-solid);
    border: 1px solid var(--color-border);
    text-decoration: none;
    color: var(--color-text);
    font-size: 0.88rem;
}
.chip:hover { border-color: var(--color-accent); color: var(--color-accent); }

table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td {
    text-align: left;
    padding: 10px 8px;
    border-bottom: 1px solid var(--color-border);
    font-size: 0.92rem;
}
table.list th { color: var(--color-text-muted); font-weight: 600; }

.word-detail h1 { margin: 0 0 4px; }
.word-detail .pos { color: var(--color-text-muted); font-style: italic; margin-bottom: 16px; }
.word-detail .translation { font-size: 1.4rem; color: var(--color-accent); margin: 8px 0; }
.word-detail .notes { margin-top: 16px; color: var(--color-text-muted); }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 16px; text-align: center; }
.stat { padding: 16px; border-radius: 10px; background: var(--color-surface-solid); border: 1px solid var(--color-border); }
.stat .value { font-size: 1.8rem; font-weight: 700; color: var(--color-accent); }
.stat .label { color: var(--color-text-muted); font-size: 0.85rem; }

footer.site-footer {
    text-align: center;
    padding: 20px;
    color: #fff;
    text-shadow: 0 1px 4px rgba(0,0,0,0.4);
    font-size: 0.85rem;
}
footer.site-footer a { color: #fff; text-decoration: underline; }

@media (max-width: 639px) {
    footer.site-footer .footer-line {
        display: block;
    }

    footer.site-footer .footer-separator {
        display: none;
    }
}

.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 0.92rem; }
.alert.success { background: rgba(46, 125, 79, 0.15); border: 1px solid var(--color-success); color: var(--color-success); }
.alert.error { background: rgba(179, 38, 30, 0.15); border: 1px solid var(--color-danger); color: var(--color-danger); }

.form-row { margin-bottom: 16px; }
.form-row label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 0.9rem; }
.help-text { color: var(--color-text-muted); font-size: 0.82rem; margin-top: 4px; }

.empty-state { text-align: center; color: var(--color-text-muted); padding: 24px; }

.grammar { scroll-margin-top: 16px; }
.grammar-lead { margin: 0 0 4px; }
.grammar-source { margin: 0 0 18px; color: var(--color-text-muted); font-size: 0.88rem; }
.grammar h3 { margin: 22px 0 6px; font-size: 1rem; }
.grammar .section-title + h3 { margin-top: 0; }
.grammar table.list td.dialect { font-weight: 600; color: var(--color-accent); }
.grammar table.list td.note,
.grammar table.list span.note { color: var(--color-text-muted); font-size: 0.82rem; }
.grammar table.list span.note { display: block; font-weight: 400; }
.grammar table.list tr.group th {
    padding-top: 18px;
    color: var(--color-text);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.78rem;
}
.grammar table.list tbody:first-of-type tr.group th { padding-top: 10px; }
.grammar-note { color: var(--color-text-muted); font-size: 0.9rem; margin: 14px 0 0; }

