/* ============================================================
   Melon Mayhem — midnight tropical fruit-slicer
   Palette derived from the fruit itself; lime reserved for the
   blade's energy glow so it reads as a choice, not a default.
   ============================================================ */
/* Self-hosted fonts (latin subsets, downloaded from Google Fonts) — zero external
   requests: faster first paint and works where fonts.googleapis.com is unreachable. */
@font-face {
  font-family: 'Lilita One';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/lilita-one-latin.woff2') format('woff2');
}
@font-face {
  font-family: 'Fredoka';
  font-style: normal;
  font-weight: 400 700; /* variable font: one file covers all weights we use */
  font-display: swap;
  src: url('../fonts/fredoka-latin.woff2') format('woff2');
}

:root {
  /* cartoon dusk-market palette — softened for young eyes, matched to the canvas */
  --bg-0:   #0b1d2c;   /* dusk navy                */
  --bg-1:   #17364e;   /* lifted dusk teal         */
  --bg-2:   #3a2154;   /* plum evening glow        */
  --ink:    #fdf3df;   /* warm cream text          */
  --ink-soft: rgba(253,243,223,0.66);
  --melon:  #ff5c7e;   /* watermelon flesh         */
  --melon-deep: #d81b54;
  --rind:   #3ecb77;   /* leaf green               */
  --lime:   #b8e07a;   /* soft sprout accent       */
  --gold:   #ffce3a;   /* score / combo gold       */
  --cyan:   #8fd3e8;   /* soft sky (blade energy)  */
  --danger: #ff6a55;   /* bomb / miss flash        */
  --shadow: 0 12px 40px rgba(0,0,0,0.45);
}

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

/* the hidden attribute must always win, even over display:flex rules */
[hidden] { display: none !important; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg-0);
  color: var(--ink);
  font-family: 'Fredoka', system-ui, sans-serif;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#game {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  display: block;
  touch-action: none;            /* critical: stop iOS scroll/zoom on swipe */
  cursor: crosshair;
}

#ui { position: fixed; inset: 0; pointer-events: none; }
#ui button { pointer-events: auto; }

/* ---------------------------------- HUD --------------------- */
#hud {
  position: absolute; inset: 0;
  padding: clamp(14px, 3vw, 28px);
  /* fullscreen home-screen mode: keep HUD clear of the status bar / notch */
  padding-top: max(clamp(14px, 3vw, 28px), env(safe-area-inset-top));
  padding-left: max(clamp(14px, 3vw, 28px), env(safe-area-inset-left));
  padding-right: max(clamp(14px, 3vw, 28px), env(safe-area-inset-right));
  display: flex; align-items: flex-start; justify-content: space-between;
  opacity: 0; transition: opacity .3s ease;
}
#hud.show { opacity: 1; }

.score-block { display: flex; flex-direction: column; gap: 2px; line-height: 1; }
.score-label {
  font-size: clamp(11px, 1.5vw, 14px); letter-spacing: .22em;
  text-transform: uppercase; color: var(--ink-soft); font-weight: 600;
}
.score-value {
  font-family: 'Lilita One', cursive;
  font-size: clamp(38px, 7vw, 64px);
  color: var(--gold);
  text-shadow: 0 3px 0 rgba(0,0,0,0.35), 0 0 14px rgba(255,206,58,0.18);
  font-variant-numeric: tabular-nums;
}
.score-best {
  font-size: clamp(12px, 1.6vw, 15px); color: var(--ink-soft);
  font-weight: 600; margin-top: 2px;
}
.score-best b { color: var(--ink); font-weight: 700; }

.right-hud { display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.lives { display: flex; gap: 7px; }
.life {
  width: clamp(24px, 3.4vw, 34px); height: clamp(24px, 3.4vw, 34px);
  transition: transform .25s cubic-bezier(.2,1.6,.4,1), opacity .4s ease, filter .3s;
  transform-origin: center;
}
.life path { fill: var(--melon); }
.life { filter: drop-shadow(0 3px 6px rgba(255,92,126,.3)); overflow: visible; }
.life.lost { opacity: .18; filter: grayscale(1) brightness(.6); transform: scale(.7); }
.life.pop { transform: scale(1.4); }

.icon-btn {
  width: clamp(40px, 5vw, 48px); height: clamp(40px, 5vw, 48px);
  border-radius: 50%; border: 2px solid rgba(253,243,223,0.22);
  background: rgba(11,29,44,0.55); color: var(--ink);
  font-size: 20px; cursor: pointer; backdrop-filter: blur(6px);
  display: grid; place-items: center; transition: transform .15s, border-color .2s, background .2s;
}
.icon-btn:hover { transform: scale(1.08); border-color: var(--lime); }
.icon-btn:active { transform: scale(.92); }
.icon-btn:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; }

.timer {
  font-family: 'Lilita One', cursive;
  font-size: clamp(26px, 4vw, 40px);
  color: var(--gold); line-height: 1;
  text-shadow: 0 3px 0 rgba(0,0,0,0.35);
  font-variant-numeric: tabular-nums;
}
.timer.low { color: var(--danger); animation: timer-pulse 1s ease-in-out infinite; }
@keyframes timer-pulse { 0%,100% { transform: scale(1); } 50% { transform: scale(1.12); } }

/* ------------------------------- Screens -------------------- */
.screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; gap: 18px; padding: 24px;
  pointer-events: auto;
  background: radial-gradient(120% 90% at 50% 18%, rgba(58,33,84,0.25), rgba(11,29,44,0.78) 70%);
  backdrop-filter: blur(2px);
  transition: opacity .45s ease, transform .45s ease;
}
.screen[hidden] { display: none; }
.screen.fade-out { opacity: 0; transform: scale(1.04); pointer-events: none; }

.eyebrow {
  font-size: clamp(13px, 2vw, 17px); letter-spacing: .42em; text-transform: uppercase;
  color: var(--lime); font-weight: 600; margin-bottom: -6px; text-indent: .42em;
}

.title {
  font-family: 'Lilita One', cursive;
  font-size: clamp(58px, 15.5vw, 168px);
  line-height: .86; letter-spacing: .01em;
  background: linear-gradient(178deg, #fff6e8 6%, var(--gold) 40%, var(--melon) 78%, var(--melon-deep));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: drop-shadow(0 6px 0 rgba(0,0,0,.28)) drop-shadow(0 16px 30px rgba(255,92,126,.22));
  -webkit-text-stroke: 2px rgba(11,29,44,.25);
}
.title .row { display: block; }
.title .mayhem {
  background: linear-gradient(178deg, #d7ffa6 4%, var(--rind) 48%, #1f9c5b);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}

.subtitle {
  font-size: clamp(15px, 2.4vw, 22px); color: var(--ink-soft);
  max-width: 30ch; font-weight: 500; line-height: 1.45;
}

.final-score {
  font-family: 'Lilita One', cursive;
  font-size: clamp(64px, 14vw, 132px); line-height: .9; color: var(--gold);
  text-shadow: 0 4px 0 rgba(0,0,0,.3), 0 0 40px rgba(255,206,58,.4);
}
.final-label { font-size: clamp(13px,2vw,16px); letter-spacing:.3em; text-transform:uppercase; color: var(--ink-soft); font-weight:600; }
.newbest {
  font-family:'Lilita One', cursive; font-size: clamp(18px,3vw,26px); color: var(--bg-0);
  background: linear-gradient(120deg, var(--gold), var(--melon));
  padding: 6px 18px; border-radius: 999px; transform: rotate(-3deg);
  box-shadow: var(--shadow); animation: badge-pop .5s cubic-bezier(.2,1.7,.4,1) both;
}
@keyframes badge-pop { from { transform: rotate(-3deg) scale(0); } to { transform: rotate(-3deg) scale(1); } }
.bestline { font-size: clamp(14px,2vw,18px); color: var(--ink-soft); font-weight:600; }
.bestline b { color: var(--ink); }

/* Big chunky play button */
.btn {
  font-family: 'Lilita One', cursive;
  font-size: clamp(22px, 3.4vw, 32px); letter-spacing: .02em;
  color: #3a0d1c;
  padding: clamp(15px,2.2vw,20px) clamp(38px,6vw,64px);
  border: none; border-radius: 999px; cursor: pointer;
  background: linear-gradient(170deg, #ffe39a 0%, var(--gold) 38%, var(--melon) 100%);
  box-shadow: 0 8px 0 var(--melon-deep), 0 18px 34px rgba(255,92,126,.3);
  transition: transform .12s ease, box-shadow .12s ease, filter .2s;
  position: relative;
}
.btn:hover { filter: brightness(1.05) saturate(1.05); }
.btn:active { transform: translateY(6px); box-shadow: 0 2px 0 var(--melon-deep), 0 8px 18px rgba(255,92,126,.28); }
.btn:focus-visible { outline: 4px solid var(--cyan); outline-offset: 4px; }
.btn .blade-emoji { margin-right: .35em; }
.btn .btn-sub { font-size: .62em; opacity: .75; font-weight: 400; }

.mode-buttons { display: flex; flex-direction: column; gap: 14px; align-items: center; }
.btn-alt {
  color: #0c3a22;
  background: linear-gradient(170deg, #d7ffa6 0%, var(--lime) 34%, var(--rind) 100%);
  box-shadow: 0 8px 0 #1f9c5b, 0 18px 34px rgba(62,203,119,.28);
}
.btn-alt:active { box-shadow: 0 2px 0 #1f9c5b, 0 8px 18px rgba(62,203,119,.26); }

.linklike {
  background: none; border: none; cursor: pointer;
  font-family: 'Fredoka', system-ui, sans-serif;
  font-size: clamp(13px, 1.8vw, 16px); font-weight: 600;
  color: var(--ink-soft); text-decoration: underline dotted;
  padding: 6px 12px;
}
.linklike:hover { color: var(--ink); }
.linklike:focus-visible { outline: 3px solid var(--cyan); outline-offset: 3px; border-radius: 6px; }

.hint {
  font-size: clamp(12px, 1.7vw, 15px); color: var(--ink-soft);
  letter-spacing: .03em; margin-top: 4px;
}
.hint kbd {
  font-family: inherit; background: rgba(253,243,223,.12); border: 1px solid rgba(253,243,223,.2);
  border-radius: 6px; padding: 1px 8px; font-weight: 600; color: var(--ink);
}

.pulse { animation: pulse 1.8s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity:.55; transform: translateY(0); } 50% { opacity:1; transform: translateY(-3px); } }

@media (prefers-reduced-motion: reduce) {
  .pulse, .newbest { animation: none; }
  .screen { transition: none; }
}
