:root {
  --ui: #f4ead8;
  --ui-dim: #cbb89a;
  --ink: #1a1410;
  --danger: #ff6b4a;
  --ok: #7dcea0;
  --panel: rgba(18, 14, 12, 0.88);
  --stroke: rgba(244, 234, 216, 0.22);
}

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

html, body {
  margin: 0; padding: 0;
  width: 100%; height: 100%;
  overflow: hidden;
  background: #0d0a08;
  color: var(--ui);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  overscroll-behavior: none;
}

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

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #2a221c;
}

.hidden { display: none !important; }

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

#hud-top {
  position: absolute;
  top: max(10px, env(safe-area-inset-top));
  left: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.hud-box {
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 10px;
  padding: 6px 10px;
  min-width: 72px;
  backdrop-filter: blur(6px);
}

.hud-label {
  display: block;
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--ui-dim);
  line-height: 1.1;
}

.hud-value {
  display: block;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1.15;
  color: var(--ui);
}

#best-box { margin-left: 2px; }
#best-box .hud-value { color: var(--ok); }

.hud-btn {
  pointer-events: auto;
  margin-left: auto;
  background: var(--panel);
  color: var(--ui);
  border: 1px solid var(--stroke);
  border-radius: 10px;
  padding: 10px 12px;
  font: 700 11px/1 "Trebuchet MS", system-ui, sans-serif;
  letter-spacing: 0.08em;
  cursor: pointer;
  min-height: 44px;
  min-width: 88px;
  backdrop-filter: blur(6px);
}
.hud-btn:active { transform: scale(0.97); background: rgba(60,48,38,0.9); }
.hud-btn.muted { color: var(--danger); }

/* stamina */
#stamina-wrap {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: max(64px, calc(env(safe-area-inset-top) + 58px));
  width: min(360px, 70vw);
  pointer-events: none;
}

#stamina-bar {
  position: relative;
  height: 18px;
  border-radius: 12px;
  background: rgba(10, 8, 6, 0.75);
  border: 2px solid var(--stroke);
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
}

#stamina-fill {
  position: absolute;
  left: 2px; top: 2px; bottom: 2px;
  width: 100%;
  border-radius: 9px;
  background: linear-gradient(180deg, #b8f06a, #5fbf4a 55%, #3d8f38);
  transition: width 0.08s linear, background 0.15s ease;
}

#stamina-fill.low {
  background: linear-gradient(180deg, #ffd36a, #ff9f3a 55%, #e06a20);
}
#stamina-fill.critical {
  background: linear-gradient(180deg, #ff8a6a, #ff4a32 55%, #c02a18);
  animation: pulse 0.55s ease-in-out infinite alternate;
}

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

#stamina-gloss {
  position: absolute;
  left: 8px; right: 8px; top: 3px;
  height: 5px;
  border-radius: 4px;
  background: linear-gradient(90deg, rgba(255,255,255,0.28), rgba(255,255,255,0.05));
  pointer-events: none;
}

#stamina-label {
  text-align: center;
  margin-top: 3px;
  font-size: 10px;
  letter-spacing: 0.16em;
  color: var(--ui-dim);
  text-shadow: 0 1px 2px rgba(0,0,0,0.7);
}

/* warning */
#warning-banner {
  position: absolute;
  left: 50%;
  top: 18%;
  transform: translate(-50%, -50%);
  padding: 12px 20px;
  border-radius: 14px;
  background: rgba(40, 10, 6, 0.88);
  border: 2px solid var(--danger);
  color: #ffd8c8;
  font-size: clamp(16px, 4.2vw, 24px);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-align: center;
  box-shadow: 0 0 30px rgba(255, 80, 40, 0.35);
  animation: warn-pop 0.45s ease-out;
  max-width: 88vw;
  pointer-events: none;
}
#warning-banner.safe {
  background: rgba(8, 30, 16, 0.82);
  border-color: var(--ok);
  color: #c8f0d8;
  box-shadow: 0 0 30px rgba(80, 200, 120, 0.3);
}
@keyframes warn-pop {
  from { transform: translate(-50%, -50%) scale(0.7); opacity: 0; }
  to   { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

/* ---------- Touch controls ---------- */
#touch-ui {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
}

#stick-base {
  position: absolute;
  left: 22px;
  bottom: max(28px, calc(env(safe-area-inset-bottom) + 16px));
  width: 150px;
  height: 150px;
  border-radius: 50%;
  background: rgba(12, 10, 8, 0.45);
  border: 3px solid rgba(244, 234, 216, 0.35);
  box-shadow: 0 6px 18px rgba(0,0,0,0.4), inset 0 0 20px rgba(0,0,0,0.35);
  pointer-events: auto;
  touch-action: none;
}

#stick-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 62px; height: 62px;
  margin: -31px 0 0 -31px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff5e8, #d8c09a 55%, #a08858);
  border: 2px solid rgba(255,255,255,0.35);
  box-shadow: 0 4px 10px rgba(0,0,0,0.45);
  transition: transform 0.02s linear;
  will-change: transform;
}

#stick-hint {
  position: absolute;
  left: 22px;
  bottom: max(8px, calc(env(safe-area-inset-bottom) + 2px));
  width: 150px;
  text-align: center;
  font-size: 10px;
  letter-spacing: 0.14em;
  color: var(--ui-dim);
  pointer-events: none;
  text-shadow: 0 1px 2px #000;
}

/* ---------- Screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 30%, rgba(40,28,18,0.55), rgba(8,6,5,0.82));
  padding: 16px;
  pointer-events: auto;
}

.panel {
  width: min(440px, 94vw);
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: 22px;
  padding: 26px 22px 22px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.55);
  backdrop-filter: blur(8px);
  max-height: 94vh;
  overflow: auto;
}

.title {
  margin: 0 0 8px;
  font-size: clamp(34px, 9vw, 52px);
  line-height: 0.95;
  letter-spacing: 0.02em;
  color: var(--ui);
  text-shadow: 0 4px 0 rgba(0,0,0,0.35);
}
.title span { color: var(--ok); }
.title.small { font-size: clamp(28px, 7vw, 40px); }

.tagline {
  margin: 0 0 16px;
  color: var(--ui-dim);
  font-size: 15px;
}

.howto {
  list-style: none;
  margin: 0 0 20px;
  padding: 12px 14px;
  text-align: left;
  background: rgba(0,0,0,0.28);
  border-radius: 14px;
  border: 1px solid var(--stroke);
}
.howto li {
  margin: 7px 0;
  font-size: 14px;
  color: var(--ui);
  line-height: 1.3;
}
.howto b { color: var(--ok); }

.big-btn {
  display: inline-block;
  min-width: 200px;
  min-height: 56px;
  padding: 14px 28px;
  font: 800 20px/1 "Trebuchet MS", system-ui, sans-serif;
  letter-spacing: 0.12em;
  color: var(--ink);
  background: linear-gradient(180deg, #d8f58a, #7dcea0 60%, #57a87a);
  border: 0;
  border-radius: 16px;
  cursor: pointer;
  box-shadow: 0 6px 0 #2f6b4a, 0 12px 24px rgba(0,0,0,0.4);
}
.big-btn:active {
  transform: translateY(4px);
  box-shadow: 0 2px 0 #2f6b4a, 0 6px 12px rgba(0,0,0,0.4);
}

.tiny {
  margin: 14px 0 0;
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--ui-dim);
}

.score-recap {
  display: flex;
  justify-content: center;
  gap: 28px;
  margin: 8px 0 12px;
}
.big-score {
  font-size: 34px;
  font-weight: 800;
  color: var(--ui);
  line-height: 1.1;
}

#fade-hint {
  position: absolute;
  left: 50%;
  bottom: 22%;
  transform: translateX(-50%);
  z-index: 6;
  padding: 8px 14px;
  border-radius: 10px;
  background: rgba(10, 8, 6, 0.72);
  border: 1px solid var(--stroke);
  color: var(--ui);
  font-size: clamp(12px, 3vw, 15px);
  letter-spacing: 0.03em;
  pointer-events: none;
  text-align: center;
  max-width: 80vw;
  transition: opacity 0.4s ease;
}
#fade-hint.fade-out { opacity: 0; }

/* small phones: slightly smaller stick so HUD fits */
@media (max-height: 520px) {
  #stick-base { width: 120px; height: 120px; }
  #stick-knob { width: 50px; height: 50px; margin: -25px 0 0 -25px; }
  #stamina-wrap { width: min(280px, 55vw); top: max(52px, calc(env(safe-area-inset-top) + 46px)); }
}

@media (max-width: 380px) {
  .hud-box { min-width: 58px; padding: 5px 7px; }
  .hud-value { font-size: 15px; }
  .hud-btn { min-width: 74px; padding: 8px 8px; font-size: 10px; }
}
