/* The tournament, practice and trophy screens (src/ui/modeScreens.js) on their own layer, and the
   in-game mode panel. They use the menus' tokens and buttons (styles.css: --accent, --glass-strong,
   --line, --dim, .btn, .pill): dark glass with the Tiny Pickle green as the accent. */

/* --- the layer ---------------------------------------------------------------------------------- */

/* Beside the menus (30), above the touch controls (20) and the HUD (25); the scene, the players and
   any confetti stay in view behind it. */
.mode-screens {
  position: fixed;
  inset: 0;
  z-index: 31;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: radial-gradient(ellipse at 50% 50%, rgba(5, 7, 11, 0.3), rgba(5, 7, 11, 0.62));
  touch-action: manipulation;
}

/* Under a mode screen its own panel is the read-out, as under the menus. */
body.mode-screen-open #hud {
  visibility: hidden;
}

/* --- panels ------------------------------------------------------------------------------------- */

.mode-panel {
  position: relative;
  z-index: 1;
  box-sizing: border-box;
  min-width: 320px;
  max-width: min(92vw, 560px);
  max-height: 92vh;
  max-height: 92dvh;
  overflow-y: auto;
  padding: 24px 32px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  text-align: center;
  color: #fff;
}

.mode-panel.mode-wide {
  width: 100%;
  max-width: min(96vw, 980px);
}

.mode-kicker {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--accent);
}

.mode-panel h1 {
  margin: 6px 0 4px;
  font-size: 30px;
  line-height: 1.15;
}

.mode-panel h1 small {
  font-size: 0.5em;
  color: var(--dim);
}

.mode-sub {
  margin: 4px 0 10px;
  font-size: 15px;
  color: var(--dim);
}

.mode-next {
  margin: 12px 0 4px;
  font-size: 14px;
  line-height: 1.5;
}

.mode-good {
  color: var(--accent);
}

.mode-bad {
  color: var(--fault);
}

.mode-chip {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 4px;
  border-radius: 3px;
  vertical-align: -1px;
  background: linear-gradient(135deg, var(--court) 55%, var(--kitchen) 55%);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.4);
}

.mode-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
}

.pill.mode-small {
  min-height: 30px;
  padding: 4px 12px;
  font-size: 12px;
}

/* --- the bracket ------------------------------------------------------------------------------ */

/* Three rounds and the champion in columns. A round's matches share its column in equal slots, so
   each match sits level with the middle of the two that feed it; connectors run from each match to
   a bar in the next column that joins the two feeders (at 25% and 75% of the later slot). */
.tp-bracket {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 0.8fr);
  column-gap: 14px;
  margin: 14px 0 6px;
  text-align: left;
}

.tp-round {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.tp-round-title {
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-align: center;
  text-transform: uppercase;
  color: var(--dim);
}

.tp-slots {
  display: flex;
  flex-direction: column;
  height: 300px;
}

.tp-slot {
  position: relative;
  display: flex;
  flex: 1;
  align-items: center;
  min-height: 0;
}

.tp-round:not(.tp-round-champion) .tp-slot::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 100%;
  width: 14px;
  border-top: 2px solid var(--line);
}

.tp-round-1 .tp-slot,
.tp-round-2 .tp-slot,
.tp-round-champion .tp-slot {
  padding-left: 12px;
  background: linear-gradient(var(--line), var(--line)) no-repeat 0 50% / 12px 2px;
}

.tp-round-1 .tp-slot::before,
.tp-round-2 .tp-slot::before {
  content: '';
  position: absolute;
  top: 25%;
  bottom: 25%;
  left: 0;
  border-left: 2px solid var(--line);
}

.tp-round .tp-slot.tp-path::after {
  border-top-color: var(--accent);
}

.tp-match {
  position: relative;
  width: 100%;
  padding: 3px 0;
  border: 1px solid var(--line);
  border-top: 3px solid var(--court, #3657b8);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  font-size: 13px;
}

.tp-venue {
  padding: 0 8px 2px;
  font-size: 9px;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--dim);
}

.tp-line {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
}

.tp-seed {
  width: 14px;
  font-size: 11px;
  text-align: right;
  color: var(--dim);
}

.tp-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.tp-score {
  min-width: 16px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.tp-won .tp-name {
  font-weight: 800;
}

.tp-decided .tp-line:not(.tp-won) {
  opacity: 0.5;
}

.tp-line.tp-human {
  background: rgba(184, 255, 60, 0.16);
  box-shadow: inset 3px 0 0 var(--accent);
  color: var(--accent);
  opacity: 1;
}

.tp-next {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(184, 255, 60, 0.35), 0 0 18px rgba(184, 255, 60, 0.25);
  animation: tp-pulse 1.8s ease-in-out infinite;
}

@keyframes tp-pulse {
  50% {
    box-shadow: 0 0 0 2px rgba(184, 255, 60, 0.12), 0 0 6px rgba(184, 255, 60, 0.08);
  }
}

.tp-champion {
  width: 100%;
  padding: 10px 6px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  font-weight: 800;
  text-align: center;
  color: var(--dim);
}

.tp-champion.tp-human {
  border: 1px solid var(--accent);
  color: var(--accent);
}

/* --- results, runs and the trophy -------------------------------------------------------------- */

.mode-run {
  max-width: 360px;
  margin: 10px auto;
  padding: 0;
  list-style: none;
  text-align: left;
}

.mode-run li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.mode-run-won b {
  color: var(--accent);
}

.mode-run-lost b {
  color: var(--fault);
}

.mode-trophy {
  border-color: rgba(184, 255, 60, 0.5);
}

.mode-cup {
  width: 84px;
  height: 84px;
  color: #ffd21f;
  filter: drop-shadow(0 0 18px rgba(255, 210, 31, 0.55));
  animation: mode-cup 3s ease-in-out infinite;
}

@keyframes mode-cup {
  50% {
    transform: translateY(-5px) rotate(-3deg);
  }
}

.mode-team {
  margin: 2px 0 8px;
  font-size: 20px;
  font-weight: 800;
  color: var(--accent);
}

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

.mode-confetti span {
  position: absolute;
  top: -24px;
  left: var(--x);
  width: 8px;
  height: 13px;
  border-radius: 2px;
  background: var(--c);
  opacity: 0.95;
  transform: rotate(var(--r));
  animation: mode-fall var(--d) linear var(--delay) infinite;
}

@keyframes mode-fall {
  to {
    transform: translate(var(--sway), calc(100vh + 48px)) rotate(calc(var(--r) + 720deg));
  }
}

.mode-score {
  font-size: 56px;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.mode-best {
  font-size: 16px;
}

.mode-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--accent);
  color: #10131a;
  font-size: 12px;
  font-weight: 800;
}

/* --- the drill picker -------------------------------------------------------------------------- */

.mode-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0 4px;
}

.mode-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font: inherit;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
}

.mode-card:hover {
  border-color: var(--accent);
  background: rgba(184, 255, 60, 0.08);
}

.mode-card-name {
  font-size: 17px;
  font-weight: 800;
}

.mode-card-blurb {
  flex: 1;
  font-size: 13px;
  line-height: 1.35;
  color: var(--dim);
}

.mode-card-best {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
}

/* --- the in-game mode panel: the tournament round tag and the running drill --------------------- */

/* Top right, below the HUD's pause button, clear of both thumb zones. */
.mode-hud {
  position: fixed;
  top: calc(66px + var(--safe-top));
  right: calc(12px + var(--safe-right));
  z-index: 25;
  pointer-events: none;
}

/* The fly-in is the broadcast's; the pause menu's sheet is the read-out. */
body.in-intro .mode-hud,
body.menu-open .mode-hud {
  visibility: hidden;
}

/* A drill keeps no score: its panel is the scoreboard, and the HUD's scorebug steps aside. */
body.mode-drill .scorebug {
  visibility: hidden;
}

.mode-tag,
.mode-drill {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--glass);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  color: #fff;
  text-align: right;
}

.mode-tag {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.mode-tag-round,
.mode-drill-name {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--accent);
}

.mode-tag-venue,
.mode-tag-game,
.mode-drill-progress {
  font-size: 12px;
  color: var(--dim);
}

.mode-drill {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  min-width: 150px;
}

.mode-drill-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.mode-drill-score b {
  font-size: 26px;
  font-variant-numeric: tabular-nums;
}

.mode-hud .pill {
  pointer-events: auto;
}

.mode-target {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  margin-top: 3px;
  font-size: 12px;
}

.mode-map {
  display: block;
  border-radius: 4px;
}

.mode-map-court {
  fill: #2d5a8a;
}

.mode-map-kitchen {
  fill: rgba(255, 255, 255, 0.16);
}

.mode-map-box {
  fill: none;
  stroke: #fff;
  stroke-width: 1.2;
}

.mode-map-target {
  fill: rgba(184, 255, 60, 0.9);
  animation: mode-lit 1.2s ease-in-out infinite;
}

.mode-map-line {
  stroke: #fff;
  stroke-width: 1;
}

@keyframes mode-lit {
  50% {
    fill: rgba(184, 255, 60, 0.45);
  }
}

/* --- short landscape phones ---------------------------------------------------------------------- */

@media (max-height: 500px) {
  .mode-panel {
    max-height: 96vh;
    max-height: 96dvh;
    padding: 10px 18px;
    border-radius: 12px;
  }
  .mode-panel h1 {
    margin: 2px 0;
    font-size: 20px;
  }
  .mode-kicker {
    font-size: 10px;
  }
  .mode-sub,
  .mode-next {
    margin: 4px 0;
    font-size: 12px;
    line-height: 1.35;
  }
  .mode-actions {
    gap: 8px;
    margin-top: 8px;
  }
  .mode-actions .btn {
    min-height: 40px;
    padding: 8px 16px;
    font-size: 13px;
  }
  .tp-bracket {
    margin: 6px 0 2px;
  }
  .tp-slots {
    height: 186px;
  }
  .tp-round-title {
    margin-bottom: 3px;
    font-size: 9px;
  }
  .tp-match {
    padding: 1px 0;
    border-top-width: 2px;
    font-size: 11px;
  }
  .tp-venue {
    display: none;
  }
  .tp-line {
    padding: 1px 6px;
  }
  .tp-champion {
    padding: 6px 4px;
    font-size: 11px;
  }
  .mode-cards {
    gap: 8px;
    margin: 8px 0 2px;
  }
  .mode-card {
    gap: 3px;
    padding: 8px 10px;
  }
  .mode-card-name {
    font-size: 14px;
  }
  .mode-card-blurb,
  .mode-card-best {
    font-size: 11px;
  }
  .mode-score {
    font-size: 38px;
  }
  .mode-cup {
    width: 50px;
    height: 50px;
  }
  .mode-run {
    margin: 4px auto;
  }
  .mode-run li {
    padding: 3px 8px;
    font-size: 12px;
  }
  .mode-team {
    margin: 0 0 4px;
    font-size: 16px;
  }
  .mode-hud {
    top: calc(62px + var(--safe-top));
  }
  .mode-drill-score b {
    font-size: 20px;
  }
  .mode-map {
    width: 52px;
    height: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mode-confetti span,
  .mode-cup,
  .tp-next,
  .mode-map-target {
    animation: none;
  }
}
