/* Fusion de fruits: soft garden skin over the shared header. Mobile first;
   sizes grow with the screen (vmin) up to a 4K TV. Page frame, chips,
   cards, buttons and overlays here; start screen in start.css, play stage
   in stage.css. */
html {
  font-size: clamp(16px, 2.4vmin, 64px);
}

html,
body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  min-height: 0;
  background: #cfe7c8;
  color: #3d3a4b;
}

.game-nav {
  flex: 0 0 auto;
  background: #cfe7c8;
  border-bottom: 1px solid rgba(61, 58, 75, 0.12);
  box-shadow: none;
}

.nav-title {
  color: #3d3a4b;
  font-weight: 900;
  letter-spacing: 0.02em;
}

.back-button,
.options-button {
  background: #9b5aa3;
  color: #ffffff;
}

.options-panel-sheet {
  color: #1f2937;
}

.fm-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.fm-chip {
  min-width: 3.5em;
  min-height: 2.75em;
  padding: 0.5em 0.9em;
  border: 2px solid #d1d5db;
  border-radius: 0.75em;
  background: #ffffff;
  color: #1f2937;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.fm-chip.active,
.fm-chip[aria-pressed="true"] {
  border-color: #9b5aa3;
  background: #f3e6f5;
}

/* Rule 6.2: Android bars can cover the bottom even when the safe-area
   inset is 0, and the sides carry the system back gestures. The start
   screen, the stage and the overlays all pad with these. */
.fm-app {
  --fm-pad-l: max(24px, env(safe-area-inset-left, 0px));
  --fm-pad-r: max(24px, env(safe-area-inset-right, 0px));
  --fm-pad-b: max(40px, calc(env(safe-area-inset-bottom, 0px) + 24px));
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.fm-app [hidden] {
  display: none !important;
}

.fm-app button:focus-visible,
.fm-app canvas:focus-visible,
.fm-chip:focus-visible {
  outline: 3px solid #ffb703;
  outline-offset: 3px;
}

.fm-card {
  width: min(100%, 26em);
  padding: 1.1em 1em 1.25em;
  border: 0.25em solid #ffffff;
  border-radius: 1.5em;
  background: #fff4e2;
  text-align: center;
  box-shadow: 0 0.6em 1.6em rgba(61, 58, 75, 0.25);
}

.fm-card p {
  margin: 0 0 0.6em;
  line-height: 1.4;
}

.fm-button {
  display: block;
  width: min(100%, 14em);
  min-height: 3em;
  margin: 0.6em auto 0;
  padding: 0.6em 1.4em;
  border: none;
  border-radius: 0.9em;
  background: #9b5aa3;
  color: #ffffff;
  font: inherit;
  font-size: 1.15em;
  font-weight: 900;
  box-shadow: 0 0.25em 0 #6c3a73;
  cursor: pointer;
  touch-action: manipulation;
}

.fm-button:active {
  transform: translateY(0.15em);
  box-shadow: 0 0.08em 0 #6c3a73;
}

.fm-button:disabled {
  background: #8d8a94;
  box-shadow: 0 0.25em 0 #5e5b66;
  cursor: default;
}

.fm-button-soft {
  background: #ffffff;
  color: #6c3a73;
  box-shadow: 0 0.25em 0 #d9c2dc;
}

.fm-best {
  margin-top: 0.8em !important;
  font-weight: 800;
  color: #b4572f;
}

.fm-overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 1em var(--fm-pad-r) var(--fm-pad-b) var(--fm-pad-l);
  overflow-y: auto;
  background: rgba(43, 20, 20, 0.55);
}

.fm-overlay-title {
  margin: 0 0 0.5em;
  font-size: 1.7em;
  font-weight: 900;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.fm-score-line {
  font-size: 1.6em;
  font-weight: 900;
  color: #9b5aa3;
}

.fm-end-card {
  animation: fm-pop 0.4s ease-out 0.5s both;
}

.fm-end-fruit {
  display: block;
  width: 5em;
  height: 5em;
  margin: 0 auto 0.4em;
}

@keyframes fm-pop {
  from {
    opacity: 0;
    transform: scale(0.85);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Desktop and TV, 960x540 up to 3840x2160: the shared header grows with
   the screen and everything keeps 3% away from the edges (TV overscan). */
@media (min-width: 960px) and (min-height: 500px) {
  .game-nav {
    height: auto;
    padding: 3dvh max(3vw, env(safe-area-inset-right, 0px)) 1dvh
      max(3vw, env(safe-area-inset-left, 0px));
  }

  .back-button,
  .options-button {
    width: max(36px, 6dvh);
    height: max(36px, 6dvh);
    font-size: max(1rem, 3dvh);
  }

  .back-button svg,
  .options-button svg {
    width: 50%;
    height: 50%;
  }

  .fm-app {
    --fm-pad-l: max(3vw, env(safe-area-inset-left, 0px));
    --fm-pad-r: max(3vw, env(safe-area-inset-right, 0px));
    --fm-pad-b: max(40px, 4dvh);
  }

  .fm-overlay {
    padding-top: 2dvh;
  }
}

/* TV remote: a thick, high-contrast ring on the focused control. */
html.tv :focus {
  outline: 0.25rem solid #ffb703 !important;
  outline-offset: 0.2rem;
  box-shadow: 0 0 0 0.5rem rgba(61, 42, 90, 0.85);
}

/* Short landscape screens: the overlays must fit in ~300px. */
@media (orientation: landscape) and (max-height: 500px) {
  .fm-card {
    width: min(100%, 34em);
    padding: 0.6em 1em 0.8em;
  }

  .fm-overlay-title {
    margin-bottom: 0.2em;
    font-size: 1.3em;
  }

  .fm-button {
    min-height: 2.6em;
    margin-top: 0.4em;
  }

  .fm-end-fruit {
    width: 3em;
    height: 3em;
  }
}
