:root {
  --bg: #12301d;
  --panel: #1b4029;
  --text: #f2f7f3;
  --muted: #b8cdbf;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, sans-serif;
}

main {
  max-width: 980px;
  margin: 0 auto;
  padding: 16px;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 10px;
  outline: none;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
}

.hint {
  color: var(--muted);
  font-size: 14px;
  margin: 8px 0;
}

h2 { margin: 28px 0 0; }
h3 { margin: 12px 0 6px; font-size: 16px; }

#lab {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 16px;
  margin-top: 12px;
}

.team-card {
  background: var(--panel);
  border-top: 6px solid var(--team-color);
  border-radius: 10px;
  padding: 12px 14px;
}

.team-header {
  display: flex;
  gap: 8px;
}

input[type="text"], select {
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
}

.team-name {
  flex: 1;
  font-weight: bold;
  font-size: 18px;
  min-width: 0;
}

.slider {
  display: grid;
  grid-template-columns: 110px 1fr 24px;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  margin: 2px 0;
}

.slider small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
  margin: -2px 0 6px;
}

.slider input { width: 100%; accent-color: var(--team-color); }
.slider b { text-align: right; }

.player {
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding: 8px 0;
}

.player.is-you {
  background: rgba(255, 225, 77, 0.1);
  border-radius: 8px;
  padding: 8px;
}

.player-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
}

.player-top input { flex: 1; min-width: 0; }

.number {
  background: var(--team-color);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  font-weight: bold;
  font-size: 13px;
  flex: none;
}

.position {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.reset {
  grid-column: 1 / -1;
  justify-self: start;
  background: transparent;
  color: var(--muted);
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 6px;
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
}

/* ===== TOUCH CONTROLS (phones and tablets only) ===== */
/* touch.js adds the "touch" class to the page when it's on a touch screen. */

#stage { position: relative; }

body.touch #field {
  touch-action: none;
}

body.touch .touch-controls,
body.touch .touch-controls * {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

body.touch main > .hint:first-of-type { display: none; } /* "click the field" is for keyboards */

/* Standing the phone up: the controls sit under the field. */
.touch-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 6px 6px;
}

.joystick {
  position: relative;
  width: 112px;
  height: 112px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  border: 2px solid rgba(255, 255, 255, 0.35);
  flex: none;
}

.knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 50px;
  height: 50px;
  margin: -25px 0 0 -25px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.75);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

.action-buttons {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.touch-btn {
  display: grid;
  place-items: center;
  align-content: center;
  width: 62px;
  height: 62px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.45);
  background: rgba(0, 0, 0, 0.35);
  color: white;
  font: 22px/1 system-ui, sans-serif;
}

.touch-btn small {
  font-size: 10px;
  margin-top: 2px;
  font-weight: 600;
}

.touch-btn.shoot {
  width: 78px;
  height: 78px;
  font-size: 28px;
  background: rgba(46, 160, 67, 0.6);
}

.touch-btn.pass { background: rgba(40, 110, 200, 0.55); margin-bottom: 30px; }
.touch-btn.sprint { background: rgba(230, 150, 20, 0.55); }

.touch-btn.down {
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.45);
}

.corner-buttons {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 6px;
}

.touch-btn.small {
  width: 36px;
  height: 36px;
  font-size: 16px;
}

/* Only show what makes sense right now. */
body:not([data-state="paused"]) .touch-btn.quit { display: none; }
body[data-state="menu"] .touch-btn.pause,
body[data-state="over"] .touch-btn.pause { display: none; }
body[data-state="menu"] .joystick,
body[data-state="menu"] .action-buttons,
body[data-state="over"] .joystick,
body[data-state="over"] .action-buttons { visibility: hidden; }

/* Turning the phone sideways: the field fills the screen and the controls
   float on top, joystick on the left and buttons on the right. */
@media (orientation: landscape) {
  body.touch main {
    max-width: none;
    padding: 0;
  }

  body.touch #stage {
    height: 100vh;
    height: 100svh;
    display: flex;
    justify-content: center;
    align-items: center;
  }

  body.touch #field {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    border-radius: 0;
  }

  body.touch .touch-controls {
    position: absolute;
    inset: 0;
    padding: 0;
    pointer-events: none;
  }

  body.touch .joystick,
  body.touch .action-buttons,
  body.touch .corner-buttons { pointer-events: auto; }

  body.touch .joystick {
    position: absolute;
    left: max(16px, env(safe-area-inset-left));
    bottom: 20px;
  }

  body.touch .action-buttons {
    position: absolute;
    right: max(16px, env(safe-area-inset-right));
    bottom: 20px;
    flex-direction: column;
    align-items: center;
  }

  body.touch .touch-btn.pass { margin-bottom: 0; }

  body.touch .corner-buttons {
    right: max(16px, env(safe-area-inset-right));
    top: 10px;
  }

  body.touch main > h2,
  body.touch main > h2 ~ * { margin-left: 16px; margin-right: 16px; }
}
