.comic-guide-dialog {
  inline-size: min(37rem, calc(100% - 1.25rem));
  max-inline-size: none;
  max-block-size: calc(100dvh - 1.25rem - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  margin: auto;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: inherit;
  overflow: auto;
}

.comic-guide-dialog::backdrop { background: #142d2bba; }

.comic-guide {
  --guide-ink: #23383a;
  --guide-deep: #173c34;
  --guide-paper: #fff3d8;
  --guide-light: #fff9ec;
  --guide-amber: #fbc66f;
  container-type: inline-size;
  inline-size: min(100%, 37rem);
  min-inline-size: 0;
  margin-inline: auto;
  border: 2px solid var(--guide-ink);
  border-radius: 8px;
  overflow: hidden;
  background: var(--guide-paper);
  color: var(--guide-ink);
  box-shadow: 3px 4px 0 #23383a;
}

.comic-guide-dialog .comic-guide {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  max-block-size: calc(100dvh - 1.5rem - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  box-shadow: inset 0 -3px #b18c54;
}

.comic-guide-mast {
  display: flex;
  align-items: center;
  gap: .38rem .6rem;
  flex-wrap: wrap;
  padding: .52rem .72rem;
  border-block-end: 2px solid var(--guide-ink);
  background: var(--guide-deep);
  color: var(--guide-light);
}

.comic-guide-mast > :is(svg, .ink-icon) {
  display: block;
  flex: 0 0 auto;
  inline-size: 1.45rem;
  block-size: 1.45rem;
  color: var(--guide-amber);
}

.comic-guide-mast :is(h1, h2) {
  flex: 1 1 auto;
  margin: 0;
  color: inherit;
  font-size: clamp(.96rem, 4.5vw, 1.24rem);
  font-weight: 850;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.comic-guide .comic-guide-close {
  flex: 0 0 auto;
  min-block-size: 44px;
  max-inline-size: 100%;
  margin-inline-start: auto;
  padding: .35rem .56rem;
  border: 1px solid #ffebbf92;
  border-radius: 4px;
  background: transparent;
  color: var(--guide-light);
  box-shadow: none;
  font-size: .75rem;
  line-height: 1.35;
}

.comic-guide-leaf {
  min-inline-size: 0;
  min-block-size: 0;
  padding: .55rem clamp(.65rem, 3vw, 1.15rem) .7rem;
  background:
    linear-gradient(to left, #6e502d23, transparent 14px),
    repeating-linear-gradient(148deg, #6e502d07 0 1px, transparent 1px 6px),
    var(--guide-paper);
}

.comic-guide-dialog .comic-guide-leaf { overflow: auto; overscroll-behavior: contain; }

.guide-story {
  display: grid;
  min-inline-size: 0;
  align-content: start;
  align-items: stretch;
  gap: .55rem;
}

.guide-story:has(.guide-map, .guide-record) { gap: .42rem; }

.guide-art {
  display: block;
  inline-size: 100%;
  block-size: clamp(75px, 23dvh, 164px);
  min-inline-size: 0;
  margin: 0;
  border: 2px solid var(--guide-ink);
  border-radius: 3px;
  background: var(--guide-deep);
  object-fit: cover;
  overflow: hidden;
}

.guide-art img { display: block; inline-size: 100%; block-size: 100%; object-fit: cover; }

.guide-story:has(.guide-deck) .guide-art { object-position: 53% 38%; }
.guide-story:has(.guide-preview) .guide-art { object-position: 50% 22%; }
.guide-story:has(.guide-record) .guide-art { object-position: 43% 45%; }

.guide-action {
  position: relative;
  display: flex;
  min-inline-size: 0;
  align-items: center;
  flex-wrap: wrap;
  gap: .36rem .55rem;
  padding: .4rem .56rem;
  border: 1.5px solid var(--guide-ink);
  border-radius: 3px;
  background: var(--guide-light);
  color: var(--guide-ink);
  font-size: .8rem;
  font-weight: 700;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.guide-action :is(svg, .ink-icon) { inline-size: 1.35rem; block-size: 1.35rem; }
.guide-action-label {
  display: inline-flex;
  min-inline-size: 0;
  align-items: center;
  gap: .28rem;
  font-weight: 800;
}

.guide-action-label svg { flex: none; }

.guide-action.guide-map {
  border-inline-start-width: 5px;
  background: #fbe2ab;
  color: #38291c;
}

.guide-action.guide-deck {
  justify-content: center;
  box-shadow: 2px 2px 0 #d9b990;
}

.guide-deck ol {
  display: flex;
  min-inline-size: 0;
  align-items: stretch;
  flex-wrap: wrap;
  gap: .26rem;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: demo-card;
}

.guide-deck li {
  display: flex;
  align-items: baseline;
  gap: .2rem;
  padding: .18rem .32rem;
  border: 1px solid var(--guide-ink);
  border-radius: 3px;
  background: #f5e1a8;
  counter-increment: demo-card;
}

.guide-deck li::before {
  content: counter(demo-card, persian);
  color: #724420;
  font-size: .66rem;
  font-weight: 850;
}

.comic-guide .guide-swap {
  min-block-size: 44px;
  max-inline-size: 100%;
  padding: .2rem .44rem;
  border: 1px solid var(--guide-ink);
  border-radius: 3px;
  background: var(--guide-deep);
  color: var(--guide-light);
  font-size: .75rem;
  line-height: 1.4;
}

.guide-action.guide-preview {
  justify-content: space-between;
  border-block-end-width: 3px;
  background:
    repeating-linear-gradient(0deg, #29413710 0 1px, transparent 1px 8px),
    var(--guide-light);
}

.guide-action.guide-reactions {
  display: grid;
  grid-template-columns: 1fr;
  gap: .3rem;
  padding: 0;
  overflow: hidden;
  border: 0;
  background: transparent;
}

.guide-reactions ul {
  display: grid;
  gap: .3rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.guide-reactions li {
  display: flex;
  min-inline-size: 0;
  align-items: center;
  flex-wrap: wrap;
  gap: .38rem;
  padding: .18rem .42rem;
  border: 1px solid #53635a;
  border-radius: 3px;
  background: #e2efcf;
}

.guide-reactions li[data-guide-reaction="neutral"] { background: #fbe0a1; }
.guide-reactions li[data-guide-reaction="bad"] { background: #f8dbca; }
.guide-reactions li svg { flex: none; inline-size: 2.65rem; }
.guide-reactions li span { margin-inline-start: auto; font-weight: 600; }

.guide-action.guide-record {
  border-inline-end: 4px double var(--guide-ink);
  color: #fff3d8;
  background: var(--guide-deep);
}

.guide-passage {
  min-inline-size: 0;
  padding: .34rem .52rem .4rem;
  border-inline-start: 3px solid var(--guide-ink);
  background: #fff8e6;
  overflow-wrap: anywhere;
}

.guide-passage h3 {
  margin: 0 0 .16rem;
  color: var(--guide-deep);
  font-size: clamp(1rem, 4.8vw, 1.38rem);
  font-weight: 880;
  line-height: 1.4;
}

.guide-passage p { margin: 0; font-size: .91rem; line-height: 1.75; }
.guide-callout { color: var(--guide-deep); font-weight: 800; }

.guide-navigation {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: .35rem .5rem;
  padding: .48rem .65rem max(.48rem, env(safe-area-inset-bottom));
  border-block-start: 2px solid var(--guide-ink);
  background: #efd8a5;
}

.guide-navigation .guide-index {
  margin: 0;
  padding-inline: .12rem;
  text-align: center;
  font-size: .78rem;
  font-weight: 800;
  line-height: 1.4;
}

.guide-navigation :is(.guide-previous, .guide-next, .guide-done) {
  display: flex;
  min-inline-size: 0;
  min-block-size: 44px;
  align-items: center;
  justify-content: center;
  padding: .28rem .4rem;
  border: 1.5px solid var(--guide-ink);
  border-radius: 4px;
  background: var(--guide-light);
  color: var(--guide-deep);
  box-shadow: 1px 2px 0 var(--guide-ink);
  font-size: .8rem;
  font-weight: 750;
  line-height: 1.4;
  text-align: center;
  overflow-wrap: anywhere;
}

.guide-navigation :is(.guide-next, .guide-done) { background: var(--guide-amber); color: #33271a; }
.guide-navigation button:disabled { opacity: .58; box-shadow: none; }
.guide-navigation [hidden] { display: none; }

.comic-guide :is(button, a, h3):focus-visible {
  outline: 2px solid #163f89;
  outline-offset: 2px;
}

.comic-guide .comic-guide-close:focus-visible { outline-color: #ffe297; }

.map-guide-link {
  min-block-size: 44px;
  max-inline-size: 100%;
  text-align: center;
  overflow-wrap: anywhere;
}

@container (min-width: 30rem) {
  .guide-story:has(.guide-art):has(.guide-deck, .guide-record) {
    grid-template-columns: minmax(0, 1.12fr) minmax(0, 1fr);
  }
  .guide-story:has(.guide-art):has(.guide-deck, .guide-record) .guide-art { grid-row: span 2; block-size: 100%; }
}

@container (max-width: 18em) {
  .comic-guide-mast {
    display: grid;
    gap: .15rem;
    padding: .27rem .42rem;
  }
  .comic-guide-mast > :is(svg, .ink-icon) { display: none; }
  .comic-guide-mast :is(h1, h2) { font-size: .9rem; }
  .comic-guide-mast .comic-guide-close { margin-inline-start: auto; padding: .15rem .35rem; font-size: .69rem; }
  .guide-art { block-size: 68px; }
  .guide-story:has(.guide-deck, .guide-preview, .guide-reactions) .guide-art { object-position: 53% 18%; }
  .guide-reactions li {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: .13rem .3rem;
  }
  .guide-reactions li svg { grid-row: span 2; inline-size: min(49px, 15vw); }
  .guide-reactions li span { grid-column: 2; margin: 0; font-size: .71rem; }
  .guide-passage p { line-height: 1.6; }
  .guide-navigation {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: .24rem .39rem max(.24rem, env(safe-area-inset-bottom));
  }
  .guide-navigation .guide-index { grid-column: 1 / -1; grid-row: 1; font-size: .66rem; }
  .guide-navigation :is(.guide-previous, .guide-next, .guide-done) { padding: .18rem .27rem; font-size: .68rem; }
}

@media (max-height: 27rem) {
  .comic-guide-dialog .comic-guide { display: block; max-block-size: none; }
  .comic-guide-dialog .comic-guide-leaf { overflow: visible; }
  .guide-art { block-size: 5rem; }
}

@media (prefers-reduced-motion: no-preference) {
  .comic-guide:not([data-reduced-motion]) .comic-guide-leaf[data-turn="next"] {
    transform-origin: right center;
    animation: guide-leaf-next 170ms ease-out both;
  }
  .comic-guide:not([data-reduced-motion]) .comic-guide-leaf[data-turn="prev"] {
    transform-origin: left center;
    animation: guide-leaf-prev 170ms ease-out both;
  }
  .app.reduced-motion .comic-guide .comic-guide-leaf[data-turn] { animation: none; }

  @keyframes guide-leaf-next {
    from { opacity: .82; transform: perspective(750px) rotateY(-6deg) translateX(-7px); box-shadow: inset 6px 0 #52362435; }
    to { opacity: 1; transform: none; box-shadow: none; }
  }
  @keyframes guide-leaf-prev {
    from { opacity: .82; transform: perspective(750px) rotateY(6deg) translateX(7px); box-shadow: inset -6px 0 #52362435; }
    to { opacity: 1; transform: none; box-shadow: none; }
  }
}
