:root {
  --bg: #0b1410;
  --bg-2: #12211a;
  --line: rgba(255, 255, 255, .12);
  --text: #e8f2ea;
  --muted: #93a89b;
  --team-a: #4ea8ff;
  --team-b: #ff6b5e;
  --accent: #57e08a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", Roboto, system-ui, sans-serif;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;

  /* No text selection or the iOS "Copy" bubble while playing. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* Inputs are the one place where selection must still work. */
input, textarea {
  -webkit-user-select: text;
  user-select: text;
}

.hidden { display: none !important; }

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

/* ---------- HUD ---------- */

#hud {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: linear-gradient(180deg, rgba(0, 0, 0, .45), transparent);
}

.hud-team {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 600;
}

.hud-team-b { justify-content: flex-end; }

.hud-names {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
  font-weight: 500;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex: none;
}

.dot-a { background: var(--team-a); }
.dot-b { background: var(--team-b); }

.hud-center { text-align: center; }

#score {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 2px;
  font-variant-numeric: tabular-nums;
}

#clock {
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- Stage ---------- */

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
}

#field {
  max-width: 100%;
  max-height: 100%;
  border-radius: 10px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
  touch-action: none;
}

#banner {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  padding: 14px 30px;
  border-radius: 14px;
  background: rgba(6, 14, 10, .82);
  border: 1px solid var(--line);
  font-size: clamp(22px, 5vw, 44px);
  font-weight: 800;
  letter-spacing: 2px;
  text-align: center;
  white-space: pre-line;
  line-height: 1.25;
  pointer-events: none;
}

/* Goal: big, coloured and impossible to miss. */
#banner.banner-goal {
  padding: 20px 44px;
  font-size: clamp(34px, 9vw, 86px);
  letter-spacing: 5px;
  border-width: 4px;
  animation: goal-pop .45s cubic-bezier(.2, 1.5, .4, 1) both, goal-beat .7s .45s ease-in-out infinite;
}

#banner.banner-a {
  border-color: var(--team-a);
  color: #dff0ff;
  box-shadow: 0 0 0 6px rgba(78, 168, 255, .18), 0 0 60px rgba(78, 168, 255, .55);
  text-shadow: 0 0 22px rgba(78, 168, 255, .9);
}

#banner.banner-b {
  border-color: var(--team-b);
  color: #ffe6e3;
  box-shadow: 0 0 0 6px rgba(255, 107, 94, .18), 0 0 60px rgba(255, 107, 94, .55);
  text-shadow: 0 0 22px rgba(255, 107, 94, .9);
}

#banner.banner-kickoff {
  font-size: clamp(18px, 4vw, 34px);
  opacity: .9;
}

#banner.banner-final {
  border-color: var(--accent);
  box-shadow: 0 0 40px rgba(87, 224, 138, .35);
}

@keyframes goal-pop {
  from { transform: translate(-50%, -50%) scale(.35); opacity: 0; }
  to   { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

@keyframes goal-beat {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50%      { transform: translate(-50%, -50%) scale(1.06); }
}

@media (prefers-reduced-motion: reduce) {
  #banner.banner-goal { animation: none; }
}

/* ---------- Bottom bar ---------- */

#bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 14px 10px;
  color: var(--muted);
  font-size: 12px;
}

.bar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill {
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
}

/* ---------- Buttons ---------- */

.btn {
  font: inherit;
  font-weight: 700;
  padding: 10px 20px;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  color: var(--text);
  background: rgba(255, 255, 255, .08);
}

.btn:hover { background: rgba(255, 255, 255, .14); }

.btn-primary {
  background: var(--accent);
  color: #06170d;
}

.btn-primary:hover { background: #6bf09b; }

.btn-ghost { border-color: var(--line); background: transparent; }

/* ---------- Lobby ---------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(5, 10, 8, .78);
  backdrop-filter: blur(4px);

  /* A short landscape phone cannot fit the panel: let it scroll. */
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-top: max(18px, env(safe-area-inset-top));
  padding-bottom: max(18px, env(safe-area-inset-bottom));
  padding-left: max(18px, env(safe-area-inset-left));
  padding-right: max(18px, env(safe-area-inset-right));
}

.panel {
  width: 100%;
  max-width: 380px;
  margin: auto;          /* centres while still allowing scroll when tall */
  padding: 22px;
  border-radius: 16px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .6);
}

/*
 * Landscape on a phone: roughly 350 px of height for a panel that wants 600.
 * Two columns and tighter spacing make it fit without scrolling on an iPhone.
 */
@media (max-height: 520px) and (orientation: landscape) {
  .overlay { align-items: flex-start; }

  .panel {
    max-width: 760px;
    padding: 12px 16px;
  }

  /* Three columns of controls, and the long explanations step aside: a
     landscape iPhone leaves roughly 350 px of height for all of this. */
  #lobby .panel {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    column-gap: 16px;
    align-items: start;
  }

  #lobby .panel h1,
  #lobby .panel .panel-actions,
  #lobby .panel .error { grid-column: 1 / -1; }

  #lobby .panel .lead,
  #lobby .panel .hint,
  #lobby .panel .controls-hint { display: none; }

  #roomPanel .panel .seats { columns: 2; column-gap: 12px; }

  .panel h1 { font-size: 18px; margin: 0 0 6px; }
  .panel .panel-title { font-size: 16px; margin-bottom: 4px; }
  .panel input { margin-bottom: 8px; padding: 7px 10px; }
  .panel .field-label { margin-bottom: 3px; font-size: 11px; }
  .segmented { margin-bottom: 8px; gap: 4px; }
  .seg { padding: 6px 2px; font-size: 11px; }
  .skins { margin-bottom: 8px; gap: 4px; }
  .seat { padding: 5px 8px; margin-bottom: 4px; }
  .stats-score { font-size: 20px; margin-bottom: 8px; }
  .btn { padding: 8px 14px; }
  .panel-actions { margin-top: 2px; }
}

.panel h1 {
  margin: 0 0 6px;
  font-size: 24px;
}

.lead {
  margin: 0 0 18px;
  color: var(--muted);
}

.field-label {
  display: block;
  margin: 0 0 5px;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.panel input {
  width: 100%;
  margin-bottom: 14px;
  padding: 11px 12px;
  font: inherit;
  color: var(--text);
  background: rgba(0, 0, 0, .3);
  border: 1px solid var(--line);
  border-radius: 10px;
}

.panel input:focus {
  outline: none;
  border-color: var(--accent);
}

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

/* Bot level picker */
.segmented {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}

.seg {
  flex: 1;
  padding: 9px 4px;
  font: 600 13px/1 "Segoe UI", Roboto, sans-serif;
  color: var(--muted);
  background: rgba(0, 0, 0, .3);
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
}

.seg:hover { color: var(--text); }

.seg-on {
  color: #06170d;
  background: var(--accent);
  border-color: var(--accent);
}

.panel-actions {
  display: flex;
  gap: 10px;
}

.panel-actions .btn { flex: 1; }

.controls-hint {
  margin: 18px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.error {
  margin: 12px 0 0;
  color: #ff9c92;
  font-size: 13px;
}

/* ---------- Seat list in the waiting room ---------- */

.panel-title {
  margin: 0 0 6px;
  font-size: 20px;
}

.seats {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
}

.seat {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  margin-bottom: 6px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(0, 0, 0, .22);
}

.seat-free { opacity: .55; }

.seat-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.seat-tag {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 1px;
}

.seat-you { border-color: var(--accent); }

/* ---------- Skin picker ---------- */

.skins {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  margin-bottom: 14px;
}

.skin {
  padding: 0;
  aspect-ratio: 1;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, .3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.skin canvas { width: 100%; height: 100%; display: block; }

.skin-on {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(87, 224, 138, .35);
  background: rgba(87, 224, 138, .12);
}

/* ---------- Quick chat ---------- */

/*
 * The shout bar is part of the page flow, not an overlay: floating it over the
 * canvas covered the corner of the pitch. Sitting in its own row means the
 * pitch is simply scaled to the space that is left.
 */
#shouts {
  flex: none;
  z-index: 13;
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 4px 10px 6px;
}

.shout {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .07);
  font-size: 19px;
  line-height: 1;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

/* On a phone the row is tighter and sits clear of the thumb pads. */
@media (max-height: 520px) and (orientation: landscape) {
  #shouts { padding: 2px 8px 4px; gap: 6px; }
  .shout { width: 34px; height: 34px; font-size: 16px; }
}

.shout:hover { background: rgba(255, 255, 255, .16); }
.shout:active { transform: scale(.92); }

/* ---------- Match summary ---------- */

.stats-score {
  margin: 0 0 14px;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 2px;
  font-variant-numeric: tabular-nums;
}

.stats-scroll {
  overflow-x: auto;
  margin-bottom: 16px;
}

table.stats {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

table.stats th {
  text-align: right;
  padding: 6px 8px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

table.stats th:first-child,
table.stats td:first-child { text-align: left; }

table.stats td {
  text-align: right;
  padding: 7px 8px;
  border-bottom: 1px solid rgba(255, 255, 255, .06);
  white-space: nowrap;
}

table.stats td:first-child {
  display: flex;
  align-items: center;
  gap: 7px;
}

tr.stats-me td { color: var(--accent); font-weight: 600; }

/* ---------- Touch controls ---------- */

#touch {
  position: fixed;
  inset: 23% 0 0 0;
  z-index: 10;
  display: flex;
  pointer-events: none;
  touch-action: none;
}

.touch-zone {
  flex: 1;
  position: relative;
  pointer-events: auto;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

/* Joystick: sits bottom-left, jumps to wherever the thumb lands. */
#stick {
  position: absolute;
  left: 26px;
  bottom: 26px;
  width: 132px;
  height: 132px;
  margin: -66px 0 0 -66px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .22);
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, .12), rgba(255, 255, 255, .04) 70%);
  box-shadow: 0 6px 22px rgba(0, 0, 0, .35);
  transition: opacity .15s;
  opacity: .55;
}

#stick.stick-live {
  opacity: 1;
  border-color: rgba(255, 255, 255, .4);
}

#stickKnob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 58px;
  height: 58px;
  margin: -29px 0 0 -29px;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 32%, #ffffff, #b9c6bd);
  box-shadow: 0 3px 10px rgba(0, 0, 0, .45);
}

#kickBtn {
  position: absolute;
  right: 26px;
  bottom: 26px;
  width: 108px;
  height: 108px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font: 700 15px/1 "Segoe UI", Roboto, sans-serif;
  letter-spacing: 1px;
  color: #06170d;
  background: radial-gradient(circle at 38% 32%, #7bf2a9, var(--accent));
  box-shadow: 0 6px 22px rgba(0, 0, 0, .4);
  transition: transform .08s, filter .08s;
}

#kickBtn.kick-live {
  transform: scale(.92);
  filter: brightness(.85);
}

#rotateTip {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  z-index: 12;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(6, 14, 10, .88);
  border: 1px solid var(--line);
  font-size: 13px;
  pointer-events: none;
}

/* Keep the bottom bar clickable above the touch zones. */
#bar {
  position: relative;
  z-index: 11;
}

@media (max-height: 520px) {
  #hud { padding: 4px 10px; }
  #score { font-size: 20px; }
  #bar { display: none; }
}
