:root {
  color-scheme: dark;
  --ink: #080707;
  --ink-soft: #121010;
  --paper: #eadcc9;
  --paper-deep: #cdbba7;
  --ash: #9a9995;
  --ash-dark: #55534f;
  --wine: #5f1d30;
  --rose: #ad6976;
  --rust: #8d4c37;
  --line: rgba(234, 220, 201, 0.24);
  --serif: "Iowan Old Style", "Baskerville", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--ink);
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 28%, rgba(95, 29, 48, 0.14), transparent 34rem),
    var(--ink);
  color: var(--paper);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
}

button {
  color: inherit;
  font: inherit;
}

button:focus-visible {
  outline: 2px solid var(--paper);
  outline-offset: 4px;
}

.grain {
  position: fixed;
  z-index: 100;
  inset: 0;
  pointer-events: none;
  opacity: 0.16;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.92' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.25'/%3E%3C/svg%3E");
  mix-blend-mode: soft-light;
}

.topbar {
  position: relative;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  min-height: 72px;
  padding: 14px clamp(18px, 3vw, 46px);
  border-bottom: 1px solid rgba(234, 220, 201, 0.12);
}

.wordmark,
.sound-toggle {
  appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.wordmark {
  display: grid;
  grid-template-columns: 44px auto;
  column-gap: 10px;
  align-content: center;
  justify-self: start;
  padding: 0;
  text-align: left;
  text-transform: uppercase;
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.18em;
  line-height: 1.35;
}

.wordmark span {
  display: block;
  grid-column: 2;
}

.wordmark-logo {
  grid-column: 1;
  grid-row: 1 / 3;
  width: 44px;
  height: 44px;
  align-self: center;
}

.wordmark span:last-child {
  color: var(--rose);
}

.progress-wrap {
  display: grid;
  grid-template-columns: auto minmax(64px, 9vw) auto;
  align-items: center;
  gap: 10px;
  color: var(--ash);
  font-size: 0.67rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.progress-count {
  color: var(--paper);
  font-variant-numeric: tabular-nums;
}

.progress-track {
  height: 1px;
  overflow: hidden;
  background: var(--ash-dark);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--rose);
  transition: width 700ms var(--ease);
}

.sound-toggle {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 44px;
  padding: 0 0 0 12px;
  color: var(--ash);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.sound-icon {
  position: relative;
  display: inline-flex;
  align-items: end;
  gap: 2px;
  width: 15px;
  height: 12px;
}

.sound-icon::before,
.sound-icon::after {
  content: "";
  width: 2px;
  background: currentColor;
  box-shadow: 4px 0 0 currentColor, 8px 0 0 currentColor, 12px 0 0 currentColor;
}

.sound-icon::before {
  height: 3px;
}

.sound-icon::after {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  opacity: 0;
}

.sound-toggle[aria-pressed="true"] .sound-icon::before {
  animation: soundbars 1.4s steps(4, end) infinite;
}

.game-shell {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(320px, 31vw, 470px);
  height: calc(100vh - 72px);
  height: calc(100dvh - 72px);
}

.mirror-zone {
  position: relative;
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: center;
  padding: 40px clamp(30px, 5vw, 78px) 24px;
  overflow: hidden;
}

.mirror-instruction {
  position: absolute;
  z-index: 5;
  top: 18px;
  left: 50%;
  margin: 0;
  transform: translateX(-50%);
  color: var(--ash);
  font-family: var(--serif);
  font-size: 0.88rem;
  font-style: italic;
  white-space: nowrap;
}

.mirror {
  position: relative;
  width: min(58vh, 570px, 76vw);
  aspect-ratio: 0.79;
  border: 1px solid rgba(184, 183, 179, 0.66);
  box-shadow:
    0 0 0 8px var(--ink),
    0 0 0 9px rgba(184, 183, 179, 0.22),
    0 42px 90px rgba(0, 0, 0, 0.72);
}

.mirror::before,
.mirror::after {
  content: "";
  position: absolute;
  z-index: -1;
  pointer-events: none;
}

.mirror::before {
  inset: -17px 12px 10px -13px;
  border-top: 1px solid rgba(184, 183, 179, 0.22);
  border-left: 1px solid rgba(184, 183, 179, 0.22);
}

.mirror::after {
  inset: 10px -16px -15px 12px;
  border-right: 1px solid rgba(184, 183, 179, 0.13);
  border-bottom: 1px solid rgba(184, 183, 179, 0.13);
}

.mirror-index {
  position: absolute;
  z-index: 8;
  color: rgba(234, 220, 201, 0.52);
  font-size: 0.58rem;
  letter-spacing: 0.2em;
}

.mirror-index--top {
  top: 13px;
  left: 15px;
}

.mirror-index--bottom {
  right: 12px;
  bottom: 11px;
}

.portrait-stage,
.portrait-body {
  position: absolute;
  inset: 0;
}

.portrait-stage {
  overflow: hidden;
  background:
    linear-gradient(115deg, transparent 25%, rgba(255, 255, 255, 0.025), transparent 62%),
    radial-gradient(circle at 50% 45%, rgba(234, 220, 201, 0.035), transparent 58%);
}

.portrait-body {
  transform-origin: 50% 92%;
  animation: breathe 7.8s ease-in-out infinite;
}

.portrait-body.is-travelling { animation-play-state: paused; }

.portrait-base,
.micro-fragment img {
  position: absolute;
  bottom: -1.7%;
  left: 50%;
  width: 95%;
  height: 96%;
  object-fit: contain;
  object-position: center bottom;
  transform: translateX(-50%);
  user-select: none;
  filter: saturate(0.82) brightness(0.83) contrast(1.08);
  transition: filter 1.2s var(--ease), transform 1.2s var(--ease);
}

.portrait-body[data-tone="confronto"] .portrait-base,
.portrait-body[data-tone="confronto"] .micro-fragment img {
  filter: saturate(0.92) sepia(0.08) brightness(0.86) contrast(1.12);
}

.portrait-body[data-tone="cuidado"] .portrait-base,
.portrait-body[data-tone="cuidado"] .micro-fragment img {
  filter: saturate(0.72) brightness(0.94) contrast(1.02);
}

.portrait-body[data-tone="invencao"] .portrait-base,
.portrait-body[data-tone="invencao"] .micro-fragment img {
  filter: saturate(1.08) hue-rotate(-7deg) brightness(0.9) contrast(1.08);
}

.micro-fragment {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.micro-fragment--eye {
  clip-path: polygon(24% 27%, 74% 27%, 72% 40%, 25% 40%);
  animation: eye-shift 8.6s ease-in-out infinite;
}

.micro-fragment--mouth {
  clip-path: polygon(36% 46%, 65% 46%, 66% 56%, 35% 56%);
  animation: mouth-pulse 5.6s ease-in-out infinite;
}

.body-fragment {
  position: absolute;
  z-index: 10;
  display: flex;
  min-width: 48px;
  min-height: 48px;
  align-items: flex-start;
  justify-content: space-between;
  appearance: none;
  overflow: hidden;
  border: 1px solid rgba(234, 220, 201, 0.32);
  background: rgba(8, 7, 7, 0.04);
  box-shadow: 0 0 0 rgba(0, 0, 0, 0);
  color: var(--paper);
  cursor: pointer;
  opacity: 0.64;
  transform: rotate(var(--rotate));
  transition:
    opacity 350ms ease,
    background 350ms ease,
    box-shadow 350ms ease,
    transform 500ms var(--ease);
  -webkit-tap-highlight-color: transparent;
}

.body-fragment::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 15%, rgba(234, 220, 201, 0.2), transparent 62%);
  transform: translateX(-120%);
  animation: seam-light 5.4s ease-in-out infinite;
}

.body-fragment:hover,
.body-fragment:focus-visible,
.body-fragment.is-active {
  z-index: 15;
  opacity: 1;
  background: rgba(95, 29, 48, 0.58);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.48);
  transform: rotate(0) translateY(-4px) scale(1.04);
}

.body-fragment.is-complete {
  opacity: 0.92;
  border-color: rgba(234, 220, 201, 0.6);
  background: rgba(95, 29, 48, 0.74);
}

.fragment-number {
  position: absolute;
  top: 4px;
  right: 5px;
  font-size: 0.5rem;
  letter-spacing: 0.12em;
}

.fragment-word {
  position: absolute;
  bottom: 5px;
  left: 7px;
  max-width: calc(100% - 12px);
  overflow: hidden;
  font-family: var(--serif);
  font-size: clamp(0.58rem, 1.4vw, 0.76rem);
  font-style: italic;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.body-fragment--eyes {
  --rotate: -4deg;
  top: 28%;
  left: 22%;
  width: 27%;
  height: 8.5%;
}

.body-fragment--mouth {
  --rotate: 2deg;
  top: 48%;
  left: 38%;
  width: 27%;
  height: 8%;
}

.body-fragment--throat {
  --rotate: -3deg;
  top: 62%;
  left: 43%;
  width: 20%;
  height: 11%;
}

.body-fragment--chest {
  --rotate: 4deg;
  top: 80%;
  left: 24%;
  width: 35%;
  height: 10%;
}

.body-fragment--nape {
  --rotate: 7deg;
  top: 64%;
  left: 65%;
  width: 18%;
  height: 10%;
}

.mobile-fragment-map {
  display: none;
}

.reading-rail {
  position: relative;
  min-width: 0;
  overflow: auto;
  border-left: 1px solid rgba(234, 220, 201, 0.15);
  background: rgba(14, 12, 12, 0.8);
  scrollbar-color: var(--wine) transparent;
}

.rail-empty,
.scene-panel {
  min-height: 100%;
  padding: clamp(34px, 5vh, 68px) clamp(28px, 3.2vw, 54px);
}

.eyebrow,
.scene-kicker {
  margin: 0 0 32px;
  color: var(--rose);
  font-size: 0.68rem;
  font-weight: 650;
  letter-spacing: 0.19em;
  text-transform: uppercase;
}

.rail-quote {
  max-width: 12em;
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(1.75rem, 3vw, 2.7rem);
  font-weight: 400;
  letter-spacing: -0.035em;
  line-height: 1.02;
}

.region-list {
  margin: clamp(52px, 8vh, 90px) 0 0;
  padding: 0;
  list-style: none;
}

.region-list li {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  padding: 11px 0;
  border-bottom: 1px solid rgba(234, 220, 201, 0.1);
  color: var(--ash);
  font-family: var(--serif);
  font-size: 1rem;
  transition: color 400ms ease, padding-left 400ms var(--ease);
}

.region-list li span {
  font-family: var(--sans);
  font-size: 0.58rem;
  letter-spacing: 0.13em;
}

.region-list li.is-complete {
  padding-left: 7px;
  color: var(--paper);
}

.scene-panel {
  position: relative;
  animation: rail-enter 480ms var(--ease) both;
}

.close-panel {
  position: absolute;
  top: 22px;
  right: 22px;
  width: 44px;
  height: 44px;
  appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.close-panel span::before,
.close-panel span::after {
  content: "";
  position: absolute;
  top: 21px;
  left: 12px;
  width: 21px;
  height: 1px;
  background: var(--ash);
}

.close-panel span::before {
  transform: rotate(45deg);
}

.close-panel span::after {
  transform: rotate(-45deg);
}

.scene-kicker {
  margin-bottom: 14px;
}

.scene-panel h2 {
  margin: 0 0 30px;
  font-family: var(--serif);
  font-size: clamp(2.2rem, 4.5vw, 4.2rem);
  font-weight: 400;
  letter-spacing: -0.045em;
  line-height: 0.9;
}

.scene-prose {
  max-width: 31rem;
  color: #d7cbbb;
  font-family: var(--serif);
  font-size: clamp(1.06rem, 1.7vw, 1.22rem);
  line-height: 1.58;
}

.scene-prose p {
  margin: 0 0 1em;
}

.choice-list {
  display: grid;
  gap: 10px;
  margin-top: 34px;
}

.choice-button {
  position: relative;
  display: grid;
  grid-template-columns: 25px 1fr;
  gap: 10px;
  width: 100%;
  min-height: 54px;
  align-items: center;
  padding: 12px 16px 12px 12px;
  appearance: none;
  border: 1px solid rgba(234, 220, 201, 0.19);
  border-radius: 0;
  background: rgba(234, 220, 201, 0.025);
  color: var(--paper);
  cursor: pointer;
  text-align: left;
  transition: border-color 250ms ease, background 250ms ease, transform 350ms var(--ease);
}

.choice-button:hover,
.choice-button:focus-visible,
.choice-button.is-selected {
  border-color: var(--rose);
  background: rgba(95, 29, 48, 0.35);
  transform: translateX(5px);
}

.choice-letter {
  color: var(--rose);
  font-size: 0.64rem;
  letter-spacing: 0.12em;
}

.choice-copy {
  font-family: var(--serif);
  font-size: 1rem;
  line-height: 1.25;
}

.scene-after {
  margin-top: 32px;
  padding-top: 25px;
  border-top: 1px solid rgba(234, 220, 201, 0.14);
  animation: after-enter 600ms var(--ease) both;
}

.scene-after blockquote {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.38rem;
  font-style: italic;
  line-height: 1.35;
}

.shard-received {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 24px 0 20px;
  color: var(--ash);
  font-size: 0.65rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.shard-received strong {
  display: inline-block;
  padding: 7px 11px;
  transform: rotate(-1.5deg);
  background: var(--wine);
  color: var(--paper);
  font-family: var(--serif);
  font-size: 0.9rem;
  font-style: italic;
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

.return-button {
  min-height: 48px;
  padding: 0;
  border: 0;
  border-bottom: 1px solid var(--rose);
  background: transparent;
  color: var(--paper);
  cursor: pointer;
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.ending-invitation {
  position: sticky;
  bottom: 0;
  z-index: 5;
  padding: 24px clamp(28px, 3.2vw, 54px) 28px;
  border-top: 1px solid rgba(234, 220, 201, 0.15);
  background: var(--wine);
  animation: after-enter 650ms var(--ease) both;
}

.ending-invitation p {
  margin: 0 0 14px;
  font-family: var(--serif);
  font-size: 1.1rem;
}

.primary-button,
.secondary-button,
.text-button {
  appearance: none;
  cursor: pointer;
}

.primary-button,
.secondary-button {
  min-height: 52px;
  padding: 13px 20px;
  border: 1px solid transparent;
  border-radius: 0;
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  transition: transform 350ms var(--ease), background 250ms ease, color 250ms ease;
}

.primary-button {
  background: var(--paper);
  color: var(--ink);
}

.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-3px);
}

.primary-button--light {
  width: 100%;
  border-color: var(--paper);
  background: transparent;
  color: var(--paper);
}

.primary-button--light:hover {
  background: var(--paper);
  color: var(--wine);
}

.primary-button--ink {
  background: var(--ink);
  color: var(--paper);
}

.secondary-button {
  border-color: rgba(8, 7, 7, 0.32);
  background: transparent;
  color: var(--ink);
}

.text-button {
  min-height: 42px;
  padding: 8px 0;
  border: 0;
  border-bottom: 1px solid rgba(234, 220, 201, 0.45);
  background: transparent;
  color: var(--paper);
  font-size: 0.68rem;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.text-button--ink {
  color: var(--ink);
  border-color: rgba(8, 7, 7, 0.4);
}

.start-screen,
.ending-screen {
  position: fixed;
  z-index: 80;
  inset: 0;
}

.start-screen {
  display: flex;
  align-items: center;
  padding: 8vw;
  background: var(--ink);
  transition: opacity 450ms ease 800ms, visibility 0s linear 1250ms;
}
.portrait-entry {
  position: absolute;
  right: 5%;
  bottom: 5%;
  width: min(48vw, 65vh);
  height: 88%;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  transform-origin: 50% 38%;
  transition: transform 1250ms var(--ease), filter 1250ms ease;
  -webkit-tap-highlight-color: transparent;
}
.portrait-entry img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: brightness(.55) saturate(.8);
  transition: filter 600ms ease;
}
.portrait-entry:hover img, .portrait-entry:focus-visible img { filter: brightness(.75) saturate(.8); }
.start-screen.is-leaving { opacity: 0; visibility: hidden; pointer-events: none; }
.start-screen.is-leaving .portrait-entry { transform: scale(2.7); }
.start-screen.is-leaving .portrait-entry img { filter: brightness(.95); }
.start-screen.is-leaving .start-copy { opacity: 0; transform: translateX(-20px); }
.start-copy {
  position: relative;
  z-index: 2;
  max-width: 54%;
  pointer-events: none;
  transition: opacity 400ms ease, transform 800ms ease;
}
.start-credits { line-height: 1.8; font-size: .8rem; letter-spacing: .1em; }
.start-credits span { color: var(--ash); }
.start-copy h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: clamp(3.5rem, 8vw, 8rem);
  font-weight: 400;
  letter-spacing: -.06em;
  line-height: .95;
}

.ending-screen {
  display: grid;
  place-items: center;
  padding: clamp(12px, 4vw, 50px);
  overflow: auto;
  background: rgba(8, 7, 7, 0.88);
  backdrop-filter: blur(15px);
  animation: fade-in 500ms ease both;
}

.ending-sheet {
  position: relative;
  width: min(900px, 100%);
  min-height: min(760px, calc(100vh - 40px));
  padding: clamp(34px, 7vw, 90px);
  background:
    linear-gradient(rgba(95, 29, 48, 0.05) 1px, transparent 1px) 0 0 / 100% 26px,
    var(--paper);
  box-shadow: 0 35px 100px rgba(0, 0, 0, 0.65);
  color: var(--ink);
}

.close-ending {
  position: absolute;
  top: 20px;
  right: 24px;
  min-height: 40px;
  padding: 0;
  border: 0;
  border-bottom: 1px solid rgba(8, 7, 7, 0.4);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.62rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.ending-header {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid rgba(8, 7, 7, 0.2);
}

.ending-header .eyebrow {
  margin-bottom: 16px;
  color: var(--wine);
}

.ending-date {
  margin: 0;
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.ending-sheet h2 {
  max-width: 760px;
  margin: 34px 0 38px;
  font-family: var(--serif);
  font-size: clamp(3.2rem, 8vw, 7rem);
  font-weight: 400;
  letter-spacing: -0.065em;
  line-height: 0.82;
}

.ending-text {
  max-width: 640px;
  font-family: var(--serif);
  font-size: clamp(1.12rem, 2.2vw, 1.45rem);
  line-height: 1.58;
}

.ending-text p {
  margin: 0 0 1em;
}

.collected-words {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 40px 0;
}

.collected-words span {
  display: inline-block;
  padding: 7px 12px;
  background: var(--wine);
  color: var(--paper);
  font-family: var(--serif);
  font-size: 0.92rem;
  font-style: italic;
  transform: rotate(var(--tilt));
}

.ending-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding-top: 24px;
  border-top: 1px solid rgba(8, 7, 7, 0.2);
}

.about-dialog {
  width: min(520px, calc(100vw - 32px));
  padding: 48px;
  border: 1px solid rgba(234, 220, 201, 0.3);
  border-radius: 0;
  background: var(--ink-soft);
  color: var(--paper);
  box-shadow: 0 35px 110px rgba(0, 0, 0, 0.85);
}

.about-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(7px);
}

.about-dialog h2 {
  margin: 0 0 24px;
  font-family: var(--serif);
  font-size: 2.5rem;
  font-weight: 400;
  letter-spacing: -0.04em;
  line-height: 0.98;
}

.about-dialog p:not(.eyebrow) {
  color: #d2c5b5;
  font-family: var(--serif);
  font-size: 1.05rem;
  line-height: 1.58;
}

.toast {
  position: fixed;
  z-index: 120;
  right: 22px;
  bottom: 22px;
  max-width: min(360px, calc(100vw - 44px));
  padding: 13px 17px;
  background: var(--paper);
  color: var(--ink);
  font-size: 0.78rem;
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 250ms ease, transform 350ms var(--ease);
  pointer-events: none;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

[hidden] {
  display: none !important;
}

@keyframes breathe {
  0%,
  100% {
    transform: translateY(0) scaleX(1) scaleY(1);
  }
  48% {
    transform: translateY(-3px) scaleX(1.006) scaleY(1.009);
  }
}

@keyframes eye-shift {
  0%,
  35%,
  100% {
    transform: translateX(0);
  }
  38%,
  43% {
    transform: translateX(1.2px);
  }
  47% {
    transform: translateX(-0.6px);
  }
}

@keyframes mouth-pulse {
  0%,
  42%,
  100% {
    transform: translateY(0) scaleY(1);
  }
  46% {
    transform: translateY(0.6px) scaleY(1.018);
  }
  50% {
    transform: translateY(0) scaleY(1);
  }
}

@keyframes seam-light {
  0%,
  64%,
  100% {
    transform: translateX(-120%);
  }
  78% {
    transform: translateX(130%);
  }
}

@keyframes soundbars {
  0% { height: 3px; }
  35% { height: 11px; }
  65% { height: 6px; }
  100% { height: 3px; }
}

@keyframes rail-enter {
  from {
    opacity: 0;
    transform: translateX(24px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes after-enter {
  from {
    opacity: 0;
    transform: translateY(14px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (max-width: 860px) {
  body {
    overflow: auto;
  }

  .topbar {
    position: fixed;
    inset: 0 0 auto 0;
    min-height: 62px;
    background: rgba(8, 7, 7, 0.88);
    backdrop-filter: blur(12px);
  }

  .progress-wrap {
    grid-template-columns: auto 55px;
  }

  .progress-label {
    display: none;
  }

  .game-shell {
    display: block;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    padding-top: 62px;
  }

  .mirror-zone {
    min-height: calc(100vh - 62px);
    min-height: calc(100dvh - 62px);
    padding: 62px 26px 105px;
  }

  .mirror {
    width: min(65vh, 82vw, 520px);
  }

  .mirror-instruction {
    top: 29px;
  }

  .reading-rail {
    position: fixed;
    z-index: 45;
    inset: auto 0 0;
    max-height: min(82vh, 780px);
    border-top: 1px solid rgba(234, 220, 201, 0.24);
    border-left: 0;
    background: rgba(18, 16, 16, 0.98);
    box-shadow: 0 -22px 70px rgba(0, 0, 0, 0.75);
    transform: translateY(calc(100% + 30px));
    transition: transform 560ms var(--ease);
  }

  .reading-rail.is-open {
    transform: translateY(0);
  }

  .rail-empty {
    display: none;
  }

  .scene-panel {
    min-height: auto;
    padding: 46px 26px max(34px, env(safe-area-inset-bottom));
  }

  .scene-panel h2 {
    font-size: clamp(2.45rem, 13vw, 4rem);
  }

  .scene-prose {
    font-size: 1.08rem;
  }

  .choice-list {
    margin-top: 25px;
  }

  .ending-invitation {
    position: fixed;
    z-index: 35;
    right: 16px;
    bottom: max(16px, env(safe-area-inset-bottom));
    left: 16px;
    padding: 16px;
    border: 1px solid rgba(234, 220, 201, 0.4);
    box-shadow: 0 14px 45px rgba(0, 0, 0, 0.55);
  }

  .ending-invitation p {
    display: none;
  }

  .mobile-fragment-map {
    position: absolute;
    z-index: 12;
    right: 0;
    bottom: 22px;
    left: 0;
    display: flex;
    justify-content: center;
    gap: 4px;
    padding: 0 14px;
  }

  .mobile-fragment-map button {
    min-height: 40px;
    padding: 0 8px;
    border: 0;
    border-bottom: 1px solid rgba(234, 220, 201, 0.24);
    background: transparent;
    color: var(--ash);
    font-family: var(--serif);
    font-size: 0.8rem;
    cursor: pointer;
  }

  .mobile-fragment-map button.is-complete {
    border-color: var(--rose);
    color: var(--paper);
  }

  .start-screen { align-items: flex-end; padding: 28px 24px max(32px, env(safe-area-inset-bottom)); }
  .portrait-entry { right: 9%; bottom: 24%; width: 82%; height: 72%; }
  .portrait-entry img { object-position: center top; }
  .start-copy { max-width: 100%; }
  .start-copy h1 { font-size: clamp(3rem, 13vw, 6.4rem); line-height: .95; }
  .start-credits { margin-bottom: 20px; font-size: .75rem; }

  .ending-screen {
    display: block;
    padding: 0;
  }

  .ending-sheet {
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 68px 24px 50px;
  }

  .ending-header {
    display: block;
  }

  .ending-date {
    margin-bottom: 12px;
  }

  .ending-sheet h2 {
    margin-top: 28px;
  }

  .ending-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .about-dialog {
    padding: 48px 26px 32px;
  }
}

@media (max-width: 430px) {
  .topbar {
    grid-template-columns: 1fr auto auto;
    padding: 10px 14px;
  }

  .wordmark {
    font-size: 0.59rem;
  }

  .sound-toggle {
    padding-left: 9px;
  }

  #soundLabel {
    display: none;
  }

  .mirror-zone {
    padding-right: 18px;
    padding-left: 18px;
  }

  .mirror {
    width: min(63vh, 84vw);
  }

  .body-fragment {
    border-color: rgba(234, 220, 201, 0.38);
  }

  .fragment-number {
    font-size: 0.46rem;
  }

  .fragment-word {
    display: none;
  }

  .mobile-fragment-map {
    gap: 0;
  }

  .mobile-fragment-map button {
    padding: 0 6px;
    font-size: 0.72rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media print {
  @page {
    margin: 0;
    size: A4 portrait;
  }

  body {
    overflow: visible;
    background: white;
  }

  body > :not(.ending-screen) {
    display: none !important;
  }

  .ending-screen {
    position: static;
    display: block !important;
    padding: 0;
    background: white;
  }

  .ending-sheet {
    width: 100%;
    min-height: 100vh;
    box-shadow: none;
  }

  .close-ending,
  .ending-actions {
    display: none !important;
  }
}

/* Quiet discovery surface: only paper responds to proximity. */
body { background: var(--ink); }
.topbar { grid-template-columns: 1fr auto; border: 0; background: var(--ink); }
.game-shell { display: block; }
.mirror-zone { min-height: 100%; padding: 12px 20px 20px; }
.mirror { width: min(67vh, 86vw, 680px); border: 0; box-shadow: none; }
.mirror::before,.mirror::after { display: none; }
.portrait-stage { background: var(--ink); }
.portrait-base,.micro-fragment img { filter: none !important; }
.body-fragment.discovery-fragment,
.body-fragment.discovery-fragment.is-complete,
.body-fragment.discovery-fragment.is-active {
  min-width: 0; min-height: 0; border: 0; padding: 0; background: transparent;
  opacity: 1; box-shadow: none; transform: none;
  clip-path: polygon(3% 4%,98% 0,96% 97%,0 100%);
}
.body-fragment.discovery-fragment::after { display: none; }
.body-fragment.discovery-fragment:hover,
.body-fragment.discovery-fragment:focus-visible {
  background: rgba(234,220,201,.19);
  box-shadow: inset 0 -2px rgba(234,220,201,.3);
  transform: translateY(-3px) rotate(var(--rotate));
}
.reading-rail {
  position: fixed; z-index: 50; inset: 50% auto auto 50%;
  width: min(560px, calc(100vw - 32px)); max-height: 80dvh;
  min-height: 0; transform: translate(-50%,-50%); border: 1px solid var(--line);
  background: #121010; box-shadow: 0 0 0 100vmax rgba(0,0,0,.65);
}
.reading-rail.is-open { transform: translate(-50%,-50%); }
.scene-panel { min-height: 0; padding: 48px 28px 30px; }
.ending-invitation { display: none !important; }
@media(max-width:860px) {
 .mirror-zone { min-height: calc(100dvh - 62px); padding: 10px 16px 20px; }
 .reading-rail { inset: 50% auto auto 50%; transform: translate(-50%,-50%); }
}

/* Long-form reading keeps paragraphs continuous and choices inside the fiction. */
.reading-rail.literary-reading { width: min(760px, calc(100vw - 28px)); max-height: 88dvh; }
.literary-reading .scene-panel { padding: 56px clamp(24px,6vw,64px) 38px; }
.literary-reading .scene-panel h2 { font-size: clamp(2.3rem,5vw,3.7rem); line-height: 1.04; }
.literary-reading .scene-prose { max-width: none; font-size: 1.18rem; line-height: 1.75; }
.literary-reading .scene-prose p { margin-bottom: 1.3em; }
.literary-reading .scene-after { margin-top: 20px; padding-top: 10px; border: 0; }

.discovery-continuation {
  animation: passage-enter 650ms var(--ease) both;
}

.discovery-continuation .scene-prose {
  max-width: none;
  font-size: clamp(1.12rem, 2vw, 1.35rem);
  line-height: 1.72;
}

.body-travel {
  position: fixed;
  z-index: 90;
  inset: 0;
  overflow: hidden;
}

.body-travel::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--ink);
}

.body-travel[hidden] { display: none; }

.travel-figure {
  position: absolute;
  overflow: hidden;
  transform: scale(1);
  transform-origin: 50% 50%;
  contain: layout paint;
}

.travel-figure img {
  position: absolute;
  display: block;
  max-width: none;
}

.body-travel.is-entering::before {
  animation: travel-veil 1300ms ease both;
}

.body-travel.is-returning::before {
  animation: travel-veil 1300ms ease reverse both;
}

.body-travel.is-entering .travel-figure {
  animation: enter-fragment 1300ms cubic-bezier(0.45, 0, 0.2, 1) both;
}

.body-travel.is-returning .travel-figure {
  animation: enter-fragment 1300ms cubic-bezier(0.45, 0, 0.2, 1) reverse both;
}

@keyframes travel-veil {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes enter-fragment {
  from { opacity: 1; transform: translate(0, 0) scale(var(--travel-start-scale)); }
  70% { opacity: 1; }
  to { opacity: 0; transform: translate(var(--travel-x), var(--travel-y)) scale(1); }
}

@keyframes passage-enter {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .travel-figure, .body-travel.is-entering .travel-figure, .body-travel.is-returning .travel-figure, .body-travel::before, .discovery-continuation { animation-duration: 1ms; }
}
@media(max-width:600px) {
 .literary-reading .scene-prose { font-size: 1.08rem; line-height: 1.68; }
}
