:root {
  --ink: #f6efe3;
  --panel-bg: rgba(30, 22, 16, 0.92);
  --accent: #ffb347;
  --accent-2: #4fc3f7;
  --danger: #ff5f56;
  --good: #7ed957;
  --stamina-lo: #ff5f56;
  --stamina-mid: #ffc14d;
  --stamina-hi: #7ed957;
}

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

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

#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: #1c130d;
}

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

.hidden { display: none !important; }

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

.hud-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 12px 0 12px;
  gap: 8px;
}

.hud-left, .hud-right { min-width: 76px; }

.hud-right {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.hud-label {
  font-size: 10px;
  letter-spacing: 2px;
  color: rgba(246, 239, 227, 0.65);
  font-weight: 700;
}

.score-value, .best-value {
  font-size: 30px;
  font-weight: 800;
  line-height: 1;
  text-shadow: 0 2px 6px rgba(0,0,0,0.55);
}

.score-value .unit, .best-value .unit {
  font-size: 15px;
  font-weight: 700;
  color: rgba(246, 239, 227, 0.7);
  margin-left: 1px;
}

.best-value { font-size: 18px; text-align: right; }
.best-block { text-align: right; }

/* Stamina */
.hud-center {
  flex: 1;
  max-width: 460px;
  margin-top: 2px;
}

.stamina-wrap {
  background: rgba(20, 14, 9, 0.55);
  border-radius: 12px;
  padding: 6px 10px 8px;
  backdrop-filter: blur(2px);
}

.stamina-label {
  text-align: center;
  font-size: 10px;
  letter-spacing: 3px;
  font-weight: 700;
  color: rgba(246, 239, 227, 0.75);
  margin-bottom: 4px;
}

.stamina-bar {
  height: 14px;
  border-radius: 8px;
  background: rgba(0,0,0,0.45);
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.12);
  position: relative;
}

.stamina-fill {
  height: 100%;
  width: 100%;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--stamina-lo), var(--stamina-mid), var(--stamina-hi));
  transition: width 0.08s linear;
}
.stamina-fill.pulse { animation: pulse-fill 0.5s ease-in-out infinite; }
@keyframes pulse-fill {
  0%, 100% { filter: brightness(1); }
  50% { filter: brightness(1.5); }
}

/* Mute */
.mute-btn {
  pointer-events: auto;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(255,255,255,0.2);
  background: rgba(20, 14, 9, 0.55);
  color: var(--ink);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mute-btn:active { transform: scale(0.94); }

/* Rain widget */
.rain-widget {
  position: absolute;
  top: 78px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  border-radius: 20px;
  background: rgba(20, 14, 9, 0.7);
  border: 1px solid rgba(255,255,255,0.15);
  font-weight: 700;
  letter-spacing: 1px;
}
.rain-icon { font-size: 18px; }
.rain-text { font-size: 14px; }
.rain-widget.warn {
  background: rgba(120, 30, 20, 0.8);
  border-color: var(--danger);
  animation: pulse-warn 0.5s ease-in-out infinite;
}
.rain-widget.raining {
  background: rgba(15, 30, 55, 0.85);
  border-color: var(--accent-2);
}
@keyframes pulse-warn {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,95,86,0.6); }
  50% { box-shadow: 0 0 0 8px rgba(255,95,86,0); }
}

/* ---------------- Joystick ---------------- */
#joystick {
  position: absolute;
  left: 20px;
  bottom: calc(24px + env(safe-area-inset-bottom));
  pointer-events: none;
}
.joy-base {
  position: relative;
  width: 128px;
  height: 128px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.10), rgba(0,0,0,0.28));
  border: 2px solid rgba(255,255,255,0.35);
  box-shadow: 0 4px 18px rgba(0,0,0,0.35);
  pointer-events: auto;
  touch-action: none;
}
.joy-thumb {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 54px;
  height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255,255,255,0.55), rgba(255,255,255,0.16));
  border: 2px solid rgba(255,255,255,0.55);
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

/* ---------------- Screens ---------------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 50% 35%, rgba(50,36,26,0.55), rgba(12,8,5,0.9));
  z-index: 20;
  padding: 16px;
}

.panel {
  text-align: center;
  max-width: 440px;
  width: 100%;
  background: var(--panel-bg);
  border-radius: 20px;
  padding: 28px 24px 24px;
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: 0 18px 50px rgba(0,0,0,0.5);
}

.title {
  font-size: 40px;
  line-height: 0.98;
  font-weight: 900;
  letter-spacing: 3px;
  color: var(--ink);
}
.title-spider {
  color: var(--accent);
  font-size: 44px;
}

.tagline {
  margin-top: 14px;
  font-size: 14px;
  line-height: 1.45;
  color: rgba(246, 239, 227, 0.82);
}

.howto {
  margin: 20px auto 8px;
  text-align: left;
  display: inline-flex;
  flex-direction: column;
  gap: 9px;
}
.howto-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  color: rgba(246, 239, 227, 0.88);
}
.key {
  display: inline-block;
  min-width: 42px;
  text-align: center;
  padding: 3px 8px;
  border-radius: 7px;
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.22);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 1px;
}

.big-btn {
  margin-top: 20px;
  width: 100%;
  padding: 16px;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: 1px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(180deg, var(--accent), #f28f1e);
  color: #2a1a08;
  cursor: pointer;
  box-shadow: 0 6px 0 #a35c0a, 0 10px 24px rgba(0,0,0,0.4);
  transition: transform 0.05s ease, box-shadow 0.05s ease;
}
.big-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #a35c0a, 0 6px 14px rgba(0,0,0,0.4);
}

.hint-small {
  margin-top: 12px;
  font-size: 12.5px;
  color: rgba(246, 239, 227, 0.6);
}

/* Game over */
.over-title {
  font-size: 40px;
  font-weight: 900;
  letter-spacing: 2px;
  color: var(--danger);
}
.over-cause {
  margin-top: 8px;
  font-size: 16px;
  color: rgba(246, 239, 227, 0.9);
}
.over-score {
  margin: 20px auto;
  width: 100%;
  max-width: 260px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.over-score-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 18px;
}
.over-label { color: rgba(246, 239, 227, 0.7); }
.over-num { font-weight: 800; font-size: 26px; }
.over-new {
  color: var(--accent);
  font-weight: 800;
  letter-spacing: 2px;
  animation: newbest 0.7s ease-in-out infinite;
}
@keyframes newbest {
  0%,100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

/* Touch control shown/hidden helpers */
body.is-touch .howto-row .key:first-child { min-width: 44px; }

@media (max-width: 560px) {
  .title { font-size: 32px; }
  .title-spider { font-size: 36px; }
  .score-value { font-size: 24px; }
  .stamina-bar { height: 16px; }
  .mute-btn { width: 42px; height: 42px; }
}
