/* Progressive motion and dialogs. Content never depends on animations to be readable. */
[data-reveal] {
  transition: opacity .62s var(--ease), transform .62s var(--ease);
}

.category-card[data-reveal] {
  transition: opacity .62s var(--ease), transform .62s var(--ease), translate .3s var(--ease), box-shadow .3s, border-color .3s;
}

.reveal-pending {
  opacity: 0;
  transform: translate3d(0, 26px, 0);
}

[data-stagger] > :nth-child(2) {
  transition-delay: .06s;
}

[data-stagger] > :nth-child(3) {
  transition-delay: .12s;
}

[data-stagger] > :nth-child(4) {
  transition-delay: .06s;
}

.reveal-visible {
  opacity: 1;
  transform: none;
}

.reading-progress {
  position: absolute;
  top: 0;
  left: 0;
  height: 3px;
  width: 100%;
  transform: scaleX(0);
  transform-origin: 0 50%;
  background: #2463eb;
  pointer-events: none;
}

.back-top {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  box-shadow: var(--shadow);
  border-color: var(--border);
  background: var(--surface);
}

.toast {
  position: fixed;
  z-index: 110;
  bottom: 25px;
  left: 50%;
  max-width: calc(100% - 40px);
  padding: 11px 18px;
  background: var(--text);
  color: var(--surface);
  border-radius: 12px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity .2s, transform .2s;
  font-size: 12px;
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

body.dialog-open {
  overflow: hidden;
}

.dialog {
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  margin: auto;
  box-shadow: 0 30px 120px #0005;
  overscroll-behavior: contain;
}

.dialog[open] {
  animation: dialog-enter .22s var(--ease);
}

.dialog::backdrop {
  background: #081126b0;
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 21px 24px;
  border-bottom: 1px solid var(--border);
}

.dialog-header h2 {
  font-size: 21px;
  letter-spacing: -.03em;
}

.dialog-header p {
  margin-top: 5px;
  font-size: 11px;
}

.dialog-header .icon-button {
  width: 42px;
  min-width: 42px;
  min-height: 42px;
}

.search-dialog {
  width: 650px;
}

.search-form {
  padding: 20px 24px 0;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--border);
  border-radius: 13px;
  padding: 0 15px;
  background: var(--surface-soft);
}

.search-field:focus-within {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.search-field .icon {
  width: 20px;
  color: var(--blue);
}

.search-field input {
  border: 0;
  background: transparent;
  outline: none;
  min-height: 53px;
  width: 100%;
  font-size: 14px;
}

.search-field input::placeholder {
  color: var(--subtle);
}

.result-count {
  font-size: 11px;
  margin: 15px 24px 10px;
}

.search-results {
  padding: 0 14px 16px;
  max-height: 50vh;
  overflow-y: auto;
}

.search-result {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 11px;
  border: 1px solid transparent;
  border-radius: 13px;
  min-height: 80px;
}

.search-result + .search-result {
  margin-top: 2px;
}

.search-result:hover, .search-result:focus-visible {
  background: var(--tint);
  border-color: var(--border);
}

.search-result img {
  width: 83px;
  height: 52px;
  object-fit: contain;
  background: #112033;
  border-radius: 8px;
  flex: 0 0 auto;
}

.search-result > div {
  min-width: 0;
  flex: 1;
}

.search-result strong {
  display: block;
  font-size: 14px;
  line-height: 1.3;
}

.search-result small {
  display: block;
  color: var(--muted);
  font-size: 10px;
  margin-top: 5px;
  overflow-wrap: anywhere;
}

.search-result > .icon {
  width: 17px;
  height: 17px;
  color: var(--accent);
}

.search-empty {
  padding: 24px 12px;
  font-size: 13px;
}

.gallery-dialog {
  width: 1190px;
}

.gallery-dialog .dialog-header {
  padding: 15px 20px;
}

.gallery-dialog .dialog-header h2 {
  font-size: 18px;
}

.gallery-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  background: #09111c;
  height: min(62vh, 660px);
}

.gallery-stage img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  touch-action: pan-y pinch-zoom;
}

.gallery-prev, .gallery-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 1;
  background: #101b2be8;
  color: #fff;
  border-color: #ffffff50;
}

.gallery-prev {
  left: 18px;
}

.gallery-next {
  right: 18px;
}

.gallery-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 7px 22px;
}

.gallery-bottom > span {
  font-size: 12px;
  color: var(--muted);
}

.gallery-bottom .text-link {
  font-size: 11px;
}

.gallery-thumbs {
  display: flex;
  gap: 9px;
  overflow-x: auto;
  padding: 0 20px 16px;
  overscroll-behavior-x: contain;
}

.gallery-thumbs button {
  flex: 0 0 auto;
  width: 93px;
  min-height: 59px;
  padding: 3px;
  border: 2px solid transparent;
  background: transparent;
  border-radius: 8px;
}

.gallery-thumbs img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: contain;
  border-radius: 4px;
}

.gallery-thumbs button[aria-pressed="true"] {
  border-color: var(--blue);
}

.chooser-dialog {
  width: 690px;
}

.chooser-options {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 22px 24px 3px;
}

.chooser-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 109px;
  padding: 16px 9px;
  background: var(--surface);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 15px;
  font-size: 12px;
  font-weight: 700;
}

.chooser-option[aria-pressed="true"] {
  background: var(--tint);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

@keyframes dialog-enter {
  from {
    opacity: 0;
    transform: translateY(10px) scale(.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (max-width: 540px) {
  .dialog {
    border-radius: 19px;
    max-width: calc(100vw - 20px);
    max-height: calc(100dvh - 24px);
  }
  .dialog-header {
    padding: 16px;
  }
  .dialog-header h2 {
    font-size: 19px;
  }
  .search-form {
    padding: 17px 16px 0;
  }
  .result-count {
    margin-inline: 18px;
  }
  .search-results {
    padding-inline: 7px;
  }
  .search-result {
    gap: 10px;
  }
  .search-result img {
    width: 65px;
    height: 42px;
  }
  .search-result strong {
    font-size: 12px;
  }
  .search-result small {
    font-size: 9px;
  }
  .gallery-dialog .dialog-header {
    padding: 12px;
  }
  .gallery-dialog .dialog-header h2 {
    font-size: 15px;
  }
  .gallery-stage {
    padding: 0;
    height: auto;
    aspect-ratio: 16 / 10;
  }
  .gallery-prev, .gallery-next {
    top: auto;
    bottom: 8px;
    transform: none;
    min-width: 38px;
    min-height: 38px;
  }
  .gallery-prev {
    left: 7px;
  }
  .gallery-next {
    right: 7px;
  }
  .gallery-bottom {
    padding-inline: 12px;
    gap: 8px;
  }
  .gallery-thumbs {
    padding-inline: 12px;
    gap: 6px;
  }
  .gallery-thumbs button {
    width: 77px;
  }
  .chooser-options {
    gap: 7px;
    padding: 18px 16px 3px;
  }
  .chooser-option {
    font-size: 10px;
    padding: 12px 5px;
    gap: 8px;
    min-height: 100px;
  }
  .back-top {
    bottom: 16px;
    right: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    transition-delay: 0s !important;
    scroll-behavior: auto !important;
  }
  .reveal-pending {
    opacity: 1 !important;
    transform: none !important;
  }
  .category-card:hover {
    translate: none;
  }
  .category-card:hover img {
    transform: none;
  }
}
