:root {
  color-scheme: dark;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #041b25;
  color: #f4fbf8;
  letter-spacing: 0;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #041b25;
}

button {
  font: inherit;
  letter-spacing: 0;
}

#game-shell {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 320px;
  isolation: isolate;
  overflow: hidden;
  background: #062f3a;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  touch-action: none;
}

#hud {
  position: absolute;
  z-index: 5;
  inset: max(18px, env(safe-area-inset-top)) max(22px, env(safe-area-inset-right)) auto max(22px, env(safe-area-inset-left));
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(280px, 420px) minmax(210px, 1fr);
  align-items: start;
  gap: 18px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 220ms ease, transform 220ms ease;
}

#hud.visible {
  opacity: 1;
  transform: translateY(0);
}

.brand-lockup,
.status-panel,
.level-panel,
.control-help {
  background: rgba(3, 25, 32, 0.72);
  border: 1px solid rgba(178, 241, 217, 0.18);
  box-shadow: 0 8px 28px rgba(0, 11, 15, 0.22);
  backdrop-filter: blur(10px);
}

.brand-lockup {
  justify-self: start;
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 166px;
  padding: 10px 13px;
  border-radius: 6px;
}

.brand-mark {
  width: 30px;
  height: 22px;
  flex: 0 0 auto;
  border-radius: 55% 48% 48% 55%;
  background: #f2b441;
  box-shadow: inset -8px 0 #e45f3f, 0 0 18px rgba(242, 180, 65, 0.35);
  clip-path: polygon(0 16%, 72% 16%, 100% 0, 92% 50%, 100% 100%, 72% 84%, 0 84%, 12% 50%);
}

.brand-lockup strong,
.brand-lockup small {
  display: block;
  line-height: 1;
}

.brand-lockup strong {
  font-size: 15px;
}

.brand-lockup small {
  margin-top: 5px;
  color: #78cdbb;
  font-size: 9px;
  font-weight: 700;
}

.level-panel {
  width: min(100%, 420px);
  justify-self: center;
  padding: 11px 14px 10px;
  border-radius: 6px;
}

.level-copy {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.level-copy span {
  font-size: 14px;
  font-weight: 700;
}

.level-copy strong {
  color: #f5cf62;
  font-size: 12px;
}

.progress-track {
  position: relative;
  height: 8px;
  overflow: hidden;
  background: rgba(187, 240, 225, 0.12);
  border-radius: 2px;
}

#progress-fill {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  background: #f4bd45;
  box-shadow: 0 0 14px rgba(244, 189, 69, 0.6);
  transition: width 260ms ease;
}

.progress-dots {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  background: repeating-linear-gradient(90deg, transparent 0 calc(20% - 1px), rgba(2, 25, 30, 0.55) calc(20% - 1px) 20%);
}

.progress-dots::before {
  display: none;
}

.level-panel small {
  display: block;
  margin-top: 7px;
  color: #afd0c9;
  font-size: 10px;
}

.status-panel {
  justify-self: end;
  display: flex;
  align-items: stretch;
  min-height: 55px;
  overflow: hidden;
  border-radius: 6px;
  pointer-events: auto;
}

.status-item {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 84px;
  padding: 8px 12px;
  border-right: 1px solid rgba(178, 241, 217, 0.12);
}

.status-item span {
  color: #91beb5;
  font-size: 9px;
}

.status-item strong {
  margin-top: 2px;
  font-size: 15px;
}

.status-item.danger strong {
  color: #ff8b67;
}

.text-button {
  min-width: 69px;
  border: 0;
  border-radius: 0;
  background: rgba(108, 203, 178, 0.08);
  color: #d7ede7;
  font-size: 11px;
  cursor: pointer;
}

.text-button:hover {
  background: rgba(108, 203, 178, 0.18);
}

.target-hint {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 55%;
  min-width: 116px;
  padding: 7px 10px;
  border-left: 2px solid #f4bd45;
  background: rgba(1, 18, 22, 0.56);
  color: #f5df9c;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.target-hint[data-altitude="up"] {
  border-left-color: #7bd9c8;
  color: #b8f2e7;
}

.target-hint[data-altitude="down"] {
  border-left-color: #f4bd45;
  color: #ffe099;
}

.target-hint[data-altitude="aligned"] {
  border-left-color: #86e09a;
  color: #d6f7dd;
}

.target-hint.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast {
  position: absolute;
  z-index: 7;
  left: 50%;
  top: 27%;
  max-width: min(88vw, 420px);
  padding: 9px 14px;
  border: 1px solid rgba(251, 215, 111, 0.45);
  border-radius: 4px;
  background: rgba(4, 32, 38, 0.86);
  color: #ffe292;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

#damage-vignette {
  position: absolute;
  z-index: 6;
  inset: 0;
  background: radial-gradient(circle, transparent 34%, rgba(203, 43, 30, 0.68) 100%);
  opacity: 0;
  pointer-events: none;
}

#boost-effect {
  position: absolute;
  z-index: 3;
  inset: -18%;
  background: repeating-conic-gradient(from 8deg at 50% 55%, transparent 0deg 9deg, rgba(174, 255, 238, 0.7) 9.4deg 10deg, transparent 10.4deg 19deg);
  -webkit-mask-image: radial-gradient(circle at 50% 55%, transparent 0 28%, #000 76%);
  mask-image: radial-gradient(circle at 50% 55%, transparent 0 28%, #000 76%);
  mix-blend-mode: screen;
  opacity: 0;
  pointer-events: none;
  transform: scale(0.92);
  transition: opacity 120ms ease;
}

#boost-effect.active {
  opacity: 0.32;
  animation: boost-stream 240ms linear infinite;
}

@keyframes boost-stream {
  from { transform: scale(0.92) rotate(0deg); }
  to { transform: scale(1.08) rotate(1.2deg); }
}

#damage-vignette.flash {
  animation: damage-flash 520ms ease-out;
}

@keyframes damage-flash {
  0% { opacity: 0; }
  20% { opacity: 1; }
  100% { opacity: 0; }
}

.control-help {
  position: absolute;
  z-index: 5;
  left: max(22px, env(safe-area-inset-left));
  bottom: max(20px, env(safe-area-inset-bottom));
  display: flex;
  gap: 16px;
  padding: 9px 11px;
  border-radius: 6px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 220ms ease, transform 220ms ease;
}

.control-help.visible {
  opacity: 1;
  transform: translateY(0);
}

.control-help div {
  display: flex;
  align-items: center;
  gap: 4px;
}

.control-help span {
  margin-left: 3px;
  color: #a8cbc3;
  font-size: 9px;
}

kbd {
  display: grid;
  place-items: center;
  width: 21px;
  height: 21px;
  border: 1px solid rgba(210, 248, 239, 0.3);
  border-bottom-width: 2px;
  border-radius: 3px;
  background: rgba(206, 247, 237, 0.08);
  color: #e7f7f2;
  font: 600 10px/1 monospace;
}

kbd.wide-key {
  width: 48px;
}

.overlay {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 28px;
  visibility: hidden;
  background: linear-gradient(90deg, rgba(2, 22, 28, 0.88) 0%, rgba(2, 28, 35, 0.56) 52%, rgba(2, 28, 35, 0.1) 100%);
  opacity: 0;
  transition: opacity 300ms ease, visibility 300ms;
}

.overlay.active {
  visibility: visible;
  opacity: 1;
}

.intro-copy,
.end-copy {
  width: min(100%, 560px);
  margin-right: min(30vw, 360px);
}

.eyebrow {
  display: block;
  margin-bottom: 12px;
  color: #f3c85a;
  font-size: 11px;
  font-weight: 800;
}

.intro-copy h1,
.end-copy h2 {
  margin: 0;
  font-family: Impact, Haettenschweiler, "Arial Narrow Bold", sans-serif;
  font-size: clamp(54px, 9vh, 98px);
  font-weight: 900;
  line-height: 0.9;
  text-shadow: 4px 4px 0 rgba(3, 25, 31, 0.55);
}

.intro-copy p,
.end-copy p {
  max-width: 500px;
  margin: 24px 0 20px;
  color: #c5dcd7;
  font-size: 15px;
  line-height: 1.7;
}

.rule-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  width: fit-content;
  margin-bottom: 28px;
  background: rgba(172, 225, 211, 0.18);
  border: 1px solid rgba(172, 225, 211, 0.18);
}

.rule-strip span {
  padding: 9px 13px;
  background: rgba(3, 31, 38, 0.8);
  color: #a9c9c2;
  font-size: 11px;
}

.rule-strip b {
  color: #f5cf62;
  font-size: 15px;
}

.primary-button {
  min-width: 170px;
  min-height: 48px;
  padding: 0 26px;
  border: 0;
  border-radius: 4px;
  background: #f0b83e;
  box-shadow: 4px 4px 0 #8b571f;
  color: #11262a;
  font-weight: 900;
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.primary-button:hover {
  background: #ffd164;
  transform: translate(-1px, -1px);
  box-shadow: 5px 5px 0 #8b571f;
}

.primary-button:active {
  transform: translate(3px, 3px);
  box-shadow: 1px 1px 0 #8b571f;
}

.depth-scale {
  position: absolute;
  right: max(28px, 4vw);
  top: 14%;
  bottom: 14%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  justify-items: center;
  gap: 10px;
  color: rgba(213, 241, 233, 0.64);
  font-size: 9px;
  writing-mode: vertical-rl;
}

.depth-scale i {
  width: 1px;
  height: 100%;
  background: linear-gradient(#89ded0, rgba(137, 222, 208, 0.04));
}

.end-copy h2 {
  font-size: clamp(48px, 8vh, 82px);
}

.end-stats {
  display: flex;
  width: min(100%, 420px);
  margin: 0 0 28px;
  border-top: 1px solid rgba(191, 233, 223, 0.2);
  border-bottom: 1px solid rgba(191, 233, 223, 0.2);
}

.end-stats div {
  flex: 1;
  padding: 13px 0;
}

.end-stats span,
.end-stats strong {
  display: block;
}

.end-stats span {
  color: #8fb8af;
  font-size: 10px;
}

.end-stats strong {
  margin-top: 4px;
  color: #f5cf62;
  font-size: 18px;
}

#mobile-controls {
  display: none;
}

@media (pointer: coarse), (max-width: 820px) {
  #hud {
    inset: max(9px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) auto max(10px, env(safe-area-inset-left));
    grid-template-columns: auto minmax(170px, 1fr) auto;
    gap: 7px;
  }

  .brand-lockup {
    min-width: 0;
    padding: 8px;
  }

  .brand-lockup > div,
  .status-item:first-child,
  .text-button {
    display: none;
  }

  .brand-mark {
    width: 28px;
    height: 20px;
  }

  .level-panel {
    padding: 8px 10px;
  }

  .level-panel small {
    display: none;
  }

  .level-copy {
    margin-bottom: 5px;
  }

  .status-panel {
    min-height: 43px;
  }

  .status-item {
    min-width: 76px;
    padding: 6px 9px;
    border-right: 0;
  }

  #desktop-help {
    display: none;
  }

  #mobile-controls {
    position: absolute;
    z-index: 6;
    inset: 72px 0 0;
    display: none;
    pointer-events: none;
  }

  #mobile-controls.visible {
    display: block;
  }

  .touch-zone {
    position: absolute;
    bottom: max(18px, env(safe-area-inset-bottom));
    width: 44%;
    height: 58%;
    min-height: 150px;
    pointer-events: auto;
    touch-action: none;
  }

  #move-zone {
    left: 0;
  }

  .look-zone {
    right: 0;
  }

  .look-zone span {
    position: absolute;
    right: max(18px, env(safe-area-inset-right));
    bottom: 18px;
    color: rgba(217, 239, 233, 0.34);
    font-size: 9px;
  }

  .joystick-base {
    position: absolute;
    left: max(24px, env(safe-area-inset-left));
    bottom: 10px;
    width: 94px;
    height: 94px;
    border: 1px solid rgba(218, 244, 237, 0.24);
    border-radius: 50%;
    background: rgba(2, 28, 34, 0.24);
  }

  .joystick-knob {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 42px;
    height: 42px;
    margin: -21px;
    border: 1px solid rgba(238, 252, 248, 0.4);
    border-radius: 50%;
    background: rgba(152, 220, 201, 0.28);
    box-shadow: 0 0 18px rgba(119, 212, 187, 0.16);
  }

  .boost-button {
    position: absolute;
    z-index: 2;
    right: max(22px, env(safe-area-inset-right));
    bottom: max(54px, calc(env(safe-area-inset-bottom) + 54px));
    width: 66px;
    height: 66px;
    border: 1px solid rgba(255, 223, 124, 0.5);
    border-radius: 50%;
    background: rgba(240, 184, 62, 0.2);
    color: #ffe08a;
    font-size: 11px;
    font-weight: 800;
    pointer-events: auto;
    touch-action: none;
  }

  .boost-button.active {
    background: rgba(240, 184, 62, 0.56);
    color: #142d30;
  }

  .overlay {
    place-items: end start;
    padding: 20px max(18px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
    background: linear-gradient(0deg, rgba(2, 22, 28, 0.94) 0%, rgba(2, 26, 33, 0.66) 65%, rgba(2, 28, 35, 0.2) 100%);
  }

  .intro-copy,
  .end-copy {
    width: min(100%, 500px);
    margin: 0;
  }

  .intro-copy h1,
  .end-copy h2 {
    font-size: clamp(44px, 13vw, 68px);
  }

  .intro-copy p,
  .end-copy p {
    margin: 13px 0;
    font-size: 12px;
    line-height: 1.5;
  }

  .rule-strip {
    margin-bottom: 16px;
  }

  .rule-strip span {
    padding: 7px 9px;
    font-size: 9px;
  }

  .primary-button {
    min-width: 152px;
    min-height: 44px;
  }

  .depth-scale {
    display: none;
  }
}

@media (max-height: 520px) and (pointer: coarse) {
  .eyebrow {
    margin-bottom: 6px;
  }

  .intro-copy h1,
  .end-copy h2 {
    font-size: 44px;
  }

  .intro-copy p,
  .end-copy p {
    max-width: 540px;
    margin: 8px 0;
  }

  .rule-strip {
    margin-bottom: 10px;
  }

  .primary-button {
    min-height: 40px;
  }

  .end-stats {
    margin-bottom: 12px;
  }
}
