:root {
  --game-bg: #080808;
  --game-panel: rgb(18 18 18 / 0.78);
  --game-line: rgb(255 247 231 / 0.18);
  --game-text: #fff7e7;
  --game-muted: rgb(255 247 231 / 0.68);
  --game-accent: #f6c45f;
  --game-danger: #ff695f;
  --game-good: #69d6a0;
}

* {
  box-sizing: border-box;
}

html,
body.game-page {
  min-height: 100%;
  margin: 0;
  background: var(--game-bg);
  color: var(--game-text);
  font-family: "Noto Sans TC", "Microsoft JhengHei", Inter, system-ui, sans-serif;
  overflow-x: hidden;
}

body.game-page {
  min-height: 100vh;
  min-height: 100svh;
}

[hidden],
.is-hidden {
  display: none !important;
}

.game-page a {
  color: inherit;
  text-decoration: none;
}

.game-shell {
  position: relative;
  display: grid;
  min-height: 100vh;
  min-height: 100svh;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgb(0 0 0 / 0.24), rgb(0 0 0 / 0.92)),
    #090909;
}

.game-bg-video {
  position: fixed;
  inset: 0;
  z-index: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.42;
  filter: saturate(1.08) contrast(1.08);
  pointer-events: none;
}

.game-bg-shade {
  position: fixed;
  inset: 0;
  z-index: 1;
  background:
    radial-gradient(circle at 50% 22%, rgb(246 196 95 / 0.18), transparent 32%),
    linear-gradient(90deg, rgb(0 0 0 / 0.78), transparent 28%, transparent 72%, rgb(0 0 0 / 0.78));
  pointer-events: none;
}

.game-header,
.game-main,
.game-footer {
  position: relative;
  z-index: 2;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) clamp(12px, 3vw, 28px) 10px;
}

.game-brand,
.game-actions,
.game-chip-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.game-brand {
  min-width: 0;
  font-weight: 900;
}

.game-brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  background: var(--game-text);
  color: #141414;
  font-size: 15px;
  letter-spacing: 0;
}

.game-brand-text {
  display: grid;
  min-width: 0;
  line-height: 1.15;
}

.game-brand-text span {
  color: var(--game-muted);
  font-size: 12px;
  font-weight: 700;
}

.game-icon-link,
.game-link-button,
.game-button,
.lane-button,
.game-owner-button {
  min-height: 48px;
  border: 1px solid var(--game-line);
  border-radius: 8px;
  background: rgb(255 255 255 / 0.08);
  color: var(--game-text);
  font: inherit;
  font-weight: 850;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.game-icon-link {
  display: grid;
  width: 48px;
  place-items: center;
}

.game-link-button,
.game-button,
.game-owner-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
}

.game-button.primary {
  border-color: rgb(246 196 95 / 0.65);
  background: var(--game-accent);
  color: #19140b;
}

.game-button.ghost {
  background: rgb(0 0 0 / 0.26);
}

.game-button.danger {
  border-color: rgb(255 105 95 / 0.6);
  background: rgb(255 105 95 / 0.2);
}

.game-main {
  display: grid;
  width: min(1280px, 100%);
  min-height: 0;
  margin: 0 auto;
  padding: 0 clamp(10px, 3vw, 28px) 12px;
  grid-template-columns: minmax(210px, 0.38fr) minmax(300px, 0.8fr) minmax(220px, 0.42fr);
  gap: clamp(10px, 2vw, 20px);
  align-items: stretch;
}

.game-panel {
  min-width: 0;
  border: 1px solid var(--game-line);
  border-radius: 8px;
  background: var(--game-panel);
  box-shadow: 0 24px 80px rgb(0 0 0 / 0.28);
  backdrop-filter: blur(16px);
}

.game-info,
.game-side {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 16px;
}

.game-kicker {
  margin: 0 0 6px;
  color: var(--game-accent);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

.game-title {
  margin: 0;
  font-size: clamp(26px, 5vw, 46px);
  line-height: 1.05;
  letter-spacing: 0;
}

.game-description {
  margin: 10px 0 0;
  color: var(--game-muted);
  font-size: 15px;
  line-height: 1.65;
}

.game-chip-row {
  flex-wrap: wrap;
}

.game-chip {
  border: 1px solid var(--game-line);
  border-radius: 999px;
  padding: 7px 10px;
  background: rgb(255 255 255 / 0.08);
  color: var(--game-muted);
  font-size: 12px;
  font-weight: 800;
}

.game-stage {
  position: relative;
  display: grid;
  min-height: 560px;
  overflow: hidden;
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 78%, rgb(246 196 95 / 0.12), transparent 36%),
    radial-gradient(circle at 18% 18%, rgb(105 214 160 / 0.08), transparent 32%),
    linear-gradient(180deg, rgb(255 255 255 / 0.06), transparent),
    rgb(4 4 4 / 0.88);
  touch-action: manipulation;
}

#rhythmCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 560px;
}

.game-hud {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  pointer-events: none;
}

.hud-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px;
}

.hud-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 12px 88px;
}

.hud-stat {
  min-width: 74px;
  border: 1px solid var(--game-line);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgb(0 0 0 / 0.38);
}

.hud-stat small {
  display: block;
  color: var(--game-muted);
  font-size: 11px;
  font-weight: 800;
}

.hud-stat strong {
  display: block;
  font-size: 20px;
  line-height: 1.1;
}

.track-card {
  display: grid;
  min-width: 0;
  max-width: 48%;
  border: 1px solid var(--game-line);
  border-radius: 8px;
  padding: 8px 10px;
  background: rgb(0 0 0 / 0.38);
}

.track-card small {
  color: var(--game-muted);
  font-size: 11px;
  font-weight: 800;
}

.track-card strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.center-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: linear-gradient(180deg, rgb(0 0 0 / 0.24), rgb(0 0 0 / 0.68));
  pointer-events: auto;
}

.start-card {
  width: min(420px, 100%);
  border: 1px solid rgb(255 247 231 / 0.24);
  border-radius: 8px;
  padding: 22px;
  background: rgb(10 10 10 / 0.84);
  text-align: center;
  box-shadow: 0 30px 90px rgb(0 0 0 / 0.36);
}

.start-card h2 {
  margin: 0 0 8px;
  font-size: clamp(24px, 5vw, 36px);
  line-height: 1.1;
}

.start-card p {
  margin: 0 0 16px;
  color: var(--game-muted);
  line-height: 1.6;
  white-space: pre-line;
}

.start-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.result-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 4px 0 16px;
}

.result-grade {
  grid-column: 1 / -1;
  border: 1px solid rgb(246 196 95 / 0.58);
  border-radius: 8px;
  padding: 12px;
  background: rgb(246 196 95 / 0.14);
}

.result-stat {
  border: 1px solid var(--game-line);
  border-radius: 8px;
  padding: 10px 8px;
  background: rgb(255 255 255 / 0.08);
}

.result-grade span,
.result-stat span {
  display: block;
  color: var(--game-muted);
  font-size: 11px;
  font-weight: 900;
}

.result-grade strong {
  display: block;
  color: var(--game-accent);
  font-size: clamp(44px, 12vw, 72px);
  line-height: 0.95;
}

.result-stat strong {
  display: block;
  font-size: clamp(18px, 5vw, 28px);
  line-height: 1.05;
}

.lane-controls {
  position: absolute;
  right: 12px;
  bottom: 12px;
  left: 12px;
  z-index: 7;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  pointer-events: auto;
}

.lane-button {
  display: grid;
  min-height: 72px;
  place-items: center;
  padding: 0;
  font-size: 24px;
  background:
    linear-gradient(180deg, rgb(255 255 255 / 0.18), rgb(255 255 255 / 0.07)),
    rgb(255 255 255 / 0.1);
  box-shadow: inset 0 -5px 0 rgb(0 0 0 / 0.28), 0 10px 24px rgb(0 0 0 / 0.22);
  transition: transform 90ms ease, background 90ms ease, border-color 90ms ease, box-shadow 90ms ease;
}

.lane-button span {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 999px;
  background: rgb(0 0 0 / 0.24);
}

.lane-button.is-hit {
  transform: translateY(5px) scale(0.98);
  border-color: var(--game-accent);
  background:
    radial-gradient(circle, rgb(255 247 231 / 0.28), transparent 62%),
    rgb(246 196 95 / 0.44);
  box-shadow: inset 0 -1px 0 rgb(0 0 0 / 0.18), 0 0 28px rgb(246 196 95 / 0.42);
}

.feedback {
  align-self: center;
  justify-self: center;
  min-height: 48px;
  border-radius: 999px;
  padding: 10px 18px;
  background: rgb(0 0 0 / 0.36);
  color: var(--game-accent);
  font-size: clamp(22px, 5vw, 38px);
  font-weight: 1000;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.feedback.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.feedback[data-type="miss"] {
  color: var(--game-danger);
}

.feedback[data-type="perfect"] {
  color: #fff7e7;
  text-shadow: 0 0 18px rgb(246 196 95 / 0.86), 0 0 34px rgb(246 196 95 / 0.42);
}

.feedback[data-type="good"] {
  color: var(--game-good);
  text-shadow: 0 0 16px rgb(105 214 160 / 0.42);
}

.side-list {
  display: grid;
  gap: 10px;
  max-height: min(560px, calc(100svh - 260px));
  overflow: auto;
  padding-right: 2px;
}

.side-item,
.track-select {
  display: grid;
  grid-template-columns: 54px 1fr;
  gap: 10px;
  align-items: center;
  min-width: 0;
  border: 1px solid var(--game-line);
  border-radius: 8px;
  padding: 8px;
  background: rgb(255 255 255 / 0.08);
  color: var(--game-text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.side-item img,
.track-select img {
  width: 54px;
  height: 54px;
  border-radius: 6px;
  object-fit: cover;
  background: #111;
}

.side-item strong,
.track-select strong {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.side-item span,
.track-select span,
.track-select small {
  color: var(--game-muted);
  font-size: 12px;
}

.track-select.is-active {
  border-color: rgb(246 196 95 / 0.72);
  background: rgb(246 196 95 / 0.16);
}

.owner-panel {
  display: none;
  gap: 8px;
}

.owner-panel.is-visible {
  display: grid;
}

.owner-status {
  color: var(--game-muted);
  font-size: 12px;
  line-height: 1.5;
}

.game-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  padding: 0 clamp(12px, 3vw, 28px) max(12px, env(safe-area-inset-bottom));
  color: var(--game-muted);
  font-size: 12px;
}

.game-footer a {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  padding-inline: 4px;
}

.game-footer .game-owner-button {
  min-height: 32px;
  border: 0;
  background: transparent;
  color: inherit;
  opacity: 0.58;
  padding: 0 2px;
  font-size: 12px;
  font-weight: 700;
  box-shadow: none;
}

.game-footer .game-owner-button:hover,
.game-footer .game-owner-button:focus-visible {
  opacity: 0.9;
  color: var(--game-text);
}

.game-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  padding: 18px;
  background: rgb(0 0 0 / 0.74);
}

.game-modal.is-open {
  display: grid;
}

.modal-card {
  position: relative;
  width: min(520px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  overflow: auto;
  border: 1px solid var(--game-line);
  border-radius: 8px;
  background: #111;
  color: var(--game-text);
  box-shadow: 0 28px 90px rgb(0 0 0 / 0.54);
}

.modal-inner {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.modal-card h2 {
  margin: 0;
  font-size: 26px;
  line-height: 1.15;
}

.modal-card p {
  margin: 0;
  color: var(--game-muted);
  line-height: 1.6;
}

.revive-close-button,
.install-close-button {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 3;
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 1px solid rgb(255 247 231 / 0.24);
  border-radius: 50%;
  background: rgb(0 0 0 / 0.72);
  color: var(--game-text);
  font-size: 34px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 12px 34px rgb(0 0 0 / 0.42);
}

.install-card {
  width: min(440px, 100%);
}

.revive-video-wrap {
  position: relative;
  display: grid;
  gap: 10px;
}

.revive-video {
  width: 100%;
  max-height: 360px;
  border-radius: 8px;
  background: #050505;
  object-fit: contain;
}

.revive-product-cta {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 72px;
  overflow: hidden;
  border: 1px solid rgb(246 196 95 / 0.5);
  border-radius: 8px;
  padding: 8px;
  background:
    linear-gradient(135deg, rgb(246 196 95 / 0.2), rgb(255 255 255 / 0.08)),
    rgb(16 16 16 / 0.94);
  color: var(--game-text);
  box-shadow: 0 14px 40px rgb(0 0 0 / 0.32);
}

.revive-product-cta span {
  min-width: 0;
  overflow: hidden;
}

.revive-product-cta img {
  width: 56px;
  height: 56px;
  border-radius: 7px;
  object-fit: cover;
  background: #111;
}

.revive-product-cta strong {
  display: -webkit-box;
  overflow: hidden;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  white-space: normal;
  word-break: break-word;
  font-size: 14px;
  line-height: 1.25;
}

.revive-product-cta small {
  display: block;
  margin-top: 3px;
  color: var(--game-accent);
  font-size: 12px;
  font-weight: 900;
}

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

.owner-form {
  display: grid;
  gap: 10px;
}

.owner-form input {
  min-height: 48px;
  border: 1px solid var(--game-line);
  border-radius: 8px;
  padding: 0 12px;
  background: rgb(255 255 255 / 0.08);
  color: var(--game-text);
  font: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1080px) {
  .game-main {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 0.42fr);
  }

  .game-info {
    display: none;
  }
}

@media (max-width: 900px) {
  .game-header {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    padding-inline: 10px;
  }

  .game-brand-text span {
    display: none;
  }

  .game-actions {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 6px;
  }

  .game-link-button {
    width: 100%;
    min-width: 0;
    padding: 0;
    font-size: 0;
  }

  .game-link-button::after {
    content: attr(data-short);
    font-size: 12px;
  }

  .game-main {
    min-height: 0;
    padding: 0 8px 8px;
    grid-template-columns: 1fr;
  }

  .game-side {
    order: 3;
    padding: 12px;
  }

  .game-side .side-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .game-stage {
    min-height: min(680px, calc(100svh - 198px));
  }

  #rhythmCanvas {
    min-height: min(680px, calc(100svh - 198px));
  }

  .hud-top {
    align-items: flex-start;
  }

  .track-card {
    max-width: 58%;
  }

  .hud-stat {
    min-width: 62px;
    padding: 7px 8px;
  }

  .hud-stat strong {
    font-size: 18px;
  }

  .lane-controls {
    gap: 6px;
  }

  .lane-button {
    min-height: 76px;
    font-size: 22px;
  }

  .game-footer {
    gap: 10px;
  }
}

@media (max-width: 430px) {
  .game-brand-mark {
    width: 38px;
    height: 38px;
  }

  .game-brand-text strong {
    max-width: 132px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .game-icon-link,
  .game-link-button {
    min-height: 48px;
  }

  .game-stage,
  #rhythmCanvas {
    min-height: clamp(430px, calc(100svh - 188px), 680px);
  }

  .game-side .side-list {
    grid-template-columns: 1fr;
  }

  .start-card {
    padding: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .lane-button,
  .feedback {
    transition: none;
  }
}
