/* --------------------------------------------------
   DESIGN TOKENS & RESET
-------------------------------------------------- */
:root {
  --color-bg: #0f172a;
  --color-field-light: #4ade80;
  --color-field-dark: #22c55e;
  --color-line: rgba(255, 255, 255, 0.8);
  --color-text: #f8fafc;
  --color-danger: #ef4444;
  --color-danger-hover: #dc2626;
  --color-primary: #3b82f6;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  --font-main: 'Inter', sans-serif;
}

* {
  box-sizing: border-box;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  background: var(--color-bg);
  font-family: var(--font-main);
  color: var(--color-text);
  overflow: hidden;
  touch-action: none;
  overscroll-behavior: none;
}

/* --------------------------------------------------
   LAYOUT
-------------------------------------------------- */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.app-header {
  width: 100%;
  max-width: 1200px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 1rem 1rem;
  z-index: 10;
}

.app-header h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.025em;
  background: linear-gradient(to right, #fff, #cbd5e1);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.field-container {
  flex: 1;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  perspective: 1000px;
}

.app-footer {
  padding: 1rem;
  font-size: 0.875rem;
  color: #94a3b8;
  text-align: center;
}

/* --------------------------------------------------
   BUTTONS
-------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
  border: none;
  outline: none;
}

.btn-danger {
  background: rgba(239, 68, 68, 0.1);
  color: var(--color-danger);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-danger:hover {
  background: var(--color-danger);
  color: white;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-danger:active {
  transform: translateY(0);
}

/* --------------------------------------------------
   FOOTBALL FIELD
-------------------------------------------------- */
.field {
  width: 90%;
  max-width: 1000px;
  aspect-ratio: 1.5 / 1;
  background: var(--color-field-dark);
  border: 4px solid var(--color-line);
  position: relative;
  border-radius: 8px;
  box-shadow:
    0 0 0 4px rgba(255, 255, 255, 0.1),
    0 20px 25px -5px rgba(0, 0, 0, 0.5),
    0 8px 10px -6px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  transition: transform 0.3s ease;
  touch-action: none;
}

/* Grass Pattern */
.grass-pattern {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(90deg, transparent 50%, rgba(0, 0, 0, 0.05) 50%);
  background-size: 10% 100%;
  pointer-events: none;
}

.field-lines {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Center line */
.center-line {
  width: 2px;
  height: 100%;
  background: var(--color-line);
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
}

/* Center circle */
.center-circle {
  width: 20%;
  aspect-ratio: 1;
  border: 2px solid var(--color-line);
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.center-circle::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
  background: var(--color-line);
  border-radius: 50%;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

/* Penalty boxes */
.left-box,
.right-box {
  width: 16%;
  height: 40%;
  /* Standard penalty box is roughly 40.3m wide on a 68m pitch ~ 60% */
  /* Wait, standard pitch is horizontal usually in diagrams but vertical here? 
       The original code had vertical orientation (width 80%, height 85vh).
       Let's stick to the original vertical orientation or switch to horizontal?
       The original had .left-box { top: 0 } and .right-box { bottom: 0 }, implying vertical.
       BUT aspect ratio 1.5/1 usually implies horizontal.
       Let's make it horizontal for a better desktop view, but responsive.
       Actually, let's stick to the user's likely mental model but improve it.
       If I change orientation, I need to change logic.
       Let's assume Horizontal for "Strategy Board" as it fits screens better.
    */
  border: 2px solid var(--color-line);
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
}

.left-box {
  left: 0;
  border-left: none;
}

.right-box {
  right: 0;
  border-right: none;
}

/* Goal Areas (6 yard box) */
.left-goal,
.right-goal {
  width: 6%;
  height: 18%;
  border: 2px solid var(--color-line);
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
}

.left-goal {
  left: 0;
  border-left: none;
}

.right-goal {
  right: 0;
  border-right: none;
}

/* Corner Arcs */
.corner-arc {
  width: 2%;
  aspect-ratio: 1;
  border: 2px solid var(--color-line);
  position: absolute;
  border-radius: 50%;
}

.top-left {
  top: -1%;
  left: -1%;
}

.top-right {
  top: -1%;
  right: -1%;
}

.bottom-left {
  bottom: -1%;
  left: -1%;
}

.bottom-right {
  bottom: -1%;
  right: -1%;
}


/* --------------------------------------------------
   PLAYERS
-------------------------------------------------- */
.player {
  width: 70px;
  height: 110px;
  /* background-color: white; */
  background-image: url('player.png');
  background-size: cover;
  background-position: center;
  position: absolute;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  /* border: 3px solid white; */
  /* box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3); */
  cursor: grab;
  transition: transform 0.1s, box-shadow 0.1s;
  z-index: 20;
  touch-action: none;
}

.player:active {
  cursor: grabbing;
  transform: translate(-50%, -50%) scale(1.1);
  box-shadow: 0 8px 12px rgba(0, 0, 0, 0.4);
  z-index: 30;
}

/* Player Name Label */
.player-name {
  position: absolute;
  top: 100%;
  /* Below the player */
  left: 50%;
  transform: translateX(-50%);
  margin-top: 4px;
  color: var(--color-text);
  font-size: 12px;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(2px);
}

/* --------------------------------------------------
   DELETE BUTTON (Context Menu)
-------------------------------------------------- */
.delete-btn {
  position: absolute;
  width: 28px;
  height: 28px;
  background: var(--color-danger);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: bold;
  cursor: pointer;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  z-index: 100;
  animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.delete-btn:hover {
  background: var(--color-danger-hover);
  transform: scale(1.1);
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0);
  }

  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* --------------------------------------------------
   ANIMATIONS
-------------------------------------------------- */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.8);
  }

  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

.player.animate-enter {
  animation: fadeIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* --------------------------------------------------
   BENCH (Substitutes)
-------------------------------------------------- */
.field-container {
  display: flex;
  /* Desktop Default: Column (Bench Top, Field Bottom) */
  flex-direction: column;
  gap: 2rem;
  padding: 1rem;
  align-items: center;
  width: 100%;
  flex: 1;
  /* Take remaining space */
  min-height: 0;
  /* Allow shrinking */
  overflow: hidden;
  /* Prevent full page scroll, handle inside if needed */
}

.bench {
  /* Desktop: Full width bar at top */
  width: 100%;
  max-width: 1000px;
  min-height: 80px;
  /* Reduced from 120px */
  background: rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  padding: 0.5rem 1rem;
  display: flex;
  flex-direction: row;
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  overflow-x: auto;
}

.bench h2 {
  font-size: 0.875rem;
  color: #94a3b8;
  margin: 0 1rem 0 0;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.bench-container {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 1rem;
  flex: 1;
  min-height: 100px;
  padding-bottom: 1.5rem;
  /* Space for names */
}

/* Bench Player Styling */
.bench .player {
  position: relative;
  transform: none;
  left: auto;
  top: auto;
  margin-bottom: 0;
  margin-right: 1rem;
  flex-shrink: 0;
  /* Ensure overflow is visible so name shows */
  overflow: visible;
  /* Smaller size for bench */
  width: 50px;
  height: 80px;
}

/* Removed .bench .player-name overrides as default absolute positioning works now */


/* --------------------------------------------------
   CONTEXT MENU (Edit/Delete)
-------------------------------------------------- */
.context-menu {
  position: absolute;
  display: flex;
  gap: 0.5rem;
  z-index: 100;
  animation: popIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  pointer-events: auto;
}

.ctx-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
  border: 2px solid white;
  transition: transform 0.1s;
}

.ctx-btn:hover {
  transform: scale(1.1);
}

.btn-edit {
  background: var(--color-primary);
  color: white;
}

.btn-delete {
  background: var(--color-danger);
  color: white;
}

/* --------------------------------------------------
   RESPONSIVE: TABLET & MOBILE (Side Bench, Vertical Field)
   Trigger at 1024px (Tablet Landscape/Portrait boundary)
-------------------------------------------------- */
@media (max-width: 1024px) {
  .field-container {
    /* Side by Side */
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
  }

  .field {
    width: 100%;
    max-width: 600px;
    /* Vertical Aspect Ratio */
    aspect-ratio: 2 / 3;
    margin: 0;
  }

  .bench {
    /* Sidebar */
    width: 100px;
    /* Slightly narrower */
    height: auto;
    min-height: 400px;
    /* Reduced from 600px */
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .bench h2 {
    writing-mode: vertical-rl;
    margin: 0 0 1rem 0;
    transform: rotate(180deg);
    text-align: center;
  }

  .bench-container {
    flex-direction: column;
    width: 100%;
    height: auto;
    padding-bottom: 0;
  }

  .bench .player {
    margin-right: 0;
    margin-bottom: 2rem;
  }

  /* Field Rotation Logic (Vertical) */

  /* Center Line becomes Horizontal */
  .center-line {
    width: 100%;
    height: 2px;
    top: 50%;
    left: 0;
    transform: translateY(-50%);
  }

  /* Penalty Boxes: Top and Bottom */
  .left-box,
  .right-box {
    width: 60%;
    height: 16%;
    left: 50%;
    transform: translateX(-50%);
  }

  .left-box {
    top: 0;
    border-left: 2px solid var(--color-line);
    border-bottom: 2px solid var(--color-line);
    border-right: 2px solid var(--color-line);
    border-top: none;
  }

  .right-box {
    bottom: 0;
    top: auto;
    border-left: 2px solid var(--color-line);
    border-top: 2px solid var(--color-line);
    border-right: 2px solid var(--color-line);
    border-bottom: none;
  }

  /* Goals: Top and Bottom */
  .left-goal,
  .right-goal {
    width: 30%;
    height: 5%;
    left: 50%;
    transform: translateX(-50%);
  }

  .left-goal {
    top: -5%;
    border-bottom: 2px solid var(--color-line);
    border-left: 2px solid var(--color-line);
    border-right: 2px solid var(--color-line);
    border-top: 2px solid var(--color-line);
  }

  .right-goal {
    bottom: -5%;
    top: auto;
    border-top: 2px solid var(--color-line);
    border-left: 2px solid var(--color-line);
    border-right: 2px solid var(--color-line);
    border-bottom: 2px solid var(--color-line);
  }

  /* Adjust Corner Arcs */
  .top-left {
    top: -0.5%;
    left: -0.5%;
  }

  .top-right {
    top: -0.5%;
    right: -0.5%;
  }

  .bottom-left {
    bottom: -0.5%;
    left: -0.5%;
  }

  .bottom-right {
    bottom: -0.5%;
    right: -0.5%;
  }

  /* Scale players down slightly */
  .player {
    width: 40px;
    height: 60px;
  }

  .player-name {
    font-size: 10px;
    transform: translate(-50%, 0px);
  }
}

/* Mobile Specific Tweaks (Small Screens) */
@media (max-width: 480px) {
  .field-container {
    flex-direction: column-reverse;
    /* Field Top, Bench Bottom */
    gap: 1rem;
  }

  .bench {
    width: 100%;
    min-height: 100px;
    flex-direction: row;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .bench h2 {
    writing-mode: horizontal-tb;
    transform: none;
    margin-right: 1rem;
  }

  .bench-container {
    flex-direction: row;
  }

  .bench .player {
    margin-bottom: 0;
    margin-right: 1rem;
  }
}