:root {
  --court-green: #0b6b4f;
  --court-green-dark: #0b3d2e;
  --line: #f2f7f5;
  --neutral-zone: rgba(255, 255, 255, 0.08);
  --red: #e23b3b;
  --red-dark: #a81f1f;
  --blue: #2f6fe0;
  --blue-dark: #1b4699;
  --ball: #f5c518;
  --ball-dark: #b88c00;
  --toolbar-bg: #11261f;
  --toolbar-fg: #e8f1ed;
  --accent: #2fbd87;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--court-green-dark);
  color: var(--toolbar-fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  /* Prevent iOS text selection / callouts while dragging */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

/* ---------- Toolbar ---------- */
#toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--toolbar-bg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  flex-wrap: wrap;
  z-index: 10;
}

#toolbar .title {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: 0.3px;
  margin-right: auto;
}

.toolbar-group {
  display: flex;
  gap: 6px;
}

#toolbar button {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: #1c3a30;
  color: var(--toolbar-fg);
  font-size: 15px;
  font-weight: 600;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.05s ease;
  min-height: 44px; /* comfortable touch target */
}

#toolbar button:hover { background: #26493d; }
#toolbar button:active { transform: scale(0.96); }

#toolbar button.tool.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #06241a;
}

/* ---------- Stage / court ---------- */
#stage {
  flex: 1;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  min-height: 0;
}

#court {
  width: 100%;
  height: 100%;
  touch-action: none; /* we handle all gestures ourselves */
  display: block;
}

/* ---------- Tokens ---------- */
.token {
  cursor: grab;
}
.token:active { cursor: grabbing; }

.token-circle {
  stroke: rgba(0, 0, 0, 0.35);
  stroke-width: 0.12;
}

.token.player.red .token-circle { fill: var(--red); }
.token.player.blue .token-circle { fill: var(--blue); }
.token.ball .token-circle { fill: var(--ball); stroke: var(--ball-dark); }

.token-label {
  fill: #fff;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
}

.token.dragging .token-circle {
  stroke: #fff;
  stroke-width: 0.22;
}

/* ---------- Arrows ---------- */
.arrow-path {
  fill: none;
  stroke: #ffd23f;
  stroke-width: 0.28;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.modal.hidden { display: none; }

.modal-card {
  background: #16302785;
  background: #163027;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  width: min(460px, 100%);
  max-height: 80vh;
  overflow: auto;
  padding: 18px 20px 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.modal-head h2 { margin: 0; font-size: 18px; }

.icon-btn {
  appearance: none;
  background: transparent;
  border: none;
  color: var(--toolbar-fg);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}

.plays-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.play-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: #1c3a30;
  border-radius: 10px;
}
.play-row .play-name {
  flex: 1;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.play-row button {
  appearance: none;
  border: none;
  border-radius: 8px;
  padding: 9px 14px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  min-height: 40px;
}
.play-row .load-btn { background: var(--accent); color: #06241a; }
.play-row .delete-btn { background: var(--red); color: #fff; }

.plays-empty { opacity: 0.7; text-align: center; padding: 16px 0; }

.field-label { display: block; font-size: 14px; margin-bottom: 6px; opacity: 0.85; }
.text-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 16px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: #0f241d;
  color: var(--toolbar-fg);
}
.text-input:focus { outline: 2px solid var(--accent); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}
.modal-actions button {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: #1c3a30;
  color: var(--toolbar-fg);
  padding: 11px 18px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 15px;
  cursor: pointer;
  min-height: 44px;
}
.modal-actions button.primary { background: var(--accent); color: #06241a; border-color: var(--accent); }

.hidden { display: none !important; }
