:root {
  color-scheme: dark;
  --ink: #f7fff7;
  --muted: #b8c7bf;
  --panel: rgba(10, 16, 19, 0.82);
  --line: rgba(255, 255, 255, 0.16);
  --teal: #2a9d8f;
  --coral: #e85d75;
  --sun: #f4d35e;
  --leaf: #7bd88f;
  --night: #171717;
  --shadow: rgba(0, 0, 0, 0.38);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background:
    linear-gradient(140deg, rgba(232, 93, 117, 0.18), transparent 34%),
    linear-gradient(25deg, rgba(42, 157, 143, 0.2), transparent 42%),
    #171717;
  color: var(--ink);
}

button {
  border: 0;
  color: inherit;
  font: inherit;
  cursor: pointer;
}

.app {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: 100dvh;
  padding: clamp(12px, 2vw, 22px);
  gap: clamp(10px, 1.6vw, 18px);
  overflow: hidden;
  touch-action: none;
}

.hud {
  z-index: 4;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 74px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand p,
.screen-copy > p:first-child,
.dialogue p:first-child,
.mission-card p {
  margin: 0;
  color: var(--sun);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand h1 {
  margin: 2px 0 0;
  max-width: min(680px, 58vw);
  font-size: clamp(1rem, 1.75vw, 1.42rem);
  line-height: 1.05;
}

.status {
  width: min(360px, 42vw);
  min-width: 220px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(10, 16, 19, 0.62);
  box-shadow: 0 16px 36px var(--shadow);
  backdrop-filter: blur(12px);
}

.status-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.82rem;
}

.status-top strong {
  color: var(--ink);
}

.meter {
  height: 8px;
  margin-top: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.11);
}

.meter span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--teal), var(--sun), var(--coral));
  transition: width 260ms ease;
}

.steps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin-top: 10px;
}

.steps span {
  height: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.13);
}

.steps span.done {
  background: var(--leaf);
  box-shadow: 0 0 16px rgba(123, 216, 143, 0.45);
}

.stage {
  position: relative;
  z-index: 1;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d1011;
  box-shadow:
    0 26px 80px rgba(0, 0, 0, 0.44),
    inset 0 0 0 1px rgba(255, 255, 255, 0.04);
  touch-action: none;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}

.noise {
  pointer-events: none;
  position: absolute;
  inset: 0;
  opacity: 0.16;
  mix-blend-mode: screen;
  background-image:
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.05) 0,
      rgba(255, 255, 255, 0.05) 1px,
      transparent 1px,
      transparent 5px
    ),
    repeating-linear-gradient(
      90deg,
      transparent 0,
      transparent 38px,
      rgba(232, 93, 117, 0.06) 39px,
      transparent 40px
    );
}

.stage.glitch {
  animation: stage-glitch 360ms steps(2, end);
}

.stage.glitch .noise {
  opacity: 0.42;
}

@keyframes stage-glitch {
  0%,
  100% {
    filter: none;
    transform: translate3d(0, 0, 0);
  }
  20% {
    filter: hue-rotate(70deg) contrast(1.4);
    transform: translate3d(-3px, 1px, 0);
  }
  48% {
    filter: saturate(0.6) contrast(1.8);
    transform: translate3d(4px, -2px, 0);
  }
  74% {
    filter: hue-rotate(-50deg);
    transform: translate3d(-1px, 2px, 0);
  }
}

.mission-card,
.dialogue {
  position: absolute;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 22px 48px var(--shadow);
  backdrop-filter: blur(14px);
}

.mission-card {
  top: clamp(12px, 2vw, 22px);
  right: clamp(12px, 2vw, 22px);
  width: min(245px, 32vw);
  padding: 14px;
}

.mission-card ol {
  display: grid;
  gap: 9px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}

.mission-card li {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
  font-size: 0.9rem;
}

.mission-card li::before {
  content: "";
  width: 11px;
  height: 11px;
  flex: 0 0 auto;
  border: 2px solid rgba(255, 255, 255, 0.32);
  border-radius: 50%;
}

.mission-card li.done {
  color: var(--ink);
}

.mission-card li.done::before {
  border-color: var(--leaf);
  background: var(--leaf);
  box-shadow: 0 0 14px rgba(123, 216, 143, 0.5);
}

.dialogue {
  left: clamp(12px, 2vw, 22px);
  right: clamp(12px, 2vw, 22px);
  bottom: clamp(12px, 2vw, 22px);
  max-width: 760px;
  max-height: min(34dvh, 190px);
  padding: clamp(12px, 1.5vw, 16px);
  overflow: auto;
}

.dialogue h2 {
  margin: 4px 0 6px;
  font-size: clamp(1rem, 1.65vw, 1.34rem);
  line-height: 1.12;
}

.dialogue p {
  margin: 0;
  color: var(--muted);
  font-size: clamp(0.84rem, 1.22vw, 0.98rem);
  line-height: 1.38;
}

.screen {
  position: fixed;
  z-index: 8;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background:
    linear-gradient(130deg, rgba(42, 157, 143, 0.32), transparent 42%),
    linear-gradient(35deg, rgba(244, 211, 94, 0.2), transparent 44%),
    rgba(13, 16, 17, 0.92);
}

.screen.hidden {
  display: none;
}

.screen-copy {
  width: min(700px, 100%);
  padding: clamp(22px, 5vw, 42px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  background: rgba(10, 16, 19, 0.78);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(18px);
}

.screen-copy h2 {
  margin: 10px 0 14px;
  font-size: clamp(2rem, 6vw, 4.7rem);
  line-height: 0.98;
}

.screen-copy p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: clamp(1rem, 2vw, 1.15rem);
  line-height: 1.58;
}

.screen-copy .signature {
  color: var(--ink);
  font-weight: 800;
}

.screen-copy button {
  min-width: 156px;
  min-height: 50px;
  padding: 0 22px;
  border-radius: 8px;
  background: var(--coral);
  color: #fff;
  font-weight: 850;
  box-shadow: 0 16px 34px rgba(232, 93, 117, 0.28);
}

.screen-copy button:hover {
  filter: brightness(1.08);
}

.screen-copy button:focus-visible,
.mobile-controls button:focus-visible {
  outline: 3px solid var(--sun);
  outline-offset: 3px;
}

.final-screen {
  background:
    linear-gradient(145deg, rgba(123, 216, 143, 0.26), transparent 36%),
    linear-gradient(35deg, rgba(232, 93, 117, 0.22), transparent 46%),
    rgba(15, 18, 16, 0.94);
}

.mobile-controls {
  position: fixed;
  z-index: 6;
  left: 0;
  right: 0;
  bottom: max(14px, env(safe-area-inset-bottom));
  display: none;
  justify-content: space-between;
  align-items: end;
  padding: 0 18px;
  pointer-events: none;
  touch-action: none;
}

.mobile-controls button {
  width: 64px;
  height: 64px;
  pointer-events: auto;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 50%;
  background: rgba(10, 16, 19, 0.78);
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(12px);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.mobile-controls [data-control="action"] {
  width: 82px;
  height: 82px;
  background: var(--teal);
}

.mobile-controls button span {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-size: 2rem;
  line-height: 1;
}

.mobile-controls button.active {
  transform: translateY(2px) scale(0.98);
  filter: brightness(1.2);
}

@media (hover: none), (max-width: 840px) {
  .app {
    padding: 10px;
    gap: 8px;
  }

  .hud {
    min-height: 62px;
    align-items: stretch;
    gap: 10px;
  }

  .brand h1 {
    max-width: 45vw;
    font-size: 0.92rem;
    line-height: 1.08;
  }

  .brand p {
    font-size: 0.64rem;
  }

  .status {
    width: 44vw;
    min-width: 168px;
    padding: 10px;
  }

  .status-top {
    font-size: 0.72rem;
  }

  #game {
    min-height: 0;
  }

  .mission-card {
    display: none;
  }

  .dialogue {
    bottom: 104px;
    max-width: none;
    max-height: 28dvh;
  }

  .mobile-controls {
    display: flex;
    gap: 18px;
  }
}

@media (max-width: 560px) {
  .brand {
    gap: 8px;
  }

  .brand p {
    font-size: 0.58rem;
  }

  .brand h1 {
    max-width: 36vw;
    font-size: 0.78rem;
  }

  .status {
    min-width: 112px;
    width: 34vw;
  }

  .status-top span {
    display: none;
  }

  .status-top {
    justify-content: flex-end;
  }

  .steps {
    gap: 4px;
  }

  .dialogue {
    padding: 12px;
  }

  .dialogue h2 {
    font-size: 0.98rem;
  }

  .dialogue p {
    font-size: 0.8rem;
    line-height: 1.32;
  }

  .screen-copy {
    padding: 22px;
  }
}

@media (orientation: landscape) and (hover: none) and (max-height: 520px) {
  .app {
    grid-template-rows: auto minmax(0, 1fr);
    height: 100svh;
    padding: 4px 8px max(4px, env(safe-area-inset-bottom));
    gap: 4px;
  }

  .hud {
    min-height: 34px;
    align-items: center;
    gap: 8px;
  }

  .brand p {
    font-size: 0.48rem;
    line-height: 1;
  }

  .brand h1 {
    max-width: 46vw;
    font-size: 0.72rem;
    line-height: 1.05;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .status {
    width: 38vw;
    min-width: 180px;
    padding: 6px 8px;
    border-radius: 8px;
  }

  .status-top {
    font-size: 0.58rem;
    line-height: 1;
  }

  .meter {
    height: 5px;
    margin-top: 5px;
  }

  .steps {
    gap: 4px;
    margin-top: 5px;
  }

  .steps span {
    height: 3px;
  }

  .stage {
    border-radius: 6px;
  }

  .dialogue {
    left: 60px;
    right: 60px;
    bottom: max(6px, env(safe-area-inset-bottom));
    max-height: 58px;
    padding: 7px 10px;
    border-radius: 7px;
    overflow: hidden;
    background: rgba(10, 16, 19, 0.72);
  }

  .dialogue p:first-child {
    display: none;
  }

  .dialogue h2 {
    margin: 0 0 2px;
    font-size: 0.74rem;
    line-height: 1.05;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .dialogue p {
    display: -webkit-box;
    font-size: 0.62rem;
    line-height: 1.18;
    overflow: hidden;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  .mobile-controls {
    bottom: max(8px, env(safe-area-inset-bottom));
    align-items: center;
    padding: 0 10px;
    gap: 0;
  }

  .mobile-controls button {
    width: 44px;
    height: 44px;
    background: rgba(10, 16, 19, 0.68);
  }

  .mobile-controls [data-control="action"] {
    width: 62px;
    height: 62px;
  }

  .mobile-controls button span {
    font-size: 1.55rem;
  }

  .screen {
    padding: 10px;
  }

  .screen-copy {
    max-height: calc(100svh - 20px);
    padding: 16px;
    overflow: auto;
  }

  .screen-copy h2 {
    font-size: clamp(1.4rem, 7vw, 2.5rem);
  }

  .screen-copy p {
    font-size: 0.88rem;
    line-height: 1.35;
  }
}
