:root {
  color-scheme: dark;
  --text: #fffaf0;
  --muted: rgba(255, 250, 240, 0.72);
  --line: rgba(255, 255, 255, 0.2);
  --shadow: 0 18px 70px rgba(0, 0, 0, 0.52);
  --red: #d93b2f;
  --gold: #f2cf7a;
  --app-viewport-width: 100vw;
  --app-viewport-height: 100dvh;
  --app-viewport-left: 0px;
  --app-viewport-top: 0px;
  --content-safe-top: env(safe-area-inset-top, 0px);
  --content-safe-right: env(safe-area-inset-right, 0px);
  --content-safe-bottom: env(safe-area-inset-bottom, 0px);
  --content-safe-left: env(safe-area-inset-left, 0px);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  width: 100%;
  height: 100%;
}

.game-shell,
.stage {
  width: 100%;
  height: 100%;
  height: 100dvh;
}

body {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  background: #000;
  font-family:
    "Microsoft YaHei", "PingFang SC", Inter, system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
select {
  font: inherit;
  touch-action: manipulation;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.stage {
  position: relative;
  overflow: hidden;
  background: #000;
  --video-inline-inset: 0px;
  --video-block-inset: 0px;
  --screen-inline-inset: 0px;
  --screen-block-inset: 0px;
  --screen-safe-left: max(var(--screen-inline-inset), var(--content-safe-left));
  --screen-safe-right: max(var(--screen-inline-inset), var(--content-safe-right));
  --screen-safe-top: max(var(--screen-block-inset), var(--content-safe-top));
  --screen-safe-bottom: max(var(--screen-block-inset), var(--content-safe-bottom));
}

.player,
.boot-video {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  background: #000;
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: #000;
}

.screen-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.boot {
  z-index: 20;
}

.home-logo {
  position: absolute;
  left: 10.2vw;
  top: 6.2vh;
  width: min(28vw, 520px);
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 5px 8px rgba(84, 76, 168, 0.28));
}

.home-hero {
  position: absolute;
  right: -1.5vw;
  top: -2.5vh;
  width: min(58vw, 1110px);
  aspect-ratio: 1;
  pointer-events: none;
}

.home-hero .home-slide {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  opacity: 1;
  transition: opacity 220ms ease;
}

.home-hero-deco {
  position: absolute;
  z-index: 2;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.home-hero .home-slide.is-fading {
  opacity: 0;
}

.home-menu {
  position: absolute;
  left: 7.2vw;
  top: 53vh;
  display: flex;
  gap: 22px;
}

.diamond-button {
  position: relative;
  width: 138px;
  height: 138px;
  display: grid;
  place-items: center;
  --diamond-content-gap: 8px;
  border: 4px solid rgba(255, 255, 255, 0.88);
  border-radius: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.92), rgba(237, 236, 246, 0.84));
  color: #4c4e78;
  transform: rotate(45deg);
  box-shadow:
    0 7px 12px rgba(64, 87, 132, 0.24),
    inset 0 0 18px rgba(255, 255, 255, 0.78);
}

.diamond-content {
  width: 82%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--diamond-content-gap);
  transform: rotate(-45deg);
  pointer-events: none;
}

.diamond-button strong {
  width: 100%;
  display: block;
  font-size: 22px;
  line-height: 1.1;
  text-align: center;
  white-space: nowrap;
}

.diamond-icon {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  position: relative;
}

.book-icon::before,
.trophy-icon::before,
.album-icon::before,
.gear-icon::before {
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  color: #50549a;
  font-size: 38px;
  line-height: 1;
  text-align: center;
}

.book-icon::before {
  content: "▥";
}

.trophy-icon::before {
  content: "♛";
}

.album-icon::before {
  content: "▣";
}

.gear-icon::before {
  content: "⚙";
}

.continue-button {
  position: absolute;
  left: 11vw;
  bottom: 9vh;
  width: min(520px, 36vw);
  height: 108px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 40px;
  border: 4px solid rgba(255, 255, 255, 0.34);
  border-radius: 4px;
  background:
    linear-gradient(135deg, rgba(232, 55, 148, 0.98), rgba(246, 81, 163, 0.96)),
    linear-gradient(45deg, transparent 0 40%, rgba(255, 255, 255, 0.22) 40% 47%, transparent 47%);
  color: #fff;
  box-shadow:
    0 10px 20px rgba(70, 64, 95, 0.36),
    inset 0 0 0 1px rgba(255, 255, 255, 0.28);
}

.continue-button strong {
  font-size: 44px;
  letter-spacing: 0;
  text-shadow: 0 3px 0 rgba(109, 74, 135, 0.35);
}

.play-mark {
  width: 76px;
  height: 76px;
  border: 5px solid #fff;
  border-radius: 50%;
  position: relative;
}

.play-mark::after {
  content: "";
  position: absolute;
  left: 30px;
  top: 20px;
  border-left: 22px solid #fff;
  border-top: 15px solid transparent;
  border-bottom: 15px solid transparent;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 10px 18px;
  color: var(--text);
  background: rgba(16, 16, 18, 0.7);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.25);
  cursor: pointer;
}

button:hover {
  border-color: rgba(255, 255, 255, 0.45);
  background: rgba(34, 34, 38, 0.82);
}

button:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.title-button {
  min-width: 148px;
  min-height: 54px;
  font-size: 20px;
  font-weight: 800;
}

.title-button.primary {
  border-color: transparent;
  background: linear-gradient(180deg, #f2523f, #b51e1a);
}

.hud {
  position: absolute;
  z-index: 8;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 25px calc(var(--video-inline-inset) + 28px);
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.16), transparent);
  pointer-events: none;
}

.back-button {
  position: absolute;
  z-index: 35;
  left: 28px;
  top: 24px;
  width: 86px;
  height: 72px;
  border: 0;
  background: transparent;
  box-shadow: none;
  padding: 0;
}

.back-button:hover {
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.9));
}

.back-button::before,
.back-button::after {
  content: "";
  position: absolute;
  top: 14px;
  width: 34px;
  height: 34px;
  border-left: 9px solid rgba(255, 255, 255, 0.96);
  border-bottom: 9px solid rgba(255, 255, 255, 0.96);
  transform: rotate(45deg);
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.22));
}

.back-button::before {
  left: 12px;
}

.back-button::after {
  left: 42px;
}

.back-button.in-game {
  position: relative;
  left: auto;
  top: auto;
  pointer-events: auto;
}

.hud-left,
.hud-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

.hud-left {
  display: none;
}

.hud-left span {
  max-width: 38vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 7px 12px;
  border-radius: 4px;
  color: rgba(255, 255, 255, 0.86);
  background: rgba(0, 0, 0, 0.18);
  font-size: 14px;
}

.hud-actions button {
  min-height: 36px;
  padding: 7px 12px;
  font-size: 14px;
}

.subtitle {
  position: absolute;
  z-index: 7;
  left: 50%;
  bottom: 5.5vh;
  transform: translateX(-50%);
  width: fit-content;
  max-width: min(1180px, calc(100% - 48px));
  min-height: 48px;
  padding: 0 18px;
  border-radius: 4px;
  background: transparent;
  color: #fff;
  font-size: clamp(24px, 2.8vw, 38px);
  font-weight: 800;
  line-height: 1.35;
  text-align: center;
  text-shadow:
    0 2px 2px rgba(0, 0, 0, 0.95),
    0 0 10px rgba(0, 0, 0, 0.95);
  opacity: 0;
  transition: opacity 120ms ease;
  pointer-events: none;
}

.subtitle.is-visible {
  opacity: 1;
}

.choice-layer {
  position: absolute;
  z-index: 12;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0 26px 86px;
  background: linear-gradient(180deg, transparent 0 58%, rgba(0, 0, 0, 0.22));
}

.choice-frame {
  width: 100%;
}

.choice-title {
  display: none;
}

.choices {
  display: flex;
  justify-content: center;
  gap: clamp(22px, 2.7vw, 52px);
}

.choice-button {
  position: relative;
  flex: 0 1 min(22.5vw, 455px);
  width: min(22.5vw, 455px);
  min-height: clamp(74px, 8.8vh, 98px);
  padding: 12px 18px;
  border: 0;
  border-radius: 6px;
  background:
    linear-gradient(90deg, rgba(255, 246, 251, 0.72), rgba(255, 255, 255, 0.9)),
    url("./ui-assets/choice-button.png") center / 100% 100% no-repeat;
  color: #424052;
  font-size: clamp(24px, 2vw, 38px);
  font-weight: 800;
  line-height: 1.25;
  text-align: center;
  text-shadow:
    0 2px 0 #fff,
    0 0 3px rgba(255, 255, 255, 0.85);
  box-shadow:
    0 4px 7px rgba(0, 0, 0, 0.2),
    inset 0 0 0 2px rgba(255, 255, 255, 0.7);
}

.choice-button::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(255, 182, 218, 0.26), transparent 54%);
  border-radius: 6px;
  pointer-events: none;
}

.choice-button:hover {
  background:
    linear-gradient(90deg, rgba(92, 209, 235, 0.82), rgba(244, 72, 172, 0.92)),
    url("./ui-assets/choice-button.png") center / 100% 100% no-repeat;
  color: #fff;
  text-shadow:
    0 2px 0 rgba(60, 56, 100, 0.74),
    0 0 4px rgba(255, 255, 255, 0.6);
}

.chapter-screen {
  z-index: 24;
}

.chapter-heading {
  position: absolute;
  right: 0;
  top: 7vh;
  width: 45vw;
  color: rgba(255, 255, 255, 0.84);
}

.chapter-heading strong {
  display: block;
  font-size: clamp(76px, 7.7vw, 150px);
  line-height: 0.82;
  font-weight: 900;
  letter-spacing: 0;
}

.chapter-heading strong::after {
  content: "";
  display: block;
  height: 8px;
  margin-top: -4px;
  background: rgba(255, 255, 255, 0.72);
}

.chapter-heading span {
  display: block;
  margin-top: 26px;
  font-size: clamp(24px, 2.2vw, 42px);
  font-weight: 900;
}

.chapter-cards {
  position: absolute;
  left: 5.2vw;
  right: 0;
  bottom: 34vh;
  display: flex;
  gap: 3.2vw;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 12px 8vw 28px 0;
  scrollbar-width: none;
  cursor: grab;
  user-select: none;
  -webkit-overflow-scrolling: touch;
  touch-action: none;
}

.chapter-cards::-webkit-scrollbar {
  display: none;
}

.chapter-cards.is-dragging {
  cursor: grabbing;
}

.chapter-card {
  flex: 0 0 min(23vw, 460px);
  aspect-ratio: 1.48;
  position: relative;
  border: 6px solid rgba(255, 255, 255, 0.92);
  border-radius: 2px;
  padding: 0;
  background: rgba(255, 255, 255, 0.72);
  box-shadow:
    0 5px 12px rgba(74, 78, 130, 0.28),
    inset 0 0 0 4px rgba(155, 156, 177, 0.38);
  overflow: hidden;
}

.chapter-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  display: block;
  pointer-events: none;
}

.chapter-card::after {
  content: attr(data-number);
  position: absolute;
  right: 0;
  top: 0;
  width: 70px;
  height: 70px;
  background: linear-gradient(135deg, transparent 50%, rgba(255, 255, 255, 0.96) 51%);
  color: #e8298d;
  font-size: 42px;
  font-weight: 900;
  text-align: right;
  padding-right: 10px;
}

.flow-screen {
  z-index: 25;
  --flow-blue: #2bbce0;
  --flow-pink: #ef2d99;
}

.flow-heading {
  position: absolute;
  z-index: 4;
  right: 4vw;
  top: 2.5vh;
  width: min(760px, 47vw);
  display: flex;
  justify-content: flex-end;
  align-items: flex-start;
  color: rgba(255, 255, 255, 0.55);
  pointer-events: none;
}

.flow-heading-copy {
  flex: 1;
  padding-top: 5vh;
  text-align: right;
}

.flow-heading-copy strong {
  display: block;
  border-bottom: 4px solid rgba(255, 255, 255, 0.46);
  font-size: clamp(50px, 5.2vw, 96px);
  line-height: 0.9;
}

.flow-heading-copy span {
  display: block;
  margin-top: 14px;
  padding-right: 20px;
  color: rgba(255, 255, 255, 0.66);
  font-size: clamp(20px, 1.8vw, 34px);
  font-weight: 800;
}

.flow-heading b {
  width: 160px;
  font-size: clamp(120px, 14vw, 270px);
  line-height: 0.88;
  text-align: center;
}

.flow-viewport {
  position: absolute;
  z-index: 2;
  inset: 17vh 0 0;
  overflow: auto;
  cursor: grab;
  scrollbar-width: none;
  user-select: none;
  -webkit-overflow-scrolling: touch;
  touch-action: none;
  overscroll-behavior: contain;
}

.flow-viewport::-webkit-scrollbar {
  display: none;
}

.flow-viewport.is-dragging {
  cursor: grabbing;
}

.flow-canvas {
  position: relative;
  min-width: 100%;
  min-height: 760px;
}

.flow-lines {
  position: absolute;
  inset: 0;
  overflow: visible;
  pointer-events: none;
}

.flow-lines path {
  fill: none;
  stroke: rgba(255, 255, 255, 0.94);
  stroke-width: 6;
  stroke-linejoin: round;
}

.flow-start,
.flow-node {
  position: absolute;
  z-index: 2;
  transform: translate(-50%, -50%);
}

.flow-start {
  width: 176px;
  height: 176px;
  border: 5px solid rgba(255, 255, 255, 0.95);
  background: rgba(223, 250, 255, 0.88);
  box-shadow: 10px 10px 0 rgba(97, 129, 190, 0.22);
  transform: translate(-50%, -50%) rotate(45deg);
}

.flow-start::before,
.flow-start::after {
  content: "";
  position: absolute;
  inset: 18px;
  border: 3px solid rgba(255, 255, 255, 0.75);
}

.flow-start span {
  position: absolute;
  z-index: 2;
  left: -18px;
  top: 52px;
  width: 205px;
  padding: 4px 8px 7px;
  border: 4px solid rgba(255, 255, 255, 0.85);
  background: #ef3c9b;
  color: #fff;
  font-size: 38px;
  font-weight: 900;
  line-height: 1;
  text-align: center;
  transform: rotate(-45deg);
  box-shadow: 0 3px 5px rgba(60, 70, 125, 0.22);
}

.flow-start small {
  position: absolute;
  left: 34px;
  bottom: 12px;
  width: 110px;
  color: #5673bd;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 5px;
  transform: rotate(-45deg);
}

.flow-node-card {
  width: 258px;
  border: 0;
  padding: 0;
  background: transparent;
  color: #fff;
}

.flow-node-card img {
  width: 258px;
  height: 145px;
  display: block;
  border: 4px solid rgba(255, 255, 255, 0.94);
  object-fit: cover;
  box-shadow: 0 7px 16px rgba(53, 72, 130, 0.24);
  pointer-events: none;
}

.flow-node-card span {
  display: block;
  margin-top: 8px;
  max-width: 258px;
  overflow: hidden;
  color: #fff;
  font-size: 19px;
  font-weight: 800;
  text-overflow: ellipsis;
  text-shadow: 0 2px 4px rgba(65, 71, 126, 0.65);
  white-space: nowrap;
}

.flow-node-card::after {
  content: "▶";
  position: absolute;
  left: 50%;
  top: 72px;
  width: 58px;
  height: 58px;
  display: grid;
  place-items: center;
  border: 5px solid rgba(255, 255, 255, 0.76);
  border-radius: 50%;
  background: rgba(40, 42, 58, 0.36);
  color: #fff;
  font-size: 25px;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.flow-junction {
  width: 38px;
  height: 38px;
  border: 5px solid rgba(255, 255, 255, 0.95);
  padding: 0;
  background: var(--flow-pink);
  transform: translate(-50%, -50%) rotate(45deg);
  box-shadow: inset 0 0 0 5px rgba(255, 255, 255, 0.75);
}

.flow-junction.has-video {
  cursor: pointer;
}

.flow-special {
  width: 72px;
  height: 72px;
  border: 4px solid #fff;
  padding: 0;
  background: rgba(240, 246, 255, 0.84);
  transform: translate(-50%, -50%) rotate(45deg);
}

.flow-special::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #ef2d99;
  font-size: 34px;
  font-weight: 900;
  transform: rotate(-45deg);
}

.flow-node.is-visited img,
.flow-node.is-visited.flow-junction {
  filter: saturate(1.15) brightness(1.06);
  box-shadow: 0 0 0 5px rgba(239, 45, 153, 0.62);
}

.flow-progress-panel {
  position: absolute;
  z-index: 5;
  left: 20px;
  bottom: 20px;
  width: min(780px, 40vw);
  min-width: 520px;
  padding: 0 18px 16px;
  background: rgba(226, 245, 255, 0.86);
  color: #5571ba;
  box-shadow: 0 7px 20px rgba(65, 80, 135, 0.18);
}

.flow-progress-head {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 4px solid rgba(255, 255, 255, 0.8);
  font-size: 24px;
}

.flow-progress-head span {
  padding: 7px 13px;
  background: #637cd0;
  color: #fff;
  font-size: 17px;
  font-weight: 800;
}

.flow-milestones {
  height: 77px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: center;
}

.flow-milestone {
  position: relative;
  height: 58px;
  border: 0;
  padding: 0;
  background: transparent;
}

.flow-milestone img {
  width: 92px;
  height: 52px;
  object-fit: cover;
  box-shadow: 0 3px 8px rgba(57, 66, 111, 0.28);
}

.flow-progress-track {
  position: relative;
  height: 7px;
  margin: 0 8%;
  background: rgba(239, 45, 153, 0.25);
}

.flow-progress-track i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: var(--flow-pink);
  transition: width 240ms ease;
}

.flow-progress-track::after {
  content: "25%        50%        75%        100%";
  position: absolute;
  left: -3%;
  top: 12px;
  width: 106%;
  color: var(--flow-pink);
  font-size: 18px;
  word-spacing: 56px;
  white-space: pre;
}

.drawer {
  position: absolute;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.58);
}

.drawer-panel {
  width: min(440px, 100%);
  display: grid;
  gap: 16px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(13, 14, 17, 0.94);
  box-shadow: var(--shadow);
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.field {
  display: grid;
  gap: 7px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
}

select {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0 10px;
  color: var(--text);
  background: #1b1d22;
}

.wide-button {
  width: 100%;
}

.history-list {
  position: absolute;
  z-index: 6;
  left: 16px;
  bottom: 16px;
  max-width: 360px;
  max-height: 160px;
  margin: 0;
  padding-left: 24px;
  color: rgba(255, 255, 255, 0.56);
  font-size: 12px;
  line-height: 1.5;
  pointer-events: none;
}

.toast {
  position: absolute;
  z-index: 40;
  left: 50%;
  top: 72px;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.78);
  color: #fff;
  box-shadow: var(--shadow);
}

@media (max-width: 820px) {
  .hud {
    align-items: flex-start;
    padding: 12px;
  }

  .hud-left {
    display: none;
  }

  .hud-actions {
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .choice-layer {
    place-items: end center;
    background: linear-gradient(180deg, transparent 0 38%, rgba(0, 0, 0, 0.76));
  }

  .choice-frame {
    width: min(100%, 620px);
  }

  .choice-button {
    min-height: 56px;
    font-size: 18px;
  }

  .subtitle {
    bottom: 18px;
    max-width: calc(100% - 24px);
    font-size: 22px;
  }

  .flow-heading {
    right: 2vw;
    width: 65vw;
  }

  .flow-heading b {
    width: 82px;
  }

  .flow-progress-panel {
    left: 12px;
    bottom: 12px;
    width: calc(100% - 24px);
    min-width: 0;
  }

  .flow-node-card,
  .flow-node-card img {
    width: 220px;
  }

  .flow-node-card img {
    height: 124px;
  }
}

body.mobile-expanded .game-shell,
body.mobile-expanded .stage {
  position: fixed;
  z-index: 9999;
  inset: 0;
  width: 100vw;
  height: 100dvh;
}

@media (pointer: coarse) {
  body {
    overscroll-behavior: none;
  }

  button,
  select {
    min-height: 44px;
  }

  .drawer-panel {
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
  }

  .history-list {
    display: none;
  }
}

@media (orientation: landscape) and (max-height: 600px),
  (orientation: landscape) and (pointer: coarse) and (max-width: 1200px) {
  .home-logo {
    left: 8vw;
    top: max(3dvh, env(safe-area-inset-top));
    width: 27vw;
  }

  .home-hero {
    right: -1vw;
    top: -12dvh;
    width: min(59vw, 135dvh);
  }

  .home-menu {
    left: max(6vw, env(safe-area-inset-left));
    top: 48dvh;
    gap: clamp(8px, 1.5vw, 14px);
  }

  .diamond-button {
    width: clamp(58px, 8.2vw, 76px);
    height: clamp(58px, 8.2vw, 76px);
    --diamond-content-gap: 2px;
    border-width: 2px;
    padding: 4px;
  }

  .diamond-button strong {
    font-size: clamp(10px, 1.45vw, 13px);
  }

  .diamond-icon {
    width: 22px;
    height: 22px;
  }

  .book-icon::before,
  .trophy-icon::before,
  .album-icon::before,
  .gear-icon::before {
    font-size: 23px;
    line-height: 22px;
  }

  .continue-button {
    left: 10vw;
    bottom: max(3dvh, env(safe-area-inset-bottom));
    width: 29vw;
    height: clamp(48px, 14dvh, 62px);
    gap: 18px;
    border-width: 2px;
    padding: 4px 12px;
  }

  .continue-button strong {
    font-size: clamp(21px, 3.6vw, 30px);
  }

  .play-mark {
    width: 38px;
    height: 38px;
    border-width: 3px;
  }

  .play-mark::after {
    left: 14px;
    top: 9px;
    border-left-width: 13px;
    border-top-width: 8px;
    border-bottom-width: 8px;
  }

  .back-button {
    left: max(8px, env(safe-area-inset-left));
    top: max(7px, env(safe-area-inset-top));
    width: 58px;
    height: 48px;
  }

  .back-button::before,
  .back-button::after {
    top: 11px;
    width: 22px;
    height: 22px;
    border-left-width: 6px;
    border-bottom-width: 6px;
  }

  .back-button::before {
    left: 7px;
  }

  .back-button::after {
    left: 27px;
  }

  .hud {
    gap: 6px;
    padding-top: max(7px, env(safe-area-inset-top));
    padding-right: max(calc(var(--video-inline-inset) + 10px), calc(env(safe-area-inset-right) + 8px));
    padding-bottom: 8px;
    padding-left: max(calc(var(--video-inline-inset) + 10px), calc(env(safe-area-inset-left) + 8px));
  }

  .hud-actions {
    gap: 4px;
    margin-right: 0;
  }

  .hud-actions button {
    min-height: 40px;
    padding: 5px 9px;
    font-size: 12px;
  }

  .subtitle {
    bottom: max(10px, env(safe-area-inset-bottom));
    max-width: calc(100% - 28px);
    min-height: 0;
    padding: 0 8px;
    font-size: clamp(16px, 2.6vw, 22px);
  }

  .choice-layer {
    padding: 0 max(12px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    background: linear-gradient(180deg, transparent 0 56%, rgba(0, 0, 0, 0.2));
  }

  .choices {
    gap: clamp(7px, 1.5vw, 14px);
  }

  .choice-button {
    flex-basis: min(22.5vw, 220px);
    width: min(22.5vw, 220px);
    min-height: clamp(48px, 15dvh, 64px);
    padding: 6px 8px;
    font-size: clamp(14px, 2.15vw, 18px);
  }

  .chapter-heading {
    top: 4dvh;
    width: 48vw;
  }

  .chapter-heading strong {
    font-size: clamp(46px, 8vw, 72px);
  }

  .chapter-heading strong::after {
    height: 4px;
  }

  .chapter-heading span {
    margin-top: 10px;
    font-size: clamp(15px, 2.4vw, 21px);
  }

  .chapter-cards {
    left: max(5vw, env(safe-area-inset-left));
    bottom: 23dvh;
    gap: 3vw;
    padding-bottom: 12px;
  }

  .chapter-card {
    flex-basis: min(27vw, 240px);
    border-width: 4px;
  }

  .chapter-card::after {
    width: 42px;
    height: 42px;
    padding-right: 6px;
    font-size: 26px;
  }

  .flow-heading {
    right: 2vw;
    top: 0;
    width: 50vw;
  }

  .flow-heading-copy {
    padding-top: 2dvh;
  }

  .flow-heading-copy strong {
    font-size: clamp(30px, 5.5vw, 48px);
  }

  .flow-heading-copy span {
    margin-top: 5px;
    font-size: clamp(12px, 2vw, 17px);
  }

  .flow-heading b {
    width: 72px;
    font-size: clamp(72px, 13vw, 110px);
  }

  .flow-viewport {
    inset: 12dvh 0 0;
  }

  .flow-node-card,
  .flow-node-card img {
    width: 190px;
  }

  .flow-node-card img {
    height: 107px;
  }

  .flow-node-card span {
    max-width: 190px;
    margin-top: 5px;
    font-size: 13px;
  }

  .flow-node-card::after {
    top: 53px;
    width: 42px;
    height: 42px;
    border-width: 3px;
    font-size: 18px;
  }

  .flow-progress-panel {
    left: max(8px, env(safe-area-inset-left));
    bottom: max(8px, env(safe-area-inset-bottom));
    width: min(43vw, 360px);
    min-width: 0;
    padding: 0 10px 11px;
  }

  .flow-progress-head {
    height: 34px;
    font-size: 15px;
  }

  .flow-progress-head span {
    padding: 4px 7px;
    font-size: 11px;
  }

  .flow-milestones {
    height: 46px;
  }

  .flow-milestone {
    min-height: 40px;
    height: 40px;
  }

  .flow-milestone img {
    width: 56px;
    height: 32px;
  }

  .flow-progress-track::after {
    display: none;
  }

  .drawer {
    padding: max(10px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  }

  .drawer-panel {
    width: min(390px, 86vw);
    gap: 8px;
    padding: 14px;
  }

  .toast {
    top: max(58px, calc(env(safe-area-inset-top) + 48px));
    max-width: calc(100% - 24px);
    font-size: 13px;
  }
}

@media (orientation: portrait) and (max-width: 820px) and (min-width: 821px) {
  .home-logo {
    left: 50%;
    top: max(2.5dvh, env(safe-area-inset-top));
    width: min(68vw, 380px);
    transform: translateX(-50%);
  }

  .home-hero {
    right: auto;
    left: 50%;
    top: 10dvh;
    width: min(94vw, 520px);
    transform: translateX(-50%);
  }

  .home-menu {
    left: 50%;
    top: 58dvh;
    gap: clamp(7px, 2.2vw, 12px);
    transform: translateX(-50%);
  }

  .diamond-button {
    width: clamp(56px, 16vw, 72px);
    height: clamp(56px, 16vw, 72px);
    --diamond-content-gap: 2px;
    border-width: 2px;
    padding: 4px;
  }

  .diamond-button strong {
    font-size: clamp(10px, 3vw, 13px);
  }

  .diamond-icon {
    width: 22px;
    height: 22px;
  }

  .book-icon::before,
  .trophy-icon::before,
  .album-icon::before,
  .gear-icon::before {
    font-size: 23px;
    line-height: 22px;
  }

  .continue-button {
    left: 8vw;
    bottom: max(5dvh, env(safe-area-inset-bottom));
    width: 84vw;
    height: 64px;
    gap: 24px;
  }

  .continue-button strong {
    font-size: 28px;
  }

  .play-mark {
    width: 44px;
    height: 44px;
    border-width: 3px;
  }

  .play-mark::after {
    left: 17px;
    top: 11px;
    border-left-width: 14px;
    border-top-width: 9px;
    border-bottom-width: 9px;
  }

  .back-button {
    left: max(8px, env(safe-area-inset-left));
    top: max(8px, env(safe-area-inset-top));
    width: 60px;
    height: 52px;
  }

  .back-button::before,
  .back-button::after {
    top: 12px;
    width: 23px;
    height: 23px;
    border-left-width: 6px;
    border-bottom-width: 6px;
  }

  .back-button::before {
    left: 7px;
  }

  .back-button::after {
    left: 28px;
  }

  .chapter-heading {
    top: max(6dvh, env(safe-area-inset-top));
    width: 78vw;
  }

  .chapter-heading strong {
    font-size: clamp(54px, 16vw, 84px);
  }

  .chapter-heading span {
    margin-top: 14px;
    font-size: clamp(20px, 6vw, 28px);
  }

  .chapter-cards {
    left: 6vw;
    top: 29dvh;
    right: 0;
    bottom: auto;
    gap: 7vw;
    padding-right: 14vw;
  }

  .chapter-card {
    flex-basis: 78vw;
    border-width: 4px;
  }

  .flow-heading {
    right: 0;
    top: max(1dvh, env(safe-area-inset-top));
    width: 76vw;
  }

  .flow-heading-copy {
    padding-top: 3dvh;
  }

  .flow-heading-copy strong {
    font-size: clamp(38px, 12vw, 60px);
  }

  .flow-heading-copy span {
    margin-top: 7px;
    padding-right: 8px;
    font-size: clamp(14px, 4.5vw, 21px);
  }

  .flow-heading b {
    width: 72px;
    font-size: clamp(82px, 25vw, 125px);
  }

  .flow-viewport {
    inset: 14dvh 0 0;
    padding-bottom: 145px;
  }

  .flow-node-card,
  .flow-node-card img {
    width: 200px;
  }

  .flow-node-card img {
    height: 112px;
  }

  .flow-node-card span {
    max-width: 200px;
    font-size: 14px;
  }

  .flow-progress-panel {
    left: 8px;
    bottom: max(8px, env(safe-area-inset-bottom));
    width: calc(100% - 16px);
    min-width: 0;
    padding: 0 10px 11px;
  }

  .flow-progress-head {
    height: 38px;
    font-size: 16px;
  }

  .flow-progress-head span {
    padding: 4px 8px;
    font-size: 12px;
  }

  .flow-milestones {
    height: 52px;
  }

  .flow-milestone {
    min-height: 42px;
    height: 42px;
  }

  .flow-milestone img {
    width: 64px;
    height: 36px;
  }

  .flow-progress-track::after {
    display: none;
  }

  .hud {
    align-items: flex-start;
    gap: 5px;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) 8px max(8px, env(safe-area-inset-left));
  }

  .back-button.in-game {
    flex: 0 0 60px;
  }

  .hud-actions {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 3px;
    width: calc(100% - 65px);
  }

  .hud-actions button {
    min-width: 0;
    min-height: 44px;
    padding: 4px 2px;
    font-size: 11px;
  }

  .subtitle {
    bottom: max(18px, calc((100dvh - 56.25vw) / 2 + 14px));
    max-width: calc(100% - 20px);
    min-height: 0;
    padding: 0 6px;
    font-size: clamp(18px, 5.4vw, 24px);
  }

  .choice-layer {
    align-items: flex-end;
    padding: 0 10px max(18px, env(safe-area-inset-bottom));
    background: linear-gradient(180deg, transparent 0 44%, rgba(0, 0, 0, 0.34));
  }

  .choice-frame {
    width: 100%;
    max-height: 48dvh;
    overflow-y: auto;
  }

  .choices {
    flex-direction: column;
    gap: 8px;
  }

  .choice-button {
    flex: 0 0 auto;
    width: 100%;
    min-height: 56px;
    padding: 8px 12px;
    font-size: 18px;
  }

  .drawer {
    padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
  }

  .drawer-panel {
    width: 100%;
    max-width: 440px;
  }
}

/* Present the game as a landscape canvas when a phone is held upright. */
@media (orientation: portrait) and (max-width: 820px) {
  html,
  body {
    width: 100vw;
    height: 100dvh;
    overflow: hidden;
  }

  body .game-shell {
    position: fixed;
    z-index: 1;
    left: calc(var(--app-viewport-left) + var(--app-viewport-width));
    top: var(--app-viewport-top);
    width: var(--app-viewport-height);
    height: var(--app-viewport-width);
    transform: rotate(90deg);
    transform-origin: top left;
  }

  body .stage,
  body.mobile-expanded .stage {
    position: relative;
    inset: auto;
    width: 100%;
    height: 100%;
    --content-safe-top: env(safe-area-inset-right, 0px);
    --content-safe-right: env(safe-area-inset-bottom, 0px);
    --content-safe-bottom: env(safe-area-inset-left, 0px);
    --content-safe-left: env(safe-area-inset-top, 0px);
  }

  .home-logo {
    left: max(8dvh, calc(var(--content-safe-left) + 12px));
    top: max(3vw, calc(var(--content-safe-top) + 8px));
    width: 27dvh;
  }

  .home-hero {
    right: -1dvh;
    top: -12vw;
    width: min(59dvh, 135vw);
  }

  .home-menu {
    left: max(6dvh, calc(var(--content-safe-left) + 8px));
    top: 48vw;
    gap: clamp(8px, 1.5dvh, 14px);
    transform: none;
  }

  .diamond-button {
    width: clamp(58px, 8.2dvh, 76px);
    height: clamp(58px, 8.2dvh, 76px);
    --diamond-content-gap: 2px;
    border-width: 2px;
    padding: 4px;
  }

  .diamond-button strong {
    font-size: clamp(10px, 1.45dvh, 13px);
  }

  .diamond-icon {
    width: 22px;
    height: 22px;
  }

  .book-icon::before,
  .trophy-icon::before,
  .album-icon::before,
  .gear-icon::before {
    font-size: 23px;
    line-height: 22px;
  }

  .continue-button {
    left: max(10dvh, calc(var(--content-safe-left) + 12px));
    bottom: max(3vw, calc(var(--content-safe-bottom) + 8px));
    width: 29dvh;
    height: clamp(48px, 14vw, 62px);
    gap: 18px;
    border-width: 2px;
    padding: 4px 12px;
  }

  .continue-button strong {
    font-size: clamp(21px, 3.6dvh, 30px);
  }

  .play-mark {
    width: 38px;
    height: 38px;
    border-width: 3px;
  }

  .play-mark::after {
    left: 14px;
    top: 9px;
    border-left-width: 13px;
    border-top-width: 8px;
    border-bottom-width: 8px;
  }

  .back-button {
    left: max(8px, calc(var(--content-safe-left) + 6px));
    top: max(7px, calc(var(--content-safe-top) + 6px));
    width: 58px;
    height: 48px;
  }

  .back-button::before,
  .back-button::after {
    top: 11px;
    width: 22px;
    height: 22px;
    border-left-width: 6px;
    border-bottom-width: 6px;
  }

  .back-button::before {
    left: 7px;
  }

  .back-button::after {
    left: 27px;
  }

  .chapter-heading {
    right: max(0px, var(--content-safe-right));
    top: max(4vw, calc(var(--content-safe-top) + 4px));
    width: 48dvh;
  }

  .chapter-heading strong {
    font-size: clamp(46px, 8dvh, 72px);
  }

  .chapter-heading strong::after {
    height: 4px;
  }

  .chapter-heading span {
    margin-top: 10px;
    font-size: clamp(15px, 2.4dvh, 21px);
  }

  .chapter-cards {
    left: max(5dvh, calc(var(--content-safe-left) + 8px));
    top: auto;
    right: 0;
    bottom: max(23vw, calc(var(--content-safe-bottom) + 12px));
    gap: 3dvh;
    padding-right: max(8dvh, calc(var(--content-safe-right) + 20px));
    padding-bottom: 12px;
  }

  .chapter-card {
    flex-basis: min(27dvh, 240px);
    border-width: 4px;
  }

  .chapter-card::after {
    width: 42px;
    height: 42px;
    padding-right: 6px;
    font-size: 26px;
  }

  .flow-heading {
    right: max(2dvh, var(--content-safe-right));
    top: var(--content-safe-top);
    width: 50dvh;
  }

  .flow-heading-copy {
    padding-top: 2vw;
  }

  .flow-heading-copy strong {
    font-size: clamp(30px, 5.5dvh, 48px);
  }

  .flow-heading-copy span {
    margin-top: 5px;
    font-size: clamp(12px, 2dvh, 17px);
  }

  .flow-heading b {
    width: 72px;
    font-size: clamp(72px, 13dvh, 110px);
  }

  .flow-viewport {
    inset: 12vw 0 0;
    padding-bottom: 0;
  }

  .flow-node-card,
  .flow-node-card img {
    width: 190px;
  }

  .flow-node-card img {
    height: 107px;
  }

  .flow-node-card span {
    max-width: 190px;
    margin-top: 5px;
    font-size: 13px;
  }

  .flow-node-card::after {
    top: 53px;
    width: 42px;
    height: 42px;
    border-width: 3px;
    font-size: 18px;
  }

  .flow-progress-panel {
    left: max(8px, calc(var(--content-safe-left) + 6px));
    bottom: max(8px, calc(var(--content-safe-bottom) + 6px));
    width: min(43dvh, 360px);
    min-width: 0;
    padding: 0 10px 11px;
  }

  .flow-progress-head {
    height: 34px;
    font-size: 15px;
  }

  .flow-progress-head span {
    padding: 4px 7px;
    font-size: 11px;
  }

  .flow-milestones {
    height: 46px;
  }

  .flow-milestone {
    min-height: 40px;
    height: 40px;
  }

  .flow-milestone img {
    width: 56px;
    height: 32px;
  }

  .flow-progress-track::after {
    display: none;
  }

  .hud {
    gap: 6px;
    padding-top: max(7px, calc(var(--content-safe-top) + 5px));
    padding-right: max(calc(var(--video-inline-inset) + 10px), calc(var(--content-safe-right) + 8px));
    padding-bottom: max(8px, calc(var(--content-safe-bottom) + 5px));
    padding-left: max(calc(var(--video-inline-inset) + 10px), calc(var(--content-safe-left) + 8px));
  }

  .hud-actions {
    width: auto;
    gap: 4px;
    margin-right: 0;
    flex-wrap: nowrap;
  }

  .hud-actions button {
    min-height: 40px;
    padding: 5px 9px;
    font-size: 12px;
  }

  .subtitle {
    bottom: max(10px, calc(var(--content-safe-bottom) + 8px));
    max-width: calc(100% - 28px);
    min-height: 0;
    padding: 0 8px;
    font-size: clamp(16px, 2.6dvh, 22px);
  }

  .choice-layer {
    align-items: flex-end;
    padding: 0 max(12px, calc(var(--content-safe-right) + 8px)) max(16px, calc(var(--content-safe-bottom) + 10px)) max(12px, calc(var(--content-safe-left) + 8px));
    background: linear-gradient(180deg, transparent 0 56%, rgba(0, 0, 0, 0.2));
  }

  .choice-frame {
    width: min(100%, 620px);
    max-height: none;
    overflow: visible;
  }

  .choices {
    flex-direction: row;
    gap: clamp(7px, 1.5dvh, 14px);
  }

  .choice-button {
    flex: 0 0 min(22.5dvh, 220px);
    width: min(22.5dvh, 220px);
    min-height: clamp(48px, 15vw, 64px);
    padding: 6px 8px;
    font-size: clamp(14px, 2.15dvh, 18px);
  }

  .drawer {
    padding: max(10px, calc(var(--content-safe-top) + 6px)) max(10px, calc(var(--content-safe-right) + 6px)) max(10px, calc(var(--content-safe-bottom) + 6px)) max(10px, calc(var(--content-safe-left) + 6px));
  }

  .drawer-panel {
    width: min(390px, 86dvh);
    max-height: calc(100vw - 20px);
    gap: 8px;
    padding: 14px;
  }

  .toast {
    top: max(58px, calc(var(--content-safe-top) + 48px));
    max-width: calc(100% - 24px);
    font-size: 13px;
  }
}

/* Keep every non-video game screen inside the same visible 16:9 area as video. */
@media (orientation: landscape) and (max-height: 600px),
  (orientation: landscape) and (pointer: coarse) and (max-width: 1200px) {
  .boot .screen-bg,
  .chapter-screen .screen-bg,
  .flow-screen .screen-bg {
    object-fit: contain;
    background: #000;
  }

  .home-logo {
    left: calc(var(--screen-safe-left) + 8vw);
    top: calc(var(--screen-safe-top) + 3dvh);
  }

  .home-hero {
    right: calc(var(--screen-safe-right) - 1vw);
    top: calc(var(--screen-safe-top) - 12dvh);
  }

  .home-menu {
    left: calc(var(--screen-safe-left) + 6vw);
  }

  .continue-button {
    left: calc(var(--screen-safe-left) + 10vw);
    bottom: calc(var(--screen-safe-bottom) + 3dvh);
  }

  .chapter-screen > .back-button,
  .flow-screen > .back-button {
    left: calc(var(--screen-safe-left) + 8px);
    top: calc(var(--screen-safe-top) + 7px);
  }

  .chapter-heading {
    right: var(--screen-safe-right);
    top: calc(var(--screen-safe-top) + 4dvh);
  }

  .chapter-cards {
    left: calc(var(--screen-safe-left) + 5vw);
    right: var(--screen-safe-right);
    bottom: calc(var(--screen-safe-bottom) + 23dvh);
    padding-right: 8vw;
  }

  .flow-heading {
    right: calc(var(--screen-safe-right) + 2vw);
    top: var(--screen-safe-top);
  }

  .flow-viewport {
    left: var(--screen-safe-left);
    right: var(--screen-safe-right);
    top: calc(var(--screen-safe-top) + 12dvh);
    bottom: var(--screen-safe-bottom);
  }

  .flow-progress-panel {
    left: calc(var(--screen-safe-left) + 8px);
    bottom: calc(var(--screen-safe-bottom) + 8px);
  }
}

@media (orientation: portrait) and (max-width: 820px) {
  .boot .screen-bg,
  .chapter-screen .screen-bg,
  .flow-screen .screen-bg {
    object-fit: contain;
    background: #000;
  }

  .home-logo {
    left: calc(var(--screen-safe-left) + 8dvh);
    top: calc(var(--screen-safe-top) + 3vw);
  }

  .home-hero {
    right: calc(var(--screen-safe-right) - 1dvh);
    top: calc(var(--screen-safe-top) - 12vw);
  }

  .home-menu {
    left: calc(var(--screen-safe-left) + 6dvh);
  }

  .continue-button {
    left: calc(var(--screen-safe-left) + 10dvh);
    bottom: calc(var(--screen-safe-bottom) + 3vw);
  }

  .chapter-screen > .back-button,
  .flow-screen > .back-button {
    left: calc(var(--screen-safe-left) + 8px);
    top: calc(var(--screen-safe-top) + 7px);
  }

  .chapter-heading {
    right: var(--screen-safe-right);
    top: calc(var(--screen-safe-top) + 4vw);
  }

  .chapter-cards {
    left: calc(var(--screen-safe-left) + 5dvh);
    right: var(--screen-safe-right);
    bottom: calc(var(--screen-safe-bottom) + 23vw);
    padding-right: 8dvh;
  }

  .flow-heading {
    right: calc(var(--screen-safe-right) + 2dvh);
    top: var(--screen-safe-top);
  }

  .flow-viewport {
    left: var(--screen-safe-left);
    right: var(--screen-safe-right);
    top: calc(var(--screen-safe-top) + 12vw);
    bottom: var(--screen-safe-bottom);
  }

  .flow-progress-panel {
    left: calc(var(--screen-safe-left) + 8px);
    bottom: calc(var(--screen-safe-bottom) + 8px);
  }
}

/* Bind every mobile screen to the browser's live visual viewport. */
@media (orientation: landscape) and (max-height: 600px),
  (orientation: landscape) and (pointer: coarse) and (max-width: 1200px) {
  body .game-shell,
  body.mobile-expanded .game-shell {
    position: fixed;
    z-index: 1;
    left: var(--app-viewport-left);
    top: var(--app-viewport-top);
    width: var(--app-viewport-width);
    height: var(--app-viewport-height);
    transform: none;
  }

  body .stage,
  body.mobile-expanded .stage {
    position: relative;
    inset: auto;
    width: 100%;
    height: 100%;
    --content-safe-top: env(safe-area-inset-top, 0px);
    --content-safe-right: env(safe-area-inset-right, 0px);
    --content-safe-bottom: env(safe-area-inset-bottom, 0px);
    --content-safe-left: env(safe-area-inset-left, 0px);
  }

  .home-logo {
    left: calc(var(--screen-safe-left) + 8vw);
    top: calc(var(--screen-safe-top) + 3dvh);
  }

  .home-menu {
    left: calc(var(--screen-safe-left) + 6vw);
  }

  .continue-button {
    left: calc(var(--screen-safe-left) + 10vw);
    bottom: calc(var(--screen-safe-bottom) + 3dvh);
  }

  .chapter-screen > .back-button,
  .flow-screen > .back-button {
    left: calc(var(--screen-safe-left) + 8px);
    top: calc(var(--screen-safe-top) + 7px);
  }

  .chapter-heading {
    right: var(--screen-safe-right);
    top: calc(var(--screen-safe-top) + 4dvh);
  }

  .chapter-cards {
    left: calc(var(--screen-safe-left) + 5vw);
    right: var(--screen-safe-right);
    bottom: calc(var(--screen-safe-bottom) + 23dvh);
    padding-right: 8vw;
  }

  .flow-heading {
    right: calc(var(--screen-safe-right) + 2vw);
    top: var(--screen-safe-top);
  }

  .flow-progress-panel {
    left: calc(var(--screen-safe-left) + 8px);
    bottom: calc(var(--screen-safe-bottom) + 8px);
  }

  .hud {
    padding-top: max(7px, calc(var(--content-safe-top) + 5px));
    padding-right: max(calc(var(--video-inline-inset) + 10px), calc(var(--content-safe-right) + 8px));
    padding-bottom: max(8px, calc(var(--content-safe-bottom) + 5px));
    padding-left: max(calc(var(--video-inline-inset) + 10px), calc(var(--content-safe-left) + 8px));
  }

  .subtitle {
    bottom: max(10px, calc(var(--content-safe-bottom) + 8px));
  }

  .choice-layer {
    padding: 0 max(12px, calc(var(--content-safe-right) + 8px)) max(16px, calc(var(--content-safe-bottom) + 10px)) max(12px, calc(var(--content-safe-left) + 8px));
  }

  .drawer {
    padding: max(10px, calc(var(--content-safe-top) + 6px)) max(10px, calc(var(--content-safe-right) + 6px)) max(10px, calc(var(--content-safe-bottom) + 6px)) max(10px, calc(var(--content-safe-left) + 6px));
  }

  .toast {
    top: max(58px, calc(var(--content-safe-top) + 48px));
  }
}

@media (orientation: portrait) and (max-width: 820px) {
  body.mobile-expanded .game-shell {
    left: calc(var(--app-viewport-left) + var(--app-viewport-width));
    top: var(--app-viewport-top);
    width: var(--app-viewport-height);
    height: var(--app-viewport-width);
    transform: rotate(90deg);
    transform-origin: top left;
  }
}

/* Shared by the controls and the sibling subtitle overlay. */
.stage {
  --player-control-size: clamp(50px, 4.2vw, 86px);
}

/* Original-style video controls: five translucent diamonds along the bottom. */
.hud {
  position: absolute;
  inset: 0;
  display: block;
  padding: 0;
  background: none;
  pointer-events: none;
}

.hud .back-button.in-game {
  position: absolute;
  left: max(
    calc(var(--video-inline-inset) + 18px),
    calc(var(--content-safe-left) + 12px)
  );
  top: max(
    calc(var(--video-block-inset) + 16px),
    calc(var(--content-safe-top) + 10px)
  );
  pointer-events: auto;
}

.hud-actions {
  position: absolute;
  left: 50%;
  bottom: max(26px, calc(var(--content-safe-bottom) + 18px));
  width: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: nowrap;
  gap: clamp(24px, 5.4vw, 112px);
  margin: 0;
  transform: translateX(-50%);
  pointer-events: auto;
}

.hud-actions .player-control {
  --control-accent: #ff62b8;
  position: relative;
  flex: 0 0 var(--player-control-size);
  width: var(--player-control-size);
  height: var(--player-control-size);
  min-width: 0;
  min-height: 0;
  border: 2px solid rgba(255, 255, 255, 0.82);
  border-radius: 0;
  padding: 0;
  opacity: 0.9;
  background: rgba(68, 64, 72, 0.18);
  box-shadow:
    inset 0 0 0 2px rgba(255, 255, 255, 0.13),
    0 3px 8px rgba(0, 0, 0, 0.28);
  transform: rotate(45deg);
  transition: opacity 120ms ease, filter 120ms ease, transform 120ms ease;
}

.hud-actions .player-control.is-primary {
  flex-basis: calc(var(--player-control-size) + 10px);
  width: calc(var(--player-control-size) + 10px);
  height: calc(var(--player-control-size) + 10px);
  opacity: 0.96;
}

.hud-actions .player-control.is-mute {
  --control-accent: rgba(255, 255, 255, 0.8);
  opacity: 0.72;
}

.hud-actions .player-control:hover {
  border-color: #fff;
  filter: drop-shadow(0 0 7px rgba(255, 98, 184, 0.7));
  background: rgba(88, 80, 92, 0.26);
  transform: rotate(45deg) scale(1.05);
}

.hud-actions .player-control:active {
  transform: rotate(45deg) scale(0.94);
}

.control-glyph {
  position: absolute;
  inset: 20%;
  display: block;
  color: var(--control-accent);
  transform: rotate(-45deg);
  pointer-events: none;
}

.control-glyph::before,
.control-glyph::after {
  content: "";
  position: absolute;
  display: block;
}

.icon-rewind::before,
.icon-rewind::after,
.icon-forward::before,
.icon-forward::after {
  top: 13%;
  width: 62%;
  height: 74%;
  background: var(--control-accent);
}

.icon-rewind::before {
  left: -3%;
  clip-path: polygon(100% 0, 100% 100%, 0 50%);
}

.icon-rewind::after {
  right: -3%;
  clip-path: polygon(100% 0, 100% 100%, 0 50%);
}

.icon-forward::before {
  left: -3%;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

.icon-forward::after {
  right: -3%;
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

.icon-play-pause::before {
  inset: 5% 12%;
  background: var(--control-accent);
  clip-path: polygon(8% 0, 100% 50%, 8% 100%);
}

.player-control.is-playing .icon-play-pause::before {
  inset: 6% 13%;
  background: linear-gradient(
    90deg,
    var(--control-accent) 0 28%,
    transparent 28% 72%,
    var(--control-accent) 72% 100%
  );
  clip-path: none;
}

.icon-next::before {
  left: 3%;
  top: 6%;
  width: 72%;
  height: 88%;
  background: var(--control-accent);
  clip-path: polygon(0 0, 100% 50%, 0 100%);
}

.icon-next::after {
  right: 0;
  top: 5%;
  width: 13%;
  height: 90%;
  background: var(--control-accent);
}

.icon-mute::before {
  left: 0;
  top: 4%;
  width: 70%;
  height: 92%;
  background: var(--control-accent);
  clip-path: polygon(0 35%, 30% 35%, 75% 0, 75% 100%, 30% 65%, 0 65%);
}

.icon-mute::after {
  right: 0;
  top: 18%;
  width: 34%;
  height: 64%;
  border: 3px solid transparent;
  border-right-color: var(--control-accent);
  border-radius: 50%;
}

.player-control.is-muted .icon-mute::after {
  right: -4%;
  top: 47%;
  width: 108%;
  height: 4px;
  border: 0;
  border-radius: 2px;
  background: var(--control-accent);
  transform: rotate(45deg);
}

.subtitle {
  bottom: calc(max(26px, calc(var(--content-safe-bottom) + 18px)) + var(--player-control-size) + 34px);
}

.choice-layer {
  left: max(var(--video-inline-inset), var(--content-safe-left));
  right: max(var(--video-inline-inset), var(--content-safe-right));
  top: max(var(--video-block-inset), var(--content-safe-top));
  bottom: max(var(--video-block-inset), var(--content-safe-bottom));
  padding: 0 clamp(14px, 1.5vw, 28px) max(22px, calc(var(--content-safe-bottom) + 14px));
}

.hud.is-choosing .hud-actions {
  display: none;
}

.choice-frame,
.choices {
  max-width: 100%;
}

.choice-button {
  min-width: 0;
}

@media (orientation: landscape) and (max-height: 600px),
  (orientation: landscape) and (pointer: coarse) and (max-width: 1200px) {
  .stage {
    --player-control-size: clamp(32px, 5.6vw, 44px);
  }

  .hud .back-button.in-game {
    left: max(
      calc(var(--video-inline-inset) + 10px),
      calc(var(--content-safe-left) + 6px)
    );
    top: max(
      calc(var(--video-block-inset) + 8px),
      calc(var(--content-safe-top) + 6px)
    );
  }

  .hud-actions {
    bottom: max(10px, calc(var(--content-safe-bottom) + 7px));
    gap: clamp(15px, 4vw, 30px);
  }

  .hud-actions .player-control {
    min-height: 0;
    padding: 0;
    font-size: 0;
  }

  .subtitle {
    bottom: calc(max(10px, calc(var(--content-safe-bottom) + 7px)) + var(--player-control-size) + 18px);
  }

  .choice-layer {
    padding: 0 10px max(12px, calc(var(--content-safe-bottom) + 8px));
  }
}

@media (orientation: portrait) and (max-width: 820px) {
  .stage {
    --player-control-size: clamp(32px, 5.6dvh, 44px);
  }

  .hud .back-button.in-game {
    left: max(
      calc(var(--video-inline-inset) + 10px),
      calc(var(--content-safe-left) + 6px)
    );
    top: max(
      calc(var(--video-block-inset) + 8px),
      calc(var(--content-safe-top) + 6px)
    );
  }

  .hud-actions {
    bottom: max(10px, calc(var(--content-safe-bottom) + 7px));
    gap: clamp(14px, 3.6dvh, 27px);
  }

  .hud-actions .player-control {
    min-height: 0;
    padding: 0;
    font-size: 0;
  }

  .subtitle {
    bottom: calc(max(10px, calc(var(--content-safe-bottom) + 7px)) + var(--player-control-size) + 18px);
  }

  .choice-layer {
    padding: 0 10px max(12px, calc(var(--content-safe-bottom) + 8px));
  }
}
