/* ============================================================
   Tape Ball mini-app

   Pitch green and floodlit dusk — a partner surface again, owing nothing to
   the wallet's yellow or the bank's red. The whole screen is one fixed,
   non-scrolling board: a game that scrolls under the thumb mid-delivery is a
   game that loses the delivery.
   ============================================================ */
:root {
  --tb-turf: #157A46;
  --tb-turf-dark: #0B4B2B;
  --tb-dusk: #10243A;
  --tb-strip: #C9A46A;
  --tb-ink: #07281A;
  --tb-hot: #FFC531;
  --tb-bad: #FF6B6B;
}

.tb-app {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 100%;
  overflow: hidden;
  background: linear-gradient(180deg, var(--tb-dusk) 0%, #143A2A 42%, var(--tb-turf-dark) 100%);
  color: #FFF;
  user-select: none;
  -webkit-user-select: none;
}
.tb-app:focus { outline: none; }

/* Everything here is shown and hidden with the `hidden` attribute, and an
   author `display` declaration silently beats the browser's own
   `[hidden] { display: none }`. One overlay already shipped that way — it
   covered the pitch and swallowed every tap — so the rule is enforced for the
   whole subtree rather than remembered per element. */
.tb-app [hidden] { display: none !important; }

/* Before the first ball there is no score, no fitness to report, and the cover
   carries its own Play button — so the live scoreboard and the bat button stay
   out of the title screen rather than sitting above it looking live. The host
   note survives: it is true on every screen. */
.tb-app.on-cover .tb-hud,
.tb-app.on-cover .tb-healthbar,
.tb-app.on-cover .tb-tap { display: none; }

/* ---------- host chrome ---------- */
/* Above every overlay on purpose. The host's chrome is the one thing a partner
   surface must never be able to cover: whatever the mini-app puts on screen —
   including its own full-screen cover — the way out stays tappable. */
.tb-top {
  position: relative;
  z-index: 7;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px 4px;
  flex-shrink: 0;
}
.tb-brand { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
.tb-brand img { width: 26px; height: 26px; border-radius: 8px; display: block; }
.tb-brand span { font-size: 14px; font-weight: 700; letter-spacing: 0.01em; }

.tb-capsule {
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 3px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.22);
  backdrop-filter: blur(8px);
  color: #FFF;
  flex-shrink: 0;
}
.tb-capsule-btn {
  width: 30px; height: 26px;
  border: none; background: none;
  display: flex; align-items: center; justify-content: center;
  color: inherit; cursor: pointer;
}
.tb-capsule-btn:active { transform: scale(0.9); }
.tb-capsule-split { width: 1px; height: 15px; background: rgba(255, 255, 255, 0.3); }

/* ---------- scoreboard ---------- */
.tb-hud {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding: 2px 16px 6px;
  flex-shrink: 0;
}
.tb-score b { font-size: 40px; font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.tb-hud-right { text-align: right; }
.tb-overs, .tb-best { font-size: 11.5px; color: rgba(255, 255, 255, 0.66); letter-spacing: 0.02em; }
.tb-overs b, .tb-best b { color: #FFF; font-variant-numeric: tabular-nums; margin-left: 3px; }
.tb-best b { color: var(--tb-hot); }

/* ---------- fitness bar ----------
   The innings runs on this rather than a wicket count, so it sits directly
   under the score where the eye already is. */
.tb-healthbar {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 16px 10px;
  flex-shrink: 0;
}
.tb-health-label {
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.6);
}
.tb-health-track {
  position: relative;
  flex: 1;
  height: 9px;
  border-radius: var(--radius-pill);
  background: rgba(0, 0, 0, 0.36);
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.4);
}
.tb-health-fill {
  display: block;
  height: 100%;
  width: 100%;
  border-radius: var(--radius-pill);
  background: linear-gradient(90deg, #35C77A, #12A05C);
  transition: width 0.34s cubic-bezier(0.22, 1, 0.36, 1), background 0.34s ease;
}
.tb-health-fill.mid { background: linear-gradient(90deg, #FFD36B, #E8A200); }
.tb-health-fill.low { background: linear-gradient(90deg, #FF8A8A, #D64545); }
.tb-health-num {
  min-width: 26px;
  text-align: right;
  font-size: 12px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

/* ---------- the pitch ---------- */
.tb-pitch {
  position: relative;
  flex: 1;
  min-height: 0;
  margin: 0 12px;
  border-radius: 18px 18px 14px 14px;
  overflow: hidden;
  background:
    radial-gradient(120% 70% at 50% 0%, #1C5E7E 0%, rgba(28, 94, 126, 0) 58%),
    linear-gradient(180deg, #17663C 0%, var(--tb-turf) 40%, #0E5C33 100%);
  cursor: pointer;
}
.tb-sky {
  position: absolute; inset: 0 0 auto 0;
  height: 22%;
  background: linear-gradient(180deg, rgba(8, 28, 48, 0.55), rgba(8, 28, 48, 0));
  pointer-events: none;
}
.tb-strip {
  position: absolute;
  inset: 8% 0 0 0;
  clip-path: polygon(41% 0, 59% 0, 88% 100%, 12% 100%);
  background: linear-gradient(180deg, #A98A57 0%, var(--tb-strip) 55%, #D9B87E 100%);
}
.tb-crease {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  height: 2px;
  background: rgba(255, 255, 255, 0.78);
}
.tb-crease-far { top: 6%; width: 22%; }
.tb-crease-near { top: 84%; width: 58%; }

.tb-bowler {
  position: absolute;
  left: 50%; top: 3%;
  transform: translateX(-50%);
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: rgba(7, 40, 26, 0.55);
  color: #FFF;
  pointer-events: none;
}
.tb-bowler.runup { animation: tbRunUp 0.56s ease-in; }
@keyframes tbRunUp {
  0% { transform: translateX(-50%) translateY(-14px) scale(0.86); opacity: 0.5; }
  70% { transform: translateX(-50%) translateY(3px) scale(1.06); opacity: 1; }
  100% { transform: translateX(-50%) translateY(0) scale(1); opacity: 1; }
}

.tb-chip {
  position: absolute;
  left: 50%; top: 13%;
  transform: translateX(-50%);
  z-index: 3;
  padding: 5px 13px;
  border-radius: var(--radius-pill);
  background: rgba(7, 40, 26, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 12px; font-weight: 700; letter-spacing: 0.04em;
  pointer-events: none;
}

/* ---------- the timing cue ----------
   A fixed target on the bat, and a ring that closes onto it in step with the
   ball's real position — so a delivery that changes pace mid-flight changes the
   ring with it. The player can always see what the ball is doing. */
.tb-target {
  position: absolute;
  left: 50%; top: 82%;
  width: 52px; height: 52px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, 0.55);
  background: rgba(255, 197, 49, 0.10);
  pointer-events: none;
  z-index: 2;
}
.tb-ring {
  position: absolute;
  left: 50%; top: 82%;
  width: 52px; height: 52px;
  transform: translate(-50%, -50%) scale(5.4);
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.92);
  box-shadow: 0 0 18px rgba(255, 255, 255, 0.35);
  pointer-events: none;
  z-index: 4;
  will-change: transform;
}
.tb-ring.hot {
  border-color: var(--tb-hot);
  box-shadow: 0 0 22px rgba(255, 197, 49, 0.75);
}

.tb-ball {
  position: absolute;
  left: 50%;
  top: 0;
  width: 34px; height: 34px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #FFFFFF 0 42%, #F2F2EC 42% 100%);
  border: 2px solid #C0392B;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.55), 0 0 16px rgba(255, 255, 255, 0.45);
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.5);
  pointer-events: none;
  z-index: 5;
  will-change: top, transform;
}

.tb-bat {
  position: absolute;
  left: 50%; top: 82%;
  width: 21px; height: 74px;
  margin-left: -10px;
  border-radius: 4px 4px 8px 8px;
  background: linear-gradient(180deg,
    #5C3B1E 0 8%, #7A5430 8% 30%, #F0D6A4 30% 34%, #E2BE85 34% 100%);
  border: 1px solid rgba(60, 34, 12, 0.35);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.42);
  transform-origin: 50% 10%;
  transform: rotate(16deg);
  pointer-events: none;
  z-index: 3;
}
.tb-bat.swing { animation: tbSwing 0.34s cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes tbSwing {
  0% { transform: rotate(16deg); }
  35% { transform: rotate(-58deg); }
  100% { transform: rotate(16deg); }
}

/* ---------- verdict ---------- */
.tb-verdict {
  position: absolute;
  left: 12px; right: 12px;
  top: 28%;
  z-index: 6;
  text-align: center;
  font-size: 26px;
  font-weight: 800;
  line-height: 1.2;
  text-shadow: 0 2px 12px rgba(0, 0, 0, 0.6);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}
.tb-verdict small {
  display: block;
  margin-top: 7px;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.86);
}
.tb-plus { font-size: 20px; opacity: 0.95; }
/* What the delivery actually was, revealed after the ball rather than before —
   it teaches the variations without handing over the answer in advance. */
.tb-what {
  display: inline-block;
  margin-left: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.16);
  font-size: 11.5px;
  font-weight: 700;
  color: #FFF;
}
.tb-hp { font-size: 17px; font-weight: 800; }
.tb-hp.up { color: #6BE3A0; }
.tb-hp.down { color: var(--tb-bad); }
.tb-verdict.show { opacity: 1; }
.tb-verdict.pop { animation: tbPop 0.44s cubic-bezier(0.22, 1, 0.36, 1); }
@keyframes tbPop {
  0% { transform: scale(0.82); }
  44% { transform: scale(1.1); }
  100% { transform: scale(1); }
}
.tb-verdict.tb-six { color: var(--tb-hot); }
.tb-verdict.tb-four { color: #7FE3A6; }
.tb-verdict.tb-run { color: #FFFFFF; }
.tb-verdict.tb-out { color: var(--tb-bad); }

.tb-hint {
  position: absolute;
  left: 50%; bottom: 6%;
  transform: translateX(-50%);
  z-index: 4;
  padding: 7px 15px;
  border-radius: var(--radius-pill);
  background: rgba(7, 40, 26, 0.72);
  font-size: 12.5px; font-weight: 700;
  pointer-events: none;
}

/* ---------- cover ----------
   The game does not start until this is dismissed. A demo phone is picked up
   cold, and a title screen is where anyone expects to find out what they are
   looking at and what their best is. */
.tb-cover {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background:
    radial-gradient(120% 60% at 50% 12%, rgba(28, 94, 126, 0.55), rgba(4, 22, 14, 0) 62%),
    rgba(4, 22, 14, 0.86);
  backdrop-filter: blur(5px);
}
.tb-cover-inner { width: 100%; text-align: center; }
.tb-cover-logo {
  width: 84px; height: 84px;
  border-radius: 22px;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.5);
}
.tb-cover-title {
  margin-top: 14px;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.01em;
}
.tb-cover-tag {
  margin-top: 6px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.76);
  line-height: 1.5;
}
.tb-cover-best {
  display: inline-block;
  margin: 16px 0 20px;
  padding: 7px 16px;
  border-radius: var(--radius-pill);
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  font-size: 12px;
  letter-spacing: 0.04em;
  color: rgba(255, 255, 255, 0.8);
}
.tb-cover-best b { color: var(--tb-hot); font-size: 15px; margin-left: 4px; }
.tb-cover-links {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.6);
}
.tb-cover-links button {
  border: none;
  background: none;
  padding: 4px 2px;
  font-size: 13px;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.92);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.tb-start {
  width: 100%;
  padding: 16px 0;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--tb-hot);
  color: var(--tb-ink);
  font-size: 16px; font-weight: 800; letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 0 8px 22px rgba(255, 197, 49, 0.3);
}
.tb-start:active { transform: scale(0.98); }

/* ---------- leaderboard ---------- */
.tb-board {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 6px;
}
.tb-board-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 14px;
  color: var(--color-text-main);
}
.tb-board-row:nth-child(odd) { background: var(--color-bg-floating); }
.tb-board-row.you {
  background: rgba(21, 122, 70, 0.14);
  border: 1px solid rgba(21, 122, 70, 0.4);
  font-weight: 800;
  color: var(--tb-turf-dark);
}
.tb-board-rank {
  min-width: 22px;
  font-variant-numeric: tabular-nums;
  color: var(--color-text-muted);
  font-weight: 700;
}
.tb-board-row.you .tb-board-rank { color: var(--tb-turf); }
.tb-board-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-board-score { font-variant-numeric: tabular-nums; font-weight: 800; }
.tb-board-empty {
  padding: 12px 4px 0;
  text-align: center;
  font-size: 13px;
  color: var(--color-text-muted);
}
/* On the game-over card the board is a neighbourhood, not the whole table —
   a full list pushes the buttons off a phone screen. */
.tb-board-compact { margin: 14px 0 18px; }
.tb-board-compact .tb-board-row { padding: 7px 10px; font-size: 13px; }

/* ---------- foot ---------- */
.tb-foot { flex-shrink: 0; padding: 12px 16px calc(10px + env(safe-area-inset-bottom, 0px)); }
.tb-tap {
  width: 100%;
  padding: 15px 0;
  border: none;
  border-radius: var(--radius-pill);
  background: var(--tb-hot);
  color: var(--tb-ink);
  font-size: 15px; font-weight: 800; letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 0 6px 18px rgba(255, 197, 49, 0.28);
}
.tb-tap:active { transform: scale(0.98); }

/* ---------- innings over ---------- */
.tb-over-card {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(5, 22, 14, 0.74);
  backdrop-filter: blur(6px);
  overflow-y: auto;
}
.tb-over-inner {
  width: 100%;
  padding: 22px 18px 18px;
  border-radius: 20px;
  background: #FFF;
  color: var(--color-text-main);
  text-align: center;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
}
.tb-over-title { font-size: 14px; color: var(--color-text-muted); }
.tb-over-score {
  font-size: 54px; font-weight: 800; line-height: 1.05;
  margin-top: 4px;
  color: var(--tb-turf);
  font-variant-numeric: tabular-nums;
}
.tb-over-sub { font-size: 12.5px; color: var(--color-text-muted); margin: 6px 0 0; line-height: 1.5; }

/* ---------- how-to sheet ---------- */
.tb-sheet-body { font-size: 14px; line-height: 1.55; color: var(--color-text-main); }
.tb-sheet-body p { margin: 6px 0 14px; }
.tb-legend { display: flex; flex-direction: column; gap: 9px; }
.tb-legend-row {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; color: var(--color-text-muted);
}
.tb-pill {
  min-width: 68px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 11.5px; font-weight: 800;
  text-align: center;
  color: #FFF;
}
.tb-pill.tb-six { background: #E8A200; }
.tb-pill.tb-four { background: #12885A; }
.tb-pill.tb-run { background: #5B6B7A; }
.tb-pill.tb-out { background: #D64545; }
.tb-sheet-note {
  display: flex; align-items: center; gap: 7px;
  margin-top: 16px; padding-top: 12px;
  border-top: 1px solid var(--color-border);
  font-size: 12px; color: var(--color-text-muted);
}

@media (prefers-reduced-motion: reduce) {
  .tb-bat.swing { animation: none; }
  .tb-verdict.pop { animation: none; }
  .tb-verdict { transition: none; }
  .tb-bowler.runup { animation: none; }
  .tb-health-fill { transition: none; }
}
