html, body {
  margin: 0;
  height: 100%;
  background: #000;
  color: #f4e4b0;
  font-family: Georgia, "Times New Roman", serif;
  overflow: hidden;
  /* Touch: no double-tap zoom, text selection or long-press menus. */
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#stage {
  position: relative;
  width: 100vw;
  height: 56.25vw; /* 16:9 */
  max-height: 100vh;
  max-width: 177.78vh;
  margin: auto;
  top: 50%;
  transform: translateY(-50%);
  background: #000;
  /* Text below is sized against the stage height (cqh), capped at the desktop size, so it fits phones. */
  container-type: size;
}

/* Own stacking context: clips bump their z-index on every cut, this keeps them below the HUD. */
#videos {
  position: absolute;
  inset: 0;
  z-index: 0;
}
#hud, #hint, #overlay, #select, #gestures, #tap, #loading {
  z-index: 1;
}

/* Fade-through-black for scene changes; sits above the clips, below the HUD (same z, earlier in the DOM). */
#fader {
  position: absolute;
  inset: 0;
  background: #000;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
  z-index: 1;
}
#fader.on {
  opacity: 1;
}

#videos video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  visibility: hidden;
}
#videos video.active {
  visibility: visible;
}

#hud {
  position: absolute;
  top: 12px;
  left: 16px;
  right: 16px;
  display: flex;
  justify-content: space-between;
  font-size: min(28px, 6cqh);
  text-shadow: 0 0 6px #000, 0 0 2px #000;
  pointer-events: none;
}
#debug {
  font-family: Consolas, monospace;
  font-size: 18px;
}

#hint {
  position: absolute;
  left: 50%;
  bottom: 12%;
  transform: translateX(-50%);
  min-width: 120px;
  padding: 8px 28px;
  box-sizing: border-box;
  text-align: center;
  font-family: "Segoe UI Symbol", Arial, sans-serif;
  font-size: min(80px, 14cqh);
  line-height: 1;
  font-weight: bold;
  color: #ffd84a;
  background: rgba(0, 0, 0, 0.65);
  border: 4px solid #ffd84a;
  border-radius: 20px;
  box-shadow: 0 0 24px #ff8c00;
  text-shadow: 0 0 12px #ff8c00;
  animation: flash 0.25s steps(2) infinite;
  pointer-events: none;
}
/* A choice shows two labelled keys, so it uses smaller type. */
#hint.choice {
  font-size: min(44px, 8cqh);
  white-space: pre; /* keep the gap between the two options */
  padding: 12px 28px;
}
@keyframes flash {
  50% { opacity: 0.15; }
}

#overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.75);
  text-align: center;
}
#overlay.hidden {
  display: none;
}
#overlay h1 {
  font-size: min(64px, 12cqh);
  margin: 0 0 16px;
  color: #ffd84a;
  text-shadow: 0 0 20px #ff6a00;
}
#overlay p {
  font-size: min(26px, 5cqh);
  margin: 8px;
}
#overlay .help {
  font-size: min(18px, 3.5cqh);
  opacity: 0.8;
  margin-top: min(32px, 5cqh);
}
kbd {
  border: 1px solid #f4e4b0;
  border-radius: 4px;
  padding: 1px 7px;
  font-family: inherit;
}

/* Character select: an opaque title screen with one card per hero. */
#select {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, #2a1a0a 0%, #000 75%);
  text-align: center;
}
#select.hidden {
  display: none;
}
#select p {
  font-size: min(24px, 4.5cqh);
  margin: 4px;
}
#select .help {
  font-size: min(16px, 3.2cqh);
  opacity: 0.8;
  margin-top: min(20px, 3cqh);
}
#cards {
  display: flex;
  gap: 2.2%;
  width: min(88%, 125cqh); /* keeps the 3:4 portraits inside a short (phone) stage */
  justify-content: center;
  margin-top: min(16px, 2.5cqh);
}
.card {
  flex: 1;
  max-width: 24%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: min(10px, 1.6cqh);
  border: 3px solid #5a4320;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.5);
  color: inherit;
  font: inherit;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.card img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 8px;
  filter: brightness(0.7);
  transition: filter 0.12s;
}
.card .name {
  margin-top: min(10px, 1.5cqh);
  font-size: min(22px, 4.2cqh);
  font-weight: bold;
}
.card .tagline {
  font-size: min(15px, 3cqh);
  opacity: 0.75;
}
.card.selected {
  transform: scale(1.06);
  border-color: #ffd84a;
  box-shadow: 0 0 24px #ff8c00;
}
.card.selected img {
  filter: none;
}
.card.selected .name {
  color: #ffd84a;
}

/* Keyboard help vs touch help. */
.touch-only { display: none; }
body.touch .keys { display: none; }
body.touch .touch-only { display: block; }

/* End-screen buttons (clickable and tappable). */
.btn {
  margin: 0 8px;
  padding: min(10px, 2cqh) min(24px, 4cqh);
  font: inherit;
  font-size: min(24px, 5cqh);
  color: #1a1206;
  background: #ffd84a;
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}
.btn:active { background: #ffb020; }

/* Gesture layer: catches swipes and taps over the video; touch devices only, while playing. */
#gestures {
  position: absolute;
  inset: 0;
  display: none;
  touch-action: none; /* the swipe must not scroll or zoom the page */
}
body.touch[data-state="playing"] #gestures { display: block; }

/* iOS refused to start a clip without a tap. */
#tap {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  font-size: min(40px, 8cqh);
  color: #ffd84a;
  cursor: pointer;
}
#tap[hidden] { display: none; }

/* Shown while the next clip is still downloading (over the last frame, or black after a fade). */
#loading {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 12%;
  text-align: center;
  font-size: min(28px, 5cqh);
  color: #ffd84a;
  text-shadow: 0 0 6px #000, 0 0 12px #000;
  pointer-events: none;
}
#loading[hidden] { display: none; }

/* Phones held upright: the 16:9 stage would be tiny, so ask for landscape. */
#rotate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 10;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  font-size: 24px;
  color: #ffd84a;
  background: #000;
}
@media (orientation: portrait) {
  body.touch:not([data-layout="portrait"]) #rotate { display: flex; }
}

/* Portrait build (export_public.py --portrait): 9:16 clips, a 9:16 stage, phones held upright. */
body[data-layout="portrait"] #stage {
  width: 100vw;
  height: 177.78vw; /* 9:16 */
  max-height: 100vh;
  max-width: 56.25vh;
}
@media (orientation: landscape) {
  body.touch[data-layout="portrait"] #rotate { display: flex; }
}
/* The stage is narrow, so text is also capped by its width (cqw). */
body[data-layout="portrait"] #hint { font-size: min(80px, 20cqw); }
body[data-layout="portrait"] #hint.choice { font-size: min(44px, 8.5cqw); padding: 10px 18px; }
body[data-layout="portrait"] #overlay h1 { font-size: min(64px, 13cqw); }
body[data-layout="portrait"] #overlay p { font-size: min(26px, 5.5cqw); }
body[data-layout="portrait"] #select p { font-size: min(24px, 5cqw); }
body[data-layout="portrait"] #select .help { font-size: min(16px, 4cqw); padding: 0 6cqw; }
body[data-layout="portrait"] #cards { width: 88%; flex-wrap: wrap; }
body[data-layout="portrait"] .card { max-width: 60%; min-width: 40%; }
body[data-layout="portrait"] .card .name { font-size: min(22px, 6cqw); }
body[data-layout="portrait"] .card .tagline { font-size: min(15px, 4cqw); }
body[data-layout="portrait"] .btn { font-size: min(24px, 5.5cqw); margin: 6px; }
#rotate .keys-portrait { display: none; }
body[data-layout="portrait"] #rotate .keys-portrait { display: inline; }
body[data-layout="portrait"] #rotate .keys-landscape { display: none; }
