:root {
  --bg: #f5d400;
  --fg: #000;
  --panel-bg: #f5d400;
  --panel-border: #000;

  --layout-width: min(1120px, calc(100vw - 36px));
  --layout-height: calc(100vh - 36px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font-family: monospace;
}

.viewport {
  position: relative;
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  display: grid;
  place-items: center;
  padding: 18px;
}

/* Two-column full-height layout */
.layout {
  position: relative;
  width: var(--layout-width);
  height: var(--layout-height);

  display: grid;
  grid-template-columns: 1.618fr 1fr;
  align-items: stretch;
  gap: 0;
}

.left-side,
.right-side {
  display: flex;
  flex-direction: column;
  gap: 0;
  height: 100%;
  min-height: 0;
}

.right-side {
  margin-left: -2px;
}

/* Shared box style */
.ui-box {
  width: 100%;
  background: var(--panel-bg);
  color: var(--fg);
  border: 2px solid var(--panel-border);
  box-shadow: none;
  overflow: hidden;
}

.ui-box + .ui-box {
  margin-top: -2px;
}

/* LEFT COLUMN */

.title-box {
  flex: 0 0 72px;
  min-height: 72px;
  padding: 12px 14px;

  display: flex;
  align-items: center;
}

.scene-title {
  margin: 0;
  width: 100%;
  max-width: 100%;
  overflow: hidden;

  font-family: monospace;
  font-size: 13px;
  line-height: 1.45;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
}

.photo-box {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  padding: 0;
  background: var(--bg);
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  background: var(--bg);
  cursor: crosshair;
}

.fade {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: var(--bg);
  opacity: 0;
  transition: opacity 1200ms ease;
}

.fade.active {
  opacity: 0.12;
}

/* RIGHT COLUMN */

.description-box {
  flex: 8 1 0;
  min-height: 0;
  padding: 20px 22px;
}

.scene-description {
  margin: 0;

  font-family: monospace;
  font-size: clamp(16px, 1.55vw, 22px);
  line-height: 1.45;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  font-weight: 400;
  overflow-wrap: break-word;
}

/* NAVIGATION */

.navigation-box {
  flex: 5 1 0;
  min-height: 0;
  padding: 0;

  display: flex;
  flex-direction: column;
}

.nav-question {
  margin: 0;
  padding: 10px 14px;

  width: 100%;
  max-width: 100%;
  overflow: hidden;

  background: var(--fg);
  color: var(--bg);
  border-bottom: 2px solid var(--panel-border);

  font-family: monospace;
  font-size: 11px;
  line-height: 1.4;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 700;
}

.option-stack {
  display: flex;
  flex-direction: column;
  gap: 0;

  border: 0;

  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
}

/* Buttons fully occupy their containers */
.nav-btn,
.proceed-btn {
  display: block;
  width: 100%;
  min-width: 100%;
  min-height: 0;
  padding: 9px 10px;

  background: var(--panel-bg);
  color: var(--fg);
  border: 0;
  border-bottom: 2px solid var(--panel-border);

  font-family: monospace;
  font-size: 10px;
  line-height: 1.15;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: left;
  cursor: pointer;

  transition:
    background 0.15s ease,
    color 0.15s ease;
}

.nav-btn {
  flex: 1 1 0;
  overflow: hidden;
}

.nav-btn:last-child {
  border-bottom: 0;
}

.nav-btn:hover,
.nav-btn:focus-visible,
.proceed-btn:hover,
.proceed-btn:focus-visible {
  background: #000;
  color: var(--bg);
}

/* PENDING / SELECTED ROUTE */

.pending-box {
  flex: 3 1 0;
  min-height: 0;
  padding: 0;

  display: flex;
  flex-direction: column;
}

.pending-label {
  margin: 0;
  padding: 10px 14px;

  width: 100%;
  max-width: 100%;
  overflow: hidden;

  background: var(--fg);
  color: var(--bg);
  border-bottom: 2px solid var(--panel-border);

  font-family: monospace;
  font-size: 10px;
  line-height: 1.4;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 700;
}

.pending-text {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
  padding: 12px 14px;
  overflow: hidden;

  font-family: monospace;
  font-size: 12px;
  line-height: 1.5;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
}

.pending-text.is-empty {
  color: transparent;
}

/* Proceed button now matches the route buttons */
.proceed-btn {
  flex: 0 0 34px;
  min-height: 34px;
  border: 0;
  border-top: 2px solid var(--panel-border);
  border-bottom: 0;
  text-align: left;
}

.proceed-btn:disabled {
  cursor: default;
  opacity: 0.35;
}

.proceed-btn:disabled:hover,
.proceed-btn:disabled:focus-visible {
  background: var(--panel-bg);
  color: var(--fg);
}

/* Awkward justified text */
.justified-text {
  text-align: justify;
  text-align-last: justify;
  word-spacing: 1.1em;
  hyphens: none;
}

.justified-text::after {
  content: "";
  display: inline-block;
  width: 100%;
}

/* Full-layout interstitial screen */
.interstitial-screen {
  position: absolute;
  inset: 0;
  z-index: 80;

  background: var(--bg);
  border: 1px solid var(--panel-border);
  outline: 1px solid var(--panel-border);
  outline-offset: -2px;

  display: grid;
  place-items: center;

  opacity: 1;
  pointer-events: auto;
  overflow: hidden;
}

.interstitial-screen.is-hidden {
  display: none;
}

#interstitialCanvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  background: var(--bg);
  position: absolute;
  inset: 0;
  z-index: 0;
}

.interstitial-screen::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  border: 1px solid var(--panel-border);
}

/* Rare straight horizontal glitch distortion */
.layout.glitch-burst .glitch-target {
  position: relative;
  animation: horizontalGlitch 340ms steps(1, end);
}

.layout.glitch-burst .glitch-target::before,
.layout.glitch-burst .glitch-target::after {
  content: "";
  position: absolute;
  left: 0;
  width: 100%;
  height: 2px;
  pointer-events: none;
  background: #000;
  opacity: 0;
  z-index: 50;
}

.layout.glitch-burst .glitch-target::before {
  top: 28%;
  animation: horizontalSliceA 340ms steps(1, end);
}

.layout.glitch-burst .glitch-target::after {
  top: 63%;
  animation: horizontalSliceB 340ms steps(1, end);
}

@keyframes horizontalGlitch {
  0% {
    transform: translateX(0);
    clip-path: inset(0 0 0 0);
  }

  12% {
    transform: translateX(-3px);
    clip-path: inset(6% 0 0 0);
  }

  24% {
    transform: translateX(4px);
    clip-path: inset(0 0 72% 0);
  }

  36% {
    transform: translateX(-2px);
    clip-path: inset(38% 0 28% 0);
  }

  48% {
    transform: translateX(5px);
    clip-path: inset(70% 0 8% 0);
  }

  60% {
    transform: translateX(-4px);
    clip-path: inset(14% 0 58% 0);
  }

  72% {
    transform: translateX(2px);
    clip-path: inset(52% 0 18% 0);
  }

  100% {
    transform: translateX(0);
    clip-path: inset(0 0 0 0);
  }
}

@keyframes horizontalSliceA {
  0%,
  100% {
    opacity: 0;
    transform: translateX(0);
  }

  18% {
    opacity: 1;
    transform: translateX(-18px);
  }

  36% {
    opacity: 1;
    transform: translateX(14px);
  }

  54% {
    opacity: 0;
    transform: translateX(0);
  }
}

@keyframes horizontalSliceB {
  0%,
  100% {
    opacity: 0;
    transform: translateX(0);
  }

  24% {
    opacity: 1;
    transform: translateX(20px);
  }

  48% {
    opacity: 1;
    transform: translateX(-12px);
  }

  66% {
    opacity: 0;
    transform: translateX(0);
  }
}

.loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;

  background: var(--bg);
  color: var(--fg);
  z-index: 100;

  font-size: 13px;
  letter-spacing: 2px;
  text-transform: uppercase;
  border: none;
  box-shadow: none;
}

.loading.hidden {
  display: none;
}

/* MOBILE / NARROW VIEW */
@media (max-width: 860px) {
  :root {
    --layout-width: min(430px, calc(100vw - 24px));
    --layout-height: calc(100vh - 24px);
  }

  html,
  body {
    overflow: hidden;
  }

  .viewport {
    display: grid;
    place-items: center;
    padding: 12px;
    height: 100vh;
    overflow: hidden;
  }

  .layout {
    width: var(--layout-width);
    height: var(--layout-height);
    min-height: 0;
    display: flex;
    flex-direction: column;
    margin: 0 auto;
  }

  .left-side {
    flex: 0 0 auto;
    height: auto;
  }

  .right-side {
    margin-left: 0;
    margin-top: -2px;
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
  }

  .title-box {
    flex: none;
    height: auto;
    min-height: 48px;
    padding: 8px 10px;
  }

  .photo-box {
    flex: none;
    width: 100%;
    aspect-ratio: 1 / 1;
    max-height: 38vh;
  }

  .scene-title {
    font-size: 10px;
  }

  .description-box,
  .navigation-box,
  .pending-box {
    flex: 1 1 0;
    min-height: 0;
  }

  .description-box {
    padding: 11px;
  }

  .scene-description {
    font-size: 12px;
    line-height: 1.35;
    word-spacing: 0.55em;
  }

  .nav-question {
    font-size: 8px;
    padding: 8px 9px;
  }

  .nav-btn,
  .proceed-btn {
    min-height: 24px;
    padding: 6px;
    font-size: 7px;
  }

  .pending-label {
    font-size: 8px;
    padding: 8px 9px;
  }

  .pending-text {
    font-size: 8px;
    line-height: 1.3;
    padding: 8px 9px;
  }
}
