/*
  CourtSide - one stylesheet, phone portrait first. Every page fills exactly the viewport
  (100dvh) and never scrolls as a whole: the court takes the height that is left, and a list
  that can grow (bench, squad) scrolls inside its own box. Colours from the presentation.
*/

:root {
  --bg: #111b1a;
  --panel: #1a2725;
  --panel-2: #23332f;
  --line: #34433f;
  --text: #f2f4ec;
  --muted: #a6b5ad;
  --ink: #15211d;
  --lime: #d6f478;
  --orange: #ee946e;
  --blue: #94c6e4;
  --violet: #bba6ff;
  --danger: #ff9b8c;
  --floor: #355b49;
  --rail: 66px;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
}

:focus-visible {
  outline: 3px solid var(--lime);
  outline-offset: 2px;
}

h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.15;
  letter-spacing: -0.4px;
}

h1:focus {
  outline: none;
}

a {
  color: var(--lime);
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- Boot screen (index.html, before .NET has started) ---------- */

.boot {
  height: 100dvh;
  display: grid;
  place-content: center;
  gap: 18px;
  justify-items: center;
}

.boot__brand {
  font-weight: 900;
  letter-spacing: 4px;
  font-size: 22px;
}

.boot__brand span,
.rail__brand span {
  color: var(--lime);
}

.boot__bar {
  width: 140px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
  overflow: hidden;
}

.boot__bar i {
  display: block;
  height: 100%;
  width: var(--blazor-load-percentage, 8%);
  background: var(--lime);
  transition: width 0.2s;
}

#blazor-error-ui {
  display: none;
  position: fixed;
  inset: auto 0 0 0;
  z-index: 50;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: #3a1f1b;
  color: var(--text);
  font-size: 14px;
}

#blazor-error-ui .reload {
  margin-left: 8px;
}

#blazor-error-ui .dismiss {
  float: right;
  border: 0;
  background: none;
}

/* ---------- Shell: rail + stage ---------- */

.app {
  position: relative;
  display: flex;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.app--right {
  flex-direction: row-reverse;
}

@media (min-width: 640px) {
  /* A phone app on a big screen: keep it phone-shaped. */
  .app {
    max-width: 560px;
    margin-inline: auto;
    border-inline: 1px solid var(--line);
  }
}

.stage {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.rail {
  flex: 0 0 var(--rail);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0 12px;
  background: var(--panel);
  border-inline-end: 1px solid var(--line);
}

.app--right .rail {
  border-inline-end: 0;
  border-inline-start: 1px solid var(--line);
}

.rail__brand {
  font-weight: 900;
  font-size: 16px;
  letter-spacing: 1px;
}

.rail__items {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  padding: 0 6px;
}

.rail__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 10px 0 8px;
  border-radius: 14px;
  color: var(--muted);
  text-decoration: none;
  font-size: 10.5px;
  font-weight: 700;
}

.rail__item svg {
  width: 24px;
  height: 24px;
}

.rail__item.active {
  background: var(--lime);
  color: var(--ink);
}

.banner {
  margin: 8px 12px 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: rgb(255 155 140 / 0.14);
  color: var(--danger);
  font-size: 12.5px;
}

/* ---------- Page frame ---------- */

.page {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 12px 14px;
}

.page__head {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.page__title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}

.page__title-row h1 {
  flex: 1;
  min-width: 0;
}

.page__title-row h1,
.eyebrow {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.eyebrow {
  margin: 0 0 3px;
  font-size: 10.5px;
  font-weight: 750;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--lime);
}

/* ---------- Controls ---------- */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

.button--primary {
  background: var(--lime);
  border-color: var(--lime);
  color: var(--ink);
}

.button--danger {
  border-color: rgb(255 155 140 / 0.45);
  color: var(--danger);
}

.button--ghost {
  border-color: rgb(187 166 255 / 0.5);
  color: var(--violet);
}

.icon-button {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: transparent;
  font-size: 15px;
}

.icon-button--large {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  font-size: 22px;
}

.info {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border: 1.5px solid var(--muted);
  border-radius: 50%;
  background: transparent;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 17px;
  font-style: italic;
  font-weight: 700;
}

.pill {
  flex: 0 0 auto;
  height: 34px;
  padding: 0 11px;
  border: 1px solid var(--violet);
  border-radius: 17px;
  background: rgb(187 166 255 / 0.1);
  color: var(--violet);
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
}

.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel);
}

.segmented button {
  min-width: 0;
  height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.segmented button[aria-pressed="true"] {
  background: var(--lime);
  color: var(--ink);
}

.chips {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.chip {
  height: 34px;
  padding: 0 4px;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.chip[aria-pressed="true"] {
  border-color: var(--orange);
  background: rgb(238 148 110 / 0.13);
  color: var(--orange);
}

/* ---------- Court ---------- */

.court {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  container-type: size;
}

/* With something below it, the court sits at the top and that content takes what is left. */
.court--with-below {
  justify-content: flex-start;
}

.court__box {
  flex: none;
  position: relative;
  /* As large as fits: full width, unless the height runs out first. --ratio is set inline. */
  width: min(100cqw, 100cqh * var(--ratio));
  aspect-ratio: var(--ratio);
  container-type: inline-size;
}

.court__below {
  flex: 1;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  display: grid;
  place-items: center;
}

.court__lines {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.court__opponent {
  fill: #20302b;
}

.court__opponent-lines {
  fill: none;
  stroke: var(--text);
  stroke-width: 2;
  opacity: 0.35;
}

.court__opponent-label {
  fill: var(--muted);
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 4px;
  text-anchor: middle;
}

.court__floor {
  fill: var(--floor);
}

.court__boundary {
  fill: none;
  stroke: var(--text);
  stroke-width: 3;
}

.court__attack-line {
  stroke: var(--text);
  stroke-width: 2;
  opacity: 0.7;
}

.court__net {
  stroke: var(--lime);
  stroke-width: 6;
  stroke-linecap: round;
}

.court__zone {
  fill: var(--text);
  opacity: 0.3;
  font-size: 24px;
  font-weight: 800;
  text-anchor: middle;
}

.court__attack {
  fill: var(--orange);
}

.court__attack-path {
  fill: none;
  stroke: var(--orange);
  stroke-width: 4;
  stroke-dasharray: 9 7;
}

.court__serve {
  fill: var(--blue);
}

.court__serve-path {
  fill: none;
  stroke: var(--blue);
  stroke-width: 3.5;
  stroke-dasharray: 3 8;
  stroke-linecap: round;
  opacity: 0.8;
}

.token {
  --disc: clamp(30px, 11cqw, 48px);
  position: absolute;
  width: var(--disc);
  height: var(--disc);
  padding: 0;
  display: grid;
  place-items: center;
  border: 2.5px solid var(--bg);
  border-radius: 50%;
  background: var(--tone);
  color: var(--ink);
  transform: translate(-50%, -50%);
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.35);
  transition: left 0.4s ease, top 0.4s ease, opacity 0.2s;
}

.page--subs .token {
  --disc: clamp(32px, 12cqw, 46px);
}

.token--setter {
  --tone: var(--lime);
}

.token--receiver {
  --tone: var(--blue);
}

.token--attacker {
  --tone: var(--orange);
}

.token--libero {
  --tone: var(--violet);
}

.token__mark {
  font-size: calc(var(--disc) * 0.42);
  font-weight: 900;
  line-height: 1;
}

.token--tagged .token__mark {
  font-size: calc(var(--disc) * 0.38);
  transform: translateY(-18%);
}

.token__tag {
  position: absolute;
  bottom: 11%;
  font-size: calc(var(--disc) * 0.21);
  font-weight: 850;
  line-height: 1;
}

.token__name {
  position: absolute;
  top: calc(100% + 2px);
  left: 50%;
  transform: translateX(-50%);
  max-width: 25cqw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #fff;
  font-size: clamp(10.5px, 3.5cqw, 14px);
  font-weight: 650;
  text-shadow: 0 0 3px #10201b, 0 0 3px #10201b, 0 1px 2px #10201b;
  pointer-events: none;
}

/* The rotational position the player stands on now: a small badge on the upper right, clear
   of the name below or above the disc. */
.token__position {
  position: absolute;
  top: -6%;
  left: 74%;
  min-width: calc(var(--disc) * 0.4);
  height: calc(var(--disc) * 0.4);
  padding: 0 2px;
  display: grid;
  place-items: center;
  border: 1.5px solid var(--tone);
  border-radius: 999px;
  background: var(--bg);
  color: var(--text);
  font-size: calc(var(--disc) * 0.25);
  font-weight: 850;
  line-height: 1;
  pointer-events: none;
}

.token--name-above .token__name {
  top: auto;
  bottom: calc(100% + 2px);
}

.token.is-selected {
  outline: 3px solid #fff;
  outline-offset: 2px;
}

.token.is-dimmed {
  opacity: 0.4;
}

@media (prefers-reduced-motion: reduce) {
  .token {
    transition: none;
  }
}

/* ---------- Field page ---------- */

.statement {
  max-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  border: 0;
  background: transparent;
  text-align: center;
}

.statement__title {
  font-size: 19px;
  font-weight: 750;
  line-height: 1.25;
  letter-spacing: -0.3px;
}

.statement__more {
  color: var(--muted);
  font-size: 12.5px;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.controls__context {
  min-height: 36px;
  display: flex;
  align-items: center;
}

.controls__phase {
  margin: 0;
  color: var(--muted);
  font-size: 12.5px;
}

.rotation-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.rotation-row .segmented {
  flex: 1;
  min-width: 0;
}

.segmented--numbers button {
  font-size: 16px;
}

/* ---------- Player chips (Wechsel, Kader) ---------- */

.player-chip {
  min-width: 0;
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 6px 6px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  text-align: start;
  transition: opacity 0.2s;
}

.player-chip__mark {
  flex: 0 0 auto;
  min-width: 30px;
  height: 30px;
  padding: 0 5px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  background: var(--panel-2);
  font-size: 13px;
  font-weight: 850;
}

.player-chip__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 600;
}

.player-chip__role {
  flex: 0 0 auto;
  color: var(--violet);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.player-chip--setter .player-chip__mark {
  background: var(--lime);
  color: var(--ink);
}

.player-chip--receiver .player-chip__mark {
  background: var(--blue);
  color: var(--ink);
}

.player-chip--attacker .player-chip__mark {
  background: var(--orange);
  color: var(--ink);
}

/* The libero wears a different shirt - so they get a different colour everywhere. */
.player-chip--libero {
  border-color: rgb(187 166 255 / 0.55);
  background: rgb(187 166 255 / 0.12);
}

.player-chip--libero .player-chip__mark {
  background: var(--violet);
  color: var(--ink);
}

.player-chip.is-selected {
  border-color: var(--lime);
  box-shadow: inset 0 0 0 1px var(--lime);
}

.player-chip.is-dimmed {
  opacity: 0.4;
}

.empty {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

/* ---------- Substitution page ---------- */

.page--subs .court {
  flex: 0 0 auto;
  height: min(40dvh, 330px);
}

.libero-slot {
  display: flex;
  align-items: center;
  gap: 8px;
}

.libero-slot .player-chip {
  flex: 1;
}

.hint {
  margin: 0;
  min-height: 2.7em;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.35;
}

.bench {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.bench__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
}

.bench__head h2,
.section-label {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}

.bench__grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-content: start;
  gap: 6px;
}

/* ---------- Squad page ---------- */

.squad {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.squad .section-label {
  margin-top: 6px;
}

.chip-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

/* ---------- Settings page ---------- */

.settings {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
}

.card h2 {
  margin: 0;
  font-size: 16px;
}

.card p {
  margin: 0;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.45;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.settings__footer {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

/* ---------- Knowledge page ---------- */

.knowledge {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.knowledge__intro {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.topic {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  text-align: start;
}

.topic__title {
  font-size: 15px;
  font-weight: 700;
}

.topic__title::after {
  content: " ›";
  color: var(--muted);
}

.topic__summary {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

/* ---------- Sheet ---------- */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgb(5 10 9 / 0.62);
  animation: fade 0.18s ease-out;
}

.sheet {
  position: fixed;
  z-index: 31;
  inset: auto 0 0 0;
  max-width: 560px;
  max-height: 86dvh;
  margin-inline: auto;
  display: flex;
  flex-direction: column;
  padding: 4px 16px calc(16px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  border-radius: 20px 20px 0 0;
  background: var(--panel);
  animation: rise 0.22s ease-out;
}

.sheet__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 0 8px;
}

.sheet__head h2 {
  flex: 1;
  margin: 0;
  font-size: 19px;
  line-height: 1.2;
}

.sheet__body {
  overflow-y: auto;
  overscroll-behavior: contain;
}

.sheet__body p,
.sheet__body li {
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.55;
}

.badge {
  display: inline-block;
  margin: 0 0 4px;
  padding: 5px 9px;
  border-radius: 6px;
  background: #27392d;
  color: var(--lime) !important;
  font-size: 12px !important;
}

.tasks {
  padding-left: 20px;
}

.tasks li {
  margin-bottom: 8px;
  padding-left: 4px;
}

.libero-note {
  padding: 9px 11px;
  border-radius: 10px;
  background: rgb(187 166 255 / 0.1);
  color: var(--violet) !important;
}

.note {
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 12.5px !important;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.legend li {
  font-size: 12.5px;
}

.dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 6px;
  border-radius: 50%;
}

.dot--setter {
  background: var(--lime);
}

.dot--receiver {
  background: var(--blue);
}

.dot--attacker {
  background: var(--orange);
}

.dot--libero {
  background: var(--violet);
}

/* ---------- Player editor ---------- */

.editor {
  display: grid;
  grid-template-columns: 1fr 78px;
  gap: 12px 10px;
  padding-bottom: 4px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
}

.field input {
  height: 46px;
  min-width: 0;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--bg);
  font-size: 16px; /* below 16px iOS zooms into the field */
}

.switch {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 600;
}

.switch input {
  width: 22px;
  height: 22px;
  accent-color: var(--violet);
}

.field-hint,
.field-error {
  grid-column: 1 / -1;
  margin: -4px 0 0;
  font-size: 12.5px !important;
  line-height: 1.4;
}

.field-error {
  color: var(--danger) !important;
}

.editor__actions {
  grid-column: 1 / -1;
  display: flex;
  gap: 8px;
}

.editor__actions .button--primary {
  margin-inline-start: auto;
  min-width: 130px;
}

/* ---------- Toast ---------- */

/* Inside .app, beside the rail - never over it. */
.toast-host {
  position: absolute;
  inset: auto 0 calc(20px + env(safe-area-inset-bottom)) 0;
  z-index: 40;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.toast {
  max-width: min(90vw, 420px);
  padding: 11px 16px;
  border-radius: 12px;
  background: var(--lime);
  color: var(--ink);
  font-size: 14px;
  font-weight: 650;
  box-shadow: 0 8px 24px rgb(0 0 0 / 0.45);
  animation: rise 0.2s ease-out;
}

.app--right .toast-host {
  right: var(--rail);
}

.app--left .toast-host {
  left: var(--rail);
}

.toast--refusal {
  border: 1px solid rgb(255 155 140 / 0.5);
  background: #3b2622;
  color: #ffd2ca;
}

@keyframes rise {
  from {
    transform: translateY(18px);
    opacity: 0;
  }
}

@keyframes fade {
  from {
    opacity: 0;
  }
}
