/* バスケットボール作戦板 — MVP styles */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #1a2332;
  --panel: #243044;
  --panel-2: #2e3d54;
  --text: #f0f4fa;
  --muted: #9aabc4;
  --accent: #3d8bfd;
  --offense: #e85d4c;
  --offense-dark: #b83a2c;
  --defense: #3b82f6;
  --defense-dark: #1e5bb8;
  --ball: #f5a623;
  --court-wood: #ffffff;
  --court-line: #1a2332;
  --paint: #ffffff;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --top-h: 52px;
  --tool-h: 64px;
  --bench-w: 56px;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP",
    "Yu Gothic", Meiryo, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  max-width: 100vw;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* —— Top bar —— */
.top-bar {
  flex: 0 0 var(--top-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 10px;
  background: var(--panel);
  border-bottom: 1px solid #3a4d66;
  z-index: 2;
}

.title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.court-toggle {
  display: flex;
  align-items: stretch;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #3a4d66;
  min-height: 44px;
}

.toggle-btn {
  appearance: none;
  border: none;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
  padding: 0 12px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

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

.toggle-btn:not(.active):active {
  background: #3a4d66;
}

/* —— Stage: benches + court —— */
.stage {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: var(--bench-w) 1fr var(--bench-w);
  gap: 0;
  background: #15202e;
}

.bench {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 6px 4px;
  gap: 4px;
  background: var(--panel);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.bench-offense {
  border-right: 1px solid #3a4d66;
}

.bench-defense {
  border-left: 1px solid #3a4d66;
}

.bench-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 2px;
}

.bench-offense .bench-label { color: var(--offense); }
.bench-defense .bench-label { color: var(--defense); }

.bench-slots {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.bench-piece {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 800;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
  border: 2px solid rgba(255,255,255,0.35);
  flex-shrink: 0;
  transition: transform 0.1s, opacity 0.15s;
  touch-action: none;
}

.bench-piece.of { background: linear-gradient(145deg, var(--offense), var(--offense-dark)); }
.bench-piece.df { background: linear-gradient(145deg, var(--defense), var(--defense-dark)); }

.bench-piece:active { transform: scale(0.92); }
.bench-piece.on-court { opacity: 0.28; pointer-events: none; }

/* —— Court —— */
.court-wrap {
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  /* Court gets priority in portrait */
}

#court {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: block;
  touch-action: none;
  /* preserve aspect via viewBox; object-fit style via CSS */
}

#court .piece {
  cursor: grab;
  touch-action: none;
}

#court .piece.selected .piece-ring {
  stroke: #ffd166;
  stroke-width: 3.5;
  opacity: 1;
}

#court .piece.dragging {
  cursor: grabbing;
}

#court .loose-ball {
  cursor: grab;
}

#court .arrow-hit {
  cursor: pointer;
}

/* —— Toolbar —— */
.toolbar {
  flex: 0 0 var(--tool-h);
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 4px;
  padding: 6px 6px;
  background: var(--panel);
  border-top: 1px solid #3a4d66;
  z-index: 2;
}

.tools-left {
  display: flex;
  flex: 1 1 auto;
  gap: 4px;
  min-width: 0;
}

.tool-btn {
  appearance: none;
  border: 1px solid #3a4d66;
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 4px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  flex: 1 1 0;
  min-width: 0;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

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

.tool-btn:active:not(.active) {
  background: #3a4d66;
}

.tool-ball {
  flex: 0 0 auto;
  max-width: 88px;
  background: #3a3020;
  border-color: #8a6a30;
}

.tool-ball.active,
.tool-ball:active {
  background: #c47820;
  border-color: var(--ball);
}

.tool-icon {
  font-size: 16px;
  line-height: 1;
  font-weight: 700;
}

.ball-icon {
  color: var(--ball);
  font-size: 18px;
}

.tool-name {
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  line-height: 1.15;
}

/* —— Status —— */
.status {
  flex: 0 0 auto;
  min-height: 22px;
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  padding: 2px 8px 4px;
  background: var(--bg);
}

/* Landscape / wider: give benches a bit more room */
@media (min-width: 700px) {
  :root {
    --bench-w: 72px;
    --top-h: 56px;
    --tool-h: 68px;
  }
  .title { font-size: 17px; }
  .toggle-btn { font-size: 13px; padding: 0 16px; min-height: 44px; }
  .tool-name { font-size: 11px; }
  .bench-piece { width: 48px; height: 48px; font-size: 17px; }
}

/* Very short screens: shrink chrome, keep court big */
@media (max-height: 560px) {
  :root {
    --top-h: 52px;
    --tool-h: 52px;
  }
  .tool-name { font-size: 9px; }
  .title { font-size: 13px; }
  .status { display: none; }
}
