:root {
  /* Material 3 color roles — tonal palette seeded from the dictionary's
     terracotta brand hue, hand-derived (not run through the HCT algorithm). */
  --md-primary: #8f4c38;
  --md-on-primary: #ffffff;
  --md-primary-container: #ffdbce;
  --md-on-primary-container: #39170a;

  --md-secondary-container: #f6ded4;
  --md-on-secondary-container: #2c160c;

  --md-tertiary-container: #efe3aa;
  --md-on-tertiary-container: #201c02;

  --md-surface: #fff8f6;
  --md-on-surface: #22190f;
  --md-on-surface-variant: #53433c;
  --md-outline: #85736b;
  --md-outline-variant: #d8c2b8;

  --md-surface-container-lowest: #ffffff;
  --md-surface-container-low: #fff1ed;
  --md-surface-container: #fceae4;
  --md-surface-container-high: #f7e4de;
  --md-surface-container-highest: #f1ded8;

  --md-inverse-surface: #392e27;
  --md-inverse-on-surface: #ffede6;

  --md-sans: "Roboto", "Noto Sans Ethiopic", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --md-ge: "Noto Sans Ethiopic", "Roboto", sans-serif;

  --shape-sm: 8px;
  --shape-md: 12px;
  --shape-lg: 16px;
  --shape-xl: 28px;
  --shape-full: 999px;

  --elevation-1: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px 1px rgba(0, 0, 0, 0.12);
  --elevation-2: 0 1px 2px rgba(0, 0, 0, 0.3), 0 2px 6px 2px rgba(0, 0, 0, 0.1);
  --elevation-3: 0 1px 3px rgba(0, 0, 0, 0.3), 0 4px 8px 3px rgba(0, 0, 0, 0.1);

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --md-primary: #ffb59c;
    --md-on-primary: #5c1d0b;
    --md-primary-container: #74331f;
    --md-on-primary-container: #ffdbce;

    --md-secondary-container: #5b4034;
    --md-on-secondary-container: #ffdbce;

    --md-tertiary-container: #4e461c;
    --md-on-tertiary-container: #efe3aa;

    --md-surface: #19120d;
    --md-on-surface: #f1ded8;
    --md-on-surface-variant: #d8c2b8;
    --md-outline: #a08d84;
    --md-outline-variant: #53433c;

    --md-surface-container-lowest: #120d09;
    --md-surface-container-low: #221a14;
    --md-surface-container: #261d17;
    --md-surface-container-high: #312722;
    --md-surface-container-highest: #3d322c;

    --md-inverse-surface: #f1ded8;
    --md-inverse-on-surface: #392e27;
  }
}

:root[data-theme="dark"] {
  --md-primary: #ffb59c;
  --md-on-primary: #5c1d0b;
  --md-primary-container: #74331f;
  --md-on-primary-container: #ffdbce;

  --md-secondary-container: #5b4034;
  --md-on-secondary-container: #ffdbce;

  --md-tertiary-container: #4e461c;
  --md-on-tertiary-container: #efe3aa;

  --md-surface: #19120d;
  --md-on-surface: #f1ded8;
  --md-on-surface-variant: #d8c2b8;
  --md-outline: #a08d84;
  --md-outline-variant: #53433c;

  --md-surface-container-lowest: #120d09;
  --md-surface-container-low: #221a14;
  --md-surface-container: #261d17;
  --md-surface-container-high: #312722;
  --md-surface-container-highest: #3d322c;

  --md-inverse-surface: #f1ded8;
  --md-inverse-on-surface: #392e27;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  overflow-x: hidden;
}

body {
  margin: 0;
  font-family: var(--md-sans);
  background: var(--md-surface);
  color: var(--md-on-surface);
  padding-bottom: calc(var(--safe-bottom) + 1rem);
}

.material-symbols-outlined {
  font-variation-settings: "OPSZ" 24, "wght" 400, "FILL" 0, "GRAD" 0;
  font-size: 20px;
  line-height: 1;
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--md-surface);
  padding: calc(var(--safe-top) + 0.9rem) 1rem 0.8rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.top-bar h1 {
  margin: 0;
  font-family: var(--md-ge);
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  flex: 0 0 auto;
  color: var(--md-on-surface);
}

.search-bar {
  position: relative;
  flex: 1 1 220px;
  display: flex;
  align-items: center;
  min-width: 0;
}

.search-icon {
  position: absolute;
  left: 1rem;
  color: var(--md-on-surface-variant);
  pointer-events: none;
}

#search-input {
  width: 100%;
  font-family: var(--md-sans);
  font-size: 16px;
  padding: 0.85rem 2.75rem 0.85rem 2.9rem;
  border: none;
  border-radius: var(--shape-xl);
  outline: none;
  background: var(--md-surface-container-high);
  color: var(--md-on-surface);
  box-shadow: var(--elevation-2);
  transition: box-shadow 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}

#search-input::placeholder {
  color: var(--md-on-surface-variant);
}

#search-input::-webkit-search-cancel-button {
  -webkit-appearance: none;
}

#search-input:focus {
  box-shadow: var(--elevation-3);
}

.clear-btn {
  position: absolute;
  right: 0.4rem;
  width: 2.2rem;
  height: 2.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--md-on-surface-variant);
  cursor: pointer;
  touch-action: manipulation;
  position: relative;
  overflow: hidden;
}

.clear-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  background: currentColor;
  opacity: 0;
  transition: opacity 0.1s ease;
}

.clear-btn:hover::before {
  opacity: 0.08;
}

.clear-btn:active::before {
  opacity: 0.12;
}

.badge {
  flex: 0 0 auto;
  font-family: var(--md-sans);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  padding: 0.35rem 0.75rem;
  border-radius: var(--shape-full);
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

main {
  max-width: 980px;
  margin: 0 auto;
  padding: 0 1rem;
  display: flex;
  align-items: flex-start;
  gap: 2rem;
}

.content {
  flex: 1 1 auto;
  min-width: 0;
}

.status {
  margin-top: 1rem;
  color: var(--md-on-surface-variant);
  font-size: 0.9rem;
}

.empty-state {
  text-align: center;
  color: var(--md-on-surface-variant);
  padding: 2.5rem 0.5rem 1rem;
}

.empty-state p {
  margin: 0 0 1.1rem;
  font-size: 0.9rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.chip {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--md-outline-variant);
  background: var(--md-surface-container-lowest);
  color: var(--md-on-surface-variant);
  padding: 0.5rem 1rem;
  border-radius: var(--shape-sm);
  font-family: var(--md-ge);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
}

.chip::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--md-on-surface);
  opacity: 0;
  transition: opacity 0.1s ease;
}

.chip:hover::before {
  opacity: 0.08;
}

.chip:active::before {
  opacity: 0.12;
}

/* Jump sidebar (desktop only) — M3 navigation-rail style active indicator */
.jump-nav {
  flex: 0 0 220px;
  position: sticky;
  top: calc(var(--safe-top) + 5.2rem);
  max-height: calc(100vh - var(--safe-top) - 6rem);
  overflow-y: auto;
  padding: 1.1rem 0 1rem;
}

.jump-nav-title {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--md-on-surface-variant);
  margin: 0 0 0.6rem 1rem;
}

.jump-link {
  position: relative;
  overflow: hidden;
  display: block;
  width: calc(100% - 0.6rem);
  margin: 0.15rem 0.3rem;
  text-align: left;
  background: none;
  border: none;
  padding: 0.5rem 1rem;
  font-family: var(--md-ge);
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--md-on-surface);
  cursor: pointer;
  border-radius: var(--shape-full);
}

.jump-link::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--md-on-surface);
  opacity: 0;
  transition: opacity 0.1s ease, background-color 0.15s ease;
}

.jump-link:hover::before {
  opacity: 0.08;
}

.jump-link.active {
  background: var(--md-secondary-container);
  color: var(--md-on-secondary-container);
  font-weight: 600;
}

.jump-link.active::before {
  background: var(--md-on-secondary-container);
}

.results {
  list-style: none;
  margin: 1.1rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scroll-margin-top: calc(var(--safe-top) + 5rem);
}

.entry-card {
  background: var(--md-surface-container-low);
  border-radius: var(--shape-lg);
  padding: 1.25rem 1.4rem;
  scroll-margin-top: calc(var(--safe-top) + 5rem);
}

.entry-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.3rem;
}

.entry-word {
  font-family: var(--md-ge);
  font-size: clamp(1.3rem, 4.5vw, 1.75rem);
  font-weight: 600;
  overflow-wrap: anywhere;
  color: var(--md-on-surface);
}

.entry-pos {
  font-family: var(--md-sans);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--md-on-tertiary-container);
  background: var(--md-tertiary-container);
  border-radius: var(--shape-full);
  padding: 0.2rem 0.65rem;
}

.entry-pronunc {
  display: inline-block;
  color: var(--md-on-surface-variant);
  font-size: 0.85rem;
  background: var(--md-surface-container-high);
  border-radius: var(--shape-full);
  padding: 0.2rem 0.7rem;
  overflow-wrap: anywhere;
  margin-bottom: 0.6rem;
}

.entry-support {
  color: var(--md-on-surface-variant);
  font-size: 0.88rem;
  margin-bottom: 0.4rem;
}

.entry-def {
  font-family: var(--md-ge);
  font-size: clamp(1.02rem, 3.6vw, 1.2rem);
  line-height: 1.7;
  color: var(--md-on-surface);
}

.entry-def p {
  margin: 0 0 0.6rem;
  overflow-wrap: anywhere;
}

.entry-def ol {
  margin: 0;
  padding-left: 1.4rem;
}

.entry-def ol li {
  margin: 0 0 0.6rem;
  padding-left: 0.3rem;
  overflow-wrap: anywhere;
}

.entry-def ol li::marker {
  font-weight: 600;
  color: var(--md-primary);
}

.entry-def p:last-child,
.entry-def ol li:last-child {
  margin-bottom: 0;
}

.entry-def mark,
.entry-word mark {
  background: var(--md-primary-container);
  color: var(--md-on-primary-container);
  border-radius: var(--shape-sm);
  padding: 0 0.15em;
}

.subentries {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--md-outline-variant);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}

.subentries-title {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--md-on-surface-variant);
  margin: 0 0 0.3rem;
}

.subentry {
  padding: 0.75rem 0.9rem;
  border-radius: var(--shape-md);
  background: var(--md-surface-container);
}

.subentry .entry-word {
  font-size: clamp(1.05rem, 3.8vw, 1.15rem);
}

.subentry .entry-def {
  font-size: clamp(0.98rem, 3.4vw, 1.1rem);
}

@media (min-width: 560px) {
  .top-bar {
    padding-top: calc(var(--safe-top) + 1.1rem);
    padding-bottom: 1rem;
  }

  .top-bar h1 {
    font-size: 1.3rem;
  }
}

@media (max-width: 760px) {
  .jump-nav {
    display: none;
  }
}
