:root {
  --bg: #0b1a2b;
  --card: #102a43;
  --text: #f5f8fc;
  --muted: #9fb3c8;
  --primary: #2f80ed;
  --primary-text: #ffffff;
  --danger: #e57373;
  --ok: #4caf50;
  --accent: #f2c94c; /* the background refresh moved this chip */
  --border: #1e3a57;
  --wit-bg: #eef3f9;
  --wit-text: #0b1a2b;
  --zwart-bg: #0a1420;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  line-height: 1.4;
}

#page {
  max-width: 560px;
  margin: 0 auto;
  padding: 1.2rem 1rem 3rem;
}

.state-loading #app,
.state-loading #auth-gate {
  visibility: hidden;
}

h1 {
  font-size: 1.6rem;
  margin-bottom: 1rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  padding: 1rem;
  margin-bottom: 1rem;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

select,
input[type="text"] {
  width: 100%;
  font-size: 1.05rem;
  padding: 0.7rem 0.8rem;
  border-radius: 0.6rem;
  border: 1px solid var(--border);
  background: #0b2036;
  color: var(--text);
}

.btn {
  display: inline-block;
  font-size: 1.1rem;
  font-weight: 700;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  background: #0b2036;
  color: var(--text);
  cursor: pointer;
  text-align: center;
  text-decoration: none;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}

/* --- lineup set tabs ---------------------------------------------------------- */

#set-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.8rem;
}

.set-tab {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0.55rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 0.6rem;
  background: #0b2036;
  color: var(--muted);
  cursor: pointer;
}

.set-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-text);
}

/* --- the 2x2 board ----------------------------------------------------------- */

#board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
}

.quad {
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  padding: 0.6rem;
  min-height: 8rem;
}

.quad-wit {
  background: var(--wit-bg);
  color: var(--wit-text);
  border-color: #c6d4e4;
}

.quad-zwart {
  background: var(--zwart-bg);
  color: var(--text);
}

.quad-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.5rem;
}

.quad-title {
  opacity: 0.85;
  min-width: 0;
}

/* Compact per-team formation picker in the panel header. */
.formation-select {
  flex-shrink: 0;
  width: auto;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.25rem 0.4rem;
  border-radius: 0.4rem;
  border: 1px solid var(--border);
  background: #0b2036;
  color: var(--text);
}

.count {
  display: inline-block;
  min-width: 1.5em;
  text-align: center;
  border-radius: 999px;
  padding: 0 0.35em;
  background: rgba(127, 148, 170, 0.25);
  font-variant-numeric: tabular-nums;
}

/* Highlight every valid drop target while a player is selected. */
.quad.target,
#tray.target {
  outline: 2px dashed var(--primary);
  outline-offset: 2px;
  cursor: pointer;
}

.names {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

/* --- formation slots inside a panel ------------------------------------------ */

.slot-row {
  flex-basis: 100%;
  display: flex;
  gap: 0.35rem;
}

.pos-slot {
  flex: 1;
  min-width: 0;
  min-height: 3rem;
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  gap: 0.3rem;
  padding: 0.25rem;
  border: 1px dashed rgba(127, 148, 170, 0.5);
  border-radius: 0.5rem;
}

.pos-slot.target {
  border-color: var(--primary);
  border-style: dashed;
  cursor: pointer;
}

.slot-empty {
  opacity: 0.4;
  font-weight: 700;
  align-self: center;
}

/* Team members without a position, under the formation. */
.no-pos {
  flex-basis: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.15rem;
  padding-top: 0.4rem;
  border-top: 1px dashed rgba(127, 148, 170, 0.4);
}

.pos-slot .chip {
  font-size: 0.85rem;
  min-height: 2rem;
  padding: 0.25rem 0.55rem;
}

/* --- player chips ------------------------------------------------------------ */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  max-width: 100%;
  min-height: 2.4rem;
  padding: 0.35rem 0.7rem;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: 999px;
  cursor: pointer;
  border: 1px solid transparent;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none; /* no iOS long-press menu — long-press lifts the chip */
}

/* The floating copy that follows the finger while reordering. */
.chip.drag-clone {
  position: fixed;
  z-index: 50;
  margin: 0;
  pointer-events: none;
  opacity: 0.95;
  transform: scale(1.08);
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-text);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

/* The chip's own spot while it is being dragged. */
.chip.drag-placeholder {
  opacity: 0.35;
}

.quad-wit .chip {
  background: rgba(11, 26, 43, 0.08);
  border-color: rgba(11, 26, 43, 0.18);
  color: var(--wit-text);
}

.quad-zwart .chip,
#tray .chip {
  background: rgba(245, 248, 252, 0.08);
  border-color: rgba(245, 248, 252, 0.2);
  color: var(--text);
}

.chip.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-text);
  box-shadow: 0 0 0 3px rgba(47, 128, 237, 0.35);
}

.chip-note {
  font-size: 0.75rem;
  font-weight: 400;
  opacity: 0.7;
}

/* A chip the background refresh just moved (or that a new signup just added).
   Glows briefly so a name shifting on its own is noticed rather than mistaken
   for a mis-tap. */
.chip.changed {
  animation: chip-changed 2.5s ease-out;
}

@keyframes chip-changed {
  0%,
  60% {
    box-shadow: 0 0 0 3px var(--accent);
  }
  100% {
    box-shadow: 0 0 0 3px rgba(242, 201, 76, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chip.changed {
    animation: none;
    box-shadow: 0 0 0 3px var(--accent);
  }
}

/* A sub: shown in each of its slots, dashed with a ⇄ marker so it reads as one
   roaming player. The marker isn't part of the name text (unlike the wall
   board), so it never affects the stored name. */
.chip.is-sub {
  border-style: dashed;
  font-style: italic;
}
.chip.is-sub::before {
  content: "⇄";
  font-style: normal;
  font-weight: 700;
  opacity: 0.8;
}

/* --- unassigned tray ---------------------------------------------------------- */

#tray {
  border: 1px dashed var(--border);
  border-radius: 0.8rem;
  padding: 0.6rem;
  min-height: 4.5rem;
  margin-bottom: 1rem;
  background: rgba(16, 42, 67, 0.5);
}

/* --- add player --------------------------------------------------------------- */

.add-row {
  display: flex;
  gap: 0.6rem;
}

.add-row input {
  flex: 1;
  min-width: 0;
}

.add-row .btn {
  flex-shrink: 0;
}

/* --- misc ---------------------------------------------------------------------- */

.muted {
  color: var(--muted);
  font-size: 0.9rem;
}

.footnote {
  margin-top: 1.5rem;
  text-align: center;
}

.footnote a {
  color: var(--muted);
  margin-left: 0.5rem;
}

#last-sync {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.8rem;
  opacity: 0.75;
}

#auth-gate {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 0.8rem;
  padding: 1.5rem;
  text-align: center;
}

#auth-gate p {
  margin-bottom: 1rem;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: 1.2rem;
  transform: translateX(-50%);
  max-width: 90%;
  padding: 0.8rem 1.2rem;
  border-radius: 0.6rem;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}

#toast.ok {
  background: var(--ok);
  color: #06210a;
}

#toast.error {
  background: var(--danger);
  color: #2b0a0a;
}

#toast[hidden] {
  display: none;
}
