/* The native select still opens the platform picker. Reserve a separate
   gutter for its visible chevron in every view of the offline app. */
:root select:not([multiple]):not([size]) {
  -webkit-appearance: none;
  appearance: none;
  min-inline-size: 0;
  max-inline-size: 100%;
  min-block-size: 44px;
  margin: 0;
  padding: .5em 2.45em .5em .8em;
  border: 1px solid #bdb29f;
  border-radius: 7px;
  color: var(--ink);
  background-color: #fffcf5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 14 14'%3E%3Cpath d='m2.5 5 4.5 4.5L11.5 5' fill='none' stroke='%23675d4d' stroke-width='1.65' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right .8em center;
  background-size: 14px 14px;
  font: 400 15px/1.4 var(--sans);
  cursor: pointer;
}

.study-filters {
  display: grid;
  grid-template-columns: minmax(0, 2fr) repeat(2, minmax(0, 1fr));
  gap: 12px 16px;
  padding-bottom: 18px;
}

.study-settings-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 9.25rem), 1fr));
  gap: 12px;
}

.study-field {
  min-inline-size: 0;
  gap: 6px;
}

.study-field > :is(input, select) {
  width: 100%;
}

.study-root .study-field > input:not([type=checkbox]):not([type=file]) {
  width: 100%;
  min-height: 44px;
  margin: 0;
  padding-inline: .8em;
  border-color: #bdb29f;
  border-radius: 7px;
  background-color: #fffcf5;
}

.catalog-search {
  min-height: 44px;
  padding-inline: 12px;
}

.catalog-filters {
  display: grid;
  grid-template-columns: repeat(4,minmax(0,1fr));
  gap: 8px;
  margin: 12px 0 5px;
  align-items: end;
}
.catalog { block-size: min(82dvh,740px); }
.catalog-results { flex: 1; }
.catalog-multi {
  --picker-bg: #fffcf5;
  --picker-line: #bdb29f;
  position: relative;
  min-width: 0;
}
[data-theme="space"] .catalog-multi { --picker-bg: #142136; --picker-line: #3d4f68; }
.catalog-multi summary {
  display: flex; align-items: center; gap: 5px;
  min-height: 44px; padding: .5em .75em;
  border: 1px solid var(--picker-line); border-radius: 7px;
  background: var(--picker-bg); color: var(--ink);
  font: 400 15px/1.4 var(--sans); list-style: none; cursor: pointer;
}
.catalog-multi summary::-webkit-details-marker { display: none; }
.catalog-multi summary::after {
  content: ""; flex: none; width: 7px; height: 7px; margin: -3px 2px 0 auto;
  border: solid var(--soft); border-width: 0 1.6px 1.6px 0; transform: rotate(45deg);
}
.catalog-multi[open] summary::after { transform: rotate(225deg); margin-top: 3px; }
.catalog-multi summary > span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.catalog-multi[data-active] summary { color: var(--red-dark); border-color: var(--red-dark); }
.catalog-selection-count { flex: none; font-size: .8em; font-weight: 660; }
.catalog-options {
  position: absolute; z-index: 4; top: calc(100% + 4px);
  width: max-content; min-width: 100%; max-width: min(18rem,calc(100vw - 42px)); max-height: 45dvh;
  padding: 4px; border: 1px solid var(--picker-line); border-radius: 9px;
  overflow-y: auto; overscroll-behavior: contain;
  color: var(--ink); background: var(--card); box-shadow: 0 7px 24px #151c252d;
}
.catalog-options.opens-above { top: auto; bottom: calc(100% + 4px); }
.catalog-options > :is(button,label) {
  display: flex; align-items: center; gap: 9px; min-height: 36px;
  margin: 0; padding: 5px 8px; border-radius: 5px; font: 400 14px/1.35 var(--sans);
  cursor: pointer; overflow-wrap: anywhere; text-align: start;
}
.catalog-options > button { width: 100%; color: var(--soft); background: transparent; }
.catalog-options > button[aria-pressed="true"] { color: var(--red-dark); font-weight: 650; }
.catalog-options > button[aria-pressed="true"]::after { content: "✓"; margin-inline-start: auto; }
.catalog-options > label:has(input:checked) { color: var(--red-dark); }
.catalog-options > :is(button,label):hover { background: var(--red-pale); }
.catalog-options input { flex: none; width: 16px; height: 16px; margin: 0; accent-color: var(--red-dark); }
.catalog-multi summary:focus-visible { outline: 2px solid var(--red-dark); outline-offset: 2px; }
.catalog-options > button:focus-visible { outline-offset: -2px; }
@media (pointer: coarse) {
  .catalog-options > :is(button,label) { min-height: 44px; }
}

:root select:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 2px;
}

@media (hover: hover) {
  :root select:not([multiple]):not([size]):enabled:hover {
    border-color: #907c62;
  }
}

@media (max-width: 720px) {
  .study-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .study-filters > label:first-child { grid-column: 1 / -1; }

  /* Keep mobile input focus at the current zoom level. */
  :root select:not([multiple]):not([size]),
  .study-root input:not([type=checkbox]):not([type=file]),
  .catalog-search input {
    font-size: 16px;
  }
}

@media (max-width: 348px) {
  .study-filters { grid-template-columns: minmax(0, 1fr); }
}

@media (forced-colors: active) {
  :root select:not([multiple]):not([size]) {
    -webkit-appearance: auto;
    appearance: auto;
    padding-inline-end: .8em;
    background-image: none;
    border-color: ButtonText;
  }

  :root select:focus-visible { outline-color: Highlight; }
}

.atlas-filters {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin: -3px 0 16px;
  color: var(--soft);
  font-size: 13px;
}
.level-switch {
  display: inline-flex;
  padding: 3px;
  gap: 1px;
  border-radius: 9px;
  background: #ece6d9;
}
.level-switch button {
  min-width: 40px;
  padding: 6px 10px;
  line-height: 1.4;
  color: #5c5c4f;
  background: transparent;
  border-radius: 6px;
  font-weight: 620;
}
.level-switch button[aria-pressed="true"] { color: #fffaf0; background: #754135; }
.level-switch button:not([aria-pressed="true"]):hover { background: #fcf9f0; }
:root #map-pos {
  min-height: 36px;
  min-block-size: 36px;
  max-width: 12em;
  padding-block: 4px;
  font-size: 14px;
}
.filter-clear {
  min-height: 36px;
  padding: 4px 7px;
  background: transparent;
  color: var(--red-dark);
  font: 600 13px var(--sans);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.map-empty { padding: 42px 16px; text-align: center; border: 1px solid var(--rule); border-radius: 13px; background: var(--card); }
.map-empty h2 { font: 700 20px var(--serif); }
.map-empty p { margin: 7px 0 14px; color: var(--soft); }
.level-badge, .catalog-word .level-badge {
  display: inline-block;
  flex: none;
  padding: 2px 6px;
  border-radius: 4px;
  color: #704536;
  background: #f2e4d8;
  font: 680 12px/1.5 var(--sans);
  letter-spacing: .02em;
}
.level-badge[data-level="N5"] { color: #38563b; background: #e2ecde; }
.level-badge[data-level="N4"] { color: #345963; background: #e1ebec; }
.level-badge[data-level="N3"] { color: #635071; background: #ece5ef; }
.level-badge[data-level="N1"] { color: #883b2e; background: #f3ddd5; }
.catalog-word .result-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.catalog-status { display: flex; justify-content: space-between; align-items: center; gap: 10px; min-height: 28px; }
.catalog-count { margin: 0; }
.catalog-status .filter-clear { min-height: 28px; flex: none; }
@media (max-width: 570px) {
  .catalog-filters { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (max-width: 510px) {
  .atlas-filters { column-gap: 12px; margin-top: 0; }
  .level-switch button { min-width: 36px; padding-inline: 8px; }
}
@media (pointer: coarse) {
  .level-switch button { min-height: 38px; }
  :root #map-pos { min-block-size: 44px; font-size: 16px; }
}
@media (max-width: 350px) {
  .catalog-filters { column-gap: 7px; }
  :root .catalog-filters select:not([multiple]):not([size]) { padding-inline: 6px 20px; background-position: right 4px center; }
}

.word-aliases { margin: -6px 0 12px; color: var(--soft); font-size: 12px; line-height: 1.65; }
.word-aliases .variant-audio { display: block; margin-top: 4px; }
