* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --ink: #f3ead8;
  --panel: rgba(18, 16, 22, 0.92);
  --accent: #ffd166;
  --danger: #ff5d5d;
  --moss: #7dcf6e;
  --stam: #ffd166;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #14121a;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--ink);
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

#root {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

/* ---------- HUD ---------- */
#hud {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 5;
}

#top-left {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  padding: 8px 10px 9px;
  background: rgba(10, 9, 14, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  min-width: 132px;
  backdrop-filter: blur(4px);
}

#score-line {
  font-size: 26px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.5px;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
}

#score-unit {
  font-size: 14px;
  font-weight: 700;
  opacity: 0.75;
  margin-left: 2px;
}

#best-line {
  font-size: 12px;
  opacity: 0.85;
  margin-top: 3px;
  font-weight: 600;
}

#stamina-wrap {
  margin-top: 7px;
  width: 128px;
  height: 12px;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 7px;
  overflow: hidden;
  position: relative;
}

#stamina-bar {
  height: 100%;
  width: 100%;
  border-radius: 6px;
  background: linear-gradient(90deg, #ffe08a, #ffd166);
  transition: width 80ms linear;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.15);
}

#stamina-bar.low {
  background: linear-gradient(90deg, #ff8f5d, #ff5d5d);
  animation: pulse 0.55s ease-in-out infinite alternate;
}

#stamina-bar.mid {
  background: linear-gradient(90deg, #ffd166, #ffb347);
}

@keyframes pulse {
  from { filter: brightness(1); }
  to { filter: brightness(1.45); }
}

#rain-timer {
  margin-top: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.4px;
  color: #9fd0ff;
  opacity: 0.95;
}

#rain-timer.warnish { color: #ffd166; }

#rain-banner {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  padding: 10px 18px 11px;
  background: rgba(120, 20, 30, 0.82);
  border: 2px solid rgba(255, 120, 120, 0.85);
  border-radius: 12px;
  box-shadow: 0 6px 24px rgba(255, 40, 40, 0.35);
  animation: bannerPulse 0.5s ease-in-out infinite alternate;
  max-width: min(92vw, 420px);
}

#rain-banner.shelter-ok {
  background: rgba(20, 70, 40, 0.85);
  border-color: rgba(120, 255, 170, 0.8);
  box-shadow: 0 6px 24px rgba(40, 255, 140, 0.25);
}

#rain-banner-text {
  font-size: clamp(15px, 3.6vw, 22px);
  font-weight: 900;
  letter-spacing: 1.5px;
}

#rain-banner-sub {
  font-size: clamp(11px, 2.5vw, 13px);
  opacity: 0.9;
  margin-top: 2px;
  font-weight: 600;
}

@keyframes bannerPulse {
  from { transform: translateX(-50%) scale(1); filter: brightness(1); }
  to { transform: translateX(-50%) scale(1.035); filter: brightness(1.25); }
}

#top-right {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  display: flex;
  gap: 8px;
  pointer-events: auto;
}

#mute-btn, #joy-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(10, 9, 14, 0.6);
  color: var(--ink);
  font-size: 19px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  transition: background 0.15s, transform 0.1s;
}

#mute-btn:active, #joy-btn:active { transform: scale(0.92); }

#mute-btn.muted {
  color: #ff7b7b;
  background: rgba(60, 16, 16, 0.7);
}

#mute-btn.muted::after {
  content: "";
  position: absolute;
  width: 26px;
  height: 2.5px;
  background: #ff7b7b;
  transform: rotate(-45deg);
  border-radius: 2px;
}

#mute-btn { position: relative; }

#joy-btn.on {
  background: rgba(40, 90, 50, 0.75);
  border-color: rgba(140, 255, 170, 0.5);
}

/* ---------- toasts ---------- */
#toasts {
  position: absolute;
  left: 50%;
  bottom: 18%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: center;
  pointer-events: none;
  z-index: 6;
  width: max-content;
  max-width: 92vw;
}

.toast {
  background: rgba(12, 11, 16, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--ink);
  padding: 7px 14px;
  border-radius: 999px;
  font-size: clamp(12px, 2.8vw, 14px);
  font-weight: 600;
  text-align: center;
  animation: toastIn 0.3s ease-out;
  backdrop-filter: blur(3px);
}

.toast.bye { animation: toastOut 0.4s ease-in forwards; }

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

@keyframes toastOut {
  to { opacity: 0; transform: translateY(-8px); }
}

/* ---------- joystick ---------- */
#joystick {
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(22px, env(safe-area-inset-bottom));
  width: 148px;
  height: 148px;
  z-index: 8;
  pointer-events: auto;
  touch-action: none;
}

#joystick.hidden { display: none; }

#joy-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.07);
  border: 2.5px solid rgba(255, 255, 255, 0.35);
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.35), inset 0 0 24px rgba(0, 0, 0, 0.25);
}

#joy-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 64px;
  height: 64px;
  margin: -32px 0 0 -32px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.95), rgba(200, 205, 220, 0.75));
  border: 2px solid rgba(255, 255, 255, 0.7);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.45);
  transform: translate(0, 0);
  will-change: transform;
}

#joy-hint {
  position: absolute;
  left: 50%;
  top: -22px;
  transform: translateX(-50%);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  opacity: 0.7;
  text-shadow: 0 1px 4px #000;
}

/* ---------- overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at center, rgba(20, 16, 30, 0.55), rgba(8, 6, 12, 0.88));
  padding: 16px;
  pointer-events: auto;
}

.overlay.hidden { display: none; }

.panel {
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 18px;
  padding: clamp(18px, 4vw, 30px) clamp(18px, 5vw, 36px);
  text-align: center;
  max-width: min(440px, 94vw);
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.55);
}

.spider-icon {
  width: 54px;
  height: 54px;
  margin: 0 auto 8px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 45%, #3a3145 0 34%, transparent 35%),
    radial-gradient(circle at 50% 70%, #2c2536 0 26%, transparent 27%),
    radial-gradient(circle at 50% 50%, rgba(255, 209, 102, 0.15), transparent 70%);
  position: relative;
}

.spider-icon::before, .spider-icon::after {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  border: 2px dashed rgba(243, 234, 216, 0.55);
  border-left-color: transparent;
  border-right-color: transparent;
}

.spider-icon::after { transform: rotate(60deg); }

h1 {
  font-size: clamp(26px, 7vw, 36px);
  font-weight: 900;
  letter-spacing: 0.5px;
  background: linear-gradient(180deg, #ffe9b0, #ffb84d);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 6px;
}

h2 {
  font-size: clamp(24px, 6vw, 32px);
  font-weight: 900;
  color: #ff8b8b;
  margin-bottom: 6px;
}

.tagline {
  font-size: clamp(13px, 3vw, 15px);
  opacity: 0.9;
  margin-bottom: 16px;
  line-height: 1.4;
}

.rules {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 9px;
  margin: 0 auto 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 12px;
  padding: 12px 14px;
}

.rule {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: clamp(12px, 2.9vw, 14px);
  line-height: 1.35;
  flex-wrap: wrap;
}

.rule b { color: var(--accent); }

.key {
  display: inline-block;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-bottom-width: 2.5px;
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.5px;
}

.dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  flex: 0 0 13px;
}

.dot.stamina { background: linear-gradient(90deg, #ffd166, #ffb347); box-shadow: 0 0 6px #ffd16688; }
.dot.fly { background: radial-gradient(circle at 35% 30%, #fff6c0, #e8c547 55%, #8a6a10); box-shadow: 0 0 6px #ffe08aaa; }
.dot.rain { background: linear-gradient(180deg, #7db8ff, #3a6fd8); box-shadow: 0 0 6px #7db8ff88; }
.dot.danger { background: linear-gradient(180deg, #ff7b7b, #c22b2b); box-shadow: 0 0 6px #ff5d5d88; }

.start-best {
  font-size: 14px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 10px;
}

.start-best.hidden { display: none; }

#start-btn, #restart-btn {
  display: block;
  width: 100%;
  padding: 14px 18px;
  font-size: clamp(16px, 4vw, 19px);
  font-weight: 900;
  letter-spacing: 1px;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  color: #1a1408;
  background: linear-gradient(180deg, #ffe08a, #ffb84d);
  box-shadow: 0 6px 0 #b07a1e, 0 10px 24px rgba(255, 184, 77, 0.3);
  transition: transform 0.08s, box-shadow 0.08s;
  touch-action: manipulation;
}

#start-btn:active, #restart-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #b07a1e, 0 4px 12px rgba(255, 184, 77, 0.25);
}

.start-hint {
  margin-top: 12px;
  font-size: 12px;
  opacity: 0.65;
}

.over-cause {
  font-size: clamp(13px, 3vw, 15px);
  opacity: 0.9;
  margin-bottom: 14px;
  line-height: 1.4;
}

.scorecard {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-bottom: 12px;
}

.sc {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 10px 8px;
}

.sc-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  opacity: 0.65;
}

.sc-value {
  font-size: clamp(22px, 6vw, 30px);
  font-weight: 900;
  color: var(--accent);
}

.newbest {
  font-size: 18px;
  font-weight: 900;
  color: #7dffa8;
  letter-spacing: 2px;
  margin-bottom: 10px;
  animation: pulse 0.5s ease-in-out infinite alternate;
}

.newbest.hidden { display: none; }

.hidden { display: none !important; }

@media (max-height: 560px) {
  .panel { padding: 12px 16px; }
  .spider-icon { display: none; }
  .rules { padding: 8px 10px; gap: 6px; }
  h1 { font-size: 22px; margin-bottom: 2px; }
  .tagline { margin-bottom: 8px; }
}
