/* The session runner.
 *
 * One fixed-height screen with no scrolling, because a child mid exercise
 * should never have to find a control that has moved. Everything is laid out
 * against 100dvh with the action button pinned to the bottom third, which is
 * where a thumb rests on an iPad held in two hands.
 *
 * The court, the hoop, the ball and the confetti are all CSS. The camera
 * mirror is a live video element sitting behind the hoop, so when it is on he
 * is literally looking at his own mouth inside the backboard.
 */

body.play {
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(70rem 40rem at 50% -12rem, #26365f 0%, transparent 60%),
    var(--ink);
}

/* Full width, not a 46rem reading column. The scorebar wants the edges of an
 * iPad and the run stage wants two columns, so the width is constrained per
 * stage instead of here. Grid rather than flex so the stage gets exactly the
 * space left over: with flex it could overflow upward and print itself over
 * the scorebar, which is precisely what it did. */
.court {
  position: relative;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  padding: max(0.5rem, env(safe-area-inset-top))
           clamp(0.9rem, 3vw, 2rem)
           max(1.4rem, calc(env(safe-area-inset-bottom) + 1rem));
}

/* Hardwood, painted with gradients. The arcs are two radial gradients rather
   than an SVG, so there is nothing to fetch. */
.court::before {
  content: "";
  position: absolute;
  inset: auto 0 0 0;
  height: 42%;
  z-index: -1;
  background:
    radial-gradient(30rem 14rem at 50% 100%, transparent 58%,
      rgba(255, 255, 255, 0.16) 58.6%, rgba(255, 255, 255, 0.16) 59.6%, transparent 60%),
    radial-gradient(12rem 6rem at 50% 100%, transparent 68%,
      rgba(255, 255, 255, 0.14) 68.6%, rgba(255, 255, 255, 0.14) 69.6%, transparent 70%),
    repeating-linear-gradient(90deg,
      rgba(0, 0, 0, 0.16) 0 1px, transparent 1px 46px),
    linear-gradient(180deg, #a9682f, #8a4f24);
  opacity: 0.55;
  mask-image: linear-gradient(180deg, transparent, #000 30%);
}

/* ── Scoreboard ───────────────────────────────────────────────────────── */

.scorebar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding-bottom: 0.7rem;
  /* Above the stage in the paint order, so if anything ever does overflow it
     goes behind the controls rather than through them. */
  position: relative;
  z-index: 5;
}

.sb-group { display: flex; gap: 0.5rem; flex: 0 0 auto; }

/* The quarters float in the middle, the score is pinned right. */
.scorebar .quarters { margin: 0 auto; }

.icon-btn {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--paper);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0;
}

.icon-btn[aria-pressed="false"] { opacity: 0.4; }

.quarters {
  display: flex;
  gap: 0.3rem;
  align-items: center;
}

.quarters i {
  width: 26px;
  height: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
}

.quarters i.on { background: var(--gold); }
.quarters i.done { background: var(--mint); }

.score {
  flex: 0 0 auto;
  display: flex;
  align-items: baseline;
  gap: 0.4rem;
  padding: 0.3rem 0.7rem;
  border-radius: 10px;
  background: #05070f;
  border: 1px solid var(--line);
  box-shadow: inset 0 0 18px rgba(249, 115, 22, 0.15);
}

.score .lbl {
  font-size: 0.6rem;
  letter-spacing: 0.16em;
  color: var(--muted);
  text-transform: uppercase;
}

.score .val {
  font: 900 1.5rem/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--ball);
  text-shadow: 0 0 14px rgba(249, 115, 22, 0.7);
  font-variant-numeric: tabular-nums;
}

/* ── Stage ────────────────────────────────────────────────────────────── */

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
  text-align: center;
  min-height: 0;
  width: 100%;
  max-width: 46rem;
  margin: 0 auto;
}

.stage[hidden] { display: none; }

/* ── The run stage: instructions left, mirror right ───────────────────── */

.stage.run {
  max-width: 72rem;
  justify-content: space-between;
  gap: 0.6rem;
}

.run-grid {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.9rem;
}

.run-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}

@media (min-width: 720px) {
  .run-grid {
    flex-direction: row;
    gap: clamp(1.5rem, 5vw, 4rem);
    justify-content: center;
  }

  .run-info {
    align-items: flex-start;
    text-align: left;
    flex: 1 1 0;
    max-width: 30rem;
  }

  .run-info .shots { justify-content: flex-start; }
  .run-info .mic { width: 100%; }
}

.ex-name {
  font-size: clamp(1.5rem, 6.5vw, 2.4rem);
  font-weight: 900;
  letter-spacing: -0.02em;
  line-height: 1.05;
  margin: 0;
}

.ex-emoji { font-size: clamp(2.5rem, 12vw, 4rem); line-height: 1; }

.ex-cue {
  margin: 0;
  max-width: 30rem;
  font-size: clamp(1rem, 3.6vw, 1.2rem);
  color: #dce6ff;
}

.ex-tip {
  margin: 0;
  max-width: 28rem;
  font-size: 0.9rem;
  color: var(--muted);
}

.ex-count {
  font-weight: 900;
  color: var(--gold);
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* ── The hoop, the ring timer and the mirror ──────────────────────────── */

/* Sized off the viewport HEIGHT as well as the width, because the thing that
 * actually runs out on an iPad in landscape is vertical room. Big enough that
 * a child can see his own tongue in it, which is the entire point of the
 * mirror. */
.hoop {
  position: relative;
  /* 54vh, not more: the scorebar and the action row take roughly 240px
     between them, so anything greedier overflows on a landscape iPad with
     Safari's chrome showing. Still about half again the size it started at,
     which is the difference between a thumbnail and a usable mirror. */
  width: min(74vw, 54vh, 23rem);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.hoop svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }

.hoop .track { fill: none; stroke: rgba(255, 255, 255, 0.12); stroke-width: 9; }

.hoop .bar {
  fill: none;
  stroke: var(--ball);
  stroke-width: 9;
  stroke-linecap: round;
  filter: drop-shadow(0 0 8px rgba(249, 115, 22, 0.8));
  transition: stroke 0.2s ease;
}

.hoop.holding .bar { stroke: var(--mint); filter: drop-shadow(0 0 10px rgba(52, 211, 153, 0.9)); }

.hoop .inner {
  position: relative;
  width: 82%;
  height: 82%;
  border-radius: 50%;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 30%, #1b2547, #0a0f21);
  border: 1px solid var(--line);
}

.hoop .big {
  font: 900 clamp(2.6rem, 14vw, 4.4rem)/1 ui-monospace, SFMono-Regular, Menlo, monospace;
  font-variant-numeric: tabular-nums;
  color: #fff;
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.35);
  z-index: 2;
}

/* The camera. Mirrored, because an unmirrored view of your own face is
   confusing, and object-fit cover so a portrait iPad does not letterbox. */
#mirror {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  opacity: 0;
  transition: opacity 0.3s ease;
}

.hoop.mirror-on #mirror { opacity: 1; }

/* With the camera on, the countdown gets out of the way. Dead centre of the
 * circle is exactly where his mouth is, so leaving it there hides the one
 * thing the mirror exists to show him. It drops to a pill along the bottom
 * edge instead: still large, still glanceable, no longer in front of his
 * face. */
.hoop.mirror-on .big {
  position: absolute;
  bottom: 4%;
  left: 50%;
  transform: translateX(-50%);
  font-size: clamp(1.6rem, 7vw, 2.4rem);
  line-height: 1;
  padding: 0.1em 0.5em;
  border-radius: 999px;
  background: rgba(4, 7, 16, 0.72);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  text-shadow: none;
}

/* Ball drops through on a made rep. */
.swish {
  position: absolute;
  z-index: 3;
  font-size: 2.4rem;
  pointer-events: none;
  animation: drop 0.65s cubic-bezier(0.3, 0.1, 0.4, 1) forwards;
}

@keyframes drop {
  0% { transform: translateY(-140%) scale(0.7); opacity: 0; }
  35% { opacity: 1; }
  100% { transform: translateY(150%) scale(1.15); opacity: 0; }
}

/* ── Shot chart ───────────────────────────────────────────────────────── */

.shots {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 26rem;
}

.shots i {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.13);
  border: 1px solid var(--line);
  transition: transform 0.25s cubic-bezier(0.2, 1.6, 0.4, 1), background 0.25s ease;
}

.shots i.made {
  background: linear-gradient(180deg, var(--ball), var(--ball-2));
  border-color: transparent;
  transform: scale(1.25);
  box-shadow: 0 0 10px -1px rgba(249, 115, 22, 0.9);
}

/* ── Mic meter ────────────────────────────────────────────────────────── */

.mic {
  width: min(90%, 26rem);
  display: grid;
  gap: 0.35rem;
}

.mic .lbl {
  font-size: 0.75rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
}

.mic .bar {
  height: 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line);
  overflow: hidden;
  position: relative;
}

.mic .bar > span {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--sky), var(--mint));
  transition: width 0.06s linear;
}

/* Where the click has to land to register. */
.mic .bar::after {
  content: "";
  position: absolute;
  top: -2px;
  bottom: -2px;
  left: var(--gate, 60%);
  width: 3px;
  background: var(--gold);
  box-shadow: 0 0 8px var(--gold);
}

.mic.hot .bar > span { background: linear-gradient(90deg, var(--gold), var(--ball)); }

/* ── Action row ───────────────────────────────────────────────────────── */

.actions {
  flex: 0 0 auto;
  display: grid;
  gap: 0.6rem;
  padding-top: 0.6rem;
  width: 100%;
  max-width: 30rem;
  margin: 0 auto;
}

.actions .row { display: flex; gap: 0.6rem; }
.actions .row > * { flex: 1 1 0; }

.btn.go {
  min-height: 86px;
  font-size: 1.5rem;
  border-radius: 22px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: linear-gradient(180deg, var(--ball), var(--ball-2));
  color: #1a0b02;
  box-shadow: 0 16px 34px -14px rgba(249, 115, 22, 0.9),
              inset 0 2px 0 rgba(255, 255, 255, 0.45);
}

.btn.go.holding {
  background: linear-gradient(180deg, var(--mint), #10b981);
  box-shadow: 0 16px 34px -14px rgba(52, 211, 153, 0.9),
              inset 0 2px 0 rgba(255, 255, 255, 0.45);
  color: #04241a;
}

.btn.small { min-height: 46px; font-size: 0.95rem; padding: 0.5rem 0.9rem; }

/* ── Coach line ───────────────────────────────────────────────────────── */

.coach {
  min-height: 1.6rem;
  font-weight: 800;
  color: var(--gold);
  font-size: 1.05rem;
}

.coach.pop { animation: pop 0.4s cubic-bezier(0.2, 1.6, 0.4, 1); }

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

/* ── Timeout ──────────────────────────────────────────────────────────── */

.breathe {
  width: min(50vw, 12rem);
  aspect-ratio: 1;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, var(--sky), #1e3a8a);
  box-shadow: 0 0 60px -10px rgba(56, 189, 248, 0.8);
  animation: breathe 8s ease-in-out infinite;
  display: grid;
  place-items: center;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-size: 0.9rem;
}

@keyframes breathe {
  0%, 100% { transform: scale(0.72); }
  50% { transform: scale(1); }
}

/* ── Post game ────────────────────────────────────────────────────────── */

.post {
  overflow-y: auto;
  align-items: stretch;
  justify-content: flex-start;
  padding: 0.5rem 0 1rem;
  text-align: left;
  -webkit-overflow-scrolling: touch;
}

.post h2 {
  text-align: center;
  font-size: clamp(1.6rem, 7vw, 2.4rem);
  margin: 0.4rem 0 0.2rem;
  font-weight: 900;
}

.post .banner {
  text-align: center;
  color: var(--gold);
  font-weight: 800;
  margin-bottom: 0.8rem;
}

.boxscore { width: 100%; border-collapse: collapse; font-size: 0.95rem; }

.boxscore th, .boxscore td {
  padding: 0.5rem 0.4rem;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

.boxscore th {
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.boxscore td.n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 800; }
.boxscore tr.miss td { color: var(--muted); }

.tally {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin: 0.9rem 0;
}

.tally div {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 0.6rem;
  text-align: center;
}

.tally b { display: block; font-size: 1.5rem; font-weight: 900; }
.tally span { font-size: 0.68rem; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }

/* ── Where he stands, on the tip off screen ───────────────────────────── */

.standing {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  width: min(100%, 28rem);
}

.standing .pill {
  display: inline-flex;
  align-items: baseline;
  gap: 0.45rem;
  padding: 0.45rem 1rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  border: 1px solid var(--line);
}

.standing .pill b {
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--ball);
  font-variant-numeric: tabular-nums;
}

.standing .pill.done b { color: var(--mint); }
.standing .pill span { color: var(--muted); font-size: 0.9rem; }

.prize-next { width: 100%; }

/* ── A prize just won ─────────────────────────────────────────────────── */

.won {
  text-align: center;
  border-radius: var(--r);
  padding: 1rem;
  margin: 0.4rem 0 1rem;
  background:
    linear-gradient(180deg, rgba(251, 191, 36, 0.22), rgba(251, 191, 36, 0.03)),
    rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(251, 191, 36, 0.5);
  animation: pop 0.5s cubic-bezier(0.2, 1.6, 0.4, 1);
}

.won .em { font-size: 3rem; line-height: 1.1; }
.won .what { font-size: 1.3rem; font-weight: 900; }
.won .who { color: var(--muted); font-size: 0.9rem; margin-top: 0.3rem; }

/* ── Confetti ─────────────────────────────────────────────────────────── */

.confetti {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 50;
}

.confetti i {
  position: absolute;
  top: -12px;
  width: 9px;
  height: 14px;
  opacity: 0.95;
  animation: fall linear forwards;
}

@keyframes fall {
  to { transform: translateY(110dvh) rotate(720deg); opacity: 0.9; }
}

/* ── Short screens ────────────────────────────────────────────────────── */

@media (max-height: 620px) {
  .hoop { width: min(46vw, 46vh, 13rem); }
  .ex-tip { display: none; }
  .btn.go { min-height: 66px; font-size: 1.2rem; }
  .stage { gap: 0.5rem; }
}
