:root {
  color-scheme: light;
  --accent: #be1622;
  --accent-dark: #8f1019;
  --ink: #111111;
  --muted: #5f5a58;
  --line: #e7e1de;
  --paper: #ffffff;
  --wash: #faf8f6;
  --radius: 8px;
  --shadow: 0 14px 34px rgb(0 0 0 / 8%);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--paper); color: var(--ink); scroll-behavior: smooth; }
body { margin: 0; min-height: 100vh; }
body.dialog-open { overflow: hidden; }
button, input, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.skip-link { position: fixed; z-index: 20; top: 12px; left: 12px; padding: 12px 16px; background: var(--accent); color: white; transform: translateY(-150%); }
.skip-link:focus { transform: none; }
.app-shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 32px 0 56px; }
.topbar { display: grid; grid-template-columns: minmax(88px, 132px) 1fr; gap: 28px; align-items: center; padding-bottom: 25px; border-bottom: 4px solid var(--accent); }
.brand-logo { display: block; width: 100%; height: auto; }
h1 { margin: 0; color: var(--accent); font-size: clamp(2.35rem, 6vw, 5rem); line-height: .93; font-weight: 950; letter-spacing: -.045em; }
.title-block p { margin: 10px 0 0; font-size: clamp(1rem, 1.5vw, 1.3rem); font-weight: 650; }

.filters { display: grid; grid-template-columns: minmax(280px, 2fr) repeat(2, minmax(170px, 1fr)); gap: 14px; align-items: end; margin: 26px 0; padding: 22px; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); background: var(--paper); }
.filters label { display: grid; gap: 7px; color: var(--muted); font-size: .9rem; font-weight: 750; }
input, select { width: 100%; min-height: 48px; padding: 10px 12px; border: 1px solid #d9d2cf; border-radius: var(--radius); background: white; color: var(--ink); outline: none; }
input:focus, select:focus, button:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 4px rgb(190 22 34 / 16%); outline: none; }
.filter-actions { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 10px; }
.primary-button, .quiet-button, .load-more, .active-filter { min-height: 46px; padding: 10px 16px; border-radius: var(--radius); font-weight: 800; }
.primary-button { border: 1px solid var(--accent); background: var(--accent); color: white; }
.primary-button:hover { background: var(--accent-dark); }
.quiet-button, .load-more { border: 1px solid var(--line); background: white; color: var(--ink); }
.quiet-button:hover, .load-more:hover { border-color: var(--accent); color: var(--accent); }

.tag-section, .results-section { margin-top: 34px; }
.section-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; margin-bottom: 16px; }
.section-heading h2 { margin: 0; color: var(--ink); font-size: clamp(1.8rem, 3vw, 2.8rem); letter-spacing: -.03em; }
.eyebrow { margin: 0 0 5px; color: var(--accent); font-size: .76rem; font-weight: 900; letter-spacing: .14em; text-transform: uppercase; }
.active-filter { border: 1px solid var(--accent); background: rgb(190 22 34 / 7%); color: var(--accent); }

.tag-cloud { display: flex; flex-wrap: wrap; align-content: center; justify-content: center; column-gap: clamp(12px, 2vw, 28px); row-gap: clamp(5px, 1vw, 12px); min-height: 250px; padding: clamp(18px, 3vw, 34px); border: 1px solid var(--line); border-radius: var(--radius); background: var(--wash); overflow: hidden; }
.tag-chip { --size: 1rem; display: inline-flex; align-items: center; min-height: 36px; max-width: 100%; padding: .15em .08em; border: 0; border-radius: 0; background: transparent; color: var(--ink); font-size: var(--size); font-weight: 760; line-height: 1.05; white-space: nowrap; transition: color 160ms, transform 160ms, text-decoration-color 160ms; }
.tag-chip:nth-child(4n + 1) { transform: translateY(-5px); }
.tag-chip:nth-child(5n + 2) { transform: translateY(6px); }
.tag-chip:hover, .tag-chip:focus-visible { position: relative; z-index: 1; color: var(--accent); transform: scale(1.06); }
.tag-chip.is-active { color: var(--accent); font-weight: 950; text-decoration: underline 3px; text-underline-offset: 5px; }
.all-tags-button { display: block; min-height: 48px; margin: 18px auto 0; padding: 10px 22px; border: 1px solid var(--accent); border-radius: var(--radius); background: var(--accent); color: white; font-weight: 850; }
.all-tags-button:hover { background: var(--accent-dark); }

.tags-dialog { width: min(1040px, calc(100% - 28px)); max-height: calc(100dvh - 28px); padding: 0; border: 0; border-radius: var(--radius); box-shadow: 0 24px 70px rgb(0 0 0 / 25%); }
.tags-dialog::backdrop { background: rgb(0 0 0 / 55%); backdrop-filter: blur(3px); }
.tags-dialog-shell { position: relative; min-height: 420px; padding: clamp(25px, 4vw, 46px); }
.tags-dialog h2 { max-width: calc(100% - 60px); margin: 4px 0 8px; color: var(--ink); font-size: clamp(2rem, 4vw, 3.4rem); letter-spacing: -.035em; }
.tags-dialog-context { margin: 0 0 22px; color: var(--muted); }
.tag-search { display: grid; gap: 7px; max-width: 520px; color: var(--muted); font-size: .9rem; font-weight: 750; }
.tags-count { margin: 14px 0 22px; color: var(--muted); font-size: .9rem; font-weight: 700; }
.tag-groups { columns: 4 190px; column-gap: 38px; }
.tag-letter-group { break-inside: avoid; margin: 0 0 26px; }
.tag-letter-group h3 { margin: 0 0 6px; padding-bottom: 5px; border-bottom: 2px solid var(--accent); color: var(--accent); font-size: 1.35rem; }
.tag-letter-list { display: grid; }
.all-tag-link { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: baseline; min-height: 38px; padding: 7px 2px; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--ink); text-align: left; }
.all-tag-link:hover, .all-tag-link:focus-visible { color: var(--accent); }
.all-tag-link.is-active span { color: var(--accent); font-weight: 900; text-decoration: underline 2px; text-underline-offset: 3px; }
.all-tag-link small { color: var(--muted); font-size: .72rem; font-weight: 750; }
.empty-tags { column-span: all; color: var(--muted); }

.result-count, .source-status { color: var(--muted); }
.result-count { margin: 0; font-weight: 750; }
.result-list { display: grid; border-top: 1px solid var(--line); }
.proverb-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 18px; align-items: center; width: 100%; padding: 18px 6px; border: 0; border-bottom: 1px solid var(--line); background: white; color: var(--ink); text-align: left; }
.proverb-row:hover { background: var(--wash); }
.row-text { display: grid; gap: 5px; min-width: 0; }
.row-text strong { font-size: 1.12rem; line-height: 1.3; }
.translation-preview { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.audio-mark { width: 10px; height: 10px; overflow: hidden; border-radius: 50%; color: var(--accent); font-size: 12px; }
.audio-mark[hidden] { display: none; }
.row-arrow { color: var(--accent); font-size: 1.35rem; transition: transform 150ms; }
.proverb-row:hover .row-arrow { transform: translateX(4px); }
.load-more { display: block; margin: 22px auto 0; }

.detail-dialog { width: min(760px, calc(100% - 28px)); max-height: calc(100dvh - 28px); padding: 0; border: 0; border-radius: var(--radius); box-shadow: 0 24px 70px rgb(0 0 0 / 25%); }
.detail-dialog::backdrop { background: rgb(0 0 0 / 55%); backdrop-filter: blur(3px); }
.detail-card { position: relative; padding: clamp(25px, 5vw, 54px); }
.detail-card > h2 { max-width: 92%; margin: 5px 0 30px; color: var(--accent); font-size: clamp(2rem, 5vw, 3.5rem); line-height: 1.08; letter-spacing: -.035em; }
.detail-card h3 { margin: 24px 0 7px; font-size: .78rem; letter-spacing: .1em; text-transform: uppercase; }
.detail-card p { font-size: 1.08rem; line-height: 1.65; }
.detail-close { position: absolute; top: 16px; right: 16px; width: 46px; height: 46px; border: 0; border-radius: 50%; background: var(--ink); color: white; font-size: 1.6rem; }
.audio-section audio { width: 100%; margin-top: 20px; accent-color: var(--accent); }
.detail-tags { display: flex; flex-wrap: wrap; gap: 8px; }
.detail-tag { min-height: 40px; padding: 8px 13px; border: 1px solid var(--accent); border-radius: 999px; background: white; color: var(--accent); font-weight: 800; }
.source-status { margin: 28px 0 0; text-align: center; font-size: .85rem; }
.source-status.error { color: var(--accent); }

@media (max-width: 800px) {
  .filters { grid-template-columns: 1fr 1fr; }
  .search-field { grid-column: 1 / -1; }
  .tag-cloud { min-height: 230px; }
  .tag-groups { columns: 3 170px; }
}

@media (max-width: 580px) {
  .app-shell { width: min(100% - 22px, 1180px); padding-top: 18px; }
  .topbar { grid-template-columns: 78px 1fr; gap: 15px; }
  h1 { font-size: clamp(2rem, 11vw, 3.2rem); }
  .title-block p { font-size: .93rem; }
  .filters { grid-template-columns: 1fr; padding: 16px; }
  .search-field { grid-column: auto; }
  .filter-actions { flex-direction: column; }
  .filter-actions button { width: 100%; }
  .section-heading { align-items: start; flex-direction: column; }
  .tag-cloud { justify-content: center; column-gap: 15px; row-gap: 4px; min-height: 210px; padding: 16px 12px; }
  .tag-chip { --size: 1rem !important; min-height: 42px; white-space: normal; overflow-wrap: anywhere; text-align: center; }
  .proverb-row { grid-template-columns: minmax(0, 1fr) auto; }
  .audio-mark { display: none; }
  .detail-dialog { width: 100vw; max-width: none; height: 100dvh; max-height: none; margin: 0; border-radius: 0; }
  .detail-card { min-height: 100%; padding: 82px 20px 42px; }
  .detail-card > h2 { max-width: 100%; margin-top: 8px; }
  .detail-card .detail-close { top: 18px; right: 18px; }
  .tags-dialog { width: 100vw; max-width: none; height: 100dvh; max-height: none; margin: 0; border-radius: 0; }
  .tags-dialog-shell { min-height: 100%; padding: 28px 18px 42px; }
  .tag-groups { columns: 2 140px; column-gap: 24px; }
}

@media (max-width: 380px) {
  .tag-groups { columns: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
  .tag-chip { transform: none !important; }
}
