:root {
  color-scheme: dark;
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  background: #062f3b;
  color: #fff9e9;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  display: grid;
  place-items: center;
  overflow: hidden;
  min-height: 100dvh;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  background:
    radial-gradient(circle at 25% 15%, rgba(39, 184, 190, 0.26), transparent 32rem),
    linear-gradient(145deg, #052b38, #084f5d 55%, #07333f);
}

button {
  font: inherit;
}

.game-shell {
  width: min(100vw, 1500px);
  height: 100dvh;
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  padding:
    max(18px, env(safe-area-inset-top))
    max(26px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(26px, env(safe-area-inset-left));
}

.topbar,
.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  position: relative;
  z-index: 3;
}

.topbar {
  padding: 2px 4px 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: #ffd787;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.28em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(20px, 2.5vw, 32px);
  font-weight: 500;
  letter-spacing: 0.08em;
}

.top-actions {
  display: flex;
  gap: 10px;
}

html.mini-program .topbar {
  justify-content: flex-end;
}

html.mini-program .topbar > :first-child,
html.mini-program .install-button {
  display: none !important;
}

.icon-button,
.text-button,
.primary-button,
.secondary-button {
  min-height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.23);
  color: #fff9e9;
  cursor: pointer;
  transition: 180ms ease;
}

.icon-button:hover,
.text-button:hover,
.primary-button:hover,
.secondary-button:hover {
  transform: translateY(-1px);
  border-color: #ffd787;
  background: rgba(255, 215, 135, 0.15);
}

.icon-button {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(5, 44, 55, 0.48);
  font-weight: 900;
}

.text-button {
  padding: 0 16px;
  border-radius: 20px;
  background: rgba(5, 44, 55, 0.48);
}

.stage {
  min-height: 0;
  position: relative;
  overflow: hidden;
  border: 1px solid rgba(175, 244, 232, 0.18);
  border-radius: 28px;
  background: #0b8a94;
  box-shadow: 0 30px 80px rgba(0, 13, 25, 0.45), inset 0 0 80px rgba(13, 215, 200, 0.08);
}

#gameCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: default;
  touch-action: none;
}

.chapter-card {
  position: absolute;
  inset: 50% auto auto 50%;
  z-index: 5;
  display: grid;
  min-width: 280px;
  padding: 28px 36px;
  text-align: center;
  border: 1px solid rgba(255, 255, 255, 0.32);
  background: rgba(4, 45, 57, 0.85);
  backdrop-filter: blur(16px);
  border-radius: 20px;
  transform: translate(-50%, -50%);
  animation: chapterReveal 3.8s forwards;
  pointer-events: none;
}

.chapter-card span,
.chapter-card small {
  color: #bce9df;
  letter-spacing: 0.18em;
}

.chapter-card strong {
  margin: 7px 0 10px;
  color: #fff5d8;
  font-size: 28px;
  font-weight: 500;
  letter-spacing: 0.13em;
}

@keyframes chapterReveal {
  0%, 12% { opacity: 0; transform: translate(-50%, -46%); }
  22%, 62% { opacity: 1; transform: translate(-50%, -50%); }
  100% { opacity: 0; transform: translate(-50%, -55%); visibility: hidden; }
}

.objective {
  position: absolute;
  top: 18px;
  left: 18px;
  display: none;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 36px);
  padding: 10px 15px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 18px;
  background: rgba(3, 42, 54, 0.67);
  backdrop-filter: blur(10px);
  color: #e9fff9;
  font-size: 13px;
  pointer-events: none;
}

.objective-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #ffd46e;
  box-shadow: 0 0 12px #ffd46e;
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 26px;
  z-index: 7;
  padding: 11px 18px;
  border-radius: 18px;
  background: rgba(4, 42, 51, 0.83);
  color: #fff4cb;
  font-size: 14px;
  transform: translate(-50%, 10px);
  opacity: 0;
  pointer-events: none;
  transition: 260ms ease;
}

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

.modal[hidden] {
  display: none;
}

.modal {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(2, 27, 36, 0.66);
  backdrop-filter: blur(8px);
}

.modal-card {
  position: relative;
  width: min(100%, 460px);
  padding: 34px;
  border: 1px solid rgba(255, 232, 174, 0.25);
  border-radius: 24px;
  background: linear-gradient(145deg, rgba(10, 91, 99, 0.98), rgba(5, 52, 64, 0.98));
  box-shadow: 0 24px 60px rgba(0, 18, 27, 0.45);
}

.modal-card h2 {
  margin-bottom: 18px;
  font-size: 26px;
  font-weight: 500;
}

.modal-card ul {
  margin: 0 0 25px;
  padding-left: 1.35em;
  color: #d4f2ec;
  line-height: 1.9;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  border: 0;
  background: none;
  color: #c9eee7;
  font-size: 26px;
  cursor: pointer;
}

.primary-button {
  width: 100%;
  padding: 12px 18px;
  border-radius: 20px;
  background: #d98355;
  color: white;
  font-weight: 800;
  letter-spacing: 0.1em;
}

.secondary-button {
  width: 100%;
  min-height: 44px;
  padding: 11px 18px;
  border-radius: 20px;
  background: rgba(4, 44, 55, 0.38);
  color: #d9f5ed;
  font-weight: 700;
}

.modal-actions {
  display: grid;
  gap: 10px;
}

.ending-card {
  text-align: center;
}

.ending-card > p:not(.eyebrow) {
  color: #ccebe5;
  line-height: 1.8;
}

.ending-glyph {
  margin-bottom: 12px;
  color: #ffe08b;
  font-size: 54px;
  animation: endingPulse 2s infinite ease-in-out;
}

@keyframes endingPulse {
  50% { transform: scale(1.1) rotate(15deg); filter: drop-shadow(0 0 14px #ffe08b); }
}

.statusbar {
  min-height: 46px;
  padding: 12px 5px 0;
  color: rgba(219, 247, 241, 0.72);
  font-size: 12px;
}

.statusbar p {
  margin-bottom: 0;
  text-align: right;
}

.runes {
  display: flex;
  align-items: center;
  gap: 8px;
  letter-spacing: 0.12em;
}

.runes i {
  width: 12px;
  height: 12px;
  border: 1px solid rgba(255, 232, 174, 0.45);
  border-radius: 3px;
  transform: rotate(45deg);
  transition: 300ms ease;
}

.runes i.lit {
  border-color: #ffe08b;
  background: #ffe08b;
  box-shadow: 0 0 10px #ffe08b;
}

@media (max-width: 720px) {
  .game-shell {
    padding:
      max(8px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }

  .topbar {
    padding: 4px 2px 10px;
  }

  .stage {
    min-height: 0;
    border-radius: 18px;
  }

  .eyebrow {
    display: none;
  }

  h1 {
    max-width: 46vw;
    overflow: hidden;
    font-size: 17px;
    line-height: 1.2;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .statusbar p {
    display: none;
  }

  .text-button {
    padding: 0 12px;
  }

  .runes i {
    width: 14px;
    height: 14px;
  }

  .objective {
    top: 10px;
    left: 10px;
    max-width: calc(100% - 20px);
    padding: 8px 11px;
    font-size: 12px;
  }

  .modal {
    padding: 14px;
  }

  .modal-card {
    max-height: 100%;
    padding: 26px 22px 22px;
    overflow-y: auto;
    border-radius: 18px;
  }

  .modal-card h2 {
    margin-bottom: 12px;
    font-size: 22px;
  }

  .modal-card ul {
    margin-bottom: 18px;
    line-height: 1.65;
  }
}

@media (max-width: 720px) and (orientation: portrait) {
  .game-shell {
    grid-template-rows: auto auto auto;
    align-content: center;
  }

  .stage {
    width: 100%;
    max-height: calc(100dvh - 116px);
    aspect-ratio: 720 / 1180;
  }

}

@media (orientation: landscape) and (max-height: 540px) {
  .game-shell {
    grid-template-rows: auto 1fr;
    padding:
      max(5px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      max(5px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }

  .topbar {
    padding: 0 2px 5px;
  }

  .topbar .eyebrow,
  .statusbar {
    display: none;
  }

  h1 {
    font-size: 15px;
  }

  .icon-button,
  .text-button {
    min-height: 38px;
    height: 38px;
  }

  .icon-button {
    width: 38px;
  }

  .stage {
    width: min(100%, calc(146.34dvh - 78px));
    height: auto;
    aspect-ratio: 1200 / 820;
    align-self: center;
    justify-self: center;
  }

  .chapter-card {
    padding: 18px 24px;
  }

  .chapter-card strong {
    font-size: 22px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}
