:root {
  --fg: #1a1a1a;
  --muted: #5b5b5b;
  --bg: #fafafa;
  --card: #ffffff;
  --border: #e3e3e3;
  --accent: #0b5fff;
  --chip-bg: #eef2ff;
  --chip-fg: #243a8e;
  --stripe: #f5f7fa;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--card);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.topbar-logo {
  height: 1.75rem;
  width: auto;
  display: block;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  margin-left: auto;
}

.tabs a {
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
}

.tabs a:hover {
  background: var(--stripe);
  color: var(--fg);
}

.tabs a.active {
  background: var(--chip-bg);
  color: var(--chip-fg);
}

.tabs a.external {
  color: var(--muted);
}

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

.panel[hidden] {
  display: none;
}

#search-form,
#english-form,
#frequency-form,
#lemma-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

#search-input,
#english-input,
#frequency-input,
#lemma-input {
  flex: 1;
  padding: 0.55rem 0.75rem;
  font-size: 1.05rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
}

#search-input:focus,
#english-input:focus,
#frequency-input:focus,
#lemma-input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

button {
  padding: 0.55rem 1rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 6px;
  cursor: pointer;
}

button:hover {
  background: var(--stripe);
}

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

.status {
  color: var(--muted);
  font-size: 0.9rem;
  min-height: 1.2em;
  margin-bottom: 0.5rem;
}

.status.error {
  color: #b00020;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem 1.1rem;
  margin-bottom: 0.9rem;
}

.card-head {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-bottom: 0.4rem;
}

.card-head .lemma {
  font-size: 1.4rem;
  font-weight: 600;
}

.card-head .pos {
  color: var(--muted);
  font-style: italic;
  font-size: 0.95rem;
}

.summary {
  margin: 0.25rem 0 0.5rem;
}

.summary .ua {
  font-weight: 500;
}

.summary .en {
  color: var(--muted);
}

.glosses {
  margin: 0.25rem 0 0.75rem 1.1rem;
  padding: 0;
}

.glosses li {
  margin-bottom: 0.15rem;
}

.glosses .en {
  color: var(--muted);
}

mark {
  background: #fff9c0;
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

.section-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 0.75rem 0 0.35rem;
}

.forms-section,
.examples-section,
.morphemes-section {
  margin-top: 0.5rem;
}

.form-unmatched,
.form-unmatched .ua,
.form-unmatched .en {
  color: #aaaaaa;
}

.forms-section > summary.section-label,
.examples-section > summary.section-label,
.morphemes-section > summary.section-label {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  user-select: none;
}

.forms-section > summary.section-label::before,
.examples-section > summary.section-label::before,
.morphemes-section > summary.section-label::before {
  content: "\25B6";
  font-size: 0.6rem;
  transition: transform 0.15s ease;
  display: inline-block;
}

.forms-section[open] > summary.section-label::before,
.examples-section[open] > summary.section-label::before,
.morphemes-section[open] > summary.section-label::before {
  transform: rotate(90deg);
}

.examples-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.35rem;
}

.example {
  padding: 0.4rem 0.6rem;
  border-left: 2px solid var(--border);
}

.example .ua {
  font-weight: 500;
}

.example .en {
  color: var(--muted);
  font-size: 0.9rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.chip {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  background: var(--chip-bg);
  color: var(--chip-fg);
  border-radius: 999px;
  font-size: 0.8rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

th,
td {
  text-align: left;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--muted);
  background: var(--stripe);
}

tbody tr:nth-child(even) {
  background: var(--stripe);
}

td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.corpus-list {
  display: grid;
  gap: 0.5rem;
}

.corpus-row {
  display: flex;
  gap: 0.75rem;
  align-items: baseline;
  padding: 0.6rem 0.8rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  color: inherit;
}

.corpus-row:hover {
  border-color: var(--accent);
}

.corpus-row .name {
  font-weight: 600;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.corpus-row .meta {
  color: var(--muted);
  font-size: 0.9rem;
  margin-left: auto;
}

.corpus-head {
  margin-bottom: 1rem;
}

.corpus-head h2 {
  margin: 0 0 0.2rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.3rem;
}

.corpus-head .meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.pager {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin: 0.75rem 0;
}

.pager .spacer {
  flex: 1;
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
}

.back {
  display: inline-block;
  margin-bottom: 0.75rem;
  color: var(--muted);
  text-decoration: none;
}

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

.empty {
  color: var(--muted);
  font-style: italic;
  padding: 1rem 0;
}

.site-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.5rem;
  padding: 0.9rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--stripe);
  color: var(--muted);
  font-size: 0.85rem;
}

.site-footer > a {
  display: inline-flex;
  line-height: 0;
}

.site-footer img {
  width: 16px;
  height: 16px;
  opacity: 0.5;
  transition: opacity 0.15s ease;
}

.site-footer > a:hover img {
  opacity: 1;
}

.site-footer .crosslink {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: #a0a0a0;
}

.site-footer .sep {
  color: var(--border);
}

.site-footer .crosslink a {
  color: inherit;
  text-decoration: underline;
  transition: color 0.15s ease;
}

.site-footer .crosslink a:hover {
  color: var(--muted);
}

.morpheme-type {
  font-size: 0.75rem;
}

.morpheme-type-root     { background: #e8f4e8; color: #1a5c1a; }
.morpheme-type-prefix   { background: #fde8e8; color: #8b1a1a; }
.morpheme-type-suffix   { background: #e8eef8; color: #1a3a8b; }
.morpheme-type-interfix { background: #fef4e0; color: #7a4500; }

.morpheme-loading {
  color: var(--muted);
  font-size: 0.9rem;
  padding: 0.35rem 0;
}

.morpheme-detail .morpheme-origin {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

.morpheme-detail .morpheme-variants {
  margin-top: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.morpheme-words-label {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin: 1rem 0 0.35rem;
}

.muted {
  color: var(--muted);
}
