:root {
  color-scheme: dark;
  font-family: "Bahnschrift SemiCondensed", "DIN Alternate", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #031d36;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background:
    radial-gradient(circle at 50% 10%, rgba(26, 179, 208, .25), transparent 44%),
    #031d36;
}

button {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.page-shell {
  width: 100vw;
  height: 100dvh;
  display: grid;
  place-items: center;
  background:
    linear-gradient(90deg, rgba(1, 12, 28, .92), transparent 18%, transparent 82%, rgba(1, 12, 28, .92)),
    #031d36;
}

.game-frame {
  --joystick-accent: #8cf3c4;
  position: relative;
  width: min(100vw, calc(100dvh * 16 / 9));
  height: auto;
  aspect-ratio: 16 / 9;
  max-width: 100vw;
  max-height: 100dvh;
  overflow: hidden;
  isolation: isolate;
  background: #087aa9;
  border-block: 1px solid rgba(194, 247, 255, .18);
  box-shadow: 0 30px 110px rgba(0, 10, 28, .72);
  touch-action: none;
}

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

.hud {
  position: absolute;
  z-index: 5;
  top: max(16px, env(safe-area-inset-top));
  left: max(20px, env(safe-area-inset-left));
  width: min(680px, calc(100% - 40px));
  color: #fff;
  filter: drop-shadow(0 2px 5px rgba(0, 24, 48, .62));
  pointer-events: none;
}

.hud-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 112px 112px;
  gap: 10px;
  align-items: stretch;
}

.zone-chip,
.power-readout,
.time-readout {
  min-height: 58px;
  padding: 9px 14px;
  border: 1px solid rgba(217, 252, 255, .35);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(3, 42, 73, .76), rgba(4, 26, 53, .6));
  backdrop-filter: blur(9px);
}

.zone-chip,
.power-readout,
.time-readout {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.zone-chip span,
.power-readout span,
.time-readout span {
  color: rgba(225, 250, 255, .78);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
  white-space: nowrap;
}

.zone-chip b,
.power-readout strong,
.time-readout strong {
  margin-top: 2px;
  color: #f6ffdc;
  font-size: 18px;
  font-weight: 950;
  letter-spacing: -.02em;
  white-space: nowrap;
}

.power-readout,
.time-readout {
  text-align: center;
}

.hunger-row {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  width: min(var(--hunger-width, 360px), 100%);
  max-width: 100%;
  margin: 9px 3px 0;
  padding: 7px 11px;
  border-radius: 999px;
  background: rgba(2, 29, 54, .55);
  backdrop-filter: blur(7px);
  transition: width .5s cubic-bezier(.2, .8, .2, 1);
}

.hunger-row > span {
  color: rgba(230, 252, 255, .86);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .08em;
}

.hunger-track {
  height: 10px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 999px;
  background: rgba(1, 17, 33, .64);
}

.hunger-track i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #a3ea35, #d8fa54 60%, #f7d44f);
  box-shadow: 0 0 12px rgba(191, 245, 57, .62);
  transform-origin: left center;
  transition: width .18s linear, background .25s ease;
}

.hud.is-warning .hunger-track i {
  background: linear-gradient(90deg, #f7b83d, #ffe95a);
  box-shadow: 0 0 13px rgba(255, 204, 61, .68);
}

.hud.is-hungry .hunger-row {
  animation: hunger-alert .7s ease-in-out infinite alternate;
}

.hud.is-hungry .hunger-track i {
  background: linear-gradient(90deg, #ff544f, #ff9b3d);
  box-shadow: 0 0 15px rgba(255, 82, 66, .72);
}

.hud.is-boosting .hunger-track i {
  filter: saturate(1.35) brightness(1.12);
  animation: boost-flow .42s linear infinite;
}

@keyframes boost-flow {
  0% { box-shadow: 0 0 8px rgba(156, 247, 255, .45); }
  50% { box-shadow: 0 0 19px rgba(156, 247, 255, .92); }
  100% { box-shadow: 0 0 8px rgba(156, 247, 255, .45); }
}

@keyframes hunger-alert {
  from { box-shadow: 0 0 0 rgba(255, 76, 61, 0); }
  to { box-shadow: 0 0 18px rgba(255, 76, 61, .42); }
}

.depth-label {
  position: absolute;
  z-index: 4;
  top: 20px;
  left: auto;
  right: max(22px, env(safe-area-inset-right));
  width: 238px;
  padding: 11px 15px 12px;
  border: 1px solid rgba(215, 250, 255, .28);
  border-radius: 8px 18px 18px 8px;
  color: rgba(236, 254, 255, .88);
  background: linear-gradient(135deg, rgba(3, 38, 66, .78), rgba(3, 25, 51, .48));
  box-shadow: inset 3px 0 0 rgba(145, 241, 231, .65), 0 12px 32px rgba(0, 21, 47, .28);
  backdrop-filter: blur(9px);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .04em;
  opacity: 0;
  transform: translateX(18px);
  transition: opacity .4s ease, transform .4s cubic-bezier(.2, .8, .2, 1);
  pointer-events: none;
}

.depth-label.is-visible {
  opacity: 1;
  transform: translateX(0);
}

.depth-label small,
.depth-label b,
.depth-label em {
  display: block;
}

.depth-label small {
  color: rgba(205, 244, 248, .64);
  font-size: 9px;
  font-weight: 750;
  letter-spacing: .15em;
}

.depth-label b {
  margin-top: 2px;
  color: #f4ffdc;
  font-size: 19px;
  letter-spacing: -.02em;
}

.depth-label em {
  margin-top: 3px;
  color: rgba(218, 248, 250, .72);
  font-size: 10px;
  font-style: normal;
  font-weight: 650;
  letter-spacing: .06em;
}

.touch-hint {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: max(18px, calc(env(safe-area-inset-bottom) + 10px));
  width: max-content;
  max-width: calc(100% - 38px);
  padding: 9px 17px;
  border: 1px solid rgba(220, 252, 255, .32);
  border-radius: 999px;
  color: rgba(241, 255, 255, .9);
  background: rgba(3, 34, 60, .58);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: .04em;
  text-align: center;
  transform: translateX(-50%);
  transition: opacity .3s ease, transform .3s ease;
  pointer-events: none;
}

.touch-hint.is-hidden {
  opacity: 0;
  transform: translate(-50%, 8px);
}

.boost-button {
  position: absolute;
  z-index: 6;
  right: max(24px, env(safe-area-inset-right));
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 14px));
  width: 82px;
  height: 82px;
  display: grid;
  place-content: center;
  gap: 1px;
  padding: 0;
  border: 1px solid rgba(211, 253, 255, .5);
  border-radius: 50%;
  color: #efffff;
  background:
    radial-gradient(circle at 36% 28%, rgba(191, 255, 255, .3), transparent 30%),
    linear-gradient(145deg, rgba(20, 164, 191, .84), rgba(4, 61, 103, .88));
  box-shadow:
    inset 0 0 18px rgba(172, 251, 255, .18),
    0 8px 28px rgba(0, 23, 51, .48),
    0 0 0 5px rgba(109, 223, 239, .08);
  text-align: center;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
  transition: transform .12s ease, filter .12s ease, box-shadow .12s ease, opacity .2s ease;
}

.boost-button span {
  font-size: 18px;
  font-weight: 950;
  letter-spacing: .08em;
}

.boost-button small {
  color: rgba(222, 254, 255, .65);
  font-size: 8px;
  font-weight: 900;
  letter-spacing: .18em;
}

.boost-button.is-active,
.boost-button:active {
  transform: scale(.92);
  filter: brightness(1.24) saturate(1.3);
  box-shadow:
    inset 0 0 22px rgba(218, 255, 255, .36),
    0 4px 18px rgba(0, 23, 51, .42),
    0 0 0 7px rgba(113, 244, 255, .2),
    0 0 30px rgba(81, 225, 255, .5);
}

.boost-button:disabled {
  opacity: 0;
  pointer-events: none;
}

.result-screen {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 34px 56px;
  color: #fff;
  text-align: center;
  background:
    radial-gradient(circle at 50% 38%, rgba(29, 171, 199, .28), transparent 42%),
    rgba(1, 17, 34, .84);
  backdrop-filter: blur(10px);
}

.eyebrow {
  margin: 0 0 10px;
  color: #b7f0ff;
  font-size: 11px;
  font-weight: 950;
  letter-spacing: .2em;
}

.result-screen h1 {
  margin: 0;
  color: #f5ffdf;
  font-size: clamp(38px, 5vw, 62px);
  line-height: 1;
  letter-spacing: -.05em;
  text-shadow: 0 5px 22px rgba(0, 20, 43, .65);
}

.result-copy {
  max-width: 520px;
  margin: 16px auto 20px;
  color: rgba(224, 249, 255, .78);
  font-size: 14px;
  line-height: 1.7;
}

.result-stats {
  width: min(100%, 520px);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0 0 24px;
}

.result-stats div {
  padding: 13px 7px;
  border: 1px solid rgba(203, 246, 255, .24);
  border-radius: 15px;
  background: rgba(7, 55, 82, .55);
}

.result-stats dt {
  color: rgba(208, 242, 248, .66);
  font-size: 10px;
  font-weight: 800;
}

.result-stats dd {
  margin: 5px 0 0;
  color: #f5ffca;
  font-size: 19px;
  font-weight: 950;
}

#restart-button {
  min-width: 190px;
  padding: 14px 24px;
  border: 0;
  border-radius: 999px;
  color: #083250;
  background: linear-gradient(135deg, #e3ff63, #93ef37);
  box-shadow: 0 12px 36px rgba(111, 218, 45, .28);
  font-size: 16px;
  font-weight: 950;
  cursor: pointer;
}

#restart-button b {
  margin-left: 7px;
}

.vignette {
  position: absolute;
  z-index: 3;
  inset: 0;
  background: radial-gradient(circle, transparent 56%, rgba(0, 13, 31, calc(.2 + var(--danger, 0) * .34)) 100%);
  box-shadow: inset 0 0 calc(35px + var(--danger, 0) * 28px) rgba(95, 3, 17, calc(var(--danger, 0) * .38));
  pointer-events: none;
}

.desktop-note {
  display: none;
}

.orientation-gate {
  display: none;
}

.orientation-toast {
  display: none;
}

@media (orientation: portrait) and (pointer: coarse) {
  .orientation-gate {
    position: fixed;
    z-index: 30;
    inset: 0;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    gap: 16px;
    padding: 0 24px max(42px, calc(env(safe-area-inset-bottom) + 24px));
    color: #e9ffff;
    background:
      linear-gradient(180deg, rgba(1, 16, 34, .08) 20%, rgba(1, 16, 34, .78) 100%),
      repeating-linear-gradient(112deg, transparent 0 17px, rgba(131, 241, 222, .025) 17px 18px);
    filter: drop-shadow(0 8px 24px rgba(0, 8, 24, .72));
    pointer-events: none;
  }

  .orientation-gate__phone {
    position: relative;
    width: 30px;
    height: 52px;
    flex: 0 0 auto;
    border: 2px solid rgba(188, 255, 236, .88);
    border-radius: 8px;
    box-shadow: inset 0 0 14px rgba(83, 235, 207, .15), 0 0 20px rgba(72, 229, 208, .18);
    animation: phone-turn 1.8s cubic-bezier(.22, .85, .32, 1) infinite;
  }

  .orientation-gate__phone::before {
    content: "";
    position: absolute;
    top: 5px;
    left: 50%;
    width: 8px;
    height: 2px;
    border-radius: 2px;
    background: rgba(188, 255, 236, .72);
    transform: translateX(-50%);
  }

  .orientation-gate__phone i {
    position: absolute;
    right: -14px;
    top: 13px;
    width: 10px;
    height: 10px;
    border-top: 2px solid #bdfde9;
    border-right: 2px solid #bdfde9;
    transform: rotate(36deg);
  }

  .orientation-gate__copy {
    display: grid;
    gap: 3px;
    min-width: 210px;
    padding: 11px 15px 12px;
    border: 1px solid rgba(157, 244, 230, .28);
    border-radius: 7px 18px 7px 18px;
    background: linear-gradient(135deg, rgba(4, 68, 83, .88), rgba(2, 31, 58, .86));
    backdrop-filter: blur(9px);
  }

  .orientation-gate__copy b {
    color: #cffff0;
    font-size: 15px;
    letter-spacing: .1em;
  }

  .orientation-gate__copy small {
    color: rgba(218, 252, 255, .74);
    font-size: 11px;
    letter-spacing: .02em;
  }

  .orientation-gate[data-state="requesting"] .orientation-gate__phone {
    animation-duration: .75s;
  }

  html.force-landscape .page-shell {
    position: fixed;
    top: 0;
    left: 0;
    width: 100dvh;
    height: 100vw;
    transform: rotate(90deg) translateY(-100%);
    transform-origin: top left;
  }

  html.force-landscape .game-frame {
    width: min(100dvh, calc(100vw * 16 / 9));
    max-width: 100dvh;
    max-height: 100vw;
  }

  html.force-landscape .orientation-gate {
    display: none;
  }

  html.force-landscape .orientation-toast {
    position: absolute;
    z-index: 22;
    top: 50%;
    left: 50%;
    display: block;
    padding: 9px 15px;
    border: 1px solid rgba(194, 255, 240, .42);
    border-radius: 999px;
    color: #eafff8;
    background: rgba(2, 38, 61, .82);
    box-shadow: 0 10px 30px rgba(0, 10, 27, .45);
    backdrop-filter: blur(8px);
    font-size: 12px;
    font-weight: 850;
    letter-spacing: .05em;
    white-space: nowrap;
    transform: translate(-50%, -50%);
    transition: opacity .25s ease, visibility .25s ease;
    pointer-events: none;
  }

  html.force-landscape .orientation-toast.is-dismissed {
    opacity: 0;
    visibility: hidden;
  }

  html.force-landscape .mobile-joystick {
    left: max(12px, env(safe-area-inset-left));
    bottom: max(8px, env(safe-area-inset-bottom));
    width: 92px;
    height: 104px;
  }

  html.force-landscape .mobile-joystick__base {
    width: 92px;
    height: 92px;
  }

  html.force-landscape .mobile-joystick__thumb {
    left: calc(50% - 20px);
    top: calc(50% - 20px);
    width: 40px;
    height: 40px;
  }

  html.force-landscape .mobile-joystick__thumb::after {
    inset: 14px 10px;
  }
}

@keyframes phone-turn {
  0%, 28% { transform: rotate(0deg); }
  64%, 92% { transform: rotate(90deg); }
  100% { transform: rotate(0deg); }
}

@media (prefers-reduced-motion: reduce) {
  .orientation-gate__phone { animation: none !important; }
  .orientation-toast { transition: none !important; }
}

@media (max-width: 900px) {
  .hud {
    top: max(8px, env(safe-area-inset-top));
    left: max(10px, env(safe-area-inset-left));
    width: min(560px, calc(100% - 20px));
  }

  .hud-row {
    grid-template-columns: minmax(160px, 1fr) 86px 86px;
    gap: 6px;
  }

  .zone-chip,
  .power-readout,
  .time-readout {
    min-height: 42px;
    padding: 5px 9px;
  }

  .zone-chip span,
  .power-readout span,
  .time-readout span {
    font-size: 8px;
  }

  .zone-chip b,
  .power-readout strong,
  .time-readout strong {
    font-size: 14px;
  }

  .hunger-row {
    margin-top: 5px;
    padding: 4px 8px;
  }

  .depth-label {
    top: 92px;
    right: max(10px, env(safe-area-inset-right));
    width: 190px;
    padding: 8px 11px 9px;
  }

  .depth-label b {
    font-size: 15px;
  }

  .touch-hint {
    bottom: max(8px, env(safe-area-inset-bottom));
    padding: 6px 11px;
    font-size: 10px;
  }

  .boost-button {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(10px, env(safe-area-inset-bottom));
    width: 62px;
    height: 62px;
  }

  .boost-button span {
    font-size: 14px;
  }

  .desktop-note {
    display: none;
  }
}
