#scroll-index-trigger,
#scroll-index {
  -webkit-tap-highlight-color: rgba(157, 54, 34, .17);
}

#scroll-index-trigger {
  position: fixed;
  z-index: 24;
  inset: auto auto max(12px, env(safe-area-inset-bottom)) max(9px, env(safe-area-inset-left));
  width: 46px;
  min-height: 68px;
  padding: 7px 2px 5px;
  border: 1px solid #ab875f;
  border-radius: 0;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 4px;
  background: #2e1d16;
  color: #f3dfb9;
  box-shadow: inset 0 0 0 2px #382318, 2px 3px 0 #130e0c;
  font: 19px/1.05 Kai, serif;
  cursor: pointer;
}

#scroll-index-trigger::before {
  content: '';
  width: 6px;
  height: 6px;
  border: 1px solid #f3dfb9;
  background: var(--verm-deep);
  transform: rotate(45deg);
}

#scroll-index-trigger:lang(zh) > span { writing-mode: vertical-rl; letter-spacing: .04em; }
#scroll-index-trigger:lang(en) { font: 13px/1.17 SerifSC, serif; }
#scroll-index-trigger:is(:hover, :focus-visible) { color: #fff4dc; border-color: #e2bd78; }
#scroll-index-trigger[hidden] { display: none; }

#scroll-index {
  --index-selection-paper: #f6e0c3;
  position: fixed;
  inset: auto auto max(84px, calc(env(safe-area-inset-bottom) + 76px)) max(17px, env(safe-area-inset-left));
  width: min(552px, calc(100% - 34px));
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: visible;
  background: transparent;
  color: var(--ink);
  font: 16px/1.45 SerifSC, serif;
}

#scroll-index::backdrop { background: rgba(20, 16, 13, .32); }
#scroll-index ::selection { background-color: var(--index-selection-paper); color: var(--verm-deep); }

#scroll-index .index-scroll {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) 10px;
  transform-origin: left bottom;
  animation: index-unfurl 165ms ease-out both;
  filter: drop-shadow(0 18px 34px rgba(18, 10, 6, .46));
}

@keyframes index-unfurl {
  from { opacity: 0; transform: translateY(8px) scale(.98); }
  to { opacity: 1; transform: none; }
}

#scroll-index .index-scroll::before,
#scroll-index .index-scroll::after {
  content: '';
  height: 100%;
  border: 1px solid #553726;
  border-block: 3px solid #382319;
  border-radius: 2px;
  background: linear-gradient(90deg, #4b3021 0%, #a67d51 43%, #71482d 69%, #43291d 100%);
}

#scroll-index .index-paper {
  position: relative;
  display: flex;
  flex-direction: column;
  max-height: min(660px, calc(100vh - 111px - env(safe-area-inset-bottom)));
  max-height: min(660px, calc(100dvh - 111px - env(safe-area-inset-bottom)));
  min-height: 0;
  margin-block: 5px;
  padding: 15px 24px 15px;
  background: var(--paper) var(--grain);
  border-block: 3px double #947e61;
  box-shadow: inset 8px 0 13px -9px #9c7958, inset -10px 0 13px -9px #9c7958;
}

#scroll-index .index-head {
  min-width: 0;
  min-height: 46px;
  display: flex;
  align-items: center;
  gap: 13px;
  border-bottom: 2px solid #9a3727;
}

#scroll-index .index-seal {
  width: 34px;
  height: 34px;
  object-fit: contain;
  flex: none;
  rotate: -6deg;
}

#scroll-index h2 {
  min-width: 0;
  flex: 1;
  margin: 0;
  padding-block: 3px;
  font: 31px/1.2 Kai, serif;
  letter-spacing: .12em;
  overflow-wrap: anywhere;
}

#scroll-index h2:lang(en) { font: 25px/1.2 SerifSC, serif; letter-spacing: 0; }
#scroll-index h2:focus { outline: 0; }

#scroll-index button {
  min-height: 44px;
  min-width: 44px;
  border: 0;
  border-radius: 0;
  background: none;
  color: var(--ink);
  cursor: pointer;
}

#scroll-index button:is(:hover, :focus-visible) { color: var(--verm-deep); }
#scroll-index :is(input, button):focus-visible { outline: 2px solid var(--verm-deep); outline-offset: -2px; }
#scroll-index .index-close { flex: none; margin-inline-end: -7px; padding: 0; font: 28px/1 SerifSC, serif; color: var(--ink-soft); }

#scroll-index .index-lookup {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  margin: 8px 0 8px;
  padding: 0 8px;
  border: 1px solid rgba(130, 99, 64, .34);
  border-radius: 4px;
  background: rgba(255, 250, 238, .66);
}

#scroll-index .index-lookup label { color: var(--verm-deep); }
#scroll-index .index-lookup label:lang(zh) { font: 17px/1.3 Kai, serif; }
#scroll-index .index-lookup input {
  min-width: 0;
  min-height: 44px;
  width: 100%;
  padding: 0 3px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font: 16px/1.35 SerifSC, serif;
  appearance: none;
}

#scroll-index .index-lookup input::-webkit-search-cancel-button { appearance: none; }
#scroll-index .index-lookup input::placeholder { color: #6b5c4b; opacity: 1; }
#scroll-index [data-index-clear] { margin-inline-end: -7px; padding: 0; font-size: 22px; }

#scroll-index .index-back {
  align-self: start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px 0 6px;
  color: var(--verm-deep);
  font-size: 14px;
}

#scroll-index .index-back::before,
#scroll-index .index-chevron {
  content: '';
  width: 6px;
  height: 6px;
  border-top: 1px solid currentColor;
  border-right: 1px solid currentColor;
  transform: rotate(45deg);
  flex: none;
}

#scroll-index .index-back::before { transform: rotate(225deg); }
#scroll-index [hidden] { display: none; }

#scroll-index .index-content {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: #9b5040 transparent;
}

#scroll-index .index-content ul { list-style: none; margin: 0; padding: 0; }
#scroll-index .index-primary { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 28px; }
#scroll-index .index-content li { min-width: 0; border-bottom: 1px solid rgba(74, 63, 54, .24); }

#scroll-index .index-content button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 5px 8px 5px 2px;
  border-inline-start: 3px solid transparent;
  text-align: start;
  -webkit-tap-highlight-color: transparent;
}

#scroll-index .index-content button:is(:focus, :active, [aria-selected="true"], [data-index-detail-open]) {
  border-inline-start-color: var(--verm-deep);
  background-color: var(--index-selection-paper);
  color: var(--verm-deep);
  outline: none;
}

#scroll-index .index-content button > span:not([aria-hidden]) { flex: 1; min-width: 0; overflow-wrap: anywhere; }
#scroll-index .index-primary button { font: 23px/1.25 Kai, serif; }
#scroll-index .index-primary button:lang(en) { font: 17px/1.3 SerifSC, serif; }
#scroll-index .index-primary button .index-chevron { color: #806854; }

#scroll-index .index-diamond,
#scroll-index [data-index-entry]::before {
  content: '';
  width: 6px;
  height: 6px;
  margin: 0 1px 0 2px;
  border: 1px solid #795b4a;
  transform: rotate(45deg);
  flex: none;
}

#scroll-index [data-index-entry]::before { width: 5px; height: 5px; }
#scroll-index [aria-current="location"] .index-diamond { border-color: var(--verm-deep); background: var(--verm-deep); }
#scroll-index [aria-current="location"] { color: var(--verm-deep); background: rgba(179, 48, 28, .08); border-inline-start-color: var(--verm-deep); }
#scroll-index .index-content button:hover > span:not([aria-hidden]) { text-decoration: underline; text-underline-offset: .23em; }

#scroll-index .index-group + .index-group { margin-top: 13px; }
#scroll-index .index-group h3 {
  margin: 0;
  padding: 3px 0 4px;
  font: 19px/1.3 Kai, serif;
  color: var(--verm-deep);
  border-bottom: 1px solid #947e61;
}

#scroll-index .index-group h3:lang(en) { font: 15px/1.3 SerifSC, serif; }
#scroll-index .index-group small { max-width: 45%; color: #665544; font-size: 13px; text-align: end; overflow-wrap: anywhere; }
#scroll-index .index-empty { margin: 12px 0; color: #665544; }
#scroll-index .index-announcement { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }

@keyframes index-drawer-in {
  from { opacity: .6; transform: translateX(-100%); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 760px) {
  #scroll-index-trigger {
    inset: 2px auto auto max(6px, env(safe-area-inset-left));
    min-height: 44px;
    height: 44px;
    width: auto;
    min-width: 72px;
    padding: 0 11px;
    border-radius: 4px;
    border-color: rgba(201, 162, 90, .55);
    background: linear-gradient(180deg, #352319 0%, #241710 100%);
    box-shadow: none;
    grid-auto-flow: column;
    align-items: center;
    gap: 7px;
    font: 16px/1.1 Kai, serif;
  }
  #scroll-index-trigger::before {
    width: 15px;
    height: 11px;
    border: 0;
    transform: none;
    background: linear-gradient(180deg,
      #f3dfb9 0 2px, transparent 2px 4.5px,
      #f3dfb9 4.5px 6.5px, transparent 6.5px 9px,
      #f3dfb9 9px 11px);
  }
  #scroll-index-trigger:lang(en) { font: 13px/1.1 SerifSC, serif; padding: 0 9px; gap: 6px; }
  #scroll-index-trigger:lang(zh) > span { writing-mode: horizontal-tb; letter-spacing: .06em; }

  #scroll-index {
    inset: 0 auto 0 0;
    width: min(328px, 88vw);
    height: 100vh;
    height: 100dvh;
    max-height: 100vh;
    max-height: 100dvh;
  }
  #scroll-index::backdrop { background: rgba(14, 10, 8, .58); }
  #scroll-index .index-scroll {
    height: 100%;
    grid-template-columns: minmax(0, 1fr);
    filter: none;
    animation: index-drawer-in 180ms ease-out both;
  }
  #scroll-index .index-scroll::before,
  #scroll-index .index-scroll::after { display: none; }
  #scroll-index .index-paper {
    height: 100%;
    max-height: 100vh;
    max-height: 100dvh;
    margin: 0;
    padding: max(12px, env(safe-area-inset-top)) 14px max(14px, env(safe-area-inset-bottom));
    border-block: 0;
    border-right: 2px solid #947e61;
    box-shadow: 8px 0 28px rgba(10, 6, 4, .55);
  }
  #scroll-index .index-primary { gap: 0 14px; }
  #scroll-index .index-primary button { font-size: 19px; }
  #scroll-index .index-primary button:lang(en) { font-size: 15px; }
}

@media (min-width: 1024px) {
  #scroll-index-trigger {
    inset: auto auto 6px 12px;
    width: auto;
    min-width: 96px;
    min-height: 44px;
    height: 44px;
    padding: 0 12px;
    grid-auto-flow: column;
    align-items: center;
    gap: 6px;
    border-radius: 3px;
    font: 15px/1.1 Kai, serif;
  }
  #scroll-index-trigger:lang(zh) > span { writing-mode: horizontal-tb; letter-spacing: .06em; }
  #scroll-index-trigger:lang(en) { font: 13px/1.1 SerifSC, serif; }
  #scroll-index {
    inset: auto auto 60px 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  #scroll-index .index-scroll { animation: none; }
}
