:root {
  --bg: #f4e0bf;
  --bg-soft: #f9eed8;
  --panel: rgba(255, 247, 230, 0.86);
  --ink: #302114;
  --ink-soft: #6a5241;
  --line: rgba(57, 35, 18, 0.14);
  --accent: #ca4a1d;
  --accent-strong: #a53c18;
  --coin: #ffcf55;
  --coin-strong: #b97608;
  --skin-black: #181818;
  --skin-orange: #d8831e;
  --skin-blue: #2f93ff;
  --skin-purple: #8b4fd4;
  --energy: #2f93ff;
  --energy-strong: #1f66c7;
  --good: #2f8455;
  --shadow: 0 24px 48px rgba(54, 32, 14, 0.18);
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 18% 10%, #fff2da 0%, #f7e2bf 44%, #ebc99a 100%);
}

.bg-layer {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(circle at 78% 4%, rgba(202, 74, 29, 0.2), transparent 34%),
    radial-gradient(circle at 8% 82%, rgba(47, 132, 85, 0.22), transparent 45%),
    repeating-linear-gradient(45deg,
      rgba(255, 255, 255, 0.12) 0,
      rgba(255, 255, 255, 0.12) 3px,
      transparent 3px,
      transparent 20px);
}

.app-shell {
  width: min(1120px, calc(100% - 1.2rem));
  margin: 0.8rem auto 1.2rem;
  display: grid;
  gap: 0.8rem;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 0.9rem 1rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(4px);
}

.brand {
  min-width: 0;
}

.eyebrow {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.74rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-family: "Bricolage Grotesque", sans-serif;
}

.brand h1 {
  margin: 0.22rem 0 0.15rem;
  font-size: clamp(1.35rem, 2.8vw, 1.95rem);
  font-family: "Bricolage Grotesque", "Noto Sans SC", sans-serif;
  line-height: 1.05;
}

.subtitle {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.87rem;
}

.hud {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.45rem;
}

.hud-pill {
  min-width: 88px;
  padding: 0.44rem 0.62rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  text-align: center;
}

.hud-pill .label {
  display: block;
  font-size: 0.68rem;
  color: var(--ink-soft);
  margin-bottom: 0.16rem;
}

.hud-pill strong {
  font-family: "Bricolage Grotesque", "Noto Sans SC", sans-serif;
  font-size: 0.96rem;
  font-weight: 700;
}

.stage {
  position: relative;
  border-radius: 20px;
  overflow: hidden;
  border: 1px solid rgba(65, 35, 14, 0.18);
  box-shadow: var(--shadow);
  background: #f8ebd2;
}

.stage-hud {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  right: 3.8rem;
  z-index: 9;
  display: flex;
  flex-wrap: wrap;
  gap: 0.38rem;
  pointer-events: none;
}

.stage-hud .hud-pill {
  min-width: 72px;
  padding: 0.34rem 0.52rem;
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(3px);
}

.stage-hud .hud-pill .label {
  font-size: 0.6rem;
  margin-bottom: 0.08rem;
}

.stage-hud .hud-pill strong {
  font-size: 0.86rem;
}

.fullscreen-btn {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 10;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--ink-soft);
  transition: background 0.2s;
  backdrop-filter: blur(4px);
}

.fullscreen-btn:hover {
  background: rgba(255, 255, 255, 0.9);
  color: var(--ink);
}

.fullscreen-btn svg {
  width: 20px;
  height: 20px;
}

#gameCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: linear-gradient(180deg, #ffe8c0 0%, #f8ce90 65%, #b87c4f 100%);
}

.stage:fullscreen,
.stage:-webkit-full-screen {
  width: 100vw;
  height: 100vh;
  max-width: none;
  border: none;
  border-radius: 0;
}

.stage:fullscreen #gameCanvas,
.stage:-webkit-full-screen #gameCanvas {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
}

.stage:fullscreen .stage-hud,
.stage:-webkit-full-screen .stage-hud {
  top: calc(env(safe-area-inset-top) + 0.75rem);
  left: calc(env(safe-area-inset-left) + 0.75rem);
  right: calc(env(safe-area-inset-right) + 3.8rem);
}

.stage:fullscreen .fullscreen-btn,
.stage:-webkit-full-screen .fullscreen-btn {
  top: calc(env(safe-area-inset-top) + 0.72rem);
  right: calc(env(safe-area-inset-right) + 0.72rem);
}

.stage:fullscreen::backdrop,
.stage:-webkit-full-screen::backdrop {
  background: #f8ce90;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(49, 31, 19, 0);
  backdrop-filter: blur(0);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.24s ease, transform 0.24s ease, background 0.24s ease, backdrop-filter 0.24s ease;
  pointer-events: none;
}

.overlay.show {
  opacity: 1;
  transform: translateY(0);
  background: rgba(49, 31, 19, 0.26);
  backdrop-filter: blur(2px);
  pointer-events: auto;
}

.overlay-card {
  width: min(88%, 560px);
  text-align: center;
  background: rgba(255, 250, 242, 0.74);
  border: 1px solid rgba(72, 40, 19, 0.18);
  border-radius: 20px;
  padding: 1.1rem 1.2rem;
  box-shadow: 0 20px 40px rgba(56, 30, 12, 0.2);
}

.overlay-tag {
  margin: 0;
  color: #8a5a3f;
  font-family: "Bricolage Grotesque", sans-serif;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.overlay-card h2 {
  margin: 0.36rem 0 0.28rem;
  font-family: "Bricolage Grotesque", "Noto Sans SC", sans-serif;
  font-size: clamp(1.32rem, 3.6vw, 2rem);
  line-height: 1.05;
}

.overlay-card p {
  margin: 0;
  color: #5f4435;
}

.overlay-hint {
  margin-top: 0.48rem !important;
  font-size: 0.86rem;
  color: #76523f;
}

.overlay-record {
  margin-top: 0.72rem !important;
  padding: 0;
  font-family: "Bricolage Grotesque", "Noto Sans SC", sans-serif;
  font-size: 0.88rem;
  color: #5f4435;
  font-weight: 700;
}

.overlay-actions {
  margin-top: 0.78rem;
  display: flex;
  justify-content: center;
  gap: 0.45rem;
}

.bottom-actions {
  display: none;
  gap: 0.65rem;
}

.btn {
  border: 1px solid rgba(82, 47, 24, 0.22);
  background: #fdf4e6;
  color: var(--ink);
  border-radius: 999px;
  padding: 0.56rem 0.92rem;
  font: 700 0.9rem "Bricolage Grotesque", "Noto Sans SC", sans-serif;
  cursor: pointer;
  transition: transform 0.16s ease, background 0.16s ease;
}

.btn:hover {
  transform: translateY(-1px);
  background: #f7ebda;
}

.btn:active {
  transform: translateY(0);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.primary:hover {
  background: var(--accent-strong);
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.76);
}

.toggle-btn {
  background: none;
  border: none;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-family: inherit;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.toggle-track {
  width: 40px;
  height: 22px;
  background: #ddd;
  border-radius: 999px;
  position: relative;
  transition: background 0.2s ease;
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.toggle-thumb {
  width: 18px;
  height: 18px;
  background: white;
  border-radius: 50%;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform 0.2s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.toggle-btn[aria-pressed="true"] .toggle-track {
  background: var(--good);
}

.toggle-btn[aria-pressed="true"] .toggle-thumb {
  transform: translateX(18px);
}

.energy-pill {
  border-color: rgba(47, 147, 255, 0.36);
  background: linear-gradient(180deg, rgba(236, 247, 255, 0.92), rgba(219, 236, 255, 0.84));
}

.energy-pill strong {
  color: var(--energy-strong);
}

.coin-pill {
  border-color: rgba(214, 146, 34, 0.32);
  background: linear-gradient(180deg, rgba(255, 248, 224, 0.95), rgba(255, 237, 177, 0.9));
}

.coin-pill strong {
  color: var(--coin-strong);
}

.mystery-pill {
  border-color: rgba(123, 82, 189, 0.34);
  background: linear-gradient(180deg, rgba(245, 236, 255, 0.93), rgba(232, 219, 255, 0.9));
}

.mystery-pill strong {
  color: #6e3eb1;
}

.shop-panel {
  margin-top: 50px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 0.95rem;
  box-shadow: var(--shadow);
  display: grid;
  gap: 0.75rem;
}

.shop-heading h2 {
  margin: 0;
  font: 700 1.06rem "Bricolage Grotesque", "Noto Sans SC", sans-serif;
}

.shop-heading p {
  margin: 0.24rem 0 0;
  color: var(--ink-soft);
  font-size: 0.86rem;
}

.shop-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.6rem;
}

.shop-card {
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid rgba(77, 44, 22, 0.14);
  border-radius: 16px;
  padding: 0.72rem;
  display: grid;
  gap: 0.36rem;
  justify-items: start;
}

.shop-card h3 {
  margin: 0;
  font-size: 0.98rem;
}

.shop-cost,
.shop-perk,
.shop-status {
  margin: 0;
  font-size: 0.82rem;
}

.shop-cost {
  color: var(--ink-soft);
}

.shop-perk {
  color: #7f5b45;
}

.shop-status {
  font-weight: 700;
}

.shop-card .btn {
  padding: 0.45rem 0.82rem;
  font-size: 0.82rem;
}

.skin-preview {
  width: 48px;
  height: 92px;
  display: grid;
  place-items: center;
}

.skin-preview svg {
  width: 44px;
  height: 92px;
  stroke: currentColor;
  stroke-width: 4;
  stroke-linecap: round;
  fill: none;
}

.skin-preview circle {
  fill: currentColor;
  stroke: none;
}

.black-card .skin-preview,
.black-card .shop-status {
  color: var(--skin-black);
}

.orange-card .skin-preview,
.orange-card .shop-status {
  color: var(--skin-orange);
}

.blue-card .skin-preview,
.blue-card .shop-status {
  color: var(--skin-blue);
}

.purple-card .skin-preview,
.purple-card .shop-status {
  color: var(--skin-purple);
}

.mystery-card {
  background: linear-gradient(160deg, rgba(253, 247, 255, 0.86), rgba(240, 227, 255, 0.78));
}

.mystery-card .shop-status {
  color: #6e3eb1;
}

.history-panel {
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid rgba(82, 47, 24, 0.12);
  padding: 0.2rem 0.62rem 0.62rem;
}

.history-summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  padding: 0.42rem 0;
}

.history-summary p {
  margin: 0;
  font-size: 0.86rem;
}

.history-summary::-webkit-details-marker {
  display: none;
}

.history-summary::after {
  content: "展开";
  margin-left: auto;
  padding: 0.2rem 0.54rem;
  border-radius: 999px;
  border: 1px solid rgba(82, 47, 24, 0.2);
  color: #6e4d3b;
  font-size: 0.74rem;
  font-weight: 700;
}

.history-panel[open] .history-summary::after {
  content: "收起";
}

.history-title {
  font: 700 0.86rem "Bricolage Grotesque", "Noto Sans SC", sans-serif;
  color: #6e4d3b;
}

.history-list {
  margin: 0;
  padding: 0.1rem 0 0;
  list-style: none;
  display: grid;
  gap: 0.3rem;
}

.history-list li {
  font-size: 0.8rem;
  color: #5e4435;
  padding: 0.28rem 0.38rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(92, 48, 21, 0.1);
}

.history-list .history-empty {
  color: #7a5a48;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none !important;
}

@media (max-width: 960px) {
  .topbar {
    grid-template-columns: 1fr;
    justify-items: start;
  }

  .hud {
    justify-content: flex-start;
  }

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

@media (max-width: 760px) {
  .app-shell {
    width: calc(100% - 0.6rem);
    margin-top: 0.34rem;
    gap: 0.5rem;
  }

  .topbar {
    border-radius: 14px;
    padding: 0.68rem;
    gap: 0.62rem;
  }

  .subtitle {
    font-size: 0.78rem;
  }

  .hud {
    justify-content: flex-start;
  }

  .hud-pill {
    min-width: 0;
  }

  .stage {
    border-radius: 14px;
  }

  .stage-hud {
    top: 0.5rem;
    left: 0.5rem;
    right: 3rem;
    gap: 0.28rem;
  }

  .stage-hud .hud-pill {
    padding: 0.3rem 0.45rem;
  }

  .fullscreen-btn {
    top: 0.58rem;
    right: 0.58rem;
  }

  .overlay-card {
    width: min(92%, 560px);
    padding: 0.95rem 0.85rem;
  }

  .shop-panel {
    border-radius: 14px;
    padding: 0.74rem;
  }

  .shop-grid {
    grid-template-columns: 1fr;
  }

  .shop-card {
    gap: 0.26rem;
  }

  .history-summary {
    gap: 0.24rem 0.5rem;
  }

  .history-summary::after {
    margin-left: 0;
  }

  .bottom-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
}
