/* General Styling */
* {
  box-sizing: border-box;
}

html, body {
  touch-action: manipulation; 
  overscroll-behavior: none; 
}

body {
  margin: 0;
  font-family: 'Roboto', sans-serif;
  background-color: #f8f9fa;
  
  /* NUCLEAR FIX FOR MOBILE SCROLLING */
  position: fixed; /* Locks the body in place relative to screen */
  width: 100%;
  height: 100%; /* Fallback */
  height: 100svh; /* Modern mobile height */
  inset: 0;
  
  display: flex;
  flex-direction: column;
  overflow: hidden; 
}

h1 {
  display: none;
}

/* Controls */
.controls {
  display: flex;
  justify-content: center;
  gap: 5px;
  padding: 5px;
  flex-wrap: wrap;
  background-color: #eee;
  flex-shrink: 0; 
  z-index: 10;
}

button {
  padding: 6px 10px;
  cursor: pointer;
  border: 1px solid #ccc;
  background-color: white;
  border-radius: 4px;
  font-weight: bold;
  font-size: 0.8rem;
  touch-action: manipulation; 
}

button:hover {
  background-color: #e2e2e2;
}

.btn-danger {
  background-color: #ffcccc;
  border-color: #ff0000;
  color: #cc0000;
}

/* Headline */
.headline {
  font-size: 1.5rem;
  font-weight: bold;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  text-align: center;
  padding: 5px 0;
  border-bottom: 1px dashed transparent;
  flex-shrink: 0; 
}

.headline:focus {
  border-bottom: 1px dashed #ccc;
  outline: none;
}

/* Wrapper */
.wrapper {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  min-height: 0; 
  padding-bottom: 5px;
  width: 100%; /* Ensure wrapper doesn't overflow width */
}

/* Pitch Container */
.pitch-container {
  flex-grow: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  min-height: 0; 
  padding: 5px;
  touch-action: none;
  
  /* CRITICAL FIX: Hide the invisible hit-boxes if they go off-screen */
  overflow: hidden; 
}

.pitch {
  position: relative;
  background-color: white;
  border: 3px solid #ff0000;
  border-radius: 10px;
  overflow: hidden; 
  aspect-ratio: 6 / 10; 
  height: 100%; 
  width: auto;  
  max-width: 100%; 
  max-height: 100%; 
}

/* Field Markings */
.center-line {
  position: absolute;
  width: 100%;
  height: 3px;
  background-color: #ff0000;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none; 
}

.center-circle {
  position: absolute;
  width: 15%;
  aspect-ratio: 1;
  border: 2px solid #ff0000;
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.goal-area {
  position: absolute;
  width: 50%;
  height: 15%; 
  border: 2px solid #ff0000;
  left: 50%;
  pointer-events: none;
}

.goal-area.top {
  top: 0;
  border-radius: 0 0 50% 50%;
  border-top: 0;
  transform: translate(-50%, -50%);
}

.goal-area.bottom {
  bottom: 0;
  border-radius: 50% 50% 0 0;
  border-bottom: 0;
  transform: translate(-50%, 50%);
}

.goal-circle {
  position: absolute;
  width: 20%;
  aspect-ratio: 1;
  border: 2px solid #ff0000;
  border-radius: 50%;
  pointer-events: none;
}

.goal-area.top .goal-circle.left {
  left: 25%;
  top: 93%;
  transform: translate(-50%, -50%);
}

.goal-area.top .goal-circle.right {
  right: 25%;
  top: 93%;
  transform: translate(50%, -50%);
}

.goal-area.bottom .goal-circle.left {
  left: 25%;
  top: 7%;
  transform: translate(-50%, -50%);
}

.goal-area.bottom .goal-circle.right {
  right: 25%;
  top: 7%;
  transform: translate(50%, -50%);
}

/* Player Circle */
.player {
  position: absolute;
  width: 14%;
  aspect-ratio: 1;
  border-radius: 50%;
  background-color: red;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  font-size: 0.9rem;
  color: white;
  font-weight: bold;
  transform: translate(-50%, -50%);
  z-index: 5;
  
  transition: top 0.5s ease, left 0.5s ease;
  touch-action: none; 
  cursor: grab;
  user-select: none; 
  -webkit-user-select: none; 
  -webkit-touch-callout: none; 
}

/* Hit Area */
.player::after {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  border-radius: 50%;
  background: transparent;
  z-index: -1;
}

.player:active {
  cursor: grabbing;
  z-index: 100; 
  transform: translate(-50%, -50%) scale(1.1); 
}

/* Text Fields */
.player-name, .player-position {
  cursor: text;
  pointer-events: auto;
}

.player-name {
  font-size: 0.7rem;
  color: black;
  text-align: center;
  white-space: nowrap;
  position: absolute;
  bottom: -18px; 
  background-color: rgba(255,255,255,0.8);
  padding: 0 2px;
  border-radius: 3px;
}

/* Visual cue when editing */
[contenteditable="true"] {
  background-color: white;
  color: black;
  z-index: 1000;
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
}

/* Bench Section */
.bench-container {
  width: 100%;
  text-align: center;
  height: 15vh; 
  min-height: 80px;
  flex-shrink: 0;
  overflow-y: auto;
  border-top: 1px solid #ddd;
  padding-top: 5px;
  background-color: #f0f0f0;
}

.bench-container h2 {
  font-size: 1rem;
  font-weight: bold;
  margin: 0 0 5px 0;
}

.bench {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  padding-bottom: 20px;
}

.bench-player {
  position: relative;
  width: 35px; 
  height: 35px;
  border-radius: 50%;
  background-color: red;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 0.8rem;
  color: white;
  font-weight: bold;
  flex-shrink: 0;
}

.bench-player-name {
  position: absolute;
  bottom: -15px;
  color: black;
  white-space: nowrap;
  font-size: 0.6rem;
  width: 150%;
  text-align: center;
}

.bench-player .remove-button {
  position: absolute;
  top: -8px;
  right: -8px;
  background-color: white;
  color: red;
  border: 1px solid #ccc;
  padding: 0;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.8rem;
  width: 16px;
  height: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-weight: bold;
}
