* { margin: 0; padding: 0; box-sizing: border-box; }
html, body {
  width: 100%; height: 100%; overflow: hidden;
  font-family: -apple-system, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none; touch-action: manipulation;
}

/* ─── 治愈系配色 ─── */
:root {
  --bg: #fef9f0;
  --card: #fff;
  --card-border: #f0e6d6;
  --text: #5a4a3a;
  --text-light: #a09080;
  --pink: #f28585;
  --pink-glow: rgba(242, 133, 133, 0.3);
  --coral: #ff9a76;
  --peach: #ffd4a0;
  --green: #7ec8a0;
  --blue: #7eb8d8;
  --purple: #b8a0d8;
  --shadow: rgba(0, 0, 0, 0.06);
}

/* Screens */
.screen { display: none; position: absolute; inset: 0; }
.screen.active { display: flex; align-items: center; justify-content: center; }

/* ─── Lobby ─── */
#lobby { background: var(--bg); }

.lobby-box {
  text-align: center;
  padding: 2.5rem 2rem;
  background: var(--card);
  border-radius: 24px;
  border: 1px solid var(--card-border);
  box-shadow: 0 8px 32px var(--shadow);
  width: min(88vw, 340px);
}

.logo { font-size: 3rem; margin-bottom: 0.5rem; }
.logo.pulse { animation: logoPulse 1.2s ease-in-out infinite; }
@keyframes logoPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.lobby-box h1 { font-size: 1.8rem; color: var(--text); margin-bottom: 0.2rem; font-weight: 700; }
.subtitle { color: var(--text-light); font-size: 0.85rem; margin-bottom: 1.5rem; }

.btn {
  display: inline-block;
  padding: 0.7rem 2rem;
  border: none; border-radius: 14px;
  font-size: 1rem; font-weight: 600;
  cursor: pointer;
  color: #fff;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.96); }
.btn.primary { background: linear-gradient(135deg, var(--coral), var(--pink)); width: 100%; box-shadow: 0 4px 16px rgba(242, 133, 133, 0.3); }

.divider { color: var(--text-light); margin: 1rem 0; font-size: 0.8rem; }

.join-row { display: flex; gap: 0.5rem; }
.join-row input {
  flex: 1; min-width: 0;
  padding: 0.7rem;
  border: 2px solid var(--card-border);
  border-radius: 14px;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.3em;
  outline: none;
  -webkit-appearance: none;
}
.join-row input::placeholder { color: var(--text-light); letter-spacing: 0; text-transform: none; }
.join-row .btn { padding: 0.7rem 1.2rem; background: linear-gradient(135deg, var(--blue), var(--purple)); flex-shrink: 0; box-shadow: 0 4px 12px rgba(126, 184, 216, 0.3); }

.msg { color: var(--pink); margin-top: 1rem; font-size: 0.85rem; min-height: 1.2em; }

/* Help button */
.btn-help {
  display: inline-block;
  margin-top: 1.2rem;
  padding: 0.4rem 1rem;
  border: none; border-radius: 20px;
  font-size: 0.8rem;
  cursor: pointer;
  background: rgba(0,0,0,0.04);
  color: var(--text-light);
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}
.btn-help:active { background: rgba(0,0,0,0.08); color: var(--text); }

/* Help overlay */
.help-box {
  text-align: left;
  background: var(--card);
  border: 1px solid var(--card-border);
  box-shadow: 0 8px 32px var(--shadow);
  width: min(88vw, 360px);
  max-height: 80vh;
  overflow-y: auto;
  border-radius: 24px;
  padding: 2rem;
}
.help-box h2 { text-align: center; margin-bottom: 1rem; color: var(--text); }
.help-content { margin-bottom: 1.5rem; }
.help-section { margin-bottom: 1rem; }
.help-section h3 { font-size: 0.9rem; margin-bottom: 0.2rem; color: var(--text); }
.help-section p { font-size: 0.82rem; color: var(--text-light); line-height: 1.6; margin-left: 0.5rem; }

/* ─── Waiting ─── */
#waiting { background: var(--bg); }
.room-code {
  font-size: 3rem; letter-spacing: 0.5em;
  font-weight: bold; color: var(--pink);
  margin: 0.5rem 0;
}
.loading-dots span { animation: blink 1.4s infinite; font-size: 2rem; color: var(--text-light); }
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%,80%,100% { opacity: 0.2; } 40% { opacity: 1; } }

/* ─── Game ─── */
#game-screen { background: var(--bg); }
#game-screen.active { display: flex; flex-direction: column; }

#game-canvas { display: block; width: 100%; flex: 1; }

#hud {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 20px;
  font-size: 0.9rem; color: var(--text-light);
  background: var(--bg);
}
#hud-island { font-weight: 600; color: var(--text); }

/* ─── Tap Zone ─── */
#tap-zone {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 1.5rem 0 0.5rem;
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

#heartbeat-ring {
  width: 140px; height: 140px;
  border-radius: 50%;
  border: 4px solid var(--pink);
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.3s, box-shadow 0.3s;
  position: relative;
}
#heartbeat-ring.synced {
  border-color: var(--green);
  box-shadow: 0 0 30px rgba(126, 200, 160, 0.5);
}

#heartbeat-core {
  width: 60px; height: 60px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--coral), var(--pink));
  box-shadow: 0 0 20px var(--pink-glow);
  transition: transform 0.08s ease-out;
}

#bpm-display {
  margin-top: 0.8rem;
  font-size: 1.4rem; font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

#target-hint {
  margin-top: 0.3rem;
  font-size: 0.75rem;
  color: var(--text-light);
}

/* ─── Sync Bar ─── */
#sync-bar-wrap {
  position: relative;
  margin: 0.8rem 2rem 1.5rem;
  height: 10px;
  background: var(--card-border);
  border-radius: 5px;
  overflow: hidden;
}
#sync-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--pink), var(--coral), var(--green));
  border-radius: 5px;
  transition: width 0.3s;
}
#sync-bar-label {
  position: absolute; top: -20px;
  left: 50%; transform: translateX(-50%);
  font-size: 0.75rem; color: var(--text-light);
}

/* ─── Overlays ─── */
.overlay {
  position: absolute; inset: 0;
  background: rgba(254, 249, 240, 0.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  backdrop-filter: blur(8px);
}
.overlay.hidden { display: none; }

.overlay-box {
  text-align: center;
  padding: 2.5rem;
  width: min(85vw, 340px);
}
.overlay-box.celebration { animation: celebrateIn 0.6s ease; }
@keyframes celebrateIn {
  from { transform: scale(0.7) translateY(20px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}
.overlay-box h2 { font-size: 1.8rem; color: var(--text); margin: 0.8rem 0 0.4rem; }
.overlay-box p { color: var(--text-light); font-size: 0.95rem; margin-bottom: 1.5rem; }

#celebration-emoji { font-size: 3rem; }

/* ─── Toast ─── */
.toast {
  position: fixed; top: 60px;
  left: 50%; transform: translateX(-50%) translateY(-20px);
  background: rgba(90, 74, 58, 0.9);
  color: #fff;
  padding: 12px 24px; border-radius: 14px;
  font-size: 0.9rem; z-index: 200;
  opacity: 0; transition: all 0.3s ease;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
