.opening-whisper-image-modal,
.collection-chessboard-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
}

.opening-whisper-image-modal {
  visibility: hidden;
  pointer-events: none;
}

.opening-whisper-image-modal.is-visible {
  visibility: visible;
  pointer-events: auto;
}

.opening-whisper-image-modal-backdrop,
.collection-chessboard-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(2px);
}

.opening-whisper-image-modal-backdrop {
  opacity: 0;
  transition: opacity 280ms ease;
}

.opening-whisper-image-modal.is-visible .opening-whisper-image-modal-backdrop {
  opacity: 1;
}

.opening-whisper-image-modal.is-pre-grow .opening-whisper-image-modal-backdrop,
.opening-whisper-image-modal.is-grow-from-inline .opening-whisper-image-modal-backdrop {
  transition-duration: 1200ms;
  transition-timing-function: cubic-bezier(0.16, 0.84, 0.24, 1);
}

.opening-whisper-image-modal.is-closing .opening-whisper-image-modal-backdrop,
.opening-whisper-image-modal.is-next-handoff .opening-whisper-image-modal-backdrop {
  opacity: 0;
}

.opening-whisper-image-modal-card {
  --ow-enter-from-x: 0px;
  --ow-enter-from-y: 0px;
  --ow-enter-from-scale-x: 1;
  --ow-enter-from-scale-y: 1;
  position: absolute;
  inset: 0;
  width: fit-content;
  height: fit-content;
  max-width: calc(100vw - 24px);
  max-height: calc(100vh - 24px);
  margin: auto;
  padding: 12px;
  overflow: visible;
  border: 1px solid rgba(120, 100, 68, 0.24);
  border-radius: 12px;
  background: rgba(255, 248, 232, 0.98);
  box-shadow: 0 14px 38px rgba(0, 0, 0, 0.22);
  opacity: 1;
  transition: opacity 360ms ease-out;
}

.opening-whisper-image-modal.is-pre-grow .opening-whisper-image-modal-card {
  opacity: 0;
  transition: none;
}

.opening-whisper-image-modal.is-next-handoff {
  pointer-events: none;
}

.opening-whisper-image-modal.is-next-handoff .opening-whisper-image-modal-card {
  opacity: 0.02;
}

.opening-whisper-image-modal.is-grow-from-inline .opening-whisper-image-modal-card.is-grow-enter {
  animation: openingWhisperGrowToCenter 1200ms cubic-bezier(0.16, 0.84, 0.24, 1) both;
  transform-origin: top left;
}

.opening-whisper-image-modal.is-grow-from-inline .opening-whisper-image-modal-card.is-grow-exit {
  animation: openingWhisperShrinkToInline 460ms cubic-bezier(0.24, 0.12, 0.3, 1) both;
  transform-origin: top left;
}

.opening-whisper-image-modal-close,
.collection-chessboard-modal-close {
  position: absolute;
  z-index: 20;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(120, 100, 68, 0.3);
  border-radius: 50%;
  background: rgba(255, 248, 230, 0.96);
  color: #5f4a2f;
  line-height: 1;
  cursor: pointer;
}

.opening-whisper-image-modal-close {
  top: 8px;
  right: 10px;
  width: 30px;
  height: 30px;
  font-size: 1.2rem;
}

.opening-whisper-image-modal-content {
  position: relative;
  display: inline-block;
  width: 100%;
}

.opening-whisper-image-modal-img {
  display: block;
  width: 100%;
  max-height: min(70vh, 560px);
  object-fit: contain;
  border: 1px solid rgba(120, 100, 68, 0.2);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.72);
}

.opening-whisper-image-modal-actions,
.collection-chessboard-modal-actions {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
}

.opening-whisper-image-modal-back,
.opening-whisper-image-modal-arrow,
.collection-chessboard-modal-back,
.collection-chessboard-modal-next {
  min-width: 86px;
  height: 36px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.opening-whisper-image-modal-back,
.collection-chessboard-modal-back {
  border: 1px solid rgba(120, 100, 68, 0.3);
  background: rgba(255, 248, 230, 0.96);
  color: #5f4a2f;
}

.opening-whisper-image-modal-arrow,
.collection-chessboard-modal-next {
  margin-left: auto;
  border: 2px solid rgba(255, 255, 255, 0.3);
  background: rgba(99, 102, 241, 0.9);
  color: #fff;
  text-transform: uppercase;
}

.opening-whisper-image-modal.is-closing .opening-whisper-image-modal-actions {
  visibility: hidden;
}

@keyframes openingWhisperGrowToCenter {
  from {
    transform: translate3d(var(--ow-enter-from-x), var(--ow-enter-from-y), 0) scale(var(--ow-enter-from-scale-x), var(--ow-enter-from-scale-y));
    opacity: 0.2;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

@keyframes openingWhisperShrinkToInline {
  from {
    transform: none;
    opacity: 1;
  }
  to {
    transform: translate3d(var(--ow-enter-from-x), var(--ow-enter-from-y), 0) scale(var(--ow-enter-from-scale-x), var(--ow-enter-from-scale-y));
    opacity: 0.16;
  }
}

.collection-chessboard-modal {
  display: none;
  align-items: center;
  justify-content: center;
}

.collection-chessboard-modal.is-visible {
  display: flex;
}

.collection-chessboard-modal.is-returning,
.collection-chessboard-modal.is-view-switching .collection-chessboard-modal-card {
  opacity: 0;
  pointer-events: none;
}

.collection-chessboard-modal-card {
  position: relative;
  width: min(90vw, 700px);
  max-height: 85vh;
  padding: 24px;
  overflow-y: auto;
  border: 1px solid rgba(124, 92, 56, 0.28);
  border-radius: 16px;
  background: #fbf1de;
  box-shadow: 0 20px 60px rgba(39, 25, 8, 0.34);
  transition: opacity 140ms ease-out;
}

.collection-chessboard-modal-close {
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  font-size: 24px;
}

.collection-chessboard-modal-title {
  margin: 0 40px 20px;
  color: #4f3618;
  font-size: 22px;
  text-align: center;
}

.collection-chessboard-modal-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
}

.collection-chessboard-description {
  margin: 0;
  color: #6c4a24;
  line-height: 1.5;
}

.collection-chessboard-modal-card .markup-bold {
  font-weight: 700;
}

.collection-chessboard-modal-card .markup-custom-color {
  font-weight: 700;
}

.collection-chessboard-modal-card .markup-custom-color-laser-berry {
  display: inline;
  background: linear-gradient(92deg, #86198f 0%, #be185d 46%, #be123c 100%);
  background-size: 200% 100%;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 0.12em rgba(190, 24, 93, 0.24);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.collection-chessboard-modal-card .markup-custom-color-frost-bite {
  display: inline;
  background: linear-gradient(92deg, #0f172a 0%, #1d4ed8 52%, #0e7490 100%);
  background-size: 200% 100%;
  background-clip: text;
  color: transparent;
  text-shadow: 0 0 0.09em rgba(30, 64, 175, 0.22);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.collection-chessboard-modal-card .fch-theme-token {
  display: inline;
  margin: 0 0.08em;
  padding: 0.12em 0.56em;
  border: 1px dashed rgba(0, 119, 204, 0.45);
  border-radius: 3px;
  background: rgba(0, 119, 204, 0.12);
  color: #0077cc;
  font-style: italic;
  font-weight: 600;
}

.collection-chessboard-modal-card .fch-opening-name-token {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0 0.16em;
  padding: 0.16em 0.72em;
  border: 1px solid rgba(217, 119, 6, 0.45);
  border-radius: 0;
  background: linear-gradient(135deg, rgba(255, 251, 235, 0.96) 0%, rgba(254, 243, 199, 0.9) 48%, rgba(253, 230, 138, 0.86) 100%);
  color: #78350f;
  font-size: 0.9em;
  font-weight: 800;
  line-height: 1.1;
  text-transform: uppercase;
  vertical-align: baseline;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.85), 0 3px 10px rgba(217, 119, 6, 0.24);
}

.collection-chessboard-modal-card .fch-opening-name-token::before,
.collection-chessboard-modal-card .fch-opening-name-token::after {
  content: "♘";
  font-size: 0.72em;
  opacity: 0.72;
}

.collection-chessboard-modal-card .fch-opening-name-token::before {
  margin-right: 0.42em;
}

.collection-chessboard-modal-card .fch-opening-name-token::after {
  margin-left: 0.42em;
}

.collection-opening-position-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: min(100%, 450px);
  aspect-ratio: 1;
  border: 3px solid #5f4325;
  box-shadow: 0 14px 32px rgba(55, 35, 13, 0.24);
}

.collection-opening-position-square {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
}

.collection-opening-position-square.is-light {
  background: #e7d5b5;
}

.collection-opening-position-square.is-dark {
  background: #be9b72;
}

.collection-opening-position-square.is-last-move {
  box-shadow: inset 0 0 0 999px rgba(250, 204, 21, 0.32);
}

.collection-opening-position-piece {
  display: block;
  width: 88%;
  height: 88%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.collection-chessboard-engine-row,
.collection-chessboard-modal-actions {
  width: min(100%, 450px);
  margin-right: auto;
  margin-left: auto;
}

.collection-chessboard-engine-row {
  display: flex;
  justify-content: flex-end;
}

.collection-chessboard-engine-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  color: #4f3618;
  text-align: right;
}

.collection-chessboard-error {
  padding: 12px;
  border: 1px solid #e74c3c;
  border-radius: 6px;
  background: #fdf0ef;
  color: #c0392b;
  text-align: center;
}

@media (min-width: 800px) {
  .collection-chessboard-modal[data-position-view="typical"] .collection-chessboard-modal-card {
    width: min(92vw, 1000px);
    max-width: none;
    max-height: 92vh;
  }

  .collection-chessboard-modal[data-position-view="typical"] .collection-chessboard-modal-content {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(320px, 450px);
    grid-template-rows: auto auto;
    gap: 10px 28px;
  }

  .collection-chessboard-modal[data-position-view="typical"] .collection-chessboard-description {
    grid-row: 1 / span 2;
    align-self: center;
  }

  .collection-chessboard-modal[data-position-view="typical"] .collection-opening-position-board {
    grid-column: 2;
    grid-row: 1;
    justify-self: stretch;
    width: 100%;
  }

  .collection-chessboard-modal[data-position-view="typical"] .collection-chessboard-engine-row {
    grid-column: 2;
    grid-row: 2;
    justify-self: stretch;
    width: 100%;
    max-width: none;
    margin-right: 0;
    margin-left: 0;
  }
}

@media (max-width: 520px) {
  .opening-whisper-image-modal-card {
    max-width: calc(100vw - 16px);
    padding: 8px;
  }

  .collection-chessboard-modal-card {
    width: calc(100vw - 16px);
    max-height: calc(100vh - 16px);
    padding: 18px 12px;
  }

  .collection-chessboard-modal-title {
    margin-right: 36px;
    margin-left: 36px;
    font-size: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .opening-whisper-image-modal *,
  .collection-chessboard-modal * {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}