:root {
  --jungle-1: #0c2e16;
  --jungle-2: #145a2c;
  --jungle-3: #2b8a4a;
  --jungle-4: #6fcf6b;
  --sun: #ffd762;
  --orange: #ff8a3d;
  --coin: #f4c430;
  --danger: #ff5252;
  --paper: #fff8e7;
  --ink: #1c3322;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
  --radius: 18px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background:
    radial-gradient(ellipse at top, #2a6a3b 0%, #0c2e16 60%, #061a0c 100%);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
    "Helvetica Neue", Arial, sans-serif;
  color: var(--paper);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(180deg, #98d8a6 0%, #5fb371 35%, #2b8a4a 65%, #145a2c 100%);
  touch-action: none;
}

/* === Overlays === */
.overlay {
  position: absolute;
  inset: 0;
  background: rgba(8, 22, 14, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 20px;
  animation: fadeIn 0.25s ease-out;
}

.hidden {
  display: none !important;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.panel {
  width: min(420px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: linear-gradient(180deg, #f7eed1 0%, #f0dfa8 100%);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 22px 22px 20px;
  box-shadow: var(--shadow), inset 0 0 0 4px #2b8a4a, inset 0 0 0 8px #f7eed1;
  position: relative;
}

.panel::before {
  content: "";
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  bottom: 12px;
  border: 2px dashed rgba(43, 138, 74, 0.4);
  border-radius: 12px;
  pointer-events: none;
}

.small-panel {
  width: min(340px, 100%);
  text-align: center;
}

.logo {
  text-align: center;
  margin-bottom: 16px;
}

.logo-emoji {
  font-size: 42px;
  margin-bottom: 4px;
}

h1 {
  font-size: 30px;
  margin: 0;
  color: var(--jungle-2);
  letter-spacing: 4px;
  font-weight: 900;
  text-shadow: 2px 2px 0 var(--sun);
}

h2 {
  margin: 0 0 12px;
  color: var(--jungle-2);
  text-align: center;
  letter-spacing: 2px;
}

.subtitle {
  margin: 4px 0 0;
  color: var(--jungle-3);
  font-size: 13px;
  letter-spacing: 2px;
}

.section {
  margin-bottom: 14px;
}

.section-title {
  font-size: 13px;
  color: var(--jungle-2);
  font-weight: 700;
  margin-bottom: 8px;
  letter-spacing: 2px;
}

.section-title.small {
  font-size: 12px;
  text-align: center;
  opacity: 0.7;
}

.diff-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.diff-btn {
  background: rgba(255, 255, 255, 0.6);
  border: 2px solid rgba(43, 138, 74, 0.3);
  border-radius: 12px;
  padding: 10px;
  font: inherit;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  cursor: pointer;
  transition: transform 0.1s ease, border-color 0.15s, background 0.15s;
}

.diff-btn:active { transform: scale(0.97); }

.diff-btn.selected {
  border-color: var(--jungle-2);
  background: var(--jungle-4);
  color: var(--ink);
  box-shadow: 0 4px 0 var(--jungle-2);
}

.diff-name {
  font-weight: 800;
  font-size: 16px;
  letter-spacing: 2px;
}

.diff-desc {
  font-size: 11px;
  opacity: 0.85;
}

.cta {
  display: block;
  width: 100%;
  background: linear-gradient(180deg, #ff9d52 0%, #ff7028 100%);
  color: #fff;
  font-weight: 900;
  font-size: 18px;
  letter-spacing: 4px;
  border: none;
  border-radius: 14px;
  padding: 14px 16px;
  margin-top: 14px;
  cursor: pointer;
  box-shadow: 0 5px 0 #c4501a, 0 10px 20px rgba(255, 112, 40, 0.35);
  transition: transform 0.08s ease;
}

.cta:active {
  transform: translateY(3px);
  box-shadow: 0 2px 0 #c4501a, 0 4px 10px rgba(255, 112, 40, 0.35);
}

.cta.secondary {
  background: linear-gradient(180deg, #5fb371 0%, #2b8a4a 100%);
  box-shadow: 0 5px 0 #1a5b30, 0 10px 20px rgba(43, 138, 74, 0.35);
}

.cta.secondary:active {
  box-shadow: 0 2px 0 #1a5b30, 0 4px 10px rgba(43, 138, 74, 0.35);
}

.ghost {
  display: block;
  width: 100%;
  background: transparent;
  color: var(--jungle-2);
  border: 2px solid var(--jungle-2);
  border-radius: 12px;
  padding: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  margin-top: 8px;
  cursor: pointer;
}

.ghost:active { background: rgba(43, 138, 74, 0.1); }

.leaderboard {
  margin-top: 14px;
  background: rgba(43, 138, 74, 0.08);
  border-radius: 12px;
  padding: 10px 12px;
}

#lb-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 13px;
}

#lb-list li {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px dashed rgba(43, 138, 74, 0.2);
}

#lb-list li:last-child { border-bottom: none; }

#lb-list li .lb-rank {
  font-weight: 800;
  color: var(--orange);
  width: 24px;
}

#lb-list .empty {
  text-align: center;
  opacity: 0.5;
  padding: 4px;
}

.tips {
  margin-top: 12px;
  font-size: 11px;
  color: var(--jungle-2);
  opacity: 0.7;
  line-height: 1.6;
}

/* === HUD === */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  padding: env(safe-area-inset-top, 12px) 12px 12px;
  z-index: 10;
  display: flex;
  flex-direction: column;
}

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

.hud-row.hud-right {
  position: absolute;
  top: env(safe-area-inset-top, 12px);
  right: 12px;
  flex-direction: row;
}

.hud-pill {
  background: rgba(12, 46, 22, 0.7);
  color: #fff8e7;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  border: 2px solid rgba(255, 215, 98, 0.5);
}

.hud-pill .val {
  font-weight: 900;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.hud-pill .lbl { opacity: 0.7; }

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid rgba(255, 215, 98, 0.5);
  background: rgba(12, 46, 22, 0.7);
  color: #fff8e7;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

#powerup-row {
  position: absolute;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  pointer-events: none;
}

.pu-badge {
  background: rgba(12, 46, 22, 0.75);
  color: #fff8e7;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  border: 2px solid var(--sun);
  animation: pulse 0.8s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { transform: scale(1); }
  to { transform: scale(1.05); }
}

/* === Result card === */
.go-title {
  background: linear-gradient(180deg, var(--orange), #c4501a);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  font-size: 28px;
  letter-spacing: 8px;
}

.result-card {
  background: #fff;
  border-radius: 14px;
  padding: 14px 16px;
  margin: 10px 0 16px;
  box-shadow: inset 0 0 0 2px rgba(43, 138, 74, 0.2);
}

.rc-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
  border-bottom: 1px dashed rgba(43, 138, 74, 0.15);
}

.rc-row:last-child { border-bottom: none; }

.rc-row strong {
  font-size: 18px;
  color: var(--jungle-2);
  font-variant-numeric: tabular-nums;
}

.rc-row.best strong { color: var(--orange); }

.share-block {
  background: rgba(43, 138, 74, 0.06);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 12px;
}

.qr-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.qr-cell {
  background: #fff;
  border-radius: 10px;
  padding: 8px;
  text-align: center;
}

.qr-canvas {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.qr-canvas canvas,
.qr-canvas img {
  width: 100% !important;
  height: 100% !important;
  max-width: 140px;
  max-height: 140px;
}

.qr-label {
  font-size: 11px;
  color: var(--jungle-2);
  font-weight: 700;
  margin-top: 4px;
}

.share-actions {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.share-actions .cta {
  margin-top: 0;
  padding: 10px;
  font-size: 14px;
  letter-spacing: 2px;
}

.share-actions .ghost {
  margin-top: 0;
  padding: 8px;
  font-size: 13px;
}

.end-actions {
  display: grid;
  gap: 6px;
}

/* === Touch hint === */
#touch-hint {
  position: absolute;
  bottom: 80px;
  left: 0;
  right: 0;
  text-align: center;
  color: rgba(255, 248, 231, 0.7);
  font-size: 12px;
  pointer-events: none;
  z-index: 5;
  animation: fadeOut 4s forwards;
}

@keyframes fadeOut {
  0%, 60% { opacity: 1; }
  100% { opacity: 0; }
}

.hint-row {
  background: rgba(12, 46, 22, 0.5);
  display: inline-block;
  padding: 4px 10px;
  border-radius: 12px;
  margin: 2px;
}

/* === Responsive === */
@media (min-width: 720px) and (min-height: 720px) {
  #app {
    padding: 20px;
  }
  #game {
    width: auto;
    height: 100%;
    max-width: 540px;
    max-height: 960px;
    aspect-ratio: 9 / 16;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  }
}

@media (max-height: 700px) {
  .panel { padding: 16px; }
  h1 { font-size: 24px; }
  .logo-emoji { font-size: 32px; }
  .logo { margin-bottom: 10px; }
}

@media (max-width: 360px) {
  .diff-grid {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }
  .diff-btn { padding: 8px; }
  .diff-name { font-size: 14px; }
}
