:root {
  color-scheme: dark;
  --bg: #081725;
  --panel: #10283b;
  --line: #d8f1e2;
  --blue: #38a5ff;
  --red: #ff5d64;
  --text: #f4f8fc;
  --muted: #afc2d1;
}

* {
  box-sizing: border-box;
}

html {
  overflow-y: auto;
  scrollbar-gutter: stable;
}

html.is-editing #view {
  display: none;
}

html.is-editing #editor {
  display: block;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, sans-serif;
  background: linear-gradient(140deg, #07131f, #10283b);
  color: var(--text);
}

.taskbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: #0b1c2b;
  border-bottom: 1px solid #29465c;
}

.taskbar-row {
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.taskbar .step-count {
  margin-left: 0;
}

.taskbar-end {
  margin-left: auto;
}

.taskbar-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.taskbar-sep {
  width: 1px;
  align-self: stretch;
  margin: 6px 2px;
  background: #29465c;
}

html.is-editing .taskbar-view,
html:not(.is-editing) .taskbar-editor {
  display: none;
}

main {
  max-width: 1180px;
  margin: auto;
  padding: 24px;
}

header {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

h1 {
  margin: 0 0 8px;
  font-size: clamp(1.5rem, 3vw, 2.3rem);
  line-height: 1.1;
}

p {
  color: var(--muted);
  margin: 0;
  line-height: 1.5;
}

.formation {
  border: 1px solid #34536b;
  border-radius: 12px;
  padding: 10px 14px;
  color: #d8e9f6;
  white-space: nowrap;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 18px;
  align-items: start;
}

.pitch-card,
.side-card {
  background: #0d2131;
  border: 1px solid #29465c;
  border-radius: 16px;
  box-shadow: 0 14px 38px #0003;
}

.pitch-card {
  position: relative;
  overflow: hidden;
}

.sketch {
  position: absolute;
  pointer-events: none;
  touch-action: none;
}

.sketch.is-active {
  pointer-events: auto;
  cursor: crosshair;
}

#sketchToggle[aria-pressed="true"] {
  background: #087bdb;
  border-color: #2199f5;
}

.taskbar-group > * {
  flex-shrink: 0;
}

.sketch-color {
  flex: 0 0 43px;
  width: 43px;
  height: 43px;
  display: block;
  overflow: hidden;
}

.sketch-color input {
  display: block;
  width: 43px;
  height: 43px;
  min-width: 43px;
  max-width: 43px;
  padding: 4px;
  box-sizing: border-box;
  border: 1px solid #3a617d;
  border-radius: 10px;
  background: #17364d;
  cursor: pointer;
}

.side-card {
  overflow: auto;
}

.pitch-wrap {
  padding: 12px;
  user-select: none;
}

a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  border: 1px solid #3a617d;
  background: #17364d;
  color: white;
  padding: 10px 14px;
  border-radius: 10px;
  font: inherit;
  cursor: pointer;
}

a.btn:hover {
  background: #214b69;
}

a.btn.primary {
  background: #087bdb;
  border-color: #2199f5;
}

a.btn.primary:hover {
  background: #168eea;
}

svg {
  display: block;
}

#pitch {
  width: 100%;
  height: auto;
  border-radius: 10px;
  background: #267b3d;
}

.icon,
.icon-sprite {
  background: transparent;
  border-radius: 0;
}

.controls {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding: 14px;
  border-top: 1px solid #29465c;
}

.speed {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: #bcd0de;
  font-size: 0.85rem;
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid #3a617d;
  background: #17364d;
  color: white;
  padding: 10px 14px;
  border-radius: 10px;
  font: inherit;
  cursor: pointer;
}

button:hover {
  background: #214b69;
}

button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

#play {
  width: 180px;
  flex: 0 0 180px;
  white-space: nowrap;
}

#play .icon-pause,
#play.is-playing .icon-play {
  display: none;
}

#play.is-playing .icon-pause {
  display: block;
}

.primary {
  background: #087bdb;
  border-color: #2199f5;
}

.primary:hover {
  background: #168eea;
}

.danger {
  background: #c62828;
  border-color: #ef5350;
}

.danger:hover {
  background: #e53935;
}

.step-count {
  color: #bcd0de;
  font-variant-numeric: tabular-nums;
  margin-left: auto;
}

input[type="range"] {
  width: 100%;
  accent-color: #38a5ff;
}

.side-card {
  padding: 18px;
}

.kicker {
  text-transform: uppercase;
  color: #82c8ff;
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  font-weight: 800;
}

h2 {
  font-size: 1.25rem;
  margin: 8px 0 10px;
}

.description {
  min-height: 105px;
  color: #d4e2ed;
  line-height: 1.55;
}

.legend {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 14px;
}

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

.note {
  margin-top: 16px;
  padding: 12px;
  background: #102e42;
  border-radius: 10px;
  color: #c4d8e7;
  font-size: 0.9rem;
  line-height: 1.5;
}

.key {
  display: inline-block;
  border: 1px solid #557187;
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 0.8rem;
  color: white;
}

.editor-layout {
  grid-template-columns: minmax(0, 1fr) 380px;
}

.editor-form {
  max-height: calc(100vh - 150px);
}

.editor-form details:not([open]) > :not(summary) {
  display: none;
}

.editor-form .fold + .fold {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid #29465c;
}

.editor-form summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  padding: 8px 0;
  font-size: 1.25rem;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}

.editor-form summary::-webkit-details-marker {
  display: none;
}

.editor-form summary::after {
  content: "";
  width: 9px;
  height: 9px;
  border-right: 2px solid #82c8ff;
  border-bottom: 2px solid #82c8ff;
  transform: translateY(-2px) rotate(45deg);
  flex: none;
}

.editor-form details[open] summary::after {
  transform: translateY(2px) rotate(-135deg);
}

.editor-form summary:focus-visible {
  outline: 2px solid #38a5ff;
  border-radius: 6px;
}

.fold-status {
  margin: 0;
  color: #82c8ff;
  font-size: 0.85rem;
  font-weight: 700;
}

.editor-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.85rem;
}

.editor-form input,
.editor-form textarea {
  width: 100%;
  border: 1px solid #3a617d;
  background: #0b1c2b;
  color: white;
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  resize: vertical;
}

.player-list {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.player-group {
  grid-column: 1 / -1;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.player-list button {
  width: 100%;
  padding: 6px 4px;
  gap: 4px;
  font-size: 0.72rem;
  white-space: nowrap;
}

.player-list .dot {
  width: 8px;
  height: 8px;
  margin-right: 0;
}

.player-list button.active {
  background: #087bdb;
  border-color: #2199f5;
}

.player-list button.is-hidden {
  opacity: 0.45;
}

.team-colors {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.team-colors label {
  margin-top: 8px;
}

.editor-form input[type="color"] {
  height: 42px;
  padding: 4px;
  cursor: pointer;
}

.editor-form input[type="range"] {
  padding: 0;
  border: 0;
  background: transparent;
  height: auto;
}

.label-row {
  display: flex;
  justify-content: space-between;
}

.reset-colors {
  width: 100%;
  margin-top: 12px;
}

.editor-form input:focus,
.editor-form textarea:focus {
  outline: 2px solid #38a5ff;
  border-color: #38a5ff;
}

.editor-form .check {
  flex-direction: row;
  align-items: center;
  color: var(--text);
  font-size: 0.95rem;
}

.editor-form .check input {
  width: auto;
  padding: 0;
  accent-color: #38a5ff;
}

.hint {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.row-actions button {
  flex: 1 1 auto;
}

.step-switcher {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding: 14px;
  border-top: 1px solid #29465c;
}

.step-tab[aria-pressed="true"] {
  background: #087bdb;
  border-color: #2199f5;
}

.arrow-list {
  list-style: none;
  padding: 0;
  margin: 12px 0 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.arrow-list li:not(.hint) {
  display: flex;
  align-items: center;
  gap: 8px;
}

.arrow-list .arrow-select {
  flex: 1;
  text-align: left;
}

.arrow-list .arrow-select.active {
  background: #087bdb;
  border-color: #2199f5;
}

.arrow-list .arrow-delete {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  padding: 0;
}

body.editor svg {
  touch-action: none;
}

body.editor #players g,
body.editor #ball,
body.editor #zones rect,
body.editor #handles circle,
body.editor #handles rect,
body.editor #paths line {
  cursor: grab;
}

@media (max-width: 800px) {
  main {
    padding: 14px;
  }

  .layout,
  .editor-layout {
    grid-template-columns: 1fr;
  }

  .description {
    min-height: 0;
  }

  .step-count {
    margin-left: 0;
  }

  .taskbar-row {
    padding: 12px 14px;
  }

  .editor-form {
    max-height: none;
  }
}
