:root {
  --bg: #0f1f17;
  --surface: #173225;
  --surface-2: #1f4030;
  --line: #d7e8d7;
  --pitch: #2f6b45;
  --pitch-dark: #245437;
  --text: #f3f7f3;
  --muted: #b7c7b9;
  --accent: #f0c75e;
  --border: rgba(215, 232, 215, 0.28);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
  --page-pad: clamp(0.75rem, 3vw, 1.5rem);
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  max-width: 100%;
  overflow-x: clip;
}

body {
  margin: 0;
  min-height: 100vh;
  max-width: 100%;
  overflow-x: clip;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(240, 199, 94, 0.12), transparent 35%),
    linear-gradient(160deg, #0b1711 0%, var(--bg) 45%, #12261b 100%);
}

.app-shell {
  width: 100%;
  max-width: min(1280px, 100%);
  margin: 0 auto;
  padding: var(--page-pad);
  overflow-x: clip;
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
  min-width: 0;
}

.brand {
  margin: 0;
  font-size: clamp(1.75rem, 6vw, 2.75rem);
  letter-spacing: 0.02em;
  overflow-wrap: anywhere;
}

.tagline {
  margin: 0;
  color: var(--muted);
  max-width: 100%;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
  width: 100%;
  min-width: 0;
}

.toggle-group {
  display: inline-flex;
  flex-wrap: wrap;
  max-width: 100%;
  padding: 0.25rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(23, 50, 37, 0.85);
}

.toggle {
  border: 0;
  background: transparent;
  color: var(--muted);
  min-height: 44px;
  padding: 0.55rem 1rem;
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  touch-action: manipulation;
}

.toggle.is-active {
  background: var(--accent);
  color: #1b1608;
  font-weight: 600;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) minmax(0, 0.9fr);
  gap: 1rem;
  align-items: start;
  width: 100%;
  min-width: 0;
}

.pitch-panel,
.side-panel {
  background: rgba(23, 50, 37, 0.92);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  min-width: 0;
  max-width: 100%;
}

.pitch-panel {
  padding: clamp(0.65rem, 2vw, 1rem);
  overflow: visible;
  display: flex;
  justify-content: center;
}

.pitch {
  display: block;
  width: min(100%, calc((100vh - 10rem) * 760 / 1130));
  max-width: 100%;
  height: auto;
  /* Matches viewBox 760×1130. The playable rect inside is 680×1050 (68:105). */
  aspect-ratio: 760 / 1130;
  touch-action: manipulation;
}

.pitch-canvas {
  fill: #143526;
}

.pitch-playable {
  fill: var(--pitch);
  stroke: var(--line);
  stroke-width: 3;
}

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

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

.zone-cell {
  fill: transparent;
  stroke: none;
}

.zone-cell.is-active {
  fill: rgba(240, 199, 94, 0.4);
  stroke: var(--accent);
  stroke-width: 4;
}

.zone-grid-line {
  stroke: rgba(215, 232, 215, 0.55);
  stroke-width: 1.5;
  stroke-dasharray: 8 8;
}

.player-marker {
  cursor: pointer;
  touch-action: manipulation;
}

.player-marker.editor-draggable,
.player-marker.editor-draggable *,
.ball-marker.editor-draggable,
.ball-marker.editor-draggable *,
.arrow-end {
  touch-action: none;
}

#pitch.arrow-gesture,
#gesture-capture {
  touch-action: none;
}

.player-hit {
  fill: transparent;
  pointer-events: all;
}

.player-ours .player-body {
  fill: var(--accent);
  stroke: #1b1608;
  stroke-width: 2;
}

.player-opp .player-body,
.player-opponent .player-body {
  fill: #c4473a;
  stroke: #fff8f4;
  stroke-width: 2;
}

.player-label {
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.player-ours .player-label {
  fill: #1b1608;
}

.player-opp .player-label,
.player-opponent .player-label {
  fill: #fff8f4;
}

.ball-body {
  fill: #f7f7f7;
  stroke: #1b1608;
  stroke-width: 2;
}

.ball-hit,
.arrow-end {
  fill: transparent;
  stroke: transparent;
}

.arrow-line {
  fill: none;
  stroke: #f4f1e8;
  stroke-width: 4;
  stroke-linecap: round;
  pointer-events: stroke;
}

.arrow-movement {
  stroke-dasharray: none;
}

.arrow-pass {
  stroke-dasharray: 12 8;
}

.arrow-line.is-selected {
  stroke: var(--accent);
}

.arrow-head {
  fill: #f4f1e8;
  stroke: #1b1608;
  stroke-width: 2;
  pointer-events: none;
}

.zone-readout {
  display: grid;
  gap: 0.2rem;
  margin: 0 0 0.75rem;
  min-width: 0;
}

.zone-number {
  font-size: clamp(1.6rem, 6vw, 2.2rem);
  font-weight: 700;
  line-height: 1.1;
}

.zone-name {
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.side-panel {
  padding: clamp(1rem, 3vw, 1.25rem);
}

.side-panel h2 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
  overflow-wrap: anywhere;
}

.field-label {
  display: grid;
  gap: 0.35rem;
  margin: 0.85rem 0 0;
  min-width: 0;
  max-width: 100%;
}

.side-panel select,
#refresh-catalog,
#owner-condition,
#refresh-error,
#viewer-status,
#variant-choices,
#variant-snapshot,
#variant-label,
#variant-description,
#recommended-actions {
  max-width: 100%;
  min-width: 0;
  overflow-wrap: anywhere;
}

.side-panel select,
#refresh-catalog,
.choice-item {
  width: 100%;
  font: inherit;
  color: inherit;
}

.side-panel select,
#refresh-catalog,
.choice-item {
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

#refresh-catalog,
.choice-item {
  margin-top: 0.85rem;
  padding: 0.55rem 0.8rem;
  text-align: left;
  cursor: pointer;
}

#owner-condition,
#viewer-status,
#refresh-error {
  margin: 0.75rem 0 0;
  line-height: 1.4;
}

#refresh-error {
  color: #ffb4a8;
}

#variant-choices {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.85rem;
}

#variant-choices[hidden] {
  display: none;
}

.choice-item {
  margin-top: 0;
  white-space: normal;
}

#variant-snapshot {
  margin-top: 0.9rem;
  min-width: 0;
}

#variant-snapshot h2,
#variant-label,
#variant-description {
  margin: 0.35rem 0 0;
}

#recommended-actions {
  margin: 0.45rem 0 0;
  padding-left: 1.15rem;
}

.side-panel h2 + .muted,
.side-panel h2 + p {
  margin-top: 0;
}

.muted {
  color: var(--muted);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

#editor-draft,
.editor-controls,
#editor-properties,
#save-result,
#draft-phase,
#overlap-list {
  min-width: 0;
  max-width: 100%;
}

body:not(.mode-editor) .editor-controls {
  display: none;
}

#draft-phase,
#save-result {
  margin: 0.75rem 0 0;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

#save-result[data-save-state="error"],
#save-result[data-save-state="missing"] {
  color: #ffb4a8;
}

.editor-controls .field-label input,
.editor-controls .field-label textarea,
.editor-controls .field-label select,
.editor-commands button,
#toggle-editor-properties {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 44px;
  box-sizing: border-box;
  font: inherit;
  color: inherit;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}

.editor-controls .field-label textarea {
  min-height: 88px;
  padding: 0.55rem 0.8rem;
  resize: vertical;
}

.editor-commands {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.85rem;
}

.editor-commands button,
#toggle-editor-properties {
  padding: 0.55rem 0.8rem;
  text-align: left;
  cursor: pointer;
  white-space: normal;
  overflow-wrap: anywhere;
}

#toggle-editor-properties {
  margin-top: 0.85rem;
}

.editor-commands button.is-active,
#toggle-editor-properties.is-active {
  background: var(--accent);
  color: #1b1608;
  font-weight: 600;
}

#overlap-list {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.85rem;
}

#overlap-list[hidden] {
  display: none;
}

.status-list {
  margin: 1.5rem 0 0;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  display: grid;
  gap: 0.75rem;
}

.status-list div {
  display: grid;
  gap: 0.15rem;
}

.status-list dt {
  color: var(--muted);
  font-size: 0.85rem;
}

.status-list dd {
  margin: 0;
  font-weight: 600;
}

@media (max-width: 900px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .toolbar {
    flex-direction: column;
  }

  .toggle-group {
    width: 100%;
    border-radius: 16px;
  }

  .toggle {
    flex: 1 1 auto;
    text-align: center;
  }
}

@media (max-width: 480px) {
  .toggle-group {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  #editor-properties.is-collapsed {
    display: none;
  }
}
