html, body { 
  margin: 0; 
  padding: 0; 
  background-color: #0a0a0f; 
  overflow: hidden; 
  user-select: none;
  touch-action: none;
  width: 100%;
  height: 100%;
}

/* ── Outer page: centers the device frame ────────── */
body {
  display: flex;
  align-items: center;
  justify-content: center;
  /* Subtle radial glow behind the "phone" on desktop */
  background: radial-gradient(ellipse at center, #1a1a2e 0%, #0a0a0f 70%);
}

/* ── Game container ──────────────────────────────── 
 * Default: full-screen on desktop & mobile.
 * On tablet-sized screens & smaller, keeps full-bleed.
 * On desktop (> 1024px width AND > 640px height), goes full viewport.
 */
#game-container {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
}

/* ── Tablet & below: phone-frame look ───────────── 
 * Between 481px and 1024px (tablets) show the phone frame.
 */
@media (min-width: 481px) and (max-width: 1024px) and (min-height: 481px) {
  #game-container {
    max-width: 430px;
    max-height: 932px;
    aspect-ratio: 9 / 19.5;
    border-radius: 32px;
    box-shadow:
      0 0 0 3px rgba(255, 255, 255, 0.08),
      0 0 0 6px rgba(0, 0, 0, 0.4),
      0 20px 60px rgba(0, 0, 0, 0.6),
      0 0 120px rgba(100, 140, 255, 0.06);
  }
}

/* Canvas fills the container */
#game-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* ── UI overlay – scoped inside container ────────── 
 * In landscape, this is a simple full-screen overlay.
 * In portrait, the 3D camera is rotated 90° CW, so the
 * visual "landscape" is tilted. Instead of counter-rotating
 * each UI element individually, we rotate the ENTIRE #ui
 * container once and swap its width/height so that all
 * children can use normal landscape-style positioning.
 */
#ui {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  font-family: 'Baloo 2', cursive, sans-serif;
}

/* ── Portrait: single rotation of the whole UI layer ──
 * The 3D camera is rotated 90° CW so the scene appears in
 * landscape even though the phone is held portrait.
 * We rotate #ui 90° to match. After rotate(90deg), CSS-width
 * runs physically vertical and CSS-height runs physically
 * horizontal. We swap them to the viewport's opposite dims
 * so the overlay covers the screen correctly.
 *
 * On mobile (where portrait triggers) the game container is
 * always full-viewport, so 100vw/100vh is safe. The tablet
 * phone-frame only activates at ≥481px where orientation
 * detection returns landscape. */
#ui.portrait {
  width: 100vh;
  height: 100vw;
  top: 50%;
  left: 50%;
  transform: rotate(90deg) translate(-50%, -50%);
  transform-origin: top left;
}

/* ── Scoreboard ─────────────────────────────────────────
 * Always centered at the top of the (possibly rotated) UI
 * container. Because #ui.portrait handles the rotation,
 * children just use normal landscape-style positioning.
 */
.scoreboard {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 2px;
  background: rgba(0, 0, 0, 0.75);
  border-radius: 14px;
  padding: 4px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
  z-index: 10;
}

/* ── Individual score badge ─────────────────────── */
.score-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 42px;
  height: 34px;
  padding: 0 12px;
  border-radius: 10px;
  font-family: 'Baloo 2', cursive, sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 0.04em;
  line-height: 1;
}

.score-badge.p1 {
  background: #3399ff;
}
.score-badge.p2 {
  background: #ff7f7f;
}

/* ── Separator dash ─────────────────────────────── */
.score-sep {
  color: rgba(255, 255, 255, 0.35);
  font-size: 0.85rem;
  font-weight: 400;
  padding: 0 4px;
  line-height: 1;
}

/* ── Score pop animation ─────────────────────────── */
@keyframes scorePop {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.35); }
  100% { transform: scale(1); }
}
.score-badge.score-pop {
  animation: scorePop 0.3s ease-out;
}

/* ── Mute / Unmute Button ───────────────────────────── */
.mute-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 20;
  pointer-events: auto;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  line-height: 1;
  transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

.mute-btn:hover {
  background: rgba(60, 60, 80, 0.85);
  transform: scale(1.08);
  box-shadow: 0 3px 14px rgba(0, 0, 0, 0.5);
}

.mute-btn:active {
  transform: scale(0.94);
}

/* Unmuted state – subtle blue glow */
.mute-btn.unmuted {
  background: rgba(30, 70, 140, 0.65);
  border-color: rgba(100, 160, 255, 0.3);
  box-shadow: 0 2px 12px rgba(80, 140, 255, 0.25);
}

/* Muted state – reddish tint */
.mute-btn.muted {
  background: rgba(130, 40, 40, 0.65);
  border-color: rgba(255, 100, 100, 0.3);
  box-shadow: 0 2px 12px rgba(255, 80, 80, 0.2);
}

/* Mute button: always top-right of the (rotated) UI container.
   No portrait override needed — #ui.portrait handles rotation. */

/* ══════════════════════════════════════════════════════
   START SCREEN
   ══════════════════════════════════════════════════════ */

#start-screen {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Sky-blue → tennis-green gradient */
  background: linear-gradient(165deg, #87CEEB 0%, #7EC8E3 25%, #5DBB63 60%, #4CA64C 100%);
  transition: opacity 0.5s ease;
}

#start-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

/* ── Scattered Emoji Background ─────────────────── */
.scattered-emojis {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.scatter-emoji {
  position: absolute;
  font-size: var(--size, 1.5rem);
  transform: rotate(var(--rot, 0deg));
  opacity: 0.25;
  animation: emojiBob 3.5s ease-in-out infinite;
  animation-delay: var(--delay, 0s);
  filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

@keyframes emojiBob {
  0%, 100% { translate: 0 0; }
  50%      { translate: 0 -6px; }
}

/* ── Main Content ────────────────────────────────── */
.start-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 24px;
  position: relative;
  z-index: 2;
}

/* ── Beans Overlay ───────────────────────────────── */
.beans-overlay {
  width: 180px;
  height: auto;
  filter: drop-shadow(0 6px 20px rgba(0, 0, 0, 0.18));
  animation: beansFloat 3s ease-in-out infinite;
}

@keyframes beansFloat {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50%      { transform: translateY(-10px) rotate(2deg); }
}

/* ── Title ───────────────────────────────────────── */
.start-title {
  text-align: center;
}

.start-title h1 {
  font-family: 'Baloo 2', cursive, sans-serif;
  font-size: 2.6rem;
  font-weight: 800;
  color: #fff;
  margin: 0;
  line-height: 1.1;
  text-shadow:
    0 3px 0 rgba(0, 0, 0, 0.12),
    0 2px 12px rgba(0, 0, 0, 0.18),
    0 0 40px rgba(255, 255, 255, 0.12);
  letter-spacing: 0.02em;
}

.start-subtitle {
  font-family: 'Baloo 2', cursive, sans-serif;
  font-size: 0.85rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.8);
  margin: 6px 0 0;
  letter-spacing: 0.06em;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

/* When the difficulty panel is open we hide the gameplay-instruction
   subtitle — it's irrelevant to the difficulty choice and removing it
   keeps the visual focus on the slider. We fade rather than display:none
   so it doesn't trigger a layout reflow above. */
#start-screen.picking-difficulty .start-subtitle {
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
}

/* ── Action Slot ──────────────────────────────────
   Reserved-height container that stacks the mode-buttons and the
   difficulty-panel on top of each other so swapping between them
   does not push the title / beans image around. The min-height is
   sized to fit the LARGER of the two states (the difficulty panel)
   so the layout never reflows when toggling visibility. */
.action-slot {
  position: relative;
  width: 100%;
  max-width: 340px;
  /* Sized to fit the difficulty panel, which is the taller state. */
  min-height: 320px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

/* Both children fill the slot width and are horizontally centered via
   left:50% + translateX(-50%). This is more reliable than left:0;
   right:0; margin:auto on absolutely-positioned elements whose
   intrinsic width differs from the slot (e.g. .mode-buttons has its
   own max-width: 300px which would otherwise pin to left:0). */
.action-slot > .mode-buttons,
.action-slot > .difficulty-panel {
  position: absolute;
  top: 0;
  left: 50%;
  width: 100%;
  transform: translateX(-50%);
}

/* Vertically center the (shorter) mode buttons inside the slot so the
   start screen looks balanced when the panel isn't open. */
.action-slot > .mode-buttons {
  top: 50%;
  transform: translate(-50%, -50%);
}

/* ── Mode Buttons Container ──────────────────────── */
.mode-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  width: 100%;
  max-width: 300px;
}

/* ── OR Divider ──────────────────────────────────── */
.mode-or {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 80%;
  margin: 10px 0;
}

.mode-or-line {
  flex: 1;
  height: 1px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 1px;
}

.mode-or-text {
  font-family: 'Baloo 2', cursive, sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.55);
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

/* ── Mode Button (shared) ────────────────────────── */
.mode-btn {
  position: relative;
  overflow: hidden;
  width: 100%;
  padding: 13px 24px;
  border: none;
  border-radius: 60px;
  font-family: 'Baloo 2', cursive, sans-serif;
  font-size: 1.1rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

.mode-btn:hover {
  transform: scale(1.05);
}

.mode-btn:active {
  transform: scale(0.96);
}

/* ── Play vs AI – vibrant primary button ─────────── */
#btn-vs-ai {
  background: linear-gradient(135deg, #fff 0%, #fffde8 50%, #f0f7e0 100%);
  color: #2d6a2e;
  box-shadow:
    0 4px 20px rgba(0, 0, 0, 0.16),
    0 0 0 3px rgba(255, 255, 255, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

#btn-vs-ai:hover {
  box-shadow:
    0 6px 28px rgba(0, 0, 0, 0.22),
    0 0 0 3px rgba(255, 255, 255, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 1);
}

/* ── Play with Friend – secondary / outlined style ── */
#btn-vs-friend {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 2px solid rgba(255, 255, 255, 0.45);
  box-shadow:
    0 4px 16px rgba(0, 0, 0, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

#btn-vs-friend:hover {
  background: rgba(255, 255, 255, 0.2);
  border-color: rgba(255, 255, 255, 0.65);
  box-shadow:
    0 6px 24px rgba(0, 0, 0, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

/* ═══════════════════════════════════════════════════════════
   DIFFICULTY PANEL
   ═══════════════════════════════════════════════════════════ */
.difficulty-panel {
  width: 100%;
  max-width: 340px;
  padding: 22px 22px 18px;
  border-radius: 28px;
  background: rgba(40, 18, 50, 0.55);
  box-shadow:
    0 10px 40px rgba(0, 0, 0, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 0.08),
    0 0 0 1px rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
  animation: panelIn 0.32s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  position: relative;
}

.difficulty-panel.hidden {
  display: none;
}

/* The panel is absolutely positioned with translateX(-50%) for
   horizontal centering, so the animation must preserve that X offset
   on every keyframe — otherwise the panel jumps right during entry. */
@keyframes panelIn {
  from { opacity: 0; transform: translate(-50%, 14px) scale(0.94); }
  to   { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

.difficulty-title {
  font-family: 'Baloo 2', cursive, sans-serif;
  font-size: 1.5rem;
  font-weight: 800;
  color: #fff;
  margin: 0;
  text-align: center;
  letter-spacing: 0.02em;
  text-shadow:
    0 2px 0 rgba(0, 0, 0, 0.18),
    0 2px 10px rgba(0, 0, 0, 0.22);
}

/* ── Slider wrapper: holds the colored track + native input + tick dots ── */
.difficulty-slider-wrap {
  position: relative;
  height: 36px;
  margin: 4px 8px 0;
  display: flex;
  align-items: center;
}

/* Colored gradient track behind the native input */
.difficulty-track-bg {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 8px;
  transform: translateY(-50%);
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    #6dd97a 0%,
    #c8e26a 35%,
    #f3c84a 55%,
    #f08a4a 78%,
    #e95757 100%
  );
  box-shadow:
    inset 0 1px 2px rgba(0, 0, 0, 0.25),
    0 0 0 1px rgba(0, 0, 0, 0.12);
  pointer-events: none;
}

/* Tick dots positioned at each stop */
.difficulty-ticks {
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 8px;
  transform: translateY(-50%);
  pointer-events: none;
}

.difficulty-tick {
  position: absolute;
  top: 50%;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  transform: translate(-50%, -50%);
}

.difficulty-tick[data-idx="0"] { left: 0%; }
.difficulty-tick[data-idx="1"] { left: 50%; }
.difficulty-tick[data-idx="2"] { left: 100%; }

/* Native range input — transparent track, custom thumb */
.difficulty-slider {
  position: relative;
  width: 100%;
  height: 36px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  outline: none;
  z-index: 2;
}

/* Hide default tracks (we draw our own gradient behind) */
.difficulty-slider::-webkit-slider-runnable-track {
  height: 8px;
  background: transparent;
  border: none;
}
.difficulty-slider::-moz-range-track {
  height: 8px;
  background: transparent;
  border: none;
}

/* Thumb: golden circle with white ring */
.difficulty-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 26px;
  height: 26px;
  margin-top: -9px; /* center on 8px track */
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe27a 0%, #f4c042 60%, #d99820 100%);
  border: 3px solid #fff;
  box-shadow:
    0 3px 10px rgba(0, 0, 0, 0.35),
    0 0 0 1px rgba(0, 0, 0, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.6);
  cursor: grab;
  transition: transform 0.15s ease;
}
.difficulty-slider::-moz-range-thumb {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #ffe27a 0%, #f4c042 60%, #d99820 100%);
  border: 3px solid #fff;
  box-shadow:
    0 3px 10px rgba(0, 0, 0, 0.35),
    0 0 0 1px rgba(0, 0, 0, 0.1),
    inset 0 1px 0 rgba(255, 255, 255, 0.6);
  cursor: grab;
  transition: transform 0.15s ease;
}

.difficulty-slider:hover::-webkit-slider-thumb { transform: scale(1.08); }
.difficulty-slider:hover::-moz-range-thumb     { transform: scale(1.08); }
.difficulty-slider:active::-webkit-slider-thumb { transform: scale(0.94); cursor: grabbing; }
.difficulty-slider:active::-moz-range-thumb     { transform: scale(0.94); cursor: grabbing; }

/* ── Labels row ── */
.difficulty-labels {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px;
  margin-top: 2px;
}

.difficulty-label {
  font-family: 'Baloo 2', cursive, sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.55);
  letter-spacing: 0.02em;
  transition: color 0.2s ease, transform 0.2s ease, text-shadow 0.2s ease;
  user-select: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.difficulty-label.active {
  color: #ffd84a;
  transform: scale(1.12);
  text-shadow:
    0 2px 0 rgba(0, 0, 0, 0.2),
    0 0 14px rgba(255, 216, 74, 0.45);
}

/* ── Start Match (primary CTA) ── */
.difficulty-start-btn {
  position: relative;
  overflow: hidden;
  width: 100%;
  margin-top: 6px;
  padding: 14px 24px;
  border: none;
  border-radius: 60px;
  font-family: 'Baloo 2', cursive, sans-serif;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  cursor: pointer;
  background: linear-gradient(180deg, #ffffff 0%, #f7f7f7 100%);
  color: #2a1830;
  box-shadow:
    0 6px 20px rgba(0, 0, 0, 0.28),
    0 0 0 3px rgba(255, 255, 255, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 1);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

.difficulty-start-btn:hover {
  transform: scale(1.04);
  box-shadow:
    0 8px 26px rgba(0, 0, 0, 0.32),
    0 0 0 3px rgba(255, 255, 255, 0.28),
    inset 0 1px 0 rgba(255, 255, 255, 1);
}

.difficulty-start-btn:active {
  transform: scale(0.97);
}

/* ── Back (subtle ghost link) ── */
.difficulty-back-btn {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.65);
  font-family: 'Baloo 2', cursive, sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 4px 8px;
  margin: -4px auto 0;
  cursor: pointer;
  letter-spacing: 0.04em;
  transition: color 0.18s ease, transform 0.18s ease;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

.difficulty-back-btn:hover {
  color: #fff;
  transform: translateX(-2px);
}

/* ── Hide mode buttons while difficulty panel is up ── */
.mode-buttons.hidden {
  display: none;
}

/* Animated shine sweep across button */
.btn-shine {
  position: absolute;
  inset: 0;
  background: linear-gradient(
    105deg,
    transparent 30%,
    rgba(255, 255, 255, 0.5) 45%,
    rgba(255, 255, 255, 0.7) 50%,
    rgba(255, 255, 255, 0.5) 55%,
    transparent 70%
  );
  animation: shineSweep 3s ease-in-out infinite;
}

/* Subtler shine for the outlined friend button */
#btn-vs-friend .btn-shine {
  background: linear-gradient(
    105deg,
    transparent 30%,
    rgba(255, 255, 255, 0.15) 45%,
    rgba(255, 255, 255, 0.25) 50%,
    rgba(255, 255, 255, 0.15) 55%,
    transparent 70%
  );
}

@keyframes shineSweep {
  0%   { transform: translateX(-150%); }
  40%  { transform: translateX(150%); }
  100% { transform: translateX(150%); }
}

.btn-text {
  position: relative;
  z-index: 1;
}

/* ══════════════════════════════════════════════════════
   LOADING SCREEN
   ══════════════════════════════════════════════════════ */

#loading-screen {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(165deg, #87CEEB 0%, #7EC8E3 25%, #5DBB63 60%, #4CA64C 100%);
  transition: opacity 0.5s ease;
}

#loading-screen.fade-out {
  opacity: 0;
  pointer-events: none;
}

.loading-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 70%;
  max-width: 320px;
}

.loading-label {
  font-family: 'Baloo 2', cursive, sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  margin: 0;
  letter-spacing: 0.06em;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.2);
}

.loading-bar-track {
  width: 100%;
  height: 12px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.25);
  overflow: hidden;
  box-shadow:
    inset 0 1px 3px rgba(0, 0, 0, 0.15),
    0 1px 0 rgba(255, 255, 255, 0.1);
}

.loading-bar-fill {
  width: 0%;
  height: 100%;
  border-radius: 8px;
  background: linear-gradient(90deg, #fff 0%, #ffe066 50%, #ffb347 100%);
  box-shadow: 0 0 14px rgba(255, 224, 102, 0.5);
  transition: width 0.25s ease;
}

.loading-percent {
  font-family: 'Baloo 2', cursive, sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.75);
  margin: 0;
  letter-spacing: 0.06em;
}

/* ══════════════════════════════════════════════════════
   TAP HINT OVERLAY
   ══════════════════════════════════════════════════════ */

/* ── Full-screen overlay (transparent, above game, below score) */
.tap-hint-overlay {
  position: absolute;
  inset: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.5s ease;
}

.tap-hint-overlay.tap-hint-visible {
  opacity: 1;
}

.tap-hint-overlay.tap-hint-hidden {
  opacity: 0;
}

/* ── Reusable Hint Bubble ────────────────────────── */
.tap-hint-bubble {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: rgba(0, 0, 0, 0.78);
  color: #ffffff;
  font-family: 'Baloo 2', cursive, sans-serif;
  font-weight: 600;
  border-radius: 20px;
  padding: 10px 18px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow:
    0 4px 20px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.05);
  white-space: nowrap;
  animation: hintFloat 2.5s ease-in-out infinite;
}

.tap-hint-bubble.tap-hint-normal {
  font-size: 0.95rem;
  padding: 10px 20px;
}

.tap-hint-bubble.tap-hint-small {
  font-size: 0.78rem;
  padding: 8px 14px;
  border-radius: 16px;
  gap: 5px;
}

/* ── Emoji icon inside bubble ────────────────────── */
.tap-hint-emoji {
  font-size: 1.1em;
  line-height: 1;
  flex-shrink: 0;
}

.tap-hint-small .tap-hint-emoji {
  font-size: 1em;
}

/* ── Text inside bubble ──────────────────────────── */
.tap-hint-text {
  line-height: 1.2;
  letter-spacing: 0.02em;
}

/* ── Split layout for friend mode ────────────────── */
.tap-hint-split {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 0 16px;
  gap: 12px;
}

.tap-hint-split .tap-hint-bubble.tap-hint-left {
  animation-delay: 0s;
}

.tap-hint-split .tap-hint-bubble.tap-hint-right {
  animation-delay: 0.3s;
}

/* ── Subtle float animation ──────────────────────── */
@keyframes hintFloat {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-4px); }
}

/* Portrait tap hints: the overlay is appended inside #ui which
   is already rotated, so no per-element rotation is needed.
   The "portrait" class is kept for layout adjustments only. */

/* ══════════════════════════════════════════════════════
   WIN BANNER
   ══════════════════════════════════════════════════════ */

/* ── Dark overlay backdrop ─────────────────────── */
.win-overlay {
  position: absolute;
  inset: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: rgba(0, 0, 0, 0);
  transition: background 0.6s ease;
  pointer-events: auto;
}

/* Portrait win banner: the win overlay is appended inside #ui which
   is already rotated, so no per-element rotation is needed.
   The "win-portrait" class is kept for any future layout tweaks. */

.win-overlay.win-visible {
  background: rgba(0, 0, 0, 0.55);
}

.win-overlay.win-dismissing {
  background: rgba(0, 0, 0, 0);
  pointer-events: none;
}

/* ── Confetti layer ────────────────────────────── */
.win-confetti {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.win-confetti-piece {
  position: absolute;
  top: -10%;
  opacity: 0;
  animation: confettiFall 3.5s ease-in-out infinite;
}

.win-visible .win-confetti-piece {
  opacity: 1;
}

.win-dismissing .win-confetti-piece {
  opacity: 0;
  transition: opacity 0.3s ease;
}

@keyframes confettiFall {
  0% {
    transform: translateY(-20px) rotate(0deg) scale(0.5);
    opacity: 0;
  }
  10% {
    opacity: 1;
  }
  100% {
    transform: translateY(calc(100vh + 40px)) rotate(720deg) scale(1);
    opacity: 0;
  }
}

/* ── Main ribbon banner ────────────────────────── */
.win-ribbon {
  position: relative;
  width: 110%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 28px 20px 22px;
  /* Same sky-blue → tennis-green gradient as start screen */
  background: linear-gradient(135deg, #87CEEB 0%, #7EC8E3 25%, #5DBB63 60%, #4CA64C 100%);
  box-shadow:
    0 8px 40px rgba(0, 0, 0, 0.5),
    0 0 80px rgba(93, 187, 99, 0.2),
    inset 0 1px 0 rgba(255, 255, 255, 0.35),
    inset 0 -1px 0 rgba(0, 0, 0, 0.1);
  transform: scaleY(0);
  opacity: 0;
  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.4s ease;
  z-index: 2;
}

.win-visible .win-ribbon {
  transform: scaleY(1);
  opacity: 1;
}

.win-dismissing .win-ribbon {
  transform: scaleY(0);
  opacity: 0;
  transition: transform 0.4s ease-in, opacity 0.3s ease;
}

/* ── Finish-line checkered borders ─────────────── */
.win-finish-line {
  position: absolute;
  left: 0;
  right: 0;
  height: 8px;
  background: repeating-linear-gradient(
    90deg,
    #fff 0px,
    #fff 8px,
    #1a1a2e 8px,
    #1a1a2e 16px
  );
  opacity: 0.6;
}

.win-finish-top {
  top: 0;
}

.win-finish-bottom {
  bottom: 0;
}

/* ── Trophy ────────────────────────────────────── */
.win-trophy {
  font-size: 2.4rem;
  line-height: 1;
  filter: drop-shadow(0 3px 8px rgba(0, 0, 0, 0.25));
  animation: trophyBounce 1s ease-in-out infinite;
}

@keyframes trophyBounce {
  0%, 100% { transform: translateY(0) scale(1); }
  50%      { transform: translateY(-6px) scale(1.08); }
}

/* ── Winner title ──────────────────────────────── */
.win-title {
  font-family: 'Baloo 2', cursive, sans-serif;
  font-size: 1.7rem;
  font-weight: 800;
  color: #fff;
  margin: 0;
  line-height: 1.1;
  text-align: center;
  text-shadow:
    0 3px 0 rgba(0, 0, 0, 0.15),
    0 2px 16px rgba(0, 0, 0, 0.25),
    0 0 40px rgba(255, 255, 255, 0.15);
  letter-spacing: 0.02em;
}

/* ── Score row ─────────────────────────────────── */
.win-score-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 2px 0 6px;
}

.win-score-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  font-family: 'Baloo 2', cursive, sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.04em;
  line-height: 1;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.win-score-sep {
  color: rgba(255, 255, 255, 0.5);
  font-family: 'Baloo 2', cursive, sans-serif;
  font-size: 0.85rem;
  font-weight: 400;
  padding: 0 2px;
}

/* ── Play Again button ─────────────────────────── */
.win-play-again {
  position: relative;
  overflow: hidden;
  margin-top: 4px;
  padding: 10px 28px;
  border: none;
  border-radius: 60px;
  background: linear-gradient(135deg, #fff 0%, #fffde8 50%, #f0f7e0 100%);
  color: #2d6a2e;
  font-family: 'Baloo 2', cursive, sans-serif;
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow:
    0 4px 20px rgba(0, 0, 0, 0.2),
    0 0 0 3px rgba(255, 255, 255, 0.35),
    inset 0 1px 0 rgba(255, 255, 255, 0.9);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  -webkit-tap-highlight-color: transparent;
  outline: none;
  pointer-events: auto;
}

.win-play-again:hover {
  transform: scale(1.06);
  box-shadow:
    0 6px 28px rgba(0, 0, 0, 0.28),
    0 0 0 3px rgba(255, 255, 255, 0.5),
    inset 0 1px 0 rgba(255, 255, 255, 1);
}

.win-play-again:active {
  transform: scale(0.96);
}

.win-btn-text {
  position: relative;
  z-index: 1;
}

/* Reuse the shine sweep from start screen */
.win-play-again .btn-shine {
  animation: shineSweep 3s ease-in-out infinite;
}

/* ══════════════════════════════════════════════════════
   PRE-MATCH COUNTDOWN
   ══════════════════════════════════════════════════════ */

/* ── Full-screen overlay ──────────────────────── */
.countdown-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease, background 0.4s ease;
}

.countdown-overlay.countdown-visible {
  opacity: 1;
  background: rgba(0, 0, 0, 0.45);
}

.countdown-overlay.countdown-fade-out {
  opacity: 0;
  background: rgba(0, 0, 0, 0);
  transition: opacity 0.45s ease, background 0.45s ease;
}

/* ── Center content ───────────────────────────── */
.countdown-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

/* Portrait countdown: the overlay is appended inside #ui which
   is already rotated, so no per-element rotation is needed. */

/* ── "First to N wins!" pill ──────────────────── */
.countdown-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.72);
  border-radius: 40px;
  padding: 10px 22px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  box-shadow:
    0 4px 24px rgba(0, 0, 0, 0.4),
    0 0 0 1px rgba(255, 255, 255, 0.06);
  animation: countdownPillIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.countdown-pill.countdown-pill-hide {
  opacity: 0;
  transform: scale(0.8) translateY(-10px);
}

.countdown-pill-emoji {
  font-size: 1.2rem;
  line-height: 1;
  animation: countdownTrophySpin 2s ease-in-out infinite;
}

.countdown-pill-text {
  font-family: 'Baloo 2', cursive, sans-serif;
  font-size: 1rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.04em;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.3);
}

@keyframes countdownPillIn {
  0% {
    opacity: 0;
    transform: scale(0.5) translateY(20px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes countdownTrophySpin {
  0%, 100% { transform: rotate(-6deg) scale(1); }
  25%      { transform: rotate(8deg) scale(1.1); }
  50%      { transform: rotate(-4deg) scale(1.05); }
  75%      { transform: rotate(6deg) scale(1.08); }
}

/* ── Big countdown number / GO! ───────────────── */
.countdown-big {
  font-family: 'Baloo 2', cursive, sans-serif;
  font-weight: 800;
  color: #fff;
  line-height: 1;
  text-align: center;
  letter-spacing: 0.02em;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.countdown-big.countdown-num {
  font-size: 4.5rem;
  text-shadow:
    0 4px 0 rgba(0, 0, 0, 0.15),
    0 0 40px rgba(255, 255, 255, 0.3),
    0 0 80px rgba(93, 187, 99, 0.25);
}

.countdown-big.countdown-go {
  font-size: 3.2rem;
  text-shadow:
    0 4px 0 rgba(0, 0, 0, 0.15),
    0 0 50px rgba(255, 224, 100, 0.5),
    0 0 100px rgba(255, 180, 60, 0.3);
  color: #ffe866;
}

/* ── Pop-in keyframe for each number ──────────── */
@keyframes countdownPop {
  0% {
    opacity: 0;
    transform: scale(2.2) translateY(5px);
  }
  40% {
    opacity: 1;
    transform: scale(0.9);
  }
  60% {
    transform: scale(1.08);
  }
  80% {
    transform: scale(0.97);
  }
  100% {
    transform: scale(1);
  }
}

.countdown-big.countdown-pop {
  animation: countdownPop 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

/* ── Mode Badge (shown during countdown) ──────────── */
.countdown-mode-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 220, 80, 0.18);
  border: 1px solid rgba(255, 220, 80, 0.35);
  border-radius: 30px;
  padding: 8px 20px;
  font-family: 'Baloo 2', cursive, sans-serif;
  font-size: 1.05rem;
  font-weight: 700;
  color: #ffe866;
  letter-spacing: 0.05em;
  text-shadow: 0 1px 8px rgba(255, 220, 80, 0.4);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow:
    0 2px 16px rgba(255, 220, 80, 0.15),
    0 0 0 1px rgba(255, 255, 255, 0.05);
  animation: modeBadgeIn 0.6s 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both,
             modeBadgePulse 2s 1s ease-in-out infinite;
}

@keyframes modeBadgeIn {
  0% {
    opacity: 0;
    transform: scale(0.5) translateY(10px);
  }
  100% {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes modeBadgePulse {
  0%, 100% {
    box-shadow:
      0 2px 16px rgba(255, 220, 80, 0.15),
      0 0 0 1px rgba(255, 255, 255, 0.05);
  }
  50% {
    box-shadow:
      0 2px 24px rgba(255, 220, 80, 0.3),
      0 0 0 1px rgba(255, 255, 255, 0.1);
  }
}

/* ══════════════════════════════════════════════════════
   DESKTOP FULL-SCREEN ENHANCEMENTS
   ══════════════════════════════════════════════════════ */

/* On large desktop screens, scale up UI elements slightly */
@media (min-width: 1025px) and (min-height: 641px) {
  .start-title h1 {
    font-size: 3.2rem;
  }

  .start-subtitle {
    font-size: 1rem;
  }

  .beans-overlay {
    width: 220px;
  }

  .mode-btn {
    padding: 16px 28px;
    font-size: 1.2rem;
  }

  .difficulty-panel {
    max-width: 380px;
    padding: 26px 26px 20px;
  }

  .action-slot {
    max-width: 380px;
    min-height: 360px;
  }

  .difficulty-title {
    font-size: 1.7rem;
  }

  .difficulty-label {
    font-size: 1.1rem;
  }

  .difficulty-start-btn {
    padding: 16px 28px;
    font-size: 1.25rem;
  }

  .countdown-big.countdown-num {
    font-size: 5.5rem;
  }

  .countdown-big.countdown-go {
    font-size: 4rem;
  }

  .countdown-pill-text {
    font-size: 1.15rem;
  }

  .countdown-mode-badge {
    font-size: 1.15rem;
    padding: 10px 24px;
  }

  .score-badge {
    min-width: 48px;
    height: 38px;
    font-size: 1.15rem;
    padding: 0 14px;
  }

  .scoreboard {
    padding: 5px;
    border-radius: 16px;
  }

  .win-title {
    font-size: 2rem;
  }

  .win-trophy {
    font-size: 3rem;
  }

  .win-play-again {
    padding: 12px 36px;
    font-size: 1.05rem;
  }
}

/* ══════════════════════════════════════════════════════
   MID-MATCH MODE PILL
   ══════════════════════════════════════════════════════
   A compact pill that appears directly below the
   scoreboard. No overlay, no gameplay obstruction.
   Serves double duty: brief "announce" flash, then
   shrinks into a countdown timer.
*/

/* ── Base pill – hidden until a mode triggers ───── */
.mode-pill {
  position: absolute;
  z-index: 11;           /* just above scoreboard (z:10) */
  pointer-events: none;
  font-family: 'Baloo 2', cursive, sans-serif;
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0, 0, 0, 0.8);
  border-radius: 20px;
  padding: 5px 12px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 220, 80, 0.3);
  box-shadow:
    0 2px 12px rgba(0, 0, 0, 0.45),
    0 0 16px rgba(255, 220, 80, 0.08);
  white-space: nowrap;
  opacity: 0;
  transform: translateX(-50%) translateY(-6px) scale(0.9);
  transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ── Centered below scoreboard (works in both orientations
     because #ui.portrait handles the rotation) ───── */
.mode-pill {
  top: 52px;
  left: 50%;
}

/* ── Visible state ─────────────────────────────── */
.mode-pill.mode-pill-show {
  opacity: 1;
  transform: translateX(-50%) translateY(0) scale(1);
}

/* ── Announce phase: slightly bigger & glowy ────── */
.mode-pill.mode-pill-announce {
  padding: 6px 16px;
  border-color: rgba(255, 220, 80, 0.55);
  box-shadow:
    0 2px 16px rgba(0, 0, 0, 0.5),
    0 0 24px rgba(255, 220, 80, 0.2);
  animation: modePillPop 0.45s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.mode-pill.mode-pill-announce .mode-pill-label {
  font-size: 0.92rem;
  color: #ffe866;
  text-shadow: 0 1px 8px rgba(255, 220, 80, 0.5);
}

/* Hide track & time during announce */
.mode-pill.mode-pill-announce .mode-pill-track,
.mode-pill.mode-pill-announce .mode-pill-time {
  width: 0;
  opacity: 0;
  overflow: hidden;
  padding: 0;
  margin: 0;
}

@keyframes modePillPop {
  0%   { transform: translateX(-50%) translateY(0) scale(0.5); opacity: 0; }
  50%  { transform: translateX(-50%) translateY(0) scale(1.1); }
  100% { transform: translateX(-50%) translateY(0) scale(1); opacity: 1; }
}

/* No portrait-specific pop animation needed — #ui.portrait
   handles rotation, so the standard modePillPop works everywhere. */

/* ── Timer phase: compact with progress bar ────── */
.mode-pill.mode-pill-timer .mode-pill-track,
.mode-pill.mode-pill-timer .mode-pill-time {
  opacity: 1;
  transition: opacity 0.3s ease, width 0.3s ease;
}

.mode-pill.mode-pill-timer .mode-pill-label {
  font-size: 0.72rem;
}

/* ── Hide transition ──────────────────────────── */
.mode-pill.mode-pill-hide {
  opacity: 0;
  transform: translateX(-50%) translateY(-8px) scale(0.9);
  transition: opacity 0.35s ease, transform 0.35s ease;
}

/* ── Label ────────────────────────────────────── */
.mode-pill-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: #ffe866;
  letter-spacing: 0.03em;
  text-shadow: 0 1px 4px rgba(255, 220, 80, 0.3);
  flex-shrink: 0;
  transition: font-size 0.3s ease, color 0.3s ease;
}

/* ── Timer track ──────────────────────────────── */
.mode-pill-track {
  width: 56px;
  height: 5px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.15);
  overflow: hidden;
  flex-shrink: 0;
  transition: width 0.3s ease, opacity 0.3s ease;
}

.mode-pill-fill {
  width: 100%;
  height: 100%;
  border-radius: 3px;
  background: linear-gradient(90deg, #ff6b6b, #ffe866);
  box-shadow: 0 0 6px rgba(255, 220, 80, 0.35);
  transition: width 0.1s linear;
}

/* ── Time text ────────────────────────────────── */
.mode-pill-time {
  font-size: 0.7rem;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.8);
  min-width: 20px;
  text-align: right;
  flex-shrink: 0;
  transition: opacity 0.3s ease;
}

/* ── Urgent pulse when ≤ 2s left ──────────────── */
.mode-pill.mode-pill-urgent {
  animation: modePillUrgent 0.5s ease-in-out infinite;
}

.mode-pill.mode-pill-urgent .mode-pill-fill {
  background: linear-gradient(90deg, #ff4444, #ff6b6b);
  box-shadow: 0 0 10px rgba(255, 68, 68, 0.6);
}

@keyframes modePillUrgent {
  0%, 100% {
    border-color: rgba(255, 68, 68, 0.4);
    box-shadow:
      0 2px 12px rgba(0, 0, 0, 0.45),
      0 0 16px rgba(255, 68, 68, 0.15);
  }
  50% {
    border-color: rgba(255, 68, 68, 0.7);
    box-shadow:
      0 2px 12px rgba(0, 0, 0, 0.45),
      0 0 22px rgba(255, 68, 68, 0.3);
  }
}

/* ── Desktop scaling ─────────────────────────── */
@media (min-width: 1025px) and (min-height: 641px) {
  .mode-pill {
    top: 58px;
    padding: 6px 16px;
    gap: 8px;
  }

  .mode-pill-label {
    font-size: 0.78rem;
  }

  .mode-pill.mode-pill-announce .mode-pill-label {
    font-size: 1rem;
  }

  .mode-pill-track {
    width: 72px;
    height: 6px;
  }

  .mode-pill-time {
    font-size: 0.76rem;
  }
}

/* ── Generic hidden utility ─────────────────────── */
.hidden {
  display: none !important;
}
