:root {
  color-scheme: light;
  --ink: #181d32;
  --muted: #505b74;
  --page: #f5f6fa;
  --paper: #fff;
  --line: #e1e5f1;
  --accent: #4638bd;
  --accent-light: #eeecff;
  --front-ring: #178953;
  --back-ring: #cf3449;
  --court-surround: #858b96;
  --court-line: #fff8ed;
  font-family: "Segoe UI", "Aptos", system-ui, sans-serif;
  background: var(--page);
  color: var(--ink);
}

*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0;
  background:
    linear-gradient(144deg, #edebf9 0 19%, transparent 19.08%) top left / 100% 760px no-repeat,
    linear-gradient(34deg, transparent 0 67%, #eaedf8 67.08% 78%, transparent 78.08%) top right / 80% 840px no-repeat,
    linear-gradient(180deg, #f3f4fa, transparent 460px);
}
button, input, select { color: inherit; font: inherit; }
button { cursor: pointer; }
:is(button, input, select):focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
p, h1, h2, h3 { margin: 0; }

.viewer {
  width: min(100% - 48px, 1120px);
  margin-inline: auto;
  padding-block: 34px 40px;
}

.viewer-heading { margin-bottom: 22px; }

.team-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.team-actions button, .team-name-controls button {
  min-height: 40px;
  padding: 6px 11px;
  border: 1px solid #d9d4fc;
  border-radius: 10px;
  background: var(--paper);
  color: var(--accent);
  font-size: .82rem;
  font-weight: 700;
}
.team-actions button:hover, .team-name-controls button:hover { background: var(--accent-light); }
.team-actions button:disabled { opacity: .58; cursor: default; }
.team-feedback { color: var(--muted); font-size: .86rem; }
.team-feedback:empty { position: absolute; }
.team-feedback[data-error="true"] { color: #a02032; }

h1 {
  font-size: clamp(2.1rem, 5vw, 3.4rem);
  font-weight: 790;
  line-height: 1.04;
  letter-spacing: -.052em;
}

.workspace {
  overflow: hidden;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 16px 45px #2326530c;
}

.viewer-controls {
  display: grid;
  grid-template-columns: minmax(296px, 1fr) minmax(0, 454px);
  align-items: start;
  gap: 16px 24px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
}

.formation-controls, .team-panel { display: grid; gap: 10px; }
.formation-controls { justify-items: start; }
.control-group { display: grid; gap: 6px; }
.control-label, .lineup h3 {
  color: var(--muted);
  font-size: .73rem;
  font-weight: 760;
  letter-spacing: .065em;
  text-transform: uppercase;
}

.rotation-picker, .start-picker, .phase-picker { display: flex; gap: 5px; }
.rotation-picker { flex-wrap: wrap; }
.start-picker { background: var(--page); border-radius: 12px; padding: 3px; }

.rotation-picker button, .start-picker button, .phase-picker button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 12px;
  background: var(--paper);
  font-weight: 700;
  font-size: .88rem;
}

.rotation-picker button { min-width: 44px; padding: 5px; }
.rotation-picker button { font-variant-numeric: tabular-nums; }
.start-picker button { min-height: 38px; background: transparent; border-color: transparent; }
.rotation-picker button:hover, .start-picker button:hover, .phase-picker button:hover {
  background: var(--accent-light);
}

.rotation-picker button[aria-pressed="true"],
.start-picker button[aria-pressed="true"],
.phase-picker button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.viewer-body {
  display: grid;
  grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
}

.formation {
  min-width: 0;
  padding: 15px 22px 6px;
  background: #fcfcff;
}

.phase-picker { flex-wrap: wrap; }
.phase-picker button { min-height: 40px; }
.formation[data-serving="false"] .phase-picker button { padding-inline: 9px; }
.phase-picker .simulate-button { border-color: #dbd5fc; background: var(--accent-light); color: var(--accent); }
.phase-picker .simulate-button:hover { background: #e3defe; }
.phase-picker .simulate-button:disabled { opacity: .58; cursor: default; }
.phase-actions { display: inline-flex; gap: 5px; }
.phase-note, .player-status {
  color: var(--muted);
  font-size: .89rem;
  line-height: 1.4;
}

.phase-note { margin: 8px 0 12px; min-height: 2.8em; }
.formation[data-serving="true"] .court-frame { padding-block: 62px 82px; }

.court-frame {
  --gutter: clamp(24px, 6cqw, 44px);
  container-type: inline-size;
  position: relative;
  margin-inline: auto;
  width: min(100%, 565px);
  padding: 11px var(--gutter) 58px;
  border: 1px solid #747b88;
  border-radius: 15px;
  background-color: var(--court-surround);
  background-image: linear-gradient(90deg, #e9ecf127 1px, transparent 1px),
    linear-gradient(#e9ecf127 1px, transparent 1px);
  background-size: 24px 24px;
}

.opponent-divisions {
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  min-height: 38px;
  margin-bottom: 13px;
  border: 1px solid #3a435a38;
  border-radius: 7px;
  background: #f3f5f9ab;
  color: #263044;
  font-size: .76rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.opponent-divisions span { display: grid; place-items: center; }
.opponent-divisions span + span { border-inline-start: 1px dashed #3a435a44; }

.net {
  position: relative;
  z-index: 1;
  height: 6px;
  margin-inline: -13px;
  background: #27303f;
  border-block: 1px solid #f0f1f5;
  border-radius: 2px;
}

.net span {
  position: absolute;
  bottom: 6px;
  left: 50%;
  transform: translateX(-50%);
  color: #101724;
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .07em;
  text-transform: uppercase;
}

.court {
  container-type: inline-size;
  position: relative;
  aspect-ratio: 1;
  border: 2px solid var(--court-line);
  border-top: 0;
  background-color: #e8b77e;
  background-image:
    repeating-linear-gradient(90deg, #90521f27 0 1px, transparent 1px 7px, #ffebbc36 7px 18px, #a7652811 18px 29px),
    repeating-linear-gradient(90deg, transparent 0 2px, #9454210c 2px 3px, transparent 3px 7px),
    linear-gradient(145deg, #ffdfa96b, #cc8b4c20);
}

.attack-line {
  position: absolute;
  top: 33.333%;
  width: 100%;
  border-top: 2px solid var(--court-line);
}

.attack-line span, .end-line-label {
  position: absolute;
  left: 6px;
  padding: 2px 4px;
  border-radius: 3px;
  color: #472f1c;
  background: #f8e4c8;
  font-size: .65rem;
  font-weight: 700;
}

.attack-line span { bottom: 3px; left: 31%; transform: translateX(-50%); }
.end-line-label { top: calc(100% + 5px); color: #1d2634; background: #d9dde4; }

.court-trails {
  position: absolute;
  z-index: 1;
  left: -8%;
  top: -12%;
  width: 116%;
  height: 124%;
  pointer-events: none;
}

.serve-ball {
  position: absolute;
  z-index: 5;
  width: clamp(22px, 6.5cqw, 32px);
  height: auto;
  aspect-ratio: 1;
  border-radius: 50%;
  filter: drop-shadow(0 2px 2px #26394565);
  pointer-events: none;
}

.player-marker {
  position: absolute;
  z-index: 2;
  display: grid;
  justify-items: center;
  align-items: start;
  width: clamp(32.14365px, 11.879175cqw, 58.6971px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  transition: opacity .16s ease;
}

.player-marker[data-muted="true"] { opacity: .34; }

.player-marker:hover, .player-marker:focus-visible, .player-marker[aria-pressed="true"] {
  z-index: 3;
  opacity: 1;
}

[data-row="front"] { --row-ring: var(--front-ring); }
[data-row="back"] { --row-ring: var(--back-ring); }
[data-row="bench"] { --row-ring: #778196; }

.avatar {
  display: block;
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  overflow: visible;
  border: 2px solid var(--row-ring);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 5px #20284b32;
}

.player-marker[aria-pressed="true"] .avatar { outline: 2px solid #fff; outline-offset: 2px; }

.avatar-inner {
  position: absolute;
  inset: auto -5% 0;
  width: 110%;
  height: 113%;
  object-fit: contain;
  pointer-events: none;
}

.marker-label {
  position: absolute;
  top: 76%;
  left: 50%;
  transform: translateX(-50%);
  display: grid;
  justify-items: center;
  gap: 1px;
  pointer-events: none;
}

.role-badge {
  padding: 1px 4px 2px;
  border-radius: 4px;
  background: #1a2240;
  color: #fff;
  font-size: clamp(.55rem, 2.25cqw, .68rem);
  font-weight: 790;
  line-height: 1.05;
}

.marker-name {
  max-width: clamp(62px, 21cqw, 104px);
  overflow: hidden;
  padding: 1px 4px 2px;
  border-radius: 4px;
  background: #fff9ef;
  color: #1a2240;
  font-size: clamp(.58rem, 2.55cqw, .75rem);
  font-weight: 750;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-status { margin-top: 7px; min-height: 1.5em; font-weight: 650; }

.lineup {
  padding: 22px 18px;
  border-left: 1px solid var(--line);
}

.team-name-field { display: grid; gap: 6px; }
.team-name-controls { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px; }
.team-name-field input {
  min-width: 0;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f8f9fd;
  font-weight: 700;
}

.lineup-heading { display: flex; align-items: center; justify-content: space-between; gap: 5px; }
h2 { font-size: 1.17rem; letter-spacing: -.025em; }
.lineup p { margin-top: 6px; color: var(--muted); font-size: .88rem; line-height: 1.4; }
.lineup-row { margin-top: 17px; }
.lineup h3 { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.row-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--row-ring); }
.lineup-row-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.lineup-row-heading h3 { margin: 0; }
.lineup-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }

.lineup-card {
  min-width: 0;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  justify-items: center;
  gap: 7px;
  padding: 8px 4px 7px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8f9fd;
  text-align: center;
}

.lineup-card[data-focused="true"] { border-color: var(--accent); background: var(--accent-light); }
.portrait-edit {
  position: relative;
  width: 44px;
  height: 44px;
  padding: 1px;
  border: 0;
  border-radius: 50%;
  background: transparent;
}
.edit-mark {
  position: absolute;
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  right: -4px;
  bottom: -2px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--accent);
  background: var(--paper);
  font-size: 11px;
}
.portrait-edit:hover .edit-mark { background: var(--accent); color: white; }
.lineup-player {
  display: grid;
  align-content: start;
  gap: 2px;
  width: 100%;
  padding: 3px 1px 5px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-align: center;
  overflow-wrap: anywhere;
}
.lineup-player:hover { color: var(--accent); background: var(--accent-light); }

.trace-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 30px;
  padding: 2px 4px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: .7rem;
  font-weight: 750;
}
.trace-toggle:hover { background: var(--paper); border-color: var(--line); }
.trace-toggle[aria-pressed="true"], .trace-toggle[aria-pressed="mixed"] { color: var(--trail-color); }
.trace-swatch { width: 9px; height: 3px; border-radius: 2px; background: var(--trail-color); }
.trace-swatch[data-row="back"] {
  width: 11px;
  background: repeating-linear-gradient(to right, var(--trail-color) 0 4px, transparent 4px 6px);
}
.row-path-toggle { --trail-color: var(--accent); }
.path-switch {
  position: relative;
  flex: 0 0 27px;
  width: 27px;
  height: 15px;
  border-radius: 10px;
  background: #667188;
  transition: background-color .16s ease;
}
.path-switch::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: white;
  transition: transform .16s ease;
}
.trace-toggle[aria-pressed="true"] .path-switch { background: var(--trail-color); }
.trace-toggle[aria-pressed="true"] .path-switch::before { transform: translateX(12px); }
.trace-toggle[aria-pressed="mixed"] .path-switch { background: var(--trail-color); }
.trace-toggle[aria-pressed="mixed"] .path-switch::before { transform: translateX(6px); }
.zone-label, .role-label { color: var(--muted); font-size: .71rem; }
.zone-label { font-weight: 760; }
.lineup-player strong { font-size: .9rem; }

.clear-focus {
  border: 0;
  padding: 5px;
  background: transparent;
  color: var(--accent);
  font-size: .8rem;
  font-weight: 750;
  text-decoration: underline;
}

.libero-swap {
  margin-top: 17px;
  border-radius: 8px;
  padding: 10px 12px;
  background: #f3f2ff;
  overflow-wrap: anywhere;
}

.libero-swap h3 { margin: 0; color: var(--accent); }
.swap-players { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; margin-top: 9px; }
.swap-player {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  min-width: 0;
  padding: 7px;
  border: 1px solid #e6e2ff;
  border-radius: 9px;
  background: var(--paper);
}
.swap-player .portrait-edit { width: 36px; height: 36px; }
.swap-player strong, .swap-player .role-label { display: block; }
.swap-player strong { font-size: .82rem; }

.player-editor {
  width: min(690px, calc(100% - 30px));
  max-height: calc(100dvh - 30px);
  padding: clamp(16px, 4vw, 25px);
  border: 1px solid var(--line);
  border-radius: 20px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 18px 66px #161e4b45;
}
.player-editor::backdrop, .live-clip::backdrop { background: #11162c80; backdrop-filter: blur(3px); }

.live-clip {
  box-sizing: border-box;
  width: min(1260px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  padding: clamp(12px, 2vw, 20px);
  border: 0;
  border-radius: 18px;
  color: inherit;
}
.live-clip-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.live-clip-heading h2 { margin: 0; font-size: clamp(1rem, 2.5vw, 1.5rem); }
.live-clip-heading p { margin: 4px 0 0; }
.live-clip-heading button, .live-clip-controls button {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid #dbd5fc;
  border-radius: 10px;
  background: var(--accent-light);
  color: var(--accent);
}
.live-clip-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.live-clip-controls button { min-width: 76px; }
.live-clip-controls button:disabled { opacity: .58; cursor: default; }
.live-clip-content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(218px, 27%, 300px);
  align-items: start;
  gap: clamp(12px, 2vw, 20px);
  margin-top: 12px;
}
.live-clip iframe, .live-clip-end {
  width: 100%;
  aspect-ratio: 16 / 9;
  margin-bottom: 9px;
  border: 0;
  border-radius: 10px;
  background: #111;
}
.live-clip iframe { display: block; }
.live-clip-end {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: white;
  background: radial-gradient(ellipse at center, #333052, #181724 75%);
}
.live-clip-end button {
  min-height: 54px;
  padding: 0 32px;
  border: 0;
  border-radius: 12px;
  background: var(--accent-light);
  color: var(--accent);
  font-size: 1.2rem;
  font-weight: 750;
}
.live-clip-end button:hover { background: #fff; }
.live-clip-end button:focus-visible { outline-color: #fff; }
.live-clip a { color: var(--accent); }
.live-clip-court h3 { margin-bottom: 7px; font-size: .9rem; }
.live-clip-court .court-frame { padding: 21px 14px 46px; border-radius: 10px; }
.live-clip-court .court-frame:has(.opponent-divisions) { padding-top: 8px; }
.live-clip-court .opponent-divisions { min-height: 25px; margin-bottom: 12px; font-size: .68rem; }
.live-clip-court .net { margin-inline: -7px; }
.live-clip-court .player-marker { width: clamp(22px, 11.879175cqw, 33px); }
.live-clip-court .role-badge, .live-clip-court .marker-name { padding-inline: 3px; }

@media (max-width: 620px) {
  .live-clip-content { grid-template-columns: minmax(0, 1fr); }
  .live-clip-court { width: min(100%, 260px); justify-self: center; }
}
.editor-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 17px;
}
.editor-heading h2 { font-size: 1.45rem; }
.editor-heading p { color: var(--muted); font-size: .84rem; margin-top: 3px; }
.editor-heading .avatar { width: 56px; }
.name-field, .avatar-picker legend { font-size: .84rem; font-weight: 700; }
.name-field { display: grid; gap: 6px; }
.name-field input {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f8f9fd;
  font-size: 1rem;
}
.avatar-picker { min-width: 0; margin: 17px 0; padding: 0; border: 0; }
.avatar-picker legend { margin-bottom: 8px; padding: 0; }
.portrait-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: .8rem;
}
.portrait-toolbar label { display: flex; align-items: center; gap: 6px; }
.portrait-toolbar select {
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8f9fd;
}
.avatar-options {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 7px;
  max-height: min(46dvh, 385px);
  overflow-y: auto;
  padding: 3px;
  scrollbar-gutter: stable;
}
.avatar-option {
  position: relative;
  display: grid;
  place-items: center;
  padding: 5px;
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #f8f9fd;
}
.avatar-option .avatar { width: min(100%, 46px); }
.avatar-option:not(:disabled):hover, .avatar-option[aria-pressed="true"] { background: var(--accent-light); border-color: var(--accent); }
.avatar-option:disabled { cursor: default; }
.avatar-option:disabled .avatar { opacity: .42; }
.portrait-taken {
  position: absolute;
  bottom: 2px;
  right: 2px;
  border-radius: 4px;
  padding: 1px 3px;
  color: var(--muted);
  background: #f1f3f9;
  font-size: .62rem;
  font-weight: 700;
}
.editor-actions { display: flex; justify-content: flex-end; gap: 8px; }
.editor-actions button {
  padding: 9px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--paper);
  font-size: .86rem;
  font-weight: 700;
}
.editor-actions .save-player { background: var(--accent); border-color: var(--accent); color: white; }
.editor-actions .save-player:disabled { opacity: .55; cursor: default; }

@media (max-width: 690px) {
  .viewer { width: calc(100% - 24px); padding-top: 20px; }
  .viewer-heading { margin-bottom: 14px; }
  .viewer-controls { grid-template-columns: minmax(0, 1fr); padding: 12px; }
  .viewer-body { grid-template-columns: minmax(0, 1fr); }
  .formation { padding: 12px 12px 5px; }
  .lineup { border-left: 0; border-top: 1px solid var(--line); padding: 14px 12px; }
  .court-frame { padding-inline: 21px; }
}

@media (max-width: 370px) {
  .rotation-picker { gap: 4px; }
  .rotation-picker button { min-width: 38px; }
  .phase-picker button { padding-inline: 9px; }
  .attack-line span, .end-line-label { font-size: .58rem; }
}

@media (max-width: 420px) {
  .phase-note { min-height: 4.2em; }
}

@media (max-width: 560px) {
  .avatar-options { grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 5px; }
  .avatar-option { min-height: 48px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; }
}
