:root {
  color-scheme: dark;
  --page: #08111f;
  --ink: #fff8e7;
  --muted: #b5d7ef;
  --glass: rgba(7, 14, 24, 0.58);
  --glass-strong: rgba(8, 16, 28, 0.82);
  --line: rgba(169, 213, 255, 0.32);
  --accent: #ffd84f;
  --accent-2: #4fc3ff;
  --danger: #ff7465;
  --shadow: rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    radial-gradient(circle at 50% 0%, rgba(255, 216, 79, 0.22), transparent 30%),
    linear-gradient(180deg, #132744 0%, #08111f 58%, #050913 100%);
  color: var(--ink);
  font-family:
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC",
    sans-serif;
  touch-action: none;
}

button {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.game-shell {
  width: 100vw;
  height: 100svh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding:
    max(0px, env(safe-area-inset-top))
    max(0px, env(safe-area-inset-right))
    max(0px, env(safe-area-inset-bottom))
    max(0px, env(safe-area-inset-left));
}

.game-stage {
  position: relative;
  width: min(100vw, calc(100svh * 6 / 11), 500px);
  aspect-ratio: 6 / 11;
  max-height: 100svh;
  overflow: hidden;
  background: #02060c;
  border: 1px solid rgba(188, 226, 255, 0.35);
  border-radius: clamp(0px, 1.2vw, 10px);
  box-shadow:
    0 24px 80px var(--shadow),
    inset 0 0 0 1px rgba(255, 216, 79, 0.22);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.game-stage::after {
  content: "";
  position: absolute;
  z-index: 1;
  inset: 0;
  display: none;
  background:
    linear-gradient(90deg, rgba(5, 11, 20, 0.88), transparent 28%, transparent 72%, rgba(5, 11, 20, 0.88)),
    radial-gradient(circle at 50% 50%, rgba(255, 216, 79, 0.12), transparent 50%),
    #06101d;
  pointer-events: none;
}

canvas {
  position: absolute;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  image-rendering: auto;
}

.hud-chrome {
  position: absolute;
  z-index: 7;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: max(10px, env(safe-area-inset-top)) 12px 10px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(-8px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.game-shell[data-state="playing"] .hud-chrome,
.game-shell[data-state="paused"] .hud-chrome,
.game-shell[data-state="over"] .hud-chrome {
  opacity: 1;
  transform: translateY(0);
}

.hud-actions {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

.icon-btn,
.game-cta,
.ghost-btn {
  border: 0;
  border-radius: 8px;
  letter-spacing: 0;
  cursor: pointer;
  touch-action: manipulation;
}

.icon-btn {
  min-width: 44px;
  min-height: 34px;
  padding: 0 10px;
  color: var(--ink);
  background: rgba(9, 20, 34, 0.72);
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  font-size: 12px;
}

.touch-layer {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 1fr 1fr;
  pointer-events: none;
}

.touch-zone {
  position: relative;
  pointer-events: none;
  touch-action: none;
}

.game-shell[data-state="playing"] .touch-zone {
  pointer-events: auto;
}

.touch-zone span {
  position: absolute;
  bottom: max(16px, env(safe-area-inset-bottom));
  color: rgba(255, 248, 231, 0.58);
  font-weight: 900;
  font-size: clamp(36px, 10vw, 72px);
  line-height: 1;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.72);
  opacity: 0;
  transform: translateY(8px);
  transition:
    opacity 220ms ease,
    transform 220ms ease;
}

.touch-left span {
  left: 18px;
}

.touch-right span {
  right: 18px;
}

.game-shell[data-state="playing"] .touch-zone span {
  opacity: 0.42;
  transform: translateY(0);
}

.tap-guide {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: grid;
  grid-template-columns: 1fr 1fr;
  pointer-events: none;
  animation: guide-fade 2.6s ease forwards;
}

.tap-guide-zone {
  display: grid;
  place-items: center;
  gap: 8px;
  color: rgba(255, 248, 231, 0.9);
  font-weight: 900;
  text-shadow: 0 4px 16px rgba(0, 0, 0, 0.7);
  animation: guide-pulse 820ms ease-in-out infinite alternate;
}

.tap-guide-left {
  background: linear-gradient(90deg, rgba(79, 195, 255, 0.26), rgba(79, 195, 255, 0));
}

.tap-guide-right {
  background: linear-gradient(270deg, rgba(255, 216, 79, 0.26), rgba(255, 216, 79, 0));
}

.tap-guide-zone span {
  font-size: clamp(54px, 16vw, 92px);
  line-height: 0.8;
}

.tap-guide-zone strong {
  font-size: clamp(18px, 5vw, 28px);
  line-height: 1;
}

.tap-guide-center {
  position: absolute;
  left: 50%;
  top: 54%;
  transform: translate(-50%, -50%);
  width: max-content;
  max-width: 78%;
  padding: 8px 14px;
  border: 1px solid rgba(255, 216, 79, 0.42);
  border-radius: 999px;
  color: var(--ink);
  background: rgba(5, 14, 25, 0.66);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.3);
  font-size: clamp(13px, 3.5vw, 16px);
  font-weight: 900;
  white-space: nowrap;
  backdrop-filter: blur(7px);
}

@keyframes guide-pulse {
  from {
    opacity: 0.58;
    transform: scale(0.98);
  }

  to {
    opacity: 1;
    transform: scale(1.03);
  }
}

@keyframes guide-fade {
  0%,
  70% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}

.screen {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: clamp(16px, 4vw, 32px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 180ms ease,
    visibility 180ms ease;
}

.screen::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(180deg, rgba(2, 7, 15, 0.25), rgba(2, 7, 15, 0.76)),
    radial-gradient(circle at 50% 20%, rgba(255, 216, 79, 0.16), transparent 32%);
}

.game-shell[data-state="loading"] .screen-loading,
.game-shell[data-state="title"] .screen-title,
.game-shell[data-state="paused"] .screen-pause,
.game-shell[data-state="over"] .screen-over,
.game-shell[data-rank-open="true"] .screen-rank,
.game-shell[data-help-open="true"] .screen-help {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.game-shell[data-state="title"] .screen-title {
  place-items: stretch;
  padding: 0;
}

.screen-loading {
  place-items: stretch;
  padding: 0;
  background: #06101d url("./assets/title-bg.png") center / cover;
}

.screen-loading::before {
  background:
    linear-gradient(180deg, rgba(2, 7, 15, 0.18), rgba(2, 7, 15, 0.42) 48%, rgba(2, 7, 15, 0.78)),
    radial-gradient(circle at 50% 30%, rgba(255, 216, 79, 0.16), transparent 34%);
}

.game-shell[data-state="title"] .screen-title::before {
  background:
    linear-gradient(180deg, rgba(2, 7, 15, 0.14), rgba(2, 7, 15, 0.34) 44%, rgba(2, 7, 15, 0.72)),
    radial-gradient(circle at 50% 28%, rgba(255, 216, 79, 0.18), transparent 35%);
}

.title-card,
.pause-card,
.over-card,
.rank-card,
.help-card {
  position: relative;
  width: min(86%, 360px);
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: clamp(20px, 5vw, 30px);
  border-radius: 10px;
  background:
    linear-gradient(180deg, rgba(9, 22, 37, 0.86), rgba(7, 13, 23, 0.92));
  border: 1px solid rgba(255, 216, 79, 0.38);
  box-shadow:
    0 24px 72px rgba(0, 0, 0, 0.48),
    inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  text-align: center;
}

.title-card {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 13px;
  padding:
    max(88px, calc(env(safe-area-inset-top) + 11svh))
    clamp(20px, 7vw, 42px)
    max(26px, calc(env(safe-area-inset-bottom) + 4svh));
  border: 0;
  border-radius: 0;
  background: none;
  box-shadow: none;
}

.rank-card {
  max-height: min(76svh, 620px);
  align-content: start;
  overflow: hidden;
}

.loading-card {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 13px;
  padding:
    max(72px, calc(env(safe-area-inset-top) + 9svh))
    clamp(22px, 7vw, 42px)
    max(34px, calc(env(safe-area-inset-bottom) + 5svh));
  text-align: center;
}

.loading-copy {
  margin: 6px 0 0;
  color: #fff8e7;
  font-size: clamp(20px, 5.8vw, 30px);
  font-weight: 900;
  line-height: 1.1;
  text-shadow:
    0 3px 0 rgba(38, 13, 2, 0.8),
    0 12px 24px rgba(0, 0, 0, 0.6);
}

.loading-bar {
  width: min(64%, 250px);
  height: 12px;
  margin-top: 12px;
  padding: 2px;
  border: 1px solid rgba(169, 213, 255, 0.5);
  border-radius: 999px;
  background: rgba(5, 14, 25, 0.72);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.28);
  overflow: hidden;
}

.loading-bar span {
  display: block;
  width: 42%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #4fc3ff, #ffe36a);
  animation: loading-slide 1.05s ease-in-out infinite alternate;
}

@keyframes loading-slide {
  from {
    transform: translateX(0%);
  }

  to {
    transform: translateX(138%);
  }
}

.help-card {
  max-height: min(78svh, 620px);
  align-content: start;
  overflow: auto;
}

.kicker {
  margin: 0;
  color: var(--accent-2);
  font-weight: 900;
  font-size: clamp(11px, 2.8vw, 13px);
  letter-spacing: 0.08em;
}

h1,
h2,
.score-line,
.hint {
  margin: 0;
}

h1 {
  color: var(--accent);
  font-size: clamp(54px, 15vw, 86px);
  line-height: 0.92;
  text-shadow:
    0 4px 0 #3a1305,
    0 8px 0 rgba(137, 44, 0, 0.72),
    0 18px 34px rgba(0, 0, 0, 0.72);
}

h2 {
  color: var(--accent);
  font-size: clamp(28px, 8vw, 42px);
  line-height: 1;
  text-shadow: 0 3px 0 #3a1305;
}

.score-line,
.score-pair,
.rank-status,
.rank-result,
.rank-message,
.name-panel {
  color: var(--muted);
  font-size: clamp(13px, 3.4vw, 16px);
}

.score-pair {
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
}

.score-line strong,
.score-pair strong {
  color: #fff;
}

.rank-status,
.rank-result,
.rank-message,
.name-panel p {
  margin: 0;
  line-height: 1.45;
}

.rank-result {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid rgba(169, 213, 255, 0.2);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
}

.title-actions {
  width: min(100%, 250px);
  display: grid;
  gap: 9px;
  justify-items: center;
  margin-top: auto;
  padding: 10px;
  border: 1px solid rgba(255, 216, 79, 0.26);
  border-radius: 10px;
  background: rgba(5, 14, 25, 0.48);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(7px);
}

.game-cta,
.ghost-btn {
  min-height: 44px;
  padding: 0 20px;
  font-weight: 900;
}

.game-cta {
  min-width: 154px;
  color: #1a1708;
  background: linear-gradient(180deg, #ffe97a, #ffd13d);
  box-shadow:
    0 12px 26px rgba(255, 216, 79, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.ghost-btn {
  min-width: 116px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
}

.ghost-btn.compact {
  min-width: 72px;
  min-height: 38px;
  padding: 0 12px;
  font-size: 13px;
}

.pause-actions {
  width: 100%;
  display: grid;
  gap: 9px;
  justify-items: center;
}

.over-card {
  max-height: min(82svh, 620px);
  gap: 10px;
  padding: clamp(18px, 4.4vw, 26px);
  overflow: auto;
}

.name-panel {
  width: 100%;
  display: grid;
  gap: 7px;
  justify-items: stretch;
  text-align: left;
}

.name-panel label {
  color: var(--ink);
  font-weight: 900;
  font-size: 13px;
}

.name-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.name-row input {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(3, 9, 17, 0.74);
  font: inherit;
  font-weight: 800;
  outline: none;
}

.name-row input:focus {
  border-color: rgba(255, 216, 79, 0.78);
}

.rank-list {
  width: 100%;
  max-height: min(46svh, 360px);
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
  overflow: auto;
  scrollbar-width: thin;
}

.rank-list li {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  padding: 6px 8px;
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.07);
  font-size: clamp(12px, 3.1vw, 14px);
  font-weight: 800;
}

.rank-list .rank-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-list .rank-score {
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.help-list {
  width: 100%;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  list-style: none;
  text-align: left;
  color: var(--ink);
  font-size: clamp(13px, 3.4vw, 15px);
  line-height: 1.45;
}

.help-list li {
  padding: 9px 10px;
  border: 1px solid rgba(169, 213, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
}

.hint {
  color: rgba(255, 248, 231, 0.74);
  font-size: clamp(12px, 3.2vw, 14px);
}

@media (hover: hover) and (pointer: fine) {
  .game-stage {
    width: min(64vw, calc(94svh * 6 / 11), 500px);
  }

  .touch-layer {
    display: none;
  }

  .icon-btn:hover,
  .ghost-btn:hover {
    border-color: rgba(255, 216, 79, 0.66);
  }
}

@media (hover: none), (pointer: coarse) {
  .game-shell {
    padding: 0;
    place-items: center;
  }

  .game-stage {
    width: min(100vw, calc(100svh * 6 / 11));
    aspect-ratio: 6 / 11;
    max-width: none;
    max-height: none;
    height: auto;
  }

  canvas {
    inset: 0;
    width: 100%;
    height: 100%;
    transform: none;
  }

  .touch-layer {
    position: fixed;
  }

  .hud-chrome {
    padding:
      max(10px, env(safe-area-inset-top))
      max(12px, env(safe-area-inset-right))
      10px
      max(12px, env(safe-area-inset-left));
  }

  .touch-zone span {
    top: 50%;
    bottom: auto;
    color: rgba(255, 248, 231, 0.34);
    transform: translateY(-50%);
  }

  .touch-left span {
    left: max(16px, env(safe-area-inset-left));
  }

  .touch-right span {
    right: max(16px, env(safe-area-inset-right));
  }

  .game-shell[data-state="playing"] .touch-zone span {
    opacity: 0.34;
    transform: translateY(-50%);
  }

  .screen {
    padding:
      max(16px, env(safe-area-inset-top))
      max(16px, env(safe-area-inset-right))
      max(16px, env(safe-area-inset-bottom))
      max(16px, env(safe-area-inset-left));
  }
}
