:root {
  color-scheme: dark;
  font-family: Inter, "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
  --sky: #081018;
  --cyan: #2fffd1;
  --yellow: #ffe65a;
  --coral: #ff6d5a;
  --violet: #b96cff;
  --green: #86f06f;
  --blue: #57a8ff;
  --line: rgba(226, 255, 246, 0.22);
  color: #f4fffb;
  background: var(--sky);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow-x: hidden;
}

body {
  background:
    radial-gradient(circle at 14% 8%, rgba(47, 255, 209, 0.14), transparent 26%),
    radial-gradient(circle at 82% 10%, rgba(255, 230, 90, 0.12), transparent 25%),
    linear-gradient(135deg, #081018 0%, #102019 48%, #1c1224 100%);
}

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

.shell {
  min-height: 100vh;
  padding: 18px;
  display: grid;
  gap: 14px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(260px, 360px) 1fr;
  gap: 14px;
}

.brand,
.hud,
.info-row,
.touch-controls {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(11, 23, 29, 0.9), rgba(5, 11, 16, 0.74));
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.34), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(12px);
}

.brand {
  min-height: 78px;
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 13px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  background:
    radial-gradient(circle at 52% 36%, white 0 7%, transparent 8%),
    conic-gradient(from 215deg, var(--yellow), var(--coral), var(--violet), var(--cyan), var(--yellow));
  box-shadow: 0 0 28px rgba(255, 230, 90, 0.38);
}

.brand p,
.hud span,
.info-row span,
.overlay p {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0;
  color: rgba(232, 255, 249, 0.66);
  font-size: 11px;
}

.brand h1 {
  margin: 2px 0 0;
  font-size: 26px;
  line-height: 1;
}

.hud {
  display: grid;
  grid-template-columns: repeat(6, minmax(86px, 1fr));
  overflow: hidden;
}

.hud div {
  min-height: 78px;
  padding: 13px 14px;
  display: grid;
  align-content: center;
  gap: 5px;
  border-left: 1px solid rgba(226, 255, 246, 0.12);
}

.hud div:first-child {
  border-left: 0;
}

.hud strong {
  font-size: 24px;
  line-height: 1;
  text-shadow: 0 0 16px rgba(47, 255, 209, 0.34);
}

.stage-wrap {
  position: relative;
  width: min(100%, calc((100dvh - 250px) * 1.777777));
  aspect-ratio: 16 / 9;
  justify-self: center;
  min-height: 0;
  border: 1px solid rgba(226, 255, 246, 0.28);
  border-radius: 8px;
  overflow: hidden;
  background: #081018;
  box-shadow: 0 22px 60px rgba(0, 0, 0, 0.48), 0 0 42px rgba(47, 255, 209, 0.14);
  contain: layout paint;
  transform: translateZ(0);
}

.stage-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background:
    linear-gradient(105deg, transparent 0 40%, rgba(255, 230, 90, 0.12) 47%, transparent 56% 100%),
    repeating-linear-gradient(180deg, rgba(255, 255, 255, 0.022) 0 1px, transparent 1px 6px);
  mix-blend-mode: screen;
  opacity: 0.2;
  animation: runner-sweep 6.4s linear infinite;
}

canvas {
  display: block;
  position: relative;
  z-index: 0;
  width: 100%;
  height: 100%;
  min-height: 0;
  transform: translateZ(0);
}

@keyframes runner-sweep {
  from { background-position: -520px 0, 0 0; }
  to { background-position: 520px 0, 0 18px; }
}

.overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
  place-items: center;
  padding: 28px;
  background:
    radial-gradient(circle at 50% 42%, rgba(255, 230, 90, 0.12), transparent 36%),
    rgba(3, 8, 12, 0.62);
  backdrop-filter: blur(7px);
}

.overlay.active {
  display: grid;
}

.overlay > div {
  width: min(590px, 92vw);
  border: 1px solid rgba(226, 255, 246, 0.34);
  border-radius: 8px;
  padding: 26px;
  display: grid;
  gap: 12px;
  background: rgba(6, 16, 21, 0.84);
  box-shadow: 0 0 48px rgba(255, 230, 90, 0.18);
}

.overlay h2 {
  margin: 0;
  font-size: clamp(32px, 5vw, 58px);
  line-height: 1;
}

.overlay span {
  color: rgba(236, 255, 251, 0.78);
  line-height: 1.7;
}

.overlay button {
  width: fit-content;
  min-width: 150px;
  border-radius: 8px;
  padding: 12px 18px;
  background: linear-gradient(90deg, var(--cyan), var(--yellow));
  color: #071018;
  font-weight: 900;
  box-shadow: 0 0 24px rgba(47, 255, 209, 0.34);
}

.info-row {
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.info-row article {
  border: 1px solid rgba(226, 255, 246, 0.14);
  border-radius: 8px;
  padding: 12px;
  background: rgba(4, 12, 16, 0.55);
  display: grid;
  gap: 7px;
}

.info-row strong {
  font-size: 16px;
}

.info-row small {
  color: rgba(232, 255, 249, 0.74);
  line-height: 1.48;
}

.touch-controls {
  display: none;
}

.fullscreen-button {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 6;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  border: 1px solid rgba(226, 255, 246, 0.36);
  background: rgba(4, 12, 16, 0.72);
  color: #f4fffb;
  font-size: 20px;
  font-weight: 900;
  display: grid;
  place-items: center;
}

.mobile-control-layer {
  display: none;
}

.floating-joystick {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 5;
  width: clamp(76px, 23vw, 116px);
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid rgba(226, 255, 246, 0.34);
  background: rgba(4, 12, 16, 0.56);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.32), inset 0 0 22px rgba(255, 230, 90, 0.14);
  touch-action: none;
}

.floating-joystick span {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 42%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: linear-gradient(180deg, var(--yellow), var(--cyan));
  transform: translate(-50%, -50%);
  box-shadow: 0 0 22px rgba(255, 230, 90, 0.4);
}

.mobile-action-pad {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 5;
  width: clamp(100px, 28vw, 150px);
  display: grid;
  gap: 6px;
}

.mobile-action-pad button {
  min-height: clamp(34px, 7.5vw, 46px);
  border-radius: 8px;
  border: 1px solid rgba(226, 255, 246, 0.26);
  background: rgba(4, 12, 16, 0.76);
  color: #f4fffb;
  font-size: clamp(9px, 2.7vw, 12px);
  font-weight: 900;
  touch-action: manipulation;
}

.overlay {
  z-index: 7;
}

.fullscreen-button {
  z-index: 8;
}

body.app-fullscreen {
  overflow: hidden;
}

body.app-fullscreen::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 9998;
  background: #081018;
}

body.app-fullscreen .stage-wrap {
  position: fixed;
  left: 50%;
  top: 50%;
  z-index: 9999;
  width: min(100vw, calc(100dvh * 1.777777));
  height: min(100dvh, calc(100vw * 0.5625));
  max-width: none;
  aspect-ratio: 16 / 9;
  border: 0;
  border-radius: 0;
  transform: translate(-50%, -50%);
}

.stage-wrap:fullscreen,
.stage-wrap:-webkit-full-screen {
  position: fixed;
  left: 50%;
  top: 50%;
  width: min(100vw, calc(100vh * 1.777777));
  height: min(100vh, calc(100vw * 0.5625));
  max-width: none;
  aspect-ratio: 16 / 9;
  border: 0;
  border-radius: 0;
  background: #081018;
  transform: translate(-50%, -50%);
}

body.app-fullscreen canvas,
.stage-wrap:fullscreen canvas,
.stage-wrap:-webkit-full-screen canvas {
  width: 100%;
  height: 100%;
}

@media (orientation: portrait) {
  body.app-fullscreen .stage-wrap {
    width: min(100dvh, calc(100vw * 1.777777));
    height: min(100vw, calc(100dvh * 0.5625));
    transform: translate(-50%, -50%) rotate(90deg);
  }

  .stage-wrap:fullscreen,
  .stage-wrap:-webkit-full-screen {
    width: min(100vh, calc(100vw * 1.777777));
    height: min(100vw, calc(100vh * 0.5625));
    transform: translate(-50%, -50%) rotate(90deg);
  }
}

@media (max-width: 980px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .hud {
    grid-template-columns: repeat(3, 1fr);
  }

  .stage-wrap {
    width: min(100%, calc((100dvh - 230px) * 1.777777));
  }
}

@media (max-width: 720px) {
  .shell {
    padding: 10px;
  }

  .brand {
    min-height: 66px;
  }

  .hud {
    grid-template-columns: repeat(2, 1fr);
  }

  .hud div {
    min-height: 62px;
    padding: 10px;
  }

  .hud strong {
    font-size: 21px;
  }

  .stage-wrap {
    width: 100%;
  }

  .info-row {
    grid-template-columns: 1fr;
  }

  .touch-controls {
    padding: 10px;
    display: grid;
    grid-template-columns: repeat(3, minmax(70px, 1fr));
    gap: 8px;
  }

  .touch-controls button {
    min-height: 56px;
    border-radius: 8px;
    border: 1px solid rgba(226, 255, 246, 0.18);
    background: rgba(4, 12, 16, 0.75);
    font-weight: 900;
  }

  .overlay {
    padding: 10px;
  }

  .overlay > div {
    padding: 14px;
    gap: 8px;
  }

  .overlay h2 {
    font-size: clamp(25px, 8vw, 34px);
  }

  .overlay p,
  .overlay span {
    display: none;
  }

  .overlay button {
    min-width: 122px;
    padding: 9px 13px;
  }
}

@media (max-width: 560px) {
  .shell {
    min-height: 100dvh;
    padding: 6px;
    gap: 8px;
  }

  .topbar {
    gap: 8px;
  }

  .brand {
    min-height: 54px;
    padding: 9px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .brand h1 {
    font-size: 19px;
  }

  .hud {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .hud div {
    min-height: 44px;
    padding: 7px;
  }

  .hud span,
  .info-row span {
    font-size: 9px;
  }

  .hud strong {
    font-size: 16px;
  }

  .stage-wrap {
    width: 100%;
    border-radius: 6px;
  }

  .fullscreen-button {
    top: 6px;
    right: 6px;
    width: 34px;
    height: 34px;
    font-size: 17px;
  }

  .mobile-control-layer {
    display: block;
  }

  .info-row {
    padding: 8px;
    gap: 6px;
  }

  .info-row article {
    padding: 8px;
  }

  .info-row article:nth-child(n + 2) {
    display: none;
  }

  .info-row strong {
    font-size: 14px;
  }

  .info-row small {
    font-size: 11px;
    line-height: 1.35;
  }

  .touch-controls {
    display: none;
  }
}
