:root {
  color-scheme: dark;
  --bg: #101114;
  --surface: #171a20;
  --surface-2: #20242c;
  --ink: #f4efe5;
  --muted: #a9adb6;
  --line: rgba(244, 239, 229, 0.14);
  --accent: #e8c872;
  --soft: #91d1b4;
  --danger: #d86a5d;
  --shadow: rgba(0, 0, 0, 0.3);
  font-family: "Tiny5", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

body {
  overflow: hidden;
}

a {
  color: inherit;
}

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

button {
  font: inherit;
}

.stage,
.scene-nav,
.timeline,
.touch-controls,
.icon-button,
.touch-button,
.dot,
#game-canvas {
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.scene-nav,
.touch-controls,
.icon-button,
.touch-button,
.dot,
#game-canvas {
  touch-action: manipulation;
}

.app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

.topbar {
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 66px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 17, 20, 0.94);
  backdrop-filter: blur(14px);
}

.brand {
  display: grid;
  gap: 3px;
  text-decoration: none;
  transition: opacity 180ms linear, transform 180ms ease;
  will-change: opacity, transform;
}

.brand span {
  font-size: 1rem;
  font-weight: 800;
}

.brand small {
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.25;
}

.utility {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.text-button,
.icon-button,
.touch-button,
.hud-toggle,
.dot {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(244, 239, 229, 0.06);
  color: var(--ink);
  cursor: pointer;
}

.text-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 13px;
  font-size: 0.78rem;
  font-weight: 800;
  text-decoration: none;
}

.text-button:hover,
.icon-button:hover,
.touch-button:hover,
.dot:hover,
.hud-toggle:hover {
  border-color: rgba(244, 239, 229, 0.32);
  background: rgba(244, 239, 229, 0.1);
}

.text-button.is-primary {
  background: var(--accent);
  color: #17140c;
}

.stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: #11141a;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  image-rendering: pixelated;
  outline: none;
}

.scene-nav {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 18px;
  z-index: 2;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}

.icon-button {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  font-size: 1.1rem;
  font-weight: 900;
  border-color: rgba(16, 17, 20, 0.55);
  background: rgba(244, 239, 229, 0.86);
  color: #15171c;
  box-shadow: 0 5px 0 rgba(16, 17, 20, 0.26);
  pointer-events: auto;
}

.timeline {
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: 8px;
  min-height: 34px;
  padding: 8px;
  border: 1px solid rgba(16, 17, 20, 0.26);
  border-radius: 8px;
  background: rgba(244, 239, 229, 0.82);
  box-shadow: 0 5px 0 rgba(16, 17, 20, 0.18);
  pointer-events: auto;
}

.dot {
  position: relative;
  height: 18px;
  padding: 0;
  border-color: rgba(16, 17, 20, 0.3);
  background: rgba(16, 17, 20, 0.12);
}

.dot::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 2px;
  background: rgba(16, 17, 20, 0.42);
}

.dot.is-active::after {
  inset: 3px;
  background: var(--danger);
  box-shadow: 0 0 0 2px #15171c;
}

.dot.is-complete::after {
  background: var(--soft);
}

.touch-controls {
  position: absolute;
  right: 18px;
  bottom: 74px;
  z-index: 2;
  display: none;
  grid-template-columns: repeat(4, 42px);
  gap: 8px;
}

.touch-button {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  font-weight: 900;
  background: rgba(16, 17, 20, 0.72);
}

.hud {
  z-index: 3;
  height: clamp(218px, 25vh, 270px);
  overflow: hidden;
  border-top: 1px solid var(--line);
  background: rgba(18, 20, 25, 0.96);
  box-shadow: 0 -16px 42px var(--shadow);
}

.hud-toggle {
  display: none;
  width: calc(100% - 24px);
  min-height: 40px;
  margin: 12px;
  color: var(--soft);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

.hud-grid {
  display: grid;
  grid-template-columns: minmax(130px, 0.35fr) minmax(260px, 0.85fr) minmax(320px, 1fr);
  gap: 20px;
  height: 100%;
  padding: 18px;
}

.scene-kicker {
  display: grid;
  align-content: start;
  gap: 8px;
  color: var(--accent);
  font-weight: 900;
  text-transform: uppercase;
}

.capability,
.scene-place,
.artifact {
  margin: 0 0 7px;
  color: var(--soft);
  font-weight: 900;
  text-transform: uppercase;
}

.artifact {
  color: var(--accent);
  text-transform: none;
}

.final-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 10, 12, 0.68);
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms linear;
}

.final-overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.final-card {
  width: min(760px, 92vw);
  padding: 30px 48px 24px;
  border: 3px solid rgba(244, 239, 229, 0.72);
  border-radius: 8px;
  background: #131720;
  box-shadow:
    0 0 0 8px rgba(232, 200, 114, 0.18),
    0 18px 0 rgba(0, 0, 0, 0.32);
  text-align: center;
}

.final-kicker {
  margin: 0 0 18px;
  color: var(--accent);
  font-size: 1rem;
  line-height: 1;
  text-transform: uppercase;
}

.final-card h2 {
  margin: 0 0 16px;
  color: var(--ink);
  font-size: clamp(2.7rem, 7vw, 4.6rem);
  line-height: 0.9;
  letter-spacing: 0;
  text-transform: uppercase;
}

.final-subtitle {
  max-width: 620px;
  margin: 0 auto 26px;
  color: var(--soft);
  font-size: clamp(1rem, 2.2vw, 1.28rem);
  font-weight: 900;
  line-height: 1.35;
  text-transform: uppercase;
}

.final-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.final-button {
  min-width: 104px;
}

.final-status {
  min-height: 18px;
  margin: 16px 0 0;
  color: var(--accent);
  font-size: 0.9rem;
}

h1,
p {
  margin-top: 0;
}

#scene-title {
  margin: 0 0 8px;
  font-size: clamp(1.32rem, 2.4vw, 2rem);
  line-height: 1.05;
  letter-spacing: 0;
}

#scene-story {
  max-width: 76ch;
  margin-bottom: 0;
  color: var(--ink);
}

#scene-points {
  display: grid;
  gap: 7px;
  max-height: 150px;
  margin: 10px 0 0;
  padding-left: 18px;
  overflow: auto;
  color: var(--muted);
}

.hud .scene-kicker,
.hud .capability,
.hud .scene-place,
.hud .artifact {
  font-family: "VT323", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 22px;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1.4;
}

.hud #scene-story {
  font-family: "VT323", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 21px;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1.4;
}

.hud .scene-place,
.hud .artifact,
.hud #scene-points {
  font-family: "VT323", ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  font-size: 20px;
  font-weight: 400;
  letter-spacing: 0;
  line-height: 1.38;
}

.hud .capability,
.hud .scene-place,
.hud .artifact {
  line-height: 1.35;
}

.hud .artifact-prefix {
  font-weight: 700;
}

.hud #scene-points li {
  padding-left: 2px;
}

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

  .app {
    height: auto;
    min-height: 100svh;
    overflow: visible;
  }

  .stage {
    height: 54svh;
    min-height: 360px;
    max-height: 430px;
  }

  .topbar {
    align-items: start;
    min-height: auto;
    padding: 12px;
  }

  .brand span {
    font-size: 0.94rem;
  }

  .brand small {
    max-width: 190px;
  }

  .utility {
    gap: 6px;
  }

  .text-button {
    min-height: 34px;
    padding: 0 9px;
    font-size: 0.72rem;
  }

  #game-canvas {
    height: 100%;
    min-height: 0;
  }

  .scene-nav {
    left: 12px;
    right: 12px;
    bottom: 12px;
  }

  .timeline {
    gap: 4px;
  }

  .touch-controls {
    display: grid;
  }

  .hud-toggle {
    display: block;
  }

  .hud {
    height: auto;
    overflow: visible;
  }

  .hud-grid {
    grid-template-columns: 1fr;
    gap: 12px;
    height: auto;
    padding: 0 14px 16px;
  }

  #scene-points {
    max-height: none;
    overflow: visible;
  }

  .hud.is-collapsed .scene-proof {
    display: none;
  }

  .hud.is-collapsed #scene-story {
    display: none;
  }

  #scene-title {
    font-size: 1.28rem;
  }

  .hud .scene-kicker,
  .hud .capability {
    font-size: 20px;
  }

  .hud #scene-story {
    font-size: 19px;
  }

  .hud .scene-place,
  .hud .artifact,
  .hud #scene-points {
    font-size: 18px;
  }
}

@media (max-width: 540px) {
  .topbar {
    display: grid;
    gap: 10px;
  }

  .utility {
    justify-content: start;
  }

  .stage {
    min-height: 330px;
  }

  .touch-controls {
    right: 12px;
    bottom: 62px;
    grid-template-columns: repeat(4, 38px);
    gap: 6px;
  }

  .touch-button {
    width: 38px;
    height: 38px;
  }

  .scene-nav {
    grid-template-columns: 36px minmax(0, 1fr) 36px;
  }

  .icon-button {
    width: 36px;
    height: 36px;
  }

  .final-overlay {
    align-items: start;
    padding: 14px;
    overflow: auto;
  }

  .final-card {
    width: min(100%, 420px);
    padding: 22px 16px 18px;
    border-width: 2px;
    box-shadow:
      0 0 0 5px rgba(232, 200, 114, 0.18),
      0 10px 0 rgba(0, 0, 0, 0.32);
  }

  .final-kicker {
    margin-bottom: 14px;
    font-size: 0.88rem;
  }

  .final-card h2 {
    font-size: clamp(2.3rem, 16vw, 3.15rem);
  }

  .final-subtitle {
    margin-bottom: 18px;
    font-size: 0.92rem;
  }

  .final-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .final-button {
    width: 100%;
    min-height: 38px;
  }
}
