:root {
  --ink: #172033;
  --muted: #667085;
  --line: #d6dce8;
  --panel: #ffffff;
  --page: #eef3f8;
  --court: #f4a261;
  --court-deep: #e87945;
  --court-free: #77b7df;
  --us: #1d4ed8;
  --them: #dc2626;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--page);
  font-family: Inter, "Segoe UI", "Noto Sans KR", Arial, sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: #fff;
  cursor: pointer;
}

button:hover {
  border-color: #98a2b3;
}

button.primary {
  border-color: #155eef;
  color: #fff;
  background: #155eef;
}

button.danger {
  color: #b42318;
  border-color: #fecdca;
}

button.ghost {
  background: #fff7f7;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(220px, 260px) minmax(190px, 230px) minmax(360px, 1fr) minmax(210px, 260px);
  gap: 14px;
  min-height: 100dvh;
  padding: 14px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 14px 32px rgba(16, 24, 40, 0.08);
}

.toolbar,
.tools-panel,
.saves {
  align-self: start;
  padding: 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 8px;
  color: #fff;
  background: #172033;
  font-weight: 800;
}

.brand h1 {
  margin: 0;
  font-size: 19px;
}

.brand p,
.hint,
.board-topbar span {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.hint {
  white-space: pre-line;
}

.hint strong {
  color: #111827;
  font-weight: 900;
}

.control-group {
  display: grid;
  gap: 10px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.control-group:last-child {
  border-bottom: 0;
}

.player-edit {
  border-top: 1px solid var(--line);
}

.section-title {
  font-size: 13px;
  font-weight: 800;
  color: #344054;
  letter-spacing: 0.02em;
}

.field {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
}

.field input,
.field select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 10px;
  background: #fff;
}

.field input[type="color"] {
  padding: 3px;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

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

.team-option,
.tool-option {
  font-weight: 800;
}

.team-option[data-team="us"].active {
  border-color: #1d4ed8;
  color: #fff;
  background: #1d4ed8;
}

.team-option[data-team="them"].active {
  border-color: #dc2626;
  color: #fff;
  background: #dc2626;
}

.tool-option.active {
  border-color: #172033;
  color: #fff;
  background: #172033;
}

.quick-colors {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

.color-swatch {
  min-height: 32px;
  border-radius: 7px;
  border: 1px solid #98a2b3;
  background: var(--swatch);
}

.color-swatch[data-color="#FFFFFF"] {
  background: #fff;
}

.color-swatch.active {
  outline: 3px solid #172033;
  outline-offset: 2px;
}

.tools-panel {
  display: grid;
  gap: 12px;
}

.tool-divider {
  height: 1px;
  background: var(--line);
}

.upload {
  display: grid;
  place-items: center;
  min-height: 38px;
  border: 1px dashed #98a2b3;
  border-radius: 7px;
  color: #344054;
  background: #f8fafc;
  font-size: 14px;
  cursor: pointer;
}

.upload input {
  display: none;
}

.upload:has(input:disabled) {
  opacity: 0.55;
  cursor: not-allowed;
}

.board-area {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
}

.board-topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 12px;
}

.court-frame {
  display: grid;
  place-items: center;
  width: 100%;
  min-height: calc(100dvh - 88px);
}

#boardSvg {
  display: block;
  width: min(100%, calc((100dvh - 88px) * 0.769));
  max-height: calc(100dvh - 88px);
  aspect-ratio: 769 / 1000;
  border-radius: 8px;
  background: url("../Court.png") center / 100% 100% no-repeat;
  box-shadow: 0 18px 42px rgba(16, 24, 40, 0.18);
  touch-action: none;
  user-select: none;
}

.player {
  cursor: grab;
}

.ball-icon {
  cursor: grab;
  pointer-events: all;
}

.ball-icon:active {
  cursor: grabbing;
}

.player:active {
  cursor: grabbing;
}

.player-ring {
  stroke: #fff;
  stroke-width: 4;
  filter: drop-shadow(0 4px 8px rgba(16, 24, 40, 0.28));
}

.player.selected .player-ring {
  stroke: #fbbf24;
  stroke-width: 6;
}

.player-label {
  fill: #fff;
  font-size: 17px;
  font-weight: 900;
  text-anchor: middle;
  dominant-baseline: middle;
  pointer-events: none;
}

.player-name {
  fill: #172033;
  font-size: 13px;
  font-weight: 800;
  text-anchor: middle;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.86);
  stroke-width: 5px;
  pointer-events: none;
}

.arrow-item {
  cursor: pointer;
}

.arrow-line {
  fill: none;
  stroke-width: 4;
  marker-end: url(#arrowHead);
  pointer-events: none;
}

.arrow-hit {
  fill: none;
  stroke: transparent;
  stroke-width: 22;
  pointer-events: stroke;
}

.arrow-item:hover .arrow-line {
  stroke-width: 6;
}

.draft-arrow {
  fill: none;
  stroke-width: 4;
  marker-end: url(#arrowHead);
  pointer-events: none;
}

.draft-arrow[hidden] {
  display: none !important;
}

.saved-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.save-panel {
  display: grid;
  gap: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.saved-panel {
  padding-top: 14px;
}

.online-session {
  position: fixed;
  right: 14px;
  bottom: 14px;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: 280px;
  padding: 12px 14px;
}

.online-session.connected {
  background: rgb(150, 255, 150);
  border-color: #46b85a;
}

.online-session .section-title,
.online-session .session-field,
.online-session .hint {
  grid-column: 1 / -1;
}

.session-field {
  gap: 4px;
}

.saved-item {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.saved-item strong {
  font-size: 14px;
}

.saved-item time {
  color: var(--muted);
  font-size: 12px;
}

.saved-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.confirm-popover {
  position: fixed;
  z-index: 50;
  width: min(260px, calc(100vw - 24px));
  padding: 12px;
  border: 1px solid #fecdca;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 16px 36px rgba(16, 24, 40, 0.18);
}

.confirm-message {
  color: #172033;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.35;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.confirm-delete {
  border-color: #d92d20;
  color: #fff;
  background: #d92d20;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: minmax(220px, 260px) minmax(190px, 230px) minmax(360px, 1fr);
  }

  .saves {
    grid-column: 1 / -1;
  }
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .toolbar,
  .tools-panel,
  .saves {
    align-self: stretch;
  }

  .court-frame {
    min-height: 70vh;
  }

  .online-session {
    position: static;
    grid-template-columns: 1fr;
    margin-top: 0;
  }

  #boardSvg {
    width: min(100%, calc(70vh * 0.769));
    max-height: 70vh;
  }
}
