@font-face {
  font-family: "StageSerif";
  src: url("assets/fonts/stage-title.ttf") format("truetype");
  font-display: swap;
  font-weight: 600;
}

:root {
  color-scheme: dark;
  --ink: #f2ecdf;
  --muted: #c2beb3;
  --accent: #d7b878;
  --accent-rgb: 215, 184, 120;
  --panel: #101412d9;
  --line: #ffffff24;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #000;
  color: var(--ink);
  font-family: "Microsoft YaHei", "Noto Sans SC", "Segoe UI", sans-serif;
}

button,
select {
  font: inherit;
  color: inherit;
}

button {
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  padding: 8px 10px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover {
  background: #ffffff13;
}

button:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:disabled {
  cursor: wait;
  opacity: 0.4;
}

kbd {
  margin-left: 6px;
  color: #b4b1a8;
  font: 9px/1 "Segoe UI", sans-serif;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  isolation: isolate;
  background: #070908;
}

.scene-media {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 52%;
  opacity: 0;
  filter: saturate(0.94) contrast(1.03);
  transition: opacity 0.45s ease;
  background: #080a09;
}

.scene-media.visible {
  opacity: 1;
}

#stage[data-cue="barber"] #barber {
  object-position: center 49%;
}

#grade,
#vignette,
#transition,
#blackout {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

#grade {
  z-index: 1;
  background:
    linear-gradient(180deg, #07090824 0%, transparent 24%, transparent 72%, #05070678 100%),
    radial-gradient(ellipse at 14% 28%, rgb(var(--accent-rgb) / 0.08), transparent 42%);
  transition: background 0.8s ease;
}

#stage[data-cue="clinic"] {
  --accent: #a9d8d2;
  --accent-rgb: 169, 216, 210;
}

#stage[data-cue="clinic"] #grade {
  background:
    linear-gradient(180deg, #eafaff13, transparent 30%, transparent 68%, #06212552),
    radial-gradient(ellipse at 82% 22%, #d9fff224, transparent 40%);
}

#stage[data-cue="hartford"] {
  --accent: #c9a469;
  --accent-rgb: 201, 164, 105;
}

#stage[data-cue="hartford"] #grade {
  background:
    linear-gradient(180deg, #0d14101f, transparent 25%, transparent 70%, #05050490),
    linear-gradient(110deg, transparent 45%, #d9f1ff0d 66%, transparent 78%);
}

#stage[data-cue="barber"] {
  --accent: #c68c52;
  --accent-rgb: 198, 140, 82;
}

#stage[data-cue="barber"] #grade {
  background:
    linear-gradient(180deg, #0c070322, transparent 24%, transparent 68%, #08040298),
    radial-gradient(ellipse at 20% 44%, #d8833720, transparent 42%);
}

#stage[data-cue="return"] {
  --accent: #e2c486;
  --accent-rgb: 226, 196, 134;
}

#vignette {
  z-index: 1;
  background: radial-gradient(ellipse at center, transparent 48%, #0000005c 76%, #000000b8 100%);
}

#transition {
  z-index: 3;
  width: 100%;
  height: 100%;
  opacity: 0;
}

#blackout {
  z-index: 20;
  background: #000;
  opacity: 0;
  transition: opacity 0.2s ease;
}

#blackout.active {
  opacity: 1;
}

#era {
  position: absolute;
  z-index: 5;
  top: max(22px, env(safe-area-inset-top));
  right: max(3.5vw, env(safe-area-inset-right));
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  padding-right: 14px;
  border-right: 1px solid rgb(var(--accent-rgb) / 0.55);
  color: #eee6d7;
  text-align: right;
  text-shadow: 0 2px 14px #000c;
  pointer-events: none;
}

#era-year {
  font-family: "StageSerif", "Songti SC", SimSun, serif;
  font-size: clamp(20px, 2vw, 38px);
  font-weight: 600;
  letter-spacing: 0.08em;
}

#era-place {
  color: #d4ccbc;
  font-size: clamp(10px, 0.82vw, 16px);
  letter-spacing: 0.08em;
}

#stage[data-cue="clinic"] #era {
  color: #133f40;
  text-shadow: 0 2px 18px #ffffffb8;
  border-color: #235c5e99;
}

#stage[data-cue="clinic"] #era {
  border-radius: 6px;
}

#stage[data-cue="clinic"] #era {
  padding: 8px 14px;
  background: #effffd52;
  backdrop-filter: blur(7px);
}

#stage[data-cue="clinic"] #era-place {
  color: #315d5e;
}

#chronology {
  position: absolute;
  z-index: 5;
  top: 104px;
  right: max(3.9vw, env(safe-area-inset-right));
  display: flex;
  align-items: center;
  gap: 4px;
  color: #bdb7aa;
  font-size: 10px;
  letter-spacing: 0.05em;
  pointer-events: none;
}

.era-node {
  position: relative;
  padding: 4px 5px;
  opacity: 0.52;
}

.era-node + .era-node::before {
  content: "";
  position: absolute;
  top: 50%;
  left: -7px;
  width: 9px;
  height: 1px;
  background: #ffffff45;
}

.era-node.active {
  color: var(--accent);
  opacity: 1;
}

.era-node.passed {
  opacity: 0.82;
}

#stage[data-cue="clinic"] #chronology {
  color: #456c6d;
  text-shadow: 0 1px 8px #fff;
}

#hint {
  position: absolute;
  z-index: 6;
  top: max(22px, env(safe-area-inset-top));
  left: 50%;
  padding: 8px 13px;
  border: 1px solid #ffffff13;
  border-radius: 6px;
  background: #0b0f0db3;
  color: #e6e0d3;
  font-size: 11px;
  letter-spacing: 0.035em;
  white-space: nowrap;
  pointer-events: none;
  transform: translateX(-50%);
  transition: opacity 0.3s ease;
}

#hud {
  position: absolute;
  z-index: 10;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  align-items: center;
  gap: 3px;
  max-width: calc(100vw - 24px);
  padding: 6px 8px;
  border: 1px solid #ffffff1c;
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 10px 36px #0008;
  font-size: 12px;
  backdrop-filter: blur(18px);
  transform: translateX(-50%);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

#state {
  min-width: 104px;
  padding: 0 9px;
  color: #d8cba9;
  font-size: 11px;
  white-space: nowrap;
}

.scene-picker {
  position: relative;
}

#sceneSelect {
  min-width: 122px;
  height: 34px;
  padding: 0 28px 0 10px;
  border: 1px solid #ffffff1f;
  border-radius: 6px;
  color: #f1eadb;
  background: #f1eadb12;
  font-size: 12px;
  cursor: pointer;
}

#sceneSelect option {
  color: #eee8dc;
  background: #151a18;
}

body.ui-hidden #hud {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
}

body.ui-hidden #hint {
  opacity: 0;
}

body.ui-hidden #stage {
  cursor: none;
}

body.output #hud,
body.output #hint,
body.output #portraitGate {
  display: none;
}

body.blacked #era,
body.blacked #chronology,
body.blacked #dentalFeed,
body.blacked #moment,
body.blacked #warp,
body.blacked #portal,
body.blacked #hint,
body.blacked #hud {
  display: none;
}

#dentalFeed {
  position: absolute;
  z-index: 6;
  right: 4%;
  bottom: 17%;
  width: clamp(126px, 10.5vw, 176px);
  padding: 7px;
  border: 1px solid #a4d8d254;
  border-radius: 8px;
  color: #dffbf8;
  background: #071314c4;
  box-shadow: 0 8px 24px #00151666;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.45s ease, transform 0.45s ease;
  backdrop-filter: blur(8px);
}

#stage[data-cue="clinic"] #dentalFeed {
  opacity: 1;
  transform: translateY(0);
}

.feed-head,
.feed-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: #9cc8c5;
  font-size: 9px;
  letter-spacing: 0.06em;
}

.feed-live {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #7fe1cf;
  box-shadow: 0 0 9px #7fe1cf;
}

.tooth-graphic {
  display: block;
  width: 100%;
  height: clamp(98px, 12.5vh, 132px);
  margin: 5px 0 2px;
  overflow: hidden;
  border-top: 1px solid #b5e5df1a;
  border-bottom: 1px solid #b5e5df1a;
  background: #071110;
}

.tooth-shadow {
  fill: #0007;
  transform: translate(2px, 3px);
}

.tooth-fill {
  fill: url("#toothIvory");
  stroke: #efe5cfcc;
  stroke-width: 1.4;
}

.tooth-neck,
.tooth-root {
  fill: none;
  stroke: #756a55a8;
  stroke-width: 1.3;
  stroke-linecap: round;
}

.tooth-groove {
  fill: none;
  stroke: #8d7e6299;
  stroke-width: 1.4;
  stroke-linecap: round;
}

.scan-line {
  stroke: #88e4d2;
  stroke-width: 1.4;
  filter: drop-shadow(0 0 5px #7fe9d6);
  animation: dentalScan 2.8s linear infinite;
}

#moment {
  position: absolute;
  z-index: 7;
  top: 50%;
  left: 50%;
  padding: 12px 28px;
  border-top: 1px solid #d6e9e343;
  border-bottom: 1px solid #d6e9e343;
  color: #1a4444;
  background: #e9f5f2c7;
  font-family: StageSerif, "Songti SC", SimSun, serif;
  font-size: clamp(28px, 3.4vw, 58px);
  letter-spacing: 0.24em;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -50%) scale(0.94);
  white-space: nowrap;
}

#moment.active {
  animation: momentCard 3.2s ease both;
}

#warp {
  position: absolute;
  z-index: 4;
  inset: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

#warp.active {
  opacity: 1;
}

#warp::before {
  content: "";
  position: absolute;
  inset: 8%;
  border: 1px solid #d5edff45;
  border-radius: 50%;
  filter: blur(1px);
  animation: warpPulse 2.2s ease-out both;
}

.warp-ring {
  position: absolute;
  border: 1px solid #e9f9ff7a;
  border-radius: 50%;
  box-shadow: 0 0 40px #9ed5e555, inset 0 0 30px #d9edf055;
  animation: warpRing 2.4s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

.ring-one {
  width: 14vmin;
  height: 14vmin;
}

.ring-two {
  width: 34vmin;
  height: 34vmin;
  animation-delay: 0.1s;
}

.ring-three {
  width: 62vmin;
  height: 62vmin;
  animation-delay: 0.2s;
}

#warpLabel {
  position: relative;
  color: #effbff;
  font-family: StageSerif, "Songti SC", SimSun, serif;
  font-size: clamp(18px, 1.7vw, 32px);
  letter-spacing: 0.38em;
  text-shadow: 0 0 24px #b9e7f0;
  animation: warpLabel 2.3s ease both;
}

#portal {
  position: absolute;
  z-index: 8;
  top: 0;
  right: 0;
  width: 30vw;
  height: 100%;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

#portal.active {
  animation: portalIn 2.8s ease-in-out both;
}

.portal-core {
  position: absolute;
  top: 50%;
  right: 5vw;
  width: min(24vw, 390px);
  aspect-ratio: 0.44;
  border: 2px solid #e7fbffd9;
  border-radius: 50%;
  background: #dffbff16;
  box-shadow:
    0 0 20px #c9f1ffc4,
    0 0 80px #a8dce788,
    inset 0 0 45px #d7f8ff8c;
  transform: translateY(-50%);
}

.portal-ray {
  position: absolute;
  top: -12%;
  right: 6vw;
  width: 30vw;
  height: 124%;
  background: linear-gradient(90deg, transparent, #d5f5ff1f 45%, #e9fcff59 51%, transparent);
  filter: blur(12px);
  transform: skewX(-7deg);
}

#portal span {
  position: absolute;
  top: 50%;
  right: 9.2vw;
  color: #f2ffff;
  font-family: StageSerif, "Songti SC", SimSun, serif;
  font-size: clamp(15px, 1.5vw, 26px);
  letter-spacing: 0.28em;
  writing-mode: vertical-rl;
  transform: translateY(-50%);
  text-shadow: 0 0 18px #d6f7ff;
}

#start {
  position: absolute;
  z-index: 15;
  top: 50%;
  left: 50%;
  padding: 13px 24px;
  border-color: #e3d1aa80;
  background: #111b18e8;
  transform: translate(-50%, -50%);
}

#error {
  position: absolute;
  z-index: 15;
  left: 20px;
  bottom: 20px;
  max-width: min(500px, calc(100vw - 40px));
  padding: 10px 14px;
  border-radius: 6px;
  background: #3a1714e8;
  font-size: 12px;
}

#portraitGate {
  position: absolute;
  z-index: 50;
  inset: 0;
  display: none;
  place-items: center;
  align-content: center;
  gap: 10px;
  padding: 34px;
  background: #060807f2;
  text-align: center;
}

body.needs-landscape #portraitGate {
  display: grid;
}

.landscape-mark {
  display: grid;
  place-items: center;
  width: 76px;
  height: 76px;
  margin-bottom: 4px;
  border: 1px solid #d7c49744;
  border-radius: 50%;
  color: #d9c493;
}

.landscape-mark svg {
  width: 38px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

#portraitGate h2 {
  margin: 3px 0 0;
  font-family: StageSerif, "Songti SC", SimSun, serif;
  font-size: clamp(28px, 9vw, 40px);
  font-weight: 600;
  letter-spacing: 0.12em;
}

#portraitGate p {
  margin: 0 0 8px;
  color: #aaa59a;
  font-size: 13px;
  letter-spacing: 0.06em;
}

#enterLandscape {
  padding: 11px 24px;
  border-color: #dfca936b;
  background: #d8c28d17;
  color: #ede0c3;
}

@keyframes dentalScan {
  0% { transform: translateY(-2px); opacity: 0; }
  12% { opacity: 1; }
  82% { opacity: 1; }
  100% { transform: translateY(122px); opacity: 0; }
}

@keyframes momentCard {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.94); }
  10%, 74% { opacity: 1; transform: translate(-50%, -50%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.02); }
}

@keyframes warpRing {
  0% { opacity: 0; transform: scale(0.35); }
  20% { opacity: 0.8; }
  100% { opacity: 0; transform: scale(2.2); }
}

@keyframes warpPulse {
  0% { opacity: 0; transform: scale(0.88); }
  26% { opacity: 0.8; }
  100% { opacity: 0; transform: scale(1.12); }
}

@keyframes warpLabel {
  0%, 8% { opacity: 0; letter-spacing: 0.58em; filter: blur(6px); }
  28%, 72% { opacity: 1; letter-spacing: 0.38em; filter: blur(0); }
  100% { opacity: 0; letter-spacing: 0.2em; filter: blur(4px); }
}

@keyframes portalIn {
  0% { opacity: 0; transform: translateX(24%); filter: blur(6px); }
  18%, 68% { opacity: 1; transform: translateX(0); filter: blur(0); }
  100% { opacity: 0; transform: translateX(8%); filter: blur(4px); }
}

@media (prefers-reduced-motion: reduce) {
  .scene-media,
  #dentalFeed,
  .scan-line,
  #warp,
  #portal {
    animation: none !important;
    transition: none !important;
  }
}

@media (max-width: 1120px) {
  #hint {
    display: none;
  }

  #hud {
    gap: 1px;
    padding: 5px 6px;
  }

  #state {
    display: none;
  }

  #hud kbd {
    display: none;
  }

  #chronology {
    top: 86px;
  }
}

@media (max-width: 820px) and (orientation: landscape) {
  #era {
    top: max(11px, env(safe-area-inset-top));
    right: 18px;
  }

  #chronology,
  #openOutput,
  #momentButton {
    display: none;
  }

  #dentalFeed {
    right: 3%;
    bottom: 17%;
    width: 132px;
  }

  .tooth-graphic {
    height: 104px;
  }

  #hud {
    right: max(8px, env(safe-area-inset-right));
    bottom: max(7px, env(safe-area-inset-bottom));
    left: max(8px, env(safe-area-inset-left));
    justify-content: center;
    flex-wrap: wrap;
    max-width: none;
    font-size: 11px;
    transform: none;
  }

  #hud button {
    padding: 7px 8px;
  }

  #sceneSelect {
    min-width: 112px;
    height: 31px;
    font-size: 11px;
  }

  body.ui-hidden #hud {
    transform: translateY(10px);
  }
}

@media (max-width: 620px) and (orientation: landscape) {
  #pause {
    display: none;
  }

  #dentalFeed {
    bottom: 23%;
  }
}

@media (max-height: 500px) and (orientation: landscape) {
  #dentalFeed {
    bottom: 22%;
    width: 118px;
  }

  .tooth-graphic {
    height: 88px;
  }

  .feed-head,
  .feed-meta {
    font-size: 8px;
  }
}
