:root {
  --bg: #0f0a1e;
  --panel: #1a1030;
  --panel2: #231540;
  --accent: #ff6b35;
  --accent2: #ffd166;
  --green: #06d6a0;
  --red: #ef233c;
  --trap: #ff0054;
  --text: #f8f4ff;
  --sub: #9d8ec4;
}

*, *::before, *::after {
  margin: 0; padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* Lock entire page to viewport — no scroll ever */
html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

body {
  font-family: 'Nunito', sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  /* position:fixed is the most reliable way to kill scroll on mobile */
  position: fixed;
  inset: 0;
  /* honour notch / home-bar */
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  padding-right: env(safe-area-inset-right, 0px);
}

/* Stars */
.stars { position: fixed; inset: 0; pointer-events: none; z-index: 0; }
.star  {
  position: absolute; border-radius: 50%; background: #fff;
  animation: twinkle var(--d, 3s) infinite var(--delay, 0s);
}
@keyframes twinkle {
  0%, 100% { opacity: .1; transform: scale(1); }
  50%       { opacity: .7; transform: scale(1.5); }
}

/* ── APP SHELL ─────────────────────────────────────── */
#app {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center;
  width: 100%; max-width: 460px;
  /* fill exactly the visible area between safe-area padding */
  height: 100%;
  /* compact but breathable gaps */
  padding: 4px 7px 4px;
  gap: 4px;
  overflow: hidden;
}

/* ── TOP BAR ──────────────────────────────────────── */
.topbar {
  width: 100%; display: flex; align-items: center;
  gap: 5px; flex-shrink: 0;
}
.topbar-scores { display: flex; gap: 4px; flex: 1; min-width: 0; }
.score-pill {
  flex: 1; min-width: 0;
  background: var(--panel); border-radius: 10px; padding: 3px 6px;
  display: flex; flex-direction: column; align-items: center;
  border: 1px solid rgba(255,255,255,.07);
}
.score-pill .label {
  font-size: 7px; color: var(--sub);
  text-transform: uppercase; letter-spacing: .8px; font-weight: 800;
}
.score-pill .val {
  font-family: 'Fredoka One', cursive; font-size: 15px;
  color: var(--text); line-height: 1.1;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%;
}
.score-pill.accent .val { color: var(--accent2); }
.score-pill.green  .val { color: var(--green); }

.topbar-btns { display: flex; gap: 4px; flex-shrink: 0; }
.icon-btn {
  width: 32px; height: 32px; flex-shrink: 0; border: none;
  border-radius: 9px; background: var(--panel); color: var(--text);
  font-size: 14px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid rgba(255,255,255,.07);
  transition: transform .15s, background .15s;
}
.icon-btn:active { transform: scale(.88); }
/* Fullscreen button gets a subtle highlight */
#fullscreen-btn { color: var(--accent2); font-size: 16px; }

/* ── GOAL BANNER ─────────────────────────────────── */
.goal-banner {
  width: 100%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--panel2), var(--panel));
  border-radius: 10px; padding: 5px 10px;
  display: flex; align-items: center; gap: 7px;
  border: 1px solid rgba(255,209,102,.18);
  position: relative; overflow: hidden;
}
.goal-banner::before {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,209,102,.04), transparent);
  animation: sweep 3s infinite;
}
@keyframes sweep { 0% { transform: translateX(-100%); } 100% { transform: translateX(200%); } }
.goal-info { display: flex; flex-direction: column; gap: 0; }
.goal-label { font-size: 7px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--sub); font-weight: 800; }
.goal-text  { font-size: 11px; font-weight: 800; color: var(--accent2); line-height: 1.2; }
.goal-progress-wrap { flex: 1; max-width: 110px; }
.goal-bar-bg   { height: 6px; background: rgba(255,255,255,.1); border-radius: 3px; overflow: hidden; }
.goal-bar-fill { height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); border-radius: 3px; transition: width .4s cubic-bezier(.34,1.56,.64,1); }
.goal-pct      { font-size: 8px; color: var(--sub); text-align: right; margin-top: 1px; font-weight: 700; }
.level-badge {
  background: var(--accent); border-radius: 7px; padding: 2px 6px;
  font-family: 'Fredoka One', cursive; font-size: 12px; color: #fff; white-space: nowrap;
}

/* ── NEXT FRUIT ──────────────────────────────────── */
.next-row {
  width: 100%; flex-shrink: 0;
  display: flex; align-items: center; gap: 7px;
  background: var(--panel); border-radius: 10px; padding: 4px 10px;
  border: 1px solid rgba(255,255,255,.07);
}
.next-label { font-size: 8px; text-transform: uppercase; letter-spacing: .8px; color: var(--sub); font-weight: 800; }
#next-icon  { font-size: 22px; line-height: 1; animation: bob 2s infinite ease-in-out; }
@keyframes bob { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-3px); } }
.trap-warning {
  flex: 1; background: rgba(255,0,84,.15); border: 1px solid rgba(255,0,84,.3);
  border-radius: 7px; padding: 2px 6px; font-size: 9px; font-weight: 800; color: var(--trap);
  display: none; animation: warningPulse 1s infinite;
}
.trap-warning.show { display: block; }
@keyframes warningPulse { 0%,100% { opacity: 1; } 50% { opacity: .4; } }
.drop-hint { flex: 1; text-align: right; font-size: 8px; color: var(--sub); font-weight: 700; }

/* ── CANVAS — the star of the show ──────────────── */
.canvas-wrap {
  position: relative;
  flex: 1 1 0%;   /* grow to fill ALL remaining space */
  min-height: 0;  /* let flexbox shrink it; critical */
  width: 100%;
  border-radius: 14px; overflow: hidden;
  border: 2px solid rgba(255,255,255,.08);
  box-shadow: 0 0 30px rgba(124,45,139,.3), inset 0 0 16px rgba(0,0,0,.3);
}
#game-canvas {
  display: block; width: 100%; height: 100%;
  cursor: crosshair; touch-action: none;
}
.cursor-line {
  position: absolute; top: 0; bottom: 0; width: 2px; pointer-events: none;
  background: linear-gradient(180deg, rgba(255,209,102,.8), transparent 80%);
  transform: translateX(-50%); transition: left .05s; display: none;
}
.cursor-line.show { display: block; }
.danger-flash {
  position: absolute; inset: 0; pointer-events: none;
  background: rgba(239,35,60,0); transition: background .2s; border-radius: 14px;
}
.danger-flash.active { background: rgba(239,35,60,.12); }

/* ── BOTTOM CONTROLS ─────────────────────────────── */
.bottom-ctrl {
  width: 100%; display: flex; gap: 5px; flex-shrink: 0;
}
.ctrl-btn {
  flex: 1; height: 34px; border: none; border-radius: 10px;
  font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 11px; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 3px;
  transition: transform .13s;
  border: 1px solid rgba(255,255,255,.1);
}
.ctrl-btn:active { transform: scale(.92); }
.ctrl-btn.restart { background: linear-gradient(135deg, #ef233c, #c9184a); color: #fff; }
.ctrl-btn.pause   { background: linear-gradient(135deg, #4cc9f0, #4361ee); color: #fff; }
.ctrl-btn.mute    { background: linear-gradient(135deg, var(--panel2), var(--panel)); color: var(--sub); }

/* ── MODALS ──────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,.85); backdrop-filter: blur(6px);
  display: none; flex-direction: column;
  align-items: center; justify-content: center; padding: 14px;
}
.modal-overlay.show { display: flex; }
.modal {
  background: var(--panel); border-radius: 22px; padding: 22px 18px;
  width: 100%; max-width: 340px; text-align: center;
  border: 1px solid rgba(255,255,255,.1);
  box-shadow: 0 0 50px rgba(124,45,139,.4);
  animation: popIn .28s cubic-bezier(.34,1.56,.64,1);
}
@keyframes popIn { from { transform: scale(.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal h2   { font-family: 'Fredoka One', cursive; font-size: 1.8rem; color: var(--text); margin-bottom: 3px; }
.modal .sub { color: var(--sub); font-size: 12px; margin-bottom: 14px; }
.modal-stats {
  background: var(--panel2); border-radius: 13px; padding: 12px; margin: 12px 0;
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.stat-item  { display: flex; flex-direction: column; gap: 1px; }
.stat-label { font-size: 8px; text-transform: uppercase; letter-spacing: 1px; color: var(--sub); font-weight: 800; }
.stat-val   { font-family: 'Fredoka One', cursive; font-size: 19px; color: var(--text); }
.modal-btns { display: flex; gap: 9px; justify-content: center; flex-wrap: wrap; }
.modal-btn  {
  padding: 10px 20px; border: none; border-radius: 12px;
  font-family: 'Nunito', sans-serif; font-weight: 800; font-size: 13px; cursor: pointer;
  transition: transform .13s;
}
.modal-btn:active { transform: scale(.94); }
.modal-btn.primary   { background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; box-shadow: 0 5px 18px rgba(255,107,53,.3); }
.modal-btn.secondary { background: var(--panel2); color: var(--sub); border: 1px solid rgba(255,255,255,.1); }

.level-complete-badge { font-size: 3.2rem; margin-bottom: 4px; animation: spinIn 1s ease-in-out; }
@keyframes spinIn { from { transform: rotate(-20deg) scale(.5); } to { transform: rotate(0) scale(1); } }
.stars-rating { display: flex; justify-content: center; gap: 6px; font-size: 2rem; margin: 6px 0; }

/* Float texts */
.float-text { position: absolute; pointer-events: none; font-family: 'Fredoka One', cursive; font-size: 18px; font-weight: 900; z-index: 50; animation: floatUp 1s forwards; }
@keyframes floatUp { 0% { opacity: 1; transform: translateY(0) scale(1); } 100% { opacity: 0; transform: translateY(-55px) scale(1.3); } }

/* Trap shake */
@keyframes shake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-8px)} 40%{transform:translateX(8px)} 60%{transform:translateX(-5px)} 80%{transform:translateX(5px)} }
.shake { animation: shake .38s ease; }

/* Combo display */
.combo-display {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);
  font-family: 'Fredoka One', cursive; font-size: 2.6rem; color: var(--accent2);
  pointer-events: none; z-index: 40; display: none;
  text-shadow: 0 0 18px var(--accent);
}
@keyframes comboPop {
  0%   { transform: translate(-50%,-50%) scale(0);   opacity: 0; }
  40%  { transform: translate(-50%,-50%) scale(1.3); opacity: 1; }
  70%  { transform: translate(-50%,-50%) scale(.9);  opacity: 1; }
  100% { transform: translate(-50%,-50%) scale(1);   opacity: 0; }
}

/* Score pulse */
@keyframes scorePulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.18); } }
.pulse { animation: scorePulse .28s ease; }


/* When truly fullscreen via API, shrink safe-area paddings to 0 */
:fullscreen body,
:-webkit-full-screen body {
  padding: 0 !important;
}
