* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden;
  background: #1a1830; color: #fff;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent; touch-action: none; overscroll-behavior: none;
}
body { position: fixed; inset: 0; }
#game { position: fixed; inset: 0; overflow: hidden; }
#cv { position: absolute; left: 0; top: 0; width: 100%; height: 100%; display: block; z-index: 0; }
#touch { position: absolute; inset: 0; z-index: 1; touch-action: none; }
#safeProbe { position: absolute; left: 0; bottom: 0; width: 1px; height: 1px; padding-bottom: env(safe-area-inset-bottom, 0px); padding-top: env(safe-area-inset-top, 0px); pointer-events: none; visibility: hidden; }

/* ---------- joystick ---------- */
#joy { position: absolute; left: 0; top: 0; width: 128px; height: 128px; z-index: 2; pointer-events: none; display: none; will-change: transform; }
#joy.show { display: block; }
#joyRing { position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,0.06) 0%, rgba(255,255,255,0.14) 62%, rgba(255,255,255,0.22) 100%);
  border: 3px solid rgba(255,255,255,0.55); box-shadow: 0 0 0 2px rgba(0,0,0,0.35), 0 4px 18px rgba(0,0,0,0.35); }
#joyArrows { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center;
  font-size: 13px; line-height: 1.55; color: rgba(255,255,255,0.55); }
#knob { position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff 0%, #e8e1f5 40%, #b3a4cf 100%);
  border: 3px solid rgba(40,30,60,0.8); box-shadow: 0 3px 10px rgba(0,0,0,0.5); transform: translate(-50%,-50%); }
#joy.active #joyRing { border-color: rgba(255,255,255,0.85); }
#joy.scurry #knob { background: radial-gradient(circle at 35% 30%, #fff 0%, #ffd27a 45%, #f08a3c 100%); }
#joy.scurry #joyRing { border-color: #ffb45a; }

/* ---------- HUD ---------- */
#hud { position: absolute; left: 0; right: 0; top: 0; z-index: 3; pointer-events: none;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) calc(env(safe-area-inset-right, 0px) + 10px) 0 calc(env(safe-area-inset-left, 0px) + 10px);
  transition: opacity .3s; }
#hud.hide { opacity: 0; }
#scoreBox { min-width: 82px; text-shadow: 0 2px 0 rgba(0,0,0,0.5); }
.lbl { font-size: 10px; letter-spacing: 2px; opacity: .75; font-weight: bold; }
#score { font-size: 30px; font-weight: 900; line-height: 1; }
#score small { font-size: 14px; margin-left: 2px; opacity: .8; }
#score.bump { animation: bump .35s; }
#best { font-size: 11px; opacity: .8; margin-top: 2px; font-weight: bold; }
@keyframes bump { 0%{transform:scale(1)} 40%{transform:scale(1.25); color:#ffe27a} 100%{transform:scale(1)} }

#midBox { flex: 1; max-width: 340px; display: flex; flex-direction: column; align-items: stretch; gap: 6px; margin-top: 4px; }
#stamWrap { position: relative; height: 20px; border-radius: 12px; background: rgba(10,6,20,0.7); border: 2px solid rgba(255,255,255,0.8);
  overflow: hidden; box-shadow: 0 2px 8px rgba(0,0,0,0.4); }
#stamGhost, #stamFill { position: absolute; left: 0; top: 0; bottom: 0; width: 100%; transform-origin: left center; }
#stamGhost { background: #fff; opacity: .45; }
#stamFill { background: linear-gradient(180deg, #9ef07a, #4fbf3a); }
#stamFill.mid { background: linear-gradient(180deg, #ffe27a, #e8b12a); }
#stamFill.low { background: linear-gradient(180deg, #ff8a7a, #e03a3a); }
#stamWrap.low { animation: pulse .5s infinite alternate; border-color: #ff6a6a; }
#stamWrap.gain { box-shadow: 0 0 16px 4px #ffe27a; border-color: #ffe27a; }
#stamLbl { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 900; letter-spacing: 2px;
  color: rgba(0,0,0,0.6); text-shadow: 0 1px 0 rgba(255,255,255,0.3); }
@keyframes pulse { from { transform: scale(1); } to { transform: scale(1.04); } }
#stormRow { display: flex; align-items: center; gap: 6px; }
#cloudIco { width: 22px; height: 15px; color: #c9c6dc; flex: none; }
#stormBar { flex: 1; height: 7px; border-radius: 4px; background: rgba(10,6,20,0.6); overflow: hidden; border: 1px solid rgba(255,255,255,0.35); }
#stormFill { height: 100%; width: 0%; background: #8f8aa8; transform-origin: left; }
#stormRow.warn #cloudIco { color: #ff6060; animation: pulse .25s infinite alternate; }
#stormRow.warn #stormFill { background: #ff5050; }
#stormRow.rain #cloudIco { color: #7ab8ff; }
#stormRow.rain #stormFill { background: #6aa8ff; }
#surface { font-size: 11px; font-weight: bold; text-align: center; min-height: 14px; letter-spacing: 1px; text-shadow: 0 1px 2px #000; transition: opacity .2s; }
#surface.slick { color: #9fdcff; } #surface.moss { color: #b6e88a; } #surface.ivy { color: #8fe08f; }

#btns { display: flex; gap: 8px; pointer-events: auto; }
.hbtn { width: 44px; height: 44px; border-radius: 12px; border: 2px solid rgba(255,255,255,0.7); background: rgba(20,14,36,0.75); color: #fff;
  display: flex; align-items: center; justify-content: center; padding: 0; cursor: pointer; touch-action: manipulation; }
.hbtn svg { width: 24px; height: 24px; }
.hbtn:active { transform: scale(0.92); }

/* ---------- banners & tips ---------- */
#banner { position: absolute; left: 0; right: 0; top: calc(env(safe-area-inset-top, 0px) + max(100px, 13%)); z-index: 3; text-align: center; pointer-events: none; opacity: 0; transition: opacity .2s; }
#banner.show { opacity: 1; }
#bannerMain { font-size: clamp(26px, 8vw, 50px); font-weight: 900; letter-spacing: 2px; text-shadow: 0 4px 0 rgba(0,0,0,0.45), 0 0 24px rgba(0,0,0,0.5); }
#bannerSub { font-size: clamp(14px, 4vw, 20px); font-weight: bold; margin-top: 4px; text-shadow: 0 2px 4px #000; }
#banner.warn #bannerMain { color: #ff5a4a; animation: shake .12s infinite; }
#banner.rain #bannerMain { color: #8cc4ff; }
#banner.safe #bannerMain { color: #8ff08a; }
#banner.gold #bannerMain { color: #ffd65a; animation: bump .5s; }
@keyframes shake { 0%{transform:translateX(-2px)} 50%{transform:translateX(2px)} 100%{transform:translateX(-2px)} }
#tip { position: absolute; left: 50%; bottom: 190px; z-index: 3; transform: translateX(-50%); max-width: min(92vw, 460px); width: max-content;
  background: rgba(15,10,30,0.85); border: 2px solid rgba(255,255,255,0.5); border-radius: 14px; padding: 8px 14px; font-size: 15px; text-align: center;
  pointer-events: none; opacity: 0; transition: opacity .3s; }
#tip.show { opacity: 1; }
#tip b { color: #ffe27a; }

/* ---------- overlays ---------- */
.overlay { position: absolute; inset: 0; z-index: 5; display: flex; align-items: flex-start; justify-content: center;
  padding: calc(env(safe-area-inset-top, 0px) + 5vh) 14px 14px; background: rgba(12,8,26,0.55); overflow-y: auto; touch-action: pan-y; }
.overlay.hidden { display: none; }
#title { cursor: pointer; }
.panel { width: min(94vw, 460px); background: linear-gradient(180deg, rgba(48,34,72,0.96), rgba(28,20,46,0.96)); border: 3px solid rgba(255,255,255,0.75);
  border-radius: 22px; padding: 18px 18px 16px; text-align: center; box-shadow: 0 12px 40px rgba(0,0,0,0.6); animation: pop .35s ease-out; }
.panel.small { width: min(80vw, 300px); }
@keyframes pop { from { transform: scale(0.85); opacity: 0; } to { transform: scale(1); opacity: 1; } }
h1 { margin: 0; font-size: clamp(32px, 10vw, 48px); line-height: 0.95; font-weight: 900; color: #ffe9b8; text-shadow: 0 4px 0 #6b3b2f; }
h1 span { display: block; font-size: 0.6em; color: #f2a65a; }
h2 { margin: 0 0 4px; font-size: clamp(28px, 8vw, 40px); font-weight: 900; color: #ffd0a0; text-shadow: 0 3px 0 #5a2f2a; }
.tag { margin: 6px 0 10px; opacity: .85; font-size: 15px; }
.how { list-style: none; margin: 0 0 12px; padding: 0; text-align: left; }
.how li { display: flex; align-items: center; gap: 12px; padding: 7px 4px; font-size: 14.5px; line-height: 1.3; border-bottom: 1px dashed rgba(255,255,255,0.15); }
.how li:last-child { border-bottom: 0; }
.how b { color: #ffe27a; }
.how em { color: #ffb45a; font-style: normal; font-weight: bold; }
kbd { display: inline-block; min-width: 18px; padding: 0 4px; margin: 0 1px; border-radius: 4px; background: #eee; color: #222; font: bold 11px/17px monospace; text-align: center; box-shadow: 0 2px 0 #888; }
.ico { flex: none; width: 40px; height: 40px; border-radius: 12px; background: rgba(0,0,0,0.3); position: relative; }
.ico-move::before { content: ""; position: absolute; left: 7px; top: 7px; width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; }
.ico-move::after { content: ""; position: absolute; left: 14px; top: 11px; width: 12px; height: 12px; border-radius: 50%; background: #d8cff0; }
.ico-stam::before { content: ""; position: absolute; left: 5px; top: 15px; width: 30px; height: 10px; border-radius: 5px; border: 2px solid #fff; }
.ico-stam::after { content: ""; position: absolute; left: 8px; top: 18px; width: 14px; height: 4px; border-radius: 2px; background: #7de05a; }
.ico-fly::before { content: ""; position: absolute; left: 15px; top: 16px; width: 11px; height: 9px; border-radius: 50%; background: #222; box-shadow: 0 0 10px 4px rgba(255,230,120,0.55); }
.ico-fly::after { content: ""; position: absolute; left: 10px; top: 10px; width: 20px; height: 8px; border-radius: 50%; background: rgba(230,240,255,0.7); }
.ico-hole::before { content: ""; position: absolute; left: 8px; top: 12px; width: 24px; height: 20px; border-radius: 50%; background: radial-gradient(#000 40%, #3a1f1f 75%); border: 3px solid #7a4a3e; }
.ico-hole::after { content: ""; position: absolute; left: 6px; top: 2px; width: 28px; height: 8px; background: repeating-linear-gradient(100deg, transparent 0 4px, #8cc4ff 4px 5.5px); }
button.big { font: inherit; font-size: 20px; font-weight: 900; letter-spacing: 1px; color: #2a1a10; background: linear-gradient(180deg, #ffe08a, #f2a65a);
  border: 3px solid #fff; border-radius: 16px; padding: 12px 28px; margin-top: 6px; cursor: pointer; box-shadow: 0 5px 0 #8a4a2a, 0 8px 20px rgba(0,0,0,0.4);
  touch-action: manipulation; min-height: 52px; }
button.big:active { transform: translateY(3px); box-shadow: 0 2px 0 #8a4a2a; }
.sub { margin-top: 10px; font-size: 13px; opacity: .8; }
.bigscore { font-size: 46px; font-weight: 900; color: #fff; margin: 4px 0; text-shadow: 0 3px 0 rgba(0,0,0,0.4); }
.newbest { color: #ffd65a; font-weight: 900; font-size: 20px; animation: bump .6s infinite alternate; }
.newbest.hidden { display: none; }
.stats { display: flex; justify-content: center; gap: 16px; margin: 8px 0 6px; font-size: 14px; opacity: .9; flex-wrap: wrap; }
.stats b { color: #ffe27a; font-size: 18px; display: block; }

@media (max-height: 560px) {
  .overlay { padding-top: 8px; }
  .how li { padding: 3px 4px; font-size: 13px; }
  .ico { width: 30px; height: 30px; transform: scale(0.8); }
  h1 { font-size: 30px; }
  .panel { padding: 10px 14px; }
  button.big { padding: 8px 22px; min-height: 44px; }
}
