/* ============================================================
   Fruit Ninja — web recreation
   Wooden dojo styling, HUD, overlays
   ============================================================ */

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

:root {
  --wood-dark: #4a2c12;
  --wood-mid: #6b4020;
  --wood-light: #8a5a2e;
  --wood-edge: #2e1a08;
  --rope: #c9a15f;
  --gold: #ffd54f;
  --red: #e53935;
  --font-brush: "Brush Script MT", "Segoe Script", "Marker Felt", "Bradley Hand", "Comic Sans MS", cursive;
  --font-chunk: "Arial Black", "Avenir Next", "Segoe UI", "Trebuchet MS", sans-serif;
  --outline: 2px 2px 0 rgba(20,10,0,.9), -2px 2px 0 rgba(20,10,0,.9),
             2px -2px 0 rgba(20,10,0,.9), -2px -2px 0 rgba(20,10,0,.9),
             0 4px 6px rgba(0,0,0,.55);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: #1a0f06;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-chunk);
  color: #fff;
  user-select: none;
  -webkit-user-select: none;
  cursor: default;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  touch-action: none;
  overflow: hidden;
}

#game {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.hidden { display: none !important; }

/* ============ HUD ============ */

#hud {
  position: absolute;
  top: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: calc(10px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right)) 0 calc(14px + env(safe-area-inset-left));
  pointer-events: none;
  z-index: 5;
}

#hudLeft {
  display: flex;
  align-items: center;
  gap: 10px;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,.5));
}

#hudScore {
  font-family: var(--font-chunk);
  font-size: clamp(30px, 5vw, 46px);
  font-weight: 900;
  color: #fff;
  text-shadow: var(--outline);
  letter-spacing: 1px;
  min-width: 1.2em;
}

#hudScore.doubled { color: var(--gold); }

#hudCenter {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

#hudTimer {
  position: relative;
  width: 58px; height: 58px;
  display: flex; align-items: center; justify-content: center;
}

#hudTimer svg { position: absolute; inset: 0; width: 100%; height: 100%; }

#hudTimerNum {
  font-size: 24px;
  font-weight: 900;
  text-shadow: var(--outline);
  z-index: 1;
}

#hudTimer.low #hudTimerNum { color: #ff7043; }
#hudTimer.low #timerRingFill { stroke: #ff7043; }

#hudPowerups { display: flex; gap: 8px; }

.powerup-chip {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  width: 44px;
  animation: chipIn .25s ease-out;
}

.powerup-chip svg { width: 34px; height: 34px; filter: drop-shadow(0 2px 3px rgba(0,0,0,.6)); }
.powerup-chip .bar { width: 40px; height: 5px; border-radius: 3px; background: rgba(0,0,0,.45); overflow: hidden; }
.powerup-chip .bar > i { display: block; height: 100%; border-radius: 3px; }

#hudRight {
  display: flex;
  align-items: center;
  gap: 14px;
}

#hudMisses { display: flex; gap: 6px; min-height: 40px; }

.miss-x {
  width: 38px; height: 38px;
  animation: xPop .45s cubic-bezier(.2, 2.4, .4, 1);
  filter: drop-shadow(0 3px 3px rgba(0,0,0,.5));
}

@keyframes xPop {
  0% { transform: scale(2.6) rotate(-30deg); opacity: 0; }
  60% { transform: scale(.9) rotate(4deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}

.miss-x.doom { animation: xDoom .4s ease-in infinite alternate; }
@keyframes xDoom { from { transform: scale(1); } to { transform: scale(1.25); filter: drop-shadow(0 0 6px #ff1744); } }

#pauseBtn {
  pointer-events: auto;
  width: 46px; height: 46px;
  border-radius: 10px;
  border: 2px solid var(--wood-edge);
  background: linear-gradient(180deg, var(--wood-light), var(--wood-mid));
  color: #f5e6c8;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: inset 0 2px 3px rgba(255,235,200,.35), 0 3px 5px rgba(0,0,0,.5);
}

#pauseBtn:hover { filter: brightness(1.15); }
#pauseBtn:active { transform: translateY(1px); }
#pauseBtn svg { width: 22px; height: 22px; }

/* ============ Overlays ============ */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(14px, 3.5vh, 30px);
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  z-index: 10;
}

.overlay.no-bg { background: none; pointer-events: none; }

#menu {
  background: radial-gradient(ellipse at 50% 30%, rgba(60,32,10,.14), rgba(15,7,2,.5) 85%);
  pointer-events: none; /* let swipes reach the fruit flying behind the menu */
}

#menuButtons, #menuFooter { pointer-events: none; }

.mode-btn, #muteBtn { pointer-events: auto; }

#logoCanvas { width: min(88vw, 640px); height: auto; pointer-events: none; filter: drop-shadow(0 6px 8px rgba(0,0,0,.5)); }

#menuButtons {
  display: flex;
  gap: clamp(12px, 2.4vw, 26px);
  flex-wrap: wrap;
  justify-content: center;
}

.mode-btn {
  position: relative;
  font-family: var(--font-chunk);
  width: clamp(150px, 20vw, 205px);
  padding: 16px 14px 14px;
  border-radius: 8px;
  border: 3px solid var(--wood-edge);
  background:
    repeating-linear-gradient(93deg, rgba(30,15,4,.16) 0 3px, rgba(255,225,170,.05) 3px 9px),
    linear-gradient(180deg, var(--wood-light) 0%, var(--wood-mid) 55%, var(--wood-dark) 100%);
  box-shadow: inset 0 2px 4px rgba(255,235,200,.3), inset 0 -6px 10px rgba(20,8,0,.4), 0 6px 10px rgba(0,0,0,.5);
  color: #fff;
  cursor: pointer;
  transition: transform .12s ease, filter .12s ease;
  text-align: center;
}

.mode-btn:hover, .mode-btn:focus-visible {
  transform: translateY(-4px) rotate(-.6deg);
  filter: brightness(1.18);
  outline: none;
}

.mode-btn:active { transform: translateY(0) scale(.98); }

.mode-btn::before, .mode-btn::after {
  content: "";
  position: absolute;
  top: 8px;
  width: 9px; height: 9px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #f4d9a6, #6d5637 60%, #241505);
  box-shadow: inset 0 -1px 2px rgba(0,0,0,.6), 0 1px 1px rgba(255,240,210,.25);
}

.mode-btn::before { left: 8px; }
.mode-btn::after { right: 8px; }

.mode-btn:nth-child(2) { transform: rotate(.7deg); }
.mode-btn:nth-child(2):hover { transform: translateY(-4px) rotate(.4deg); }

.mode-title {
  display: block;
  font-family: var(--font-brush);
  font-size: clamp(30px, 4vw, 42px);
  line-height: 1.05;
  color: #ffe9c9;
  text-shadow: 0 2px 0 #1d0e02, 0 0 14px rgba(0,0,0,.35);
  margin-bottom: 6px;
}

.mode-desc {
  display: block;
  font-size: clamp(11px, 1.35vw, 13.5px);
  font-weight: 700;
  line-height: 1.45;
  color: #f0d9b4;
  opacity: .92;
  text-shadow: 0 1px 2px rgba(20,8,0,.8);
}

.mode-best {
  display: inline-block;
  margin-top: 10px;
  font-size: clamp(12px, 1.5vw, 14px);
  font-weight: 900;
  letter-spacing: .4px;
  color: var(--gold);
  text-shadow: 0 1px 0 #3a2500, 0 0 10px rgba(255,200,60,.35);
}

#menuFooter {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-top: clamp(4px, 1.5vh, 12px);
}

#muteBtn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 3px solid var(--wood-edge);
  background: radial-gradient(circle at 35% 30%, #a06a35, var(--wood-dark));
  box-shadow: 0 3px 6px rgba(0,0,0,.5), inset 0 2px 3px rgba(255,235,200,.3);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: #ffe9c9;
}

#muteBtn:hover { filter: brightness(1.2); }
#muteBtn svg { width: 22px; height: 22px; }

#menuHint {
  font-family: var(--font-brush);
  font-size: clamp(17px, 2.2vw, 22px);
  color: #f4dfb8;
  text-shadow: 0 2px 3px rgba(0,0,0,.8);
  opacity: .95;
}

/* ============ Countdown ============ */

#countNum {
  font-family: var(--font-chunk);
  font-size: clamp(110px, 24vh, 210px);
  font-weight: 900;
  color: #fff;
  text-shadow: var(--outline), 0 0 40px rgba(255,180,60,.45);
}

#countNum.pop { animation: countPop .92s cubic-bezier(.2, 1.4, .35, 1) forwards; }

@keyframes countPop {
  0% { transform: scale(2.2); opacity: 0; }
  22% { transform: scale(.95); opacity: 1; }
  78% { transform: scale(1); opacity: 1; }
  100% { transform: scale(.7); opacity: 0; }
}

/* ============ Panels (pause / results) ============ */

.panel {
  position: relative;
  min-width: min(86vw, 380px);
  max-width: 92vw;
  padding: clamp(20px, 4vh, 34px) clamp(22px, 4vw, 40px) clamp(18px, 3.5vh, 28px);
  border-radius: 14px;
  border: 4px solid var(--wood-edge);
  background:
    repeating-linear-gradient(0deg, rgba(30,15,4,.12) 0 2px, transparent 2px 26px),
    linear-gradient(180deg, #7c4e24 0%, #5f3917 60%, #472709 100%);
  box-shadow: inset 0 3px 6px rgba(255,235,200,.25), inset 0 -10px 18px rgba(20,8,0,.45), 0 16px 40px rgba(0,0,0,.65);
  text-align: center;
  animation: panelIn .32s cubic-bezier(.2, 1.5, .4, 1);
}

@keyframes panelIn {
  from { transform: scale(.6) translateY(30px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

.panel::before {
  content: "";
  position: absolute;
  top: -14px; left: 50%;
  width: 120px; height: 26px;
  transform: translateX(-50%);
  background:
    radial-gradient(circle at 12px 13px, #3c2410 5px, transparent 6px),
    radial-gradient(circle at 108px 13px, #3c2410 5px, transparent 6px),
    linear-gradient(180deg, #d8b271, #a97f3f);
  border-radius: 6px;
  box-shadow: 0 2px 4px rgba(0,0,0,.5), inset 0 2px 2px rgba(255,240,200,.5);
}

.panel-title {
  font-family: var(--font-brush);
  font-size: clamp(36px, 6vw, 54px);
  color: #ffe9c9;
  text-shadow: 0 3px 0 #1d0e02, 0 0 18px rgba(0,0,0,.4);
  margin-bottom: 10px;
}

.wood-btn {
  font-family: var(--font-chunk);
  font-weight: 900;
  font-size: clamp(15px, 2vw, 18px);
  letter-spacing: .5px;
  padding: 12px 22px;
  color: #fff;
  text-shadow: 0 2px 2px rgba(20,8,0,.8);
  border-radius: 10px;
  border: 3px solid var(--wood-edge);
  background: linear-gradient(180deg, var(--wood-light), var(--wood-dark));
  box-shadow: inset 0 2px 3px rgba(255,235,200,.35), 0 4px 7px rgba(0,0,0,.5);
  cursor: pointer;
  transition: transform .1s ease, filter .1s ease;
}

.wood-btn:hover, .wood-btn:focus-visible { filter: brightness(1.2); transform: translateY(-2px); outline: none; }
.wood-btn:active { transform: translateY(1px) scale(.97); }

.panel-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }

/* Results specifics */

#resultCause { height: 52px; display: flex; align-items: center; justify-content: center; gap: 10px; }
#resultCause svg { filter: drop-shadow(0 3px 4px rgba(0,0,0,.5)); }

#resultScore {
  font-size: clamp(58px, 11vw, 96px);
  font-weight: 900;
  line-height: 1;
  color: #fff;
  text-shadow: var(--outline);
  margin: 2px 0 4px;
}

#resultBestRow {
  font-size: clamp(15px, 2.2vw, 19px);
  font-weight: 900;
  color: var(--gold);
  text-shadow: 0 2px 2px rgba(20,8,0,.8);
}

#newBest {
  display: inline-block;
  margin: 8px 0 2px;
  padding: 5px 18px;
  font-size: clamp(16px, 2.4vw, 21px);
  font-weight: 900;
  letter-spacing: 1.5px;
  color: #4a2c00;
  background: linear-gradient(180deg, #ffe082, #ffb300);
  border: 2px solid #7a5200;
  border-radius: 999px;
  box-shadow: 0 0 18px rgba(255,190,50,.65), inset 0 2px 2px rgba(255,255,255,.65);
  animation: bestPulse 1s ease-in-out infinite alternate;
}

@keyframes bestPulse {
  from { transform: scale(1); box-shadow: 0 0 12px rgba(255,190,50,.5), inset 0 2px 2px rgba(255,255,255,.65); }
  to { transform: scale(1.07); box-shadow: 0 0 26px rgba(255,190,50,.9), inset 0 2px 2px rgba(255,255,255,.65); }
}

#resultStats {
  display: flex;
  justify-content: center;
  gap: clamp(14px, 4vw, 34px);
  margin-top: 14px;
}

.stat { display: flex; flex-direction: column; align-items: center; gap: 2px; }

.stat span {
  font-size: clamp(24px, 4vw, 34px);
  font-weight: 900;
  color: #ffe9c9;
  text-shadow: 0 2px 0 #1d0e02;
}

.stat label {
  font-size: clamp(10px, 1.3vw, 12px);
  font-weight: 700;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: #d9bd92;
}

/* ============ Small screens ============ */

@media (max-width: 620px) {
  #menuButtons { flex-direction: column; align-items: center; }
  .mode-btn { width: min(84vw, 320px); padding: 12px 14px 12px; }
  .mode-title { font-size: 34px; margin-bottom: 3px; }
  .mode-best { margin-top: 6px; }
  .panel::before { width: 90px; }
}

@media (max-height: 560px) and (orientation: landscape) {
  #menu { gap: 8px; }
  #logoCanvas { width: min(56vw, 420px); }
  .mode-btn { width: clamp(140px, 22vw, 180px); padding: 9px 10px 8px; }
  .mode-desc { display: none; }
  .mode-best { margin-top: 4px; }
  #menuHint { display: none; }
  .panel { padding: 12px 18px 12px; }
  .panel-title { font-size: 34px; margin-bottom: 4px; }
  #resultScore { font-size: 54px; }
  #resultStats { margin-top: 6px; }
  .panel-buttons { margin-top: 8px; }
}

/* Narrow-height phones (e.g. 320x568): compact the stacked menu so the
   wordmark, all three mode buttons, mute control, and footer fit the viewport
   with breathing room. */
@media (max-width: 400px) and (max-height: 660px) {
  #menu { gap: 10px; padding-top: calc(8px + env(safe-area-inset-top)); padding-bottom: calc(8px + env(safe-area-inset-bottom)); }
  .mode-btn { padding: 8px 12px 8px; }
  .mode-title { font-size: 30px; margin-bottom: 2px; }
  .mode-desc { font-size: 11px; line-height: 1.3; }
  .mode-best { margin-top: 4px; }
  #menuFooter { margin-top: 2px; gap: 10px; }
  #muteBtn { width: 40px; height: 40px; }
  #menuHint { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  .mode-btn, .wood-btn { transition: none; }
  #newBest { animation: none; }
}
