:root {
  --bg-0: #1c1230;
  --bg-1: #2a1746;
  --bg-2: #3b1f5f;
  --gold: #ffc72c;
  --gold-deep: #c98e0c;
  --cream: #fff3d6;
  --pink: #ff6584;
  --teal: #36d3c6;
  --green: #5ddc91;
  --red: #ff5a5f;
  --ink: #1d1330;
  --ink-soft: #382858;
  --panel: rgba(28, 18, 48, 0.82);
  --panel-border: rgba(255, 199, 44, 0.32);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, -apple-system,
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--cream);
  background:
    radial-gradient(1100px 700px at 50% -10%, #59348a 0%, #2a1746 55%, #170c2a 100%) fixed,
    var(--bg-0);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 14px 18px 18px;
  gap: 14px;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  font-size: 20px;
  letter-spacing: 0.5px;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.brand-emoji {
  font-size: 28px;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.4));
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand-text small {
  font-size: 11px;
  font-weight: 500;
  opacity: 0.7;
  letter-spacing: 1.5px;
}

.hud {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-left: auto;
}

.hud-item {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.06) 0%, rgba(255, 255, 255, 0.02) 100%);
  border: 1px solid rgba(255, 199, 44, 0.22);
  border-radius: 12px;
  padding: 6px 12px;
  min-width: 64px;
  text-align: center;
  backdrop-filter: blur(8px);
}

.hud-label {
  display: block;
  font-size: 10px;
  letter-spacing: 2px;
  opacity: 0.65;
  margin-bottom: 2px;
}

.hud-value {
  display: block;
  font-size: 18px;
  font-weight: 800;
  color: var(--cream);
  font-variant-numeric: tabular-nums;
}

.hud-item.gold .hud-value { color: var(--gold); }
.hud-item.time .hud-value { color: var(--teal); }
.hud-item.best .hud-value { color: var(--pink); }

.topbar-actions {
  display: flex;
  gap: 8px;
}

.iconbtn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid rgba(255, 199, 44, 0.32);
  background: rgba(255, 255, 255, 0.06);
  color: var(--cream);
  font-size: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease, background 0.12s ease;
}

.iconbtn:hover { background: rgba(255, 199, 44, 0.18); transform: translateY(-1px); }
.iconbtn:active { transform: translateY(0); }

/* ---------- stage ---------- */
.stage {
  display: flex;
  justify-content: center;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  max-width: 960px;
  aspect-ratio: 16 / 10;
  border-radius: 22px;
  overflow: hidden;
  background: linear-gradient(180deg, #6f3a1c 0%, #4a230f 38%, #2d1308 100%);
  box-shadow: var(--shadow), inset 0 0 0 2px rgba(255, 199, 44, 0.18);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: optimizeQuality;
  cursor: pointer;
  touch-action: manipulation;
}

/* ---------- overlay & panels ---------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(28, 18, 48, 0.55) 0%, rgba(15, 8, 28, 0.85) 80%);
  backdrop-filter: blur(6px);
  padding: 20px;
  animation: fadeIn 0.25s ease;
}

.overlay[hidden] { display: none; }

.panel {
  width: min(560px, 100%);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  padding: 28px 28px 22px;
  box-shadow: var(--shadow);
  text-align: center;
  position: relative;
}

.panel::before {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 18px;
  border: 1px dashed rgba(255, 199, 44, 0.18);
  pointer-events: none;
}

.panel h1 {
  margin: 0 0 4px;
  font-size: 36px;
  letter-spacing: 6px;
  color: var(--gold);
  text-shadow: 0 4px 12px rgba(255, 199, 44, 0.35);
}

.panel h2 {
  margin: 0 0 4px;
  font-size: 26px;
  color: var(--gold);
  letter-spacing: 3px;
}

.tagline {
  margin: 4px 0 18px;
  color: rgba(255, 243, 214, 0.78);
  font-size: 14px;
}

.howto {
  list-style: none;
  padding: 0;
  margin: 0 auto 18px;
  text-align: left;
  display: grid;
  gap: 6px;
  max-width: 420px;
  font-size: 13px;
  color: rgba(255, 243, 214, 0.85);
}

.howto li {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 199, 44, 0.12);
  border-radius: 10px;
  padding: 8px 12px;
}

.howto b { color: var(--gold); }

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

button.primary,
button.ghost {
  border: 0;
  border-radius: 999px;
  padding: 10px 22px;
  font-weight: 700;
  cursor: pointer;
  font-size: 14px;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
}

button.primary {
  background: linear-gradient(180deg, #ffd954 0%, var(--gold) 60%, var(--gold-deep) 100%);
  color: var(--ink);
  box-shadow: 0 6px 18px rgba(255, 199, 44, 0.32), inset 0 -2px 0 rgba(0, 0, 0, 0.18);
}

button.primary:hover { transform: translateY(-1px); box-shadow: 0 10px 22px rgba(255, 199, 44, 0.4); }
button.primary:active { transform: translateY(1px); }

button.primary.big {
  font-size: 16px;
  padding: 12px 28px;
  letter-spacing: 2px;
}

button.ghost {
  background: rgba(255, 255, 255, 0.06);
  color: var(--cream);
  border: 1px solid rgba(255, 199, 44, 0.32);
}

button.ghost:hover { background: rgba(255, 199, 44, 0.16); }

/* ---------- shop ---------- */
.panel.shop {
  width: min(620px, 100%);
  padding-bottom: 18px;
}

.wallet {
  margin: 6px auto 14px;
  display: inline-block;
  padding: 6px 14px;
  background: rgba(255, 199, 44, 0.12);
  border: 1px solid rgba(255, 199, 44, 0.32);
  border-radius: 999px;
  color: var(--cream);
  font-size: 13px;
}

.wallet b { color: var(--gold); margin-left: 4px; font-size: 16px; }

.shop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin: 6px 0 18px;
}

.shop-card {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 199, 44, 0.18);
  border-radius: 14px;
  padding: 14px 12px 12px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.shop-card .icon {
  font-size: 30px;
  line-height: 1;
}

.shop-card .name {
  font-weight: 700;
  font-size: 14px;
  color: var(--cream);
}

.shop-card .desc {
  font-size: 11.5px;
  color: rgba(255, 243, 214, 0.7);
  line-height: 1.4;
  min-height: 32px;
}

.shop-card .price {
  font-size: 13px;
  color: var(--gold);
  font-weight: 700;
}

.shop-card .owned {
  font-size: 11px;
  color: var(--teal);
}

.shop-card button {
  margin-top: 4px;
  border: 0;
  border-radius: 999px;
  padding: 6px 12px;
  background: linear-gradient(180deg, #ffd954 0%, var(--gold) 100%);
  color: var(--ink);
  font-weight: 700;
  cursor: pointer;
  font-size: 12.5px;
}

.shop-card button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ---------- result ---------- */
.result-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 6px auto 18px;
  max-width: 420px;
}

.result-stats > div {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 199, 44, 0.18);
  border-radius: 12px;
  padding: 10px 6px;
}

.result-stats b {
  display: block;
  margin-top: 4px;
  color: var(--gold);
  font-size: 20px;
}

/* ---------- toolbar ---------- */
.toolbar {
  position: absolute;
  left: 14px;
  bottom: 14px;
  display: flex;
  gap: 10px;
  z-index: 5;
}

.tool {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 199, 44, 0.28);
  border-radius: 14px;
  padding: 8px 10px 6px;
  min-width: 66px;
  color: var(--cream);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  backdrop-filter: blur(6px);
  transition: transform 0.12s ease, background 0.12s ease;
}

.tool:hover:not(:disabled) { background: rgba(255, 199, 44, 0.18); transform: translateY(-1px); }

.tool:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.tool .tool-emoji { font-size: 22px; line-height: 1; }
.tool .tool-label { font-size: 12px; font-weight: 700; }
.tool .tool-count { font-size: 11px; color: var(--gold); }

/* ---------- hint ---------- */
.hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 8, 28, 0.7);
  backdrop-filter: blur(6px);
  z-index: 10;
}

.hint[hidden] { display: none; }

.hint-card {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 22px 24px 18px;
  max-width: 420px;
  width: calc(100% - 32px);
  box-shadow: var(--shadow);
  text-align: left;
}

.hint-card h3 {
  margin: 0 0 10px;
  color: var(--gold);
  text-align: center;
  letter-spacing: 2px;
}

.hint-card ul {
  list-style: disc;
  padding-left: 20px;
  margin: 0 0 14px;
  color: rgba(255, 243, 214, 0.85);
  font-size: 13px;
  display: grid;
  gap: 4px;
}

.hint-card b { color: var(--gold); }

.hint-card button {
  display: block;
  margin: 0 auto;
}

/* ---------- footer ---------- */
.footer {
  text-align: center;
  font-size: 12px;
  color: rgba(255, 243, 214, 0.45);
  letter-spacing: 1px;
  margin-top: auto;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  #app { padding: 10px 10px 14px; gap: 10px; }
  .topbar { gap: 10px; }
  .brand { font-size: 16px; }
  .brand-emoji { font-size: 22px; }
  .brand-text small { display: none; }
  .hud-item { min-width: 56px; padding: 4px 8px; }
  .hud-label { font-size: 9px; letter-spacing: 1px; }
  .hud-value { font-size: 15px; }
  .iconbtn { width: 32px; height: 32px; font-size: 14px; }
  .panel h1 { font-size: 28px; letter-spacing: 4px; }
  .panel h2 { font-size: 20px; letter-spacing: 2px; }
  .tool { min-width: 58px; padding: 6px 8px 4px; }
  .tool .tool-emoji { font-size: 18px; }
  .tool .tool-label { font-size: 11px; }
}
