:root {
  --bg: #07110b;
  --panel: rgba(7, 17, 11, 0.78);
  --panel-border: rgba(194, 255, 154, 0.22);
  --green: #78e04a;
  --green-2: #d6ff8f;
  --lime: #a7ff68;
  --text: #f4fff0;
  --muted: rgba(240, 255, 235, 0.68);
  --danger: #ff6c58;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: var(--bg); }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: auto;
}
button { font: inherit; touch-action: manipulation; }
#app, #game-container { position: fixed; inset: 0; }
#game-container { touch-action: none; }
#game-container canvas { display: block; width: 100%; height: 100%; touch-action: none; }

body.jungle-theme {
  background:
    radial-gradient(circle at top, rgba(89, 156, 68, .18), transparent 34%),
    linear-gradient(180deg, #14361d 0%, #08110b 62%, #050a07 100%);
}

.hud {
  position: fixed;
  z-index: 20;
  pointer-events: none;
}
.hud-top {
  top: max(16px, env(safe-area-inset-top));
  left: max(16px, env(safe-area-inset-left));
  right: max(16px, env(safe-area-inset-right));
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  gap: 16px;
}
.brand {
  display: flex;
  align-items: flex-start;
  min-height: 54px;
  filter: drop-shadow(0 10px 22px rgba(0,0,0,.34));
}
.brand-logo {
  width: clamp(82px, 8vw, 118px);
  height: auto;
  display: block;
  object-fit: contain;
}
.stats { display: flex; gap: 8px; justify-content: center; }
.stat-card {
  min-width: 92px;
  padding: 9px 13px 10px;
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(5, 15, 9, .58);
  backdrop-filter: blur(16px) saturate(1.2);
  border-radius: 16px;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 12px 35px rgba(0,0,0,.18);
  text-align: center;
}
.stat-label { display: block; font-size: 9px; letter-spacing: .18em; color: var(--muted); font-weight: 800; }
.stat-card strong { display: block; margin-top: 2px; font-size: 22px; line-height: 1; font-variant-numeric: tabular-nums; }
.actions { justify-self: end; display: flex; gap: 8px; pointer-events: auto; }
.icon-btn {
  width: 44px; height: 44px; border: 1px solid rgba(255,255,255,.12); border-radius: 14px;
  color: white; background: rgba(5,15,9,.58); backdrop-filter: blur(14px);
  cursor: pointer; box-shadow: inset 0 1px 0 rgba(255,255,255,.08), 0 10px 28px rgba(0,0,0,.2);
}
.icon-btn:active { transform: translateY(1px) scale(.98); }

.fruit-indicator {
  position: fixed; z-index: 20; left: 50%; bottom: 22px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; pointer-events: none;
  padding: 7px 12px 7px 9px; border: 1px solid rgba(255,255,255,.12); border-radius: 999px;
  background: rgba(5,15,9,.52); backdrop-filter: blur(12px); color: rgba(255,255,255,.78);
  font-size: 12px; font-weight: 750; box-shadow: 0 10px 26px rgba(0,0,0,.2);
}
#fruit-emoji { font-size: 20px; }

.overlay {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center;
  padding: 24px; opacity: 0; pointer-events: none; transition: opacity .24s ease;
  background: radial-gradient(circle at 50% 42%, rgba(18, 49, 24, .18), rgba(2, 8, 4, .58));
  backdrop-filter: blur(2px);
}
.overlay.visible { opacity: 1; pointer-events: auto; }
.panel {
  width: min(620px, 92vw); padding: 34px; border-radius: 28px;
  border: 1px solid var(--panel-border);
  background: linear-gradient(145deg, rgba(12,29,17,.90), rgba(4,12,7,.86));
  box-shadow: inset 0 1px 0 rgba(255,255,255,.10), 0 30px 100px rgba(0,0,0,.48);
  text-align: center;
}
.kicker { color: var(--green-2); letter-spacing: .18em; font-size: 11px; font-weight: 900; }
.hero-logo {
  width: min(285px, 44vw);
  max-width: 100%;
  height: auto;
  margin: 6px auto 2px;
  display: block;
  object-fit: contain;
  filter: drop-shadow(0 16px 28px rgba(0,0,0,.34));
}
.intro { max-width: 560px; margin: 0 auto 14px; color: var(--muted); line-height: 1.55; font-size: 14px; }

.premium-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 4px auto 12px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.14);
  background: linear-gradient(180deg, rgba(255,238,150,.18), rgba(134,184,67,.16));
  color: #fff0a3;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .18em;
}
.premium-options {
  margin: 4px 0 14px;
  display: grid;
  gap: 12px;
}
.option-group {
  padding: 14px;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.04);
}
.option-title {
  margin-bottom: 10px;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .18em;
  color: var(--green-2);
  text-transform: uppercase;
}
.skin-picker {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}
.skin-btn {
  min-height: 40px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(8, 20, 12, .72);
  color: rgba(255,255,255,.85);
  cursor: pointer;
  font-weight: 800;
  letter-spacing: .02em;
}
.skin-btn.active {
  color: #091209;
  background: linear-gradient(180deg, #dcffb6, #74d945 60%, #58b72f);
  border-color: rgba(255,255,255,.28);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.45), 0 5px 18px rgba(71,167,45,.22);
}
.premium-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.premium-list span {
  display: block;
  padding: 11px 12px;
  border-radius: 14px;
  background: rgba(255,255,255,.035);
  border: 1px solid rgba(255,255,255,.07);
  color: rgba(255,255,255,.8);
  font-size: 12px;
  font-weight: 760;
}

.controls-guide { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0 14px; }
.guide {
  display: flex; align-items: center; justify-content: center; gap: 13px; min-height: 86px;
  padding: 13px; border-radius: 18px; border: 1px solid rgba(255,255,255,.08); background: rgba(255,255,255,.035);
  text-align: left;
}
.guide strong { display: block; font-size: 13px; }
.guide small { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.key-grid { display: grid; grid-template-columns: repeat(3, 24px); gap: 3px; }
kbd {
  height: 24px; display: grid; place-items: center; border-radius: 6px; color: #dfffd1;
  background: linear-gradient(#203225,#101b13); border: 1px solid rgba(255,255,255,.13);
  box-shadow: 0 2px 0 #050a06; font-size: 11px;
}
.mini-stick { width: 54px; height: 54px; border-radius: 50%; border: 1px solid rgba(255,255,255,.12); background: rgba(255,255,255,.04); position: relative; }
.mini-stick::before, .mini-stick::after { content:""; position:absolute; background: rgba(255,255,255,.12); }
.mini-stick::before { width: 1px; height: 34px; left: 50%; top: 10px; }
.mini-stick::after { height: 1px; width: 34px; top: 50%; left: 10px; }
.mini-stick span { position: absolute; width: 24px; height: 24px; left: 19px; top: 15px; border-radius: 50%; background: linear-gradient(145deg,#a8ff72,#397d28); box-shadow: 0 5px 12px rgba(0,0,0,.35); }
.primary-btn, .secondary-btn {
  width: min(330px, 100%); min-height: 54px; border-radius: 16px; cursor: pointer; font-weight: 950; letter-spacing: .06em;
}
.primary-btn {
  border: 1px solid rgba(255,255,255,.25); color: #0a170c;
  background: linear-gradient(180deg, #c7ff95, #68d63e 54%, #49ad2d);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.55), 0 8px 0 #235b18, 0 16px 34px rgba(37,141,36,.25);
}
.primary-btn:hover { filter: brightness(1.07); }
.primary-btn:active { transform: translateY(5px); box-shadow: inset 0 1px 0 rgba(255,255,255,.5), 0 3px 0 #235b18, 0 10px 22px rgba(37,141,36,.2); }
.secondary-btn {
  margin-top: 12px; border: 1px solid rgba(255,255,255,.12); color: white; background: rgba(255,255,255,.055);
}
.microcopy { margin: 16px 0 0; font-size: 11px; color: rgba(255,255,255,.44); }
.compact-panel { width: min(420px, 92vw); }
.compact-panel h2 { margin: 8px 0 8px; font-size: 42px; letter-spacing: -.04em; }
.compact-panel p { color: var(--muted); margin: 0 0 22px; }
.final-score { display: flex; align-items: end; justify-content: center; gap: 10px; margin: 12px 0 16px; }
.final-score span { color: var(--muted); font-size: 13px; padding-bottom: 8px; }
.final-score strong { font-size: 54px; line-height: 1; }
.new-record { display: none; margin: -4px auto 20px; color: #f5e487; font-size: 12px; font-weight: 950; letter-spacing: .16em; }
.new-record.visible { display: block; }

.mobile-controls {
  position: fixed;
  z-index: 38;
  left: max(16px, env(safe-area-inset-left));
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + var(--mobile-vv-bottom, 0px));
  display: none;
  pointer-events: none;
}
.joystick {
  position: relative; width: 132px; height: 132px; border-radius: 50%; pointer-events: auto; touch-action: none;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  background: radial-gradient(circle, rgba(255,255,255,.06) 0 18%, rgba(255,255,255,.025) 19% 47%, rgba(255,255,255,.055) 48% 50%, rgba(0,0,0,.12) 51%);
  border: 1px solid rgba(255,255,255,.12); box-shadow: inset 0 0 35px rgba(0,0,0,.22), 0 12px 30px rgba(0,0,0,.18);
  backdrop-filter: blur(8px);
}
.joystick-rings::before, .joystick-rings::after { content:""; position:absolute; background:rgba(255,255,255,.10); pointer-events:none; }
.joystick-rings::before { width:1px; height:84px; left:50%; top:21px; }
.joystick-rings::after { height:1px; width:84px; top:50%; left:21px; }
.joystick-knob {
  position:absolute; left:50%; top:50%; width:52px; height:52px; margin:-26px; border-radius:50%;
  background: linear-gradient(145deg, rgba(203,255,166,.95), rgba(75,166,48,.95));
  border:1px solid rgba(255,255,255,.38); box-shadow: inset 0 2px 7px rgba(255,255,255,.35), 0 8px 18px rgba(0,0,0,.42);
  transform: translate(0,0); transition: transform .08s ease-out;
}
.joystick.active .joystick-knob { transition: none; }
.desktop-hint { position: fixed; z-index: 18; right: 22px; bottom: 20px; color: rgba(255,255,255,.32); font-size: 9px; letter-spacing: .14em; font-weight: 800; pointer-events: none; }
.orientation-hint {
  display: none; position: fixed; z-index: 45; left: 50%; top: max(112px, calc(env(safe-area-inset-top) + 92px));
  transform: translateX(-50%); max-width: min(340px, 88vw); padding: 10px 14px; border-radius: 14px;
  background: rgba(4,12,7,.86); border: 1px solid rgba(255,255,255,.12); text-align:center; font-size: 12px; line-height:1.35;
  pointer-events: none; opacity: .88;
}

@media (pointer: coarse), (max-width: 760px) {
  body.game-active .mobile-controls { display: block; }
  .mobile-controls { display: none; }
  .desktop-hint { display: none; }
  .hud-top { grid-template-columns: 1fr auto; align-items: start; }
  .stats { grid-row: 2; grid-column: 1 / -1; justify-self: center; margin-top: -4px; }
  .actions { grid-column: 2; grid-row: 1; }
  .stat-card { min-width: 74px; padding: 7px 9px 8px; border-radius: 13px; }
  .stat-card strong { font-size: 18px; }
  .speed-card { display: none; }
  .fruit-indicator { left: auto; right: max(18px, env(safe-area-inset-right)); bottom: max(24px, env(safe-area-inset-bottom)); transform: none; }
}

@media (max-width: 560px) {
  .overlay { padding: max(8px, env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom)); }
  .panel { padding: 16px 14px; border-radius: 22px; }
  .start-panel { width: min(96vw, 620px); }
  .hero-logo { width: min(190px, 55vw); }
  .brand-logo { width: 72px; }
  .controls-guide { grid-template-columns: 1fr; }
  .desktop-guide { display: none; }
  .guide { min-height: 72px; }
  .premium-list { grid-template-columns: 1fr; }
  .skin-picker { flex-direction: column; }
  .skin-btn { width: 100%; }
  .brand { font-size: 25px; }
  .icon-btn { width: 40px; height: 40px; border-radius: 12px; }
}

@media (pointer: coarse) and (orientation: portrait) and (max-height: 900px) {
  .orientation-hint.show { display: block; }
}

.start-panel {
  width: min(740px, 94vw);
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(167,255,104,.35) transparent;
  background:
    radial-gradient(circle at top, rgba(121, 202, 90, .16), transparent 30%),
    linear-gradient(145deg, rgba(12,29,17,.94), rgba(4,12,7,.90));
}
.start-panel::-webkit-scrollbar { width: 7px; }
.start-panel::-webkit-scrollbar-thumb { background: rgba(167,255,104,.28); border-radius: 999px; }
.panel::before {
  content: "";
  position: absolute;
  inset: 1px;
  border-radius: 27px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255,255,255,.05), rgba(255,255,255,0) 22%);
}
.panel { position: relative; overflow: hidden; }
.intro strong { color: var(--green-2); }

@media (min-width: 761px) and (max-height: 850px) {
  .start-panel { padding: 22px 28px; }
  .hero-logo { width: 215px; }
  .intro { font-size: 13px; margin-bottom: 10px; }
  .controls-guide { margin: 8px 0 10px; }
  .guide { min-height: 70px; padding: 9px 12px; }
  .premium-options { gap: 8px; margin-bottom: 10px; }
  .option-group { padding: 10px; }
  .premium-list span { padding: 8px 10px; font-size: 11px; }
  .primary-btn { min-height: 48px; }
  .microcopy { margin-top: 10px; }
}


/* Mobile launch & joystick reliability patch */
.start-panel {
  overflow-x: hidden !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
}
.start-panel button, .start-panel .skin-picker { touch-action: manipulation; }

@media (pointer: coarse), (max-width: 760px) {
  .joystick {
    width: 132px;
    height: 132px;
    background: radial-gradient(circle, rgba(200,255,168,.14) 0 18%, rgba(255,255,255,.05) 19% 47%, rgba(167,255,104,.18) 48% 50%, rgba(0,0,0,.22) 51%);
    border-color: rgba(198,255,165,.28);
    box-shadow: inset 0 0 38px rgba(0,0,0,.28), 0 12px 36px rgba(0,0,0,.34), 0 0 0 5px rgba(116,224,74,.055);
  }
  .joystick::after {
    content: "JOYSTICK";
    position: absolute;
    left: 50%;
    bottom: -22px;
    transform: translateX(-50%);
    color: rgba(230,255,216,.62);
    font-size: 9px;
    font-weight: 900;
    letter-spacing: .14em;
    pointer-events: none;
  }
  body.game-active .fruit-indicator { bottom: calc(max(20px, env(safe-area-inset-bottom)) + var(--mobile-vv-bottom, 0px)); }
}

@media (max-width: 560px) and (orientation: portrait) {
  .start-panel {
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
  }
  .controls-guide { margin: 8px 0 10px; }
  .guide { min-height: 62px; padding: 9px 10px; }
  .premium-options { gap: 8px; margin-bottom: 10px; }
  .option-group { padding: 10px; }
  .premium-list { gap: 6px; }
  .premium-list span { padding: 7px 9px; font-size: 10.5px; }
  .microcopy { margin-top: 10px; }
  .primary-btn { min-height: 50px; }
}

@media (max-height: 620px) and (pointer: coarse) {
  .orientation-hint.show { display: none; }
  .mobile-controls { left: max(12px, env(safe-area-inset-left)); bottom: calc(max(12px, env(safe-area-inset-bottom)) + var(--mobile-vv-bottom, 0px)); }
  .joystick { width: 112px; height: 112px; }
  .joystick-rings::before { height: 72px; top: 20px; }
  .joystick-rings::after { width: 72px; left: 20px; }
}

@media (max-width: 560px) {
  .skin-picker { flex-direction: row; gap: 6px; }
  .skin-btn { width: auto; flex: 1 1 0; padding-left: 7px; padding-right: 7px; font-size: 10.5px; }
  .premium-list { grid-template-columns: 1fr 1fr; }
}
