/* PFC Arcade — shared gameplay layout (opt-in).

   A game opts in by linking this file and arcade-layout.js and marking up its
   gameplay screen as:

     .arc-stage                 exactly one visible screen tall (100dvh)
       .arc-top                 HUD row(s): .arc-back chip, score, title…
       .arc-fit                 the space left over for the pitch
         .arc-pitch             the pitch: as big as fits, at --arc-ratio
       .arc-bottom              coach message, question, buttons…

   Stacked (default): top / pitch / bottom in one column.
   Side: pitch on the left at full height, top + bottom in a column on the
   right that gets whatever width the pitch doesn't need (at least --arc-panel). arcade-layout.js picks side only when the viewport
   (not the content) gives a clearly bigger pitch that way, so the layout
   never jumps while coach messages or buttons change. With no JS the stacked
   layout still fits.

   Per game, set on .arc-stage:
     --arc-ratio     pitch width / height (1.5 = 3:2)
     --arc-reserve   px the stacked top + bottom need (layout choice only)
     --arc-panel     smallest side-panel width in px
     --arc-pitch-max largest pitch width

   Inside .arc-pitch (a container), sizes can follow the pitch width:
     --arc-token / --arc-token-hi / --arc-token-font   player discs and labels
     --arc-tap / --arc-tap-token                       anything tapped: never under 44px
   Each game's JS falls back to its original px size, e.g. var(--arc-token,46px). */

.arc-stage {
  --arc-ratio: 1.5;
  --arc-reserve: 250px;
  --arc-panel: 300px;
  --arc-pitch-max: 1200px;
  --arc-gap: 10px;
  --arc-pad: 10px;
  box-sizing: border-box;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  /* The pitch row grows only as tall as a full-width pitch, so on tall phones
     the HUD, pitch and coach stay together in the middle instead of drifting
     to the screen edges. */
  grid-template-rows: auto minmax(0, calc(min(100vw - var(--arc-pad) * 2, var(--arc-pitch-max)) / var(--arc-ratio))) auto;
  grid-template-areas: "top" "fit" "bottom";
  align-content: center;
  gap: var(--arc-gap);
  padding:
    max(var(--arc-pad), env(safe-area-inset-top))
    max(var(--arc-pad), env(safe-area-inset-right))
    max(var(--arc-pad), env(safe-area-inset-bottom))
    max(var(--arc-pad), env(safe-area-inset-left));
}
.arc-stage *, .arc-stage *::before, .arc-stage *::after { box-sizing: border-box; }

.arc-top, .arc-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--arc-gap);
  min-width: 0;
}
.arc-top { grid-area: top; }
.arc-bottom { grid-area: bottom; }

.arc-fit {
  grid-area: fit;
  /* Always fill the cell, whatever the page's own align-items says (a size
     container has no height of its own). */
  align-self: stretch;
  justify-self: stretch;
  container-type: size;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.arc-pitch {
  position: relative;
  flex: none;
  width: min(100cqw, calc(100cqh * var(--arc-ratio)), var(--arc-pitch-max));
  aspect-ratio: var(--arc-ratio);
  container-type: inline-size;
  --arc-token: clamp(28px, 4.9cqw, 46px);
  --arc-token-hi: clamp(32px, 5.3cqw, 50px);
  --arc-token-font: clamp(11px, 1.6cqw, 15px);
  --arc-tap: clamp(44px, 6cqw, 56px);
  --arc-tap-token: clamp(44px, 5.3cqw, 50px);
}
/* Browsers without container units (Chrome < 105, Safari < 16): size from the viewport instead. */
@supports not (width: 1cqw) {
  .arc-pitch { width: min(100%, calc((100vh - var(--arc-reserve)) * var(--arc-ratio)), var(--arc-pitch-max)); }
}

/* Side layout: pitch left, panel right, panel content centred top to bottom. */
html[data-arc-layout="side"] .arc-stage {
  /* The pitch column is only as wide as a full-height pitch; the panel gets the rest. */
  grid-template-columns: minmax(0, calc((100vh - var(--arc-pad) * 2) * var(--arc-ratio))) minmax(var(--arc-panel), 1fr);
  grid-template-columns: minmax(0, calc((100dvh - var(--arc-pad) * 2) * var(--arc-ratio))) minmax(var(--arc-panel), 1fr);
  justify-content: center;
  grid-template-rows: minmax(0, 1fr) auto auto minmax(0, 1fr);
  grid-template-areas: "fit ." "fit top" "fit bottom" "fit .";
  column-gap: 14px;
  align-content: stretch;
}
/* Never taller than the screen, even if the panel's content is. */
html[data-arc-layout="side"] .arc-fit { justify-content: flex-end; max-height: calc(100vh - var(--arc-pad) * 2); max-height: calc(100dvh - var(--arc-pad) * 2); }

/* Way back to the arcade: a chip in the HUD (never over the pitch), with a
   44px-tall touch area. .arc-back--fixed is for full-screen title / result
   overlays, which have no HUD. */
.arc-back {
  position: relative;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  background: #141414;
  color: #f2b705;
  border: 2px solid #f2b705;
  border-radius: 12px;
  font-family: Fredoka, sans-serif;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .3px;
  padding: 6px 14px;
  text-decoration: none;
  white-space: nowrap;
}
.arc-back:hover, .arc-back:focus-visible { color: #ffd75e; border-color: #ffd75e; }
.arc-back--fixed {
  position: fixed;
  left: calc(14px + env(safe-area-inset-left));
  top: calc(14px + env(safe-area-inset-top));
  z-index: 200;
  font-size: 17px;
  padding: 8px 18px;
  box-shadow: 0 4px 0 rgba(0, 0, 0, .4);
}

/* Full-screen title / result overlays (.arc-overlay): centred while they fit,
   scrollable from the top when they don't (plain centring pushes the top out of
   reach on short screens), and clear of the fixed back chip. */
.arc-overlay { overflow-y: auto; justify-content: flex-start !important; padding-top: max(24px, calc(66px + env(safe-area-inset-top))) !important; }
.arc-overlay::before, .arc-overlay::after { content: ""; flex: 1 0 0; }

/* Pop-up cards over the game (.arc-modal on the full-screen backdrop): centred
   with auto margins, which never push the card's top out of reach, and the
   backdrop scrolls when the card is taller than the screen. */
.arc-modal { overflow-y: auto; align-items: flex-start !important; justify-content: flex-start !important; }
.arc-modal > * { margin: auto; }

/* Small text links and secondary buttons: at least 44px tall to tap. */
.arc-tap44 { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; }

/* Coach row: room for two lines from the start, so a longer message doesn't
   shrink the pitch mid-game. In the side panel the badge sits above the bubble. */
.arc-coach { display: flex; align-items: center; justify-content: center; gap: 10px; min-height: var(--arc-coach-min, 76px); max-width: 100%; }
.arc-coach > :last-child { min-width: 0; }
html[data-arc-layout="side"] .arc-coach { flex-direction: column; align-items: stretch; width: 100%; }
html[data-arc-layout="side"] .arc-coach > :first-child { align-self: flex-start; }
/* A bubble's own min-width (e.g. min(300px,70vw)) would push it past a narrow panel. */
html[data-arc-layout="side"] .arc-coach > :last-child { min-width: 0 !important; }

/* HUD row and scene title (games mark them .arc-hud / .arc-title). */
.arc-hud { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px 16px; }
.arc-title { text-align: center; }
html[data-arc-layout="side"] .arc-hud { gap: 8px 10px; }

/* Short screens (landscape phones): tighter spacing and text so everything
   fits beside the pitch; the coach badge stays beside its bubble. */
@media (max-height: 520px) {
  .arc-stage { --arc-gap: 6px; --arc-pad: 6px; --arc-panel: 280px; }
  .arc-coach > :last-child { font-size: 16px !important; padding: 8px 12px !important; }
  .arc-coach { min-height: var(--arc-coach-min-short, 58px); }
  .arc-title { font-size: 15px !important; letter-spacing: 1px !important; }
  .arc-hud > :not(.arc-back) { padding: 4px 10px !important; }
  html[data-arc-layout="side"] .arc-coach { flex-direction: row; align-items: center; }
  html[data-arc-layout="side"] .arc-coach > :first-child { align-self: center; }
}
