:root {
  --pitch-light: #ddf8dd;
  --pitch-dark: #cbf3cd;
  --pitch-line: rgba(55, 95, 55, 0.38);

  --home-fill: #101010;
  --home-stroke: #ed1c24;
  --home-label: #df161f;

  --away-fill: #ffffff;
  --away-stroke: #1437e6;
  --away-label: #1437e6;

  --neutral-fill: #9aa0a6;
  --neutral-stroke: #5f6368;
  --neutral-label: #444;

  --zone-red: rgba(235, 76, 70, 0.52);
  --zone-orange: rgba(242, 143, 52, 0.45);
  --connection: #2d2d2d;

  --chrome-bg: #fcfcfb;
  --chrome-border: #e8e8e3;
  --visible-border: #333333;
}

.app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---- Top bar ---- */

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #fff;
  flex: 0 0 auto;
}

.logo {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: bold;
  text-decoration: none;
  color: var(--ink);
  font-size: 16px;
  white-space: nowrap;
}

.title-input {
  font: inherit;
  font-size: 14px;
  border: 1px solid transparent;
  border-radius: 0;
  padding: 5px 8px;
  min-width: 160px;
  background: transparent;
}

.title-input:hover,
.title-input:focus {
  border-color: var(--chrome-border);
  background: #fff;
  outline: none;
}

.viewer-title {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  margin: 0;
}

.topbar-spacer {
  flex: 1 1 auto;
}

.topbar-divider,
.toolbar-divider {
  width: 1px;
  align-self: stretch;
  background: transparent;
  margin: 0 4px;
}

.toolbar-divider {
  width: auto;
  height: 1px;
  margin: 6px 4px;
}

/* ---- Workspace ---- */

.workspace-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

.workspace {
  display: flex;
  justify-content: safe center;
  gap: 0;
  padding: 24px;
  max-width: 1200px;
  margin: 0 auto;
  min-height: 100%;
}

.box {
  background: #fff;
  border: 1px solid var(--visible-border);
  border-radius: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.workspace-viewer {
  justify-content: center;
}

.workspace-viewer .pitch-area {
  width: 100%;
  max-width: 640px;
}

/* ---- Team box ---- */

.left-column {
  flex: 1 1 480px;
  min-width: 300px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.teams-box {
  flex: 0 0 auto;
}

.properties-box {
  flex: 1 1 auto;
  min-height: 0;
  margin-top: -1px;
}

.team-tabs {
  flex: 0 0 auto;
  display: flex;
  border-bottom: 1px solid var(--visible-border);
}

.team-tab-label {
  flex: 1 1 0;
  padding: 10px 16px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  font-weight: bold;
  text-align: center;
}

.team-tab-label-home {
  background: var(--accent);
  color: #fff;
}

.team-tab-label-away {
  background: #fff;
  color: #b3261e;
  border-left: 1px solid var(--visible-border);
}

.team-box-header {
  flex: 0 0 auto;
  padding: 10px 16px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  font-weight: bold;
  color: #fff;
  border-bottom: 1px solid var(--visible-border);
}

.team-box-header-selected {
  background: #444;
}

.team-colors-row {
  display: flex;
  gap: 16px;
  margin-top: 16px;
}

.team-colors-col {
  flex: 1 1 0;
  min-width: 0;
}

.team-box-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: 16px;
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* ---- Pitch box ---- */

.pitch-box {
  flex: 2 1 540px;
  min-width: 420px;
  margin-left: -1px;
  aspect-ratio: 680 / 1050;
  height: auto;
  align-self: flex-start;
}

.pitch-area {
  background: var(--pitch-light);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  min-width: 0;
  flex: 1 1 auto;
}

#pitch {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  touch-action: none;
  user-select: none;
}

/* ---- Toolbar box ---- */

.toolbar-box {
  flex: 0 0 68px;
  background: var(--chrome-bg);
  align-items: stretch;
  padding: 8px 6px;
  gap: 4px;
  margin-left: -1px;
}

.tool-btn {
  font: inherit;
  font-size: 11px;
  padding: 8px 2px;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 0;
  cursor: pointer;
  color: var(--ink);
}

.tool-btn:hover {
  background: #ebebe5;
}

.tool-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.tool-btn-key {
  font-size: 9px;
  opacity: 0.55;
  margin-left: 3px;
  vertical-align: super;
}

.team-name-input {
  width: 100%;
  font: inherit;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 15px;
  font-weight: bold;
  border: 1px solid transparent;
  border-radius: 0;
  padding: 4px 6px;
  margin-bottom: 8px;
}

.team-name-input:hover,
.team-name-input:focus {
  border-color: var(--chrome-border);
  outline: none;
}

.swatch-row-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #777;
  margin-bottom: 4px;
}

.swatch-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid rgba(0, 0, 0, 0.25);
  cursor: pointer;
  padding: 0;
}

.color-swatch.active {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.formation-select {
  width: 100%;
  font: inherit;
  font-size: 13px;
  padding: 4px 6px;
  border: 1px solid var(--visible-border);
  border-radius: 0;
  background: #fff;
}

.roster-table-wrap {
  border: 1px solid var(--visible-border);
}

.roster-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.roster-table th,
.roster-table td {
  border: 1px solid var(--visible-border);
  padding: 4px 6px;
  text-align: left;
}

.roster-table thead th {
  position: sticky;
  top: 0;
  background: var(--chrome-bg);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #666;
}

.roster-table tbody tr {
  cursor: pointer;
}

.roster-table tbody tr:nth-child(even) {
  background: #f4f4f0;
}

.roster-table tbody tr:hover {
  background: #eaeef8;
}

.roster-row-selected {
  background: #d7deff !important;
}

.roster-badge-cell {
  width: 22px;
  text-align: center;
  color: #666;
  font-size: 11px;
}

.roster-pos-cell {
  width: 40px;
  text-align: center;
  color: #666;
  font-size: 11px;
}

.roster-table input[type="text"] {
  width: 100%;
  min-width: 0;
  font: inherit;
  font-size: 13px;
  padding: 2px;
  border: none;
  background: transparent;
}

.roster-table input[type="text"]:focus {
  outline: 1px solid var(--accent);
  background: #fff;
}

.properties-empty {
  color: #888;
  font-size: 13px;
}

.prop-group {
  margin-bottom: 14px;
}

.prop-label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #777;
  margin-bottom: 4px;
}

.prop-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  align-items: center;
}

.prop-row input[type="text"],
.prop-row select {
  flex: 1 1 auto;
  font: inherit;
  font-size: 13px;
  padding: 4px 6px;
  border: 1px solid var(--chrome-border);
  border-radius: 0;
}

.prop-row input[type="range"] {
  flex: 1 1 auto;
}

.prop-row input[type="color"] {
  width: 32px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--chrome-border);
  border-radius: 0;
}

.prop-btn-row {
  display: flex;
  gap: 6px;
}

.prop-btn-row .btn {
  flex: 1 1 auto;
}

/* ---- Pitch SVG content ---- */

.pitch-stripe-light rect,
rect.pitch-stripe-light {
  fill: var(--pitch-light);
}

rect.pitch-stripe-dark {
  fill: var(--pitch-dark);
}

.pitch-mark {
  fill: none;
  stroke: var(--pitch-line);
  stroke-width: 2;
}

.pitch-mark-fill {
  fill: var(--pitch-line);
  stroke: none;
}

/* Players */

.player-marker {
  stroke-width: 2.5;
}

.player-marker.team-home {
  fill: var(--home-fill);
  stroke: var(--home-stroke);
}

.player-marker.team-away {
  fill: var(--away-fill);
  stroke: var(--away-stroke);
}

.player-marker.team-neutral {
  fill: var(--neutral-fill);
  stroke: var(--neutral-stroke);
}

.player-marker.role-gk {
  rx: 3;
  ry: 3;
}

.player-emphasis {
  fill: rgba(255, 210, 60, 0.55);
  filter: blur(0.3px);
}

.player-label {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 13px;
  font-weight: 600;
  text-anchor: middle;
  pointer-events: none;
  /* The pitch-colored halo (so a connector passing behind a name doesn't cut
     through the letters) is applied inline, per-label, only when a connector
     is actually nearby — see updatePlayerLabelNode in pitch-render.js. A
     blanket halo here would also show up behind a name sitting over a zone's
     color, which looks like a mistake, not a feature. */
}

.player-label.team-home {
  fill: var(--home-label);
}

.player-label.team-away {
  fill: var(--away-label);
}

.player-label.team-neutral {
  fill: var(--neutral-label);
}

.player-number {
  font-family: Georgia, "Times New Roman", serif;
  font-size: 9px;
  fill: #fff;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.player-marker.team-away + .player-number,
.team-away .player-number {
  fill: #1437e6;
}

/* Zones */

.zone-shape {
  stroke-width: 1.5;
}

/* Connectors */

.connector-line {
  fill: none;
  stroke: var(--connection);
  stroke-width: 3.5;
}

.connector-line.dashed {
  stroke-dasharray: 6 5;
}

.connector-line.dotted {
  stroke-dasharray: 1.5 4;
  stroke-linecap: round;
}

.connector-arrowhead {
  stroke: none;
}

/* Text elements */

.diagram-text {
  font-family: Georgia, "Times New Roman", serif;
  fill: #222;
}

/* Selection / editor overlay */

.selection-box {
  fill: none;
  stroke: var(--accent);
  stroke-width: 1.5;
  stroke-dasharray: 4 3;
  pointer-events: none;
}

.selection-halo {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  pointer-events: none;
}

/* A generously wide, translucent glow along the whole connector, so a selected
   line/arrow reads as clearly "selected" the same way a player's selection
   ring does — a thin stroke exactly overlapping the line was too easy to miss. */
.connector-selection-halo {
  fill: none;
  stroke: var(--accent);
  stroke-width: 9;
  stroke-linecap: round;
  stroke-opacity: 0.4;
  pointer-events: none;
}

.resize-handle {
  fill: #fff;
  stroke: var(--accent);
  stroke-width: 1.5;
  cursor: nwse-resize;
}

.drag-select-rect {
  fill: rgba(20, 55, 230, 0.08);
  stroke: var(--accent);
  stroke-width: 1;
  pointer-events: none;
}

.bend-handle {
  fill: var(--accent);
  stroke: #fff;
  stroke-width: 1;
  cursor: grab;
}

.connector-snap-ring {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  pointer-events: none;
}

.connector-start-ring {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  pointer-events: none;
}

[data-editable-text="true"] {
  cursor: text;
}

.inline-edit-input {
  z-index: 50;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 13px;
  font-weight: 600;
  border: 1.5px solid var(--accent);
  border-radius: 0;
  padding: 1px 4px;
  background: #fff;
}

.share-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.share-modal-card {
  background: #fff;
  border-radius: 0;
  padding: 20px;
  width: min(420px, 90vw);
}

.share-modal-card p {
  margin: 0 0 10px;
  font-size: 14px;
}

.share-modal-card input {
  width: 100%;
  font: inherit;
  font-size: 13px;
  padding: 8px;
  border: 1px solid var(--chrome-border);
  border-radius: 0;
  margin-bottom: 12px;
}

/* ---- Narrow / mobile layout ----
 * Below this width the three-boxes-in-a-row desktop layout (roster | pitch |
 * toolbar) can't fit — their min-widths alone add up to over 800px — so it
 * was just silently overflowing off the right edge of the screen. Stack them
 * instead: pitch first (the primary thing to look at and touch), then the
 * toolbar as a horizontal strip right under it (so switching tools doesn't
 * need a scroll away from the pitch), then the roster/colors/properties.
 */
@media (max-width: 860px) {
  .topbar {
    flex-wrap: wrap;
    row-gap: 6px;
  }

  .topbar-spacer {
    flex-basis: 100%;
    height: 0;
  }

  .title-input {
    flex: 1 1 120px;
    min-width: 0;
  }

  .workspace {
    flex-direction: column;
    padding: 12px;
    gap: 0;
  }

  .left-column,
  .pitch-box,
  .toolbar-box {
    flex: 0 0 auto;
    width: 100%;
    min-width: 0;
  }

  .pitch-box {
    align-self: stretch;
    margin-left: 0;
    order: 1;
  }

  .toolbar-box {
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    margin-left: 0;
    margin-top: -1px;
    order: 2;
  }

  .toolbar-box .tool-btn {
    flex: 0 0 auto;
    min-width: 44px;
  }

  .toolbar-divider {
    width: 1px;
    height: auto;
    align-self: stretch;
    margin: 0 4px;
  }

  .left-column {
    margin-top: -1px;
    order: 3;
  }

  .roster-table-wrap {
    overflow-x: auto;
  }

  .roster-table {
    min-width: 460px;
  }

  .team-colors-row {
    flex-wrap: wrap;
  }

  .team-colors-col {
    flex: 1 1 160px;
  }
}
