:root {
  --bg-0: #07090c;
  --bg-1: #0d1218;
  --bg-2: #141b24;
  --bg-3: #1c2532;
  --line: #2a3445;
  --ink-0: #f5f7fa;
  --ink-1: #c9d2dd;
  --ink-2: #7d8a9c;
  --ink-3: #4d5666;
  --green-0: #0f3a24;
  --green-1: #1d5e3a;
  --green-2: #237049;
  --yellow: #facc15;
  --yellow-soft: #f7e07b;
  --red: #ef4444;
  --shadow-lg: 0 18px 40px -18px rgba(0,0,0,.6);
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-0);
  color: var(--ink-0);
  font-size: 14px;
  line-height: 1.4;
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse 1200px 600px at 50% -200px, rgba(29,94,58,.18), transparent 70%),
    radial-gradient(ellipse 800px 400px at 100% 100%, rgba(250,204,21,.06), transparent 70%);
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; border: 0; background: none; color: inherit; }
input, select { font-family: inherit; }
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }

.screen { display: none; }
.screen:not([hidden]) { display: block; }

/* ============== HERO / PICK SCREEN ============== */
.hero {
  text-align: center;
  padding: clamp(40px, 8vw, 90px) 24px 20px;
  max-width: 900px;
  margin: 0 auto;
}
.hero-eyebrow {
  font-size: 11px;
  letter-spacing: .25em;
  color: var(--yellow);
  font-weight: 700;
  margin-bottom: 16px;
}
.hero-title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: clamp(56px, 12vw, 120px);
  letter-spacing: .01em;
  line-height: .95;
  margin: 0 0 14px;
  font-weight: 400;
}
.accent { color: var(--yellow); }
.hero-sub {
  font-size: 16px;
  color: var(--ink-1);
  max-width: 560px;
  margin: 0 auto;
}

.picker {
  max-width: 640px;
  margin: 30px auto 0;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.picker-label {
  display: block;
  font-size: 11px;
  letter-spacing: .2em;
  color: var(--ink-2);
  margin-bottom: 8px;
  font-weight: 600;
}
.select-fat, .input-fat {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--ink-0);
  padding: 14px 16px;
  font-size: 16px;
  border-radius: var(--radius-md);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.select-fat:focus, .input-fat:focus {
  border-color: var(--yellow);
  box-shadow: 0 0 0 3px rgba(250,204,21,.15);
}
.select-fat {
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='%23c9d2dd' stroke-width='1.5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 12px;
  padding-right: 38px;
}
.club-search-wrap { position: relative; }
.club-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  list-style: none;
  margin: 0; padding: 4px;
  max-height: 320px;
  overflow-y: auto;
  z-index: 20;
  box-shadow: var(--shadow-lg);
  display: none;
}
.club-list.open { display: block; }
.club-list li {
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background .1s;
}
.club-list li:hover, .club-list li.active { background: var(--bg-3); }
.club-list .club-crest {
  width: 28px; height: 28px;
  object-fit: contain;
  flex: 0 0 28px;
}
.club-list .club-meta {
  font-size: 11px;
  color: var(--ink-2);
  margin-left: auto;
}

.hero-foot {
  text-align: center;
  margin-top: 36px;
  font-size: 11px;
  letter-spacing: .15em;
  color: var(--ink-3);
}
.hero-foot .dot {
  display: inline-block;
  width: 7px; height: 7px;
  background: var(--yellow);
  border-radius: 50%;
  margin-right: 8px;
  box-shadow: 0 0 8px var(--yellow);
  vertical-align: middle;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 0%,100% {opacity:1;} 50% {opacity:.45;} }

/* ============== TV SCOREBUG ============== */
.scorebug {
  display: grid;
  grid-template-columns: auto auto 1fr auto auto auto auto auto;
  align-items: center;
  gap: 18px;
  padding: 14px 22px;
  background: linear-gradient(180deg, var(--bg-1), var(--bg-2));
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 30;
  backdrop-filter: blur(8px);
}
.sb-back {
  width: 40px; height: 40px;
  border-radius: 8px;
  background: var(--bg-3);
  font-size: 20px;
  font-weight: 700;
  color: var(--ink-1);
  transition: background .12s, color .12s;
}
.sb-back:hover { background: var(--bg-2); color: var(--ink-0); }
.sb-crest {
  border-radius: 6px;
  background: var(--bg-3);
  padding: 4px;
  object-fit: contain;
}
.sb-id { min-width: 0; }
.sb-name {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 28px;
  letter-spacing: .03em;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sb-meta {
  font-size: 11px;
  color: var(--ink-2);
  letter-spacing: .15em;
  margin-top: 4px;
  text-transform: uppercase;
}
.sb-divider {
  width: 1px;
  align-self: stretch;
  background: var(--line);
  margin: 4px 0;
}
.sb-form, .sb-value {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 92px;
}
.sb-label {
  font-size: 10px;
  letter-spacing: .2em;
  color: var(--ink-2);
  font-weight: 600;
}
.sb-amount {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 30px;
  color: var(--yellow);
  letter-spacing: .04em;
  line-height: 1;
}
.select-bug {
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--ink-0);
  padding: 8px 30px 8px 12px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 6px;
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='%23facc15' stroke-width='1.5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 10px;
}
.sb-actions {
  display: flex;
  gap: 8px;
}

.btn {
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .12em;
  transition: transform .08s, background .12s, box-shadow .12s;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-ghost {
  background: var(--bg-3);
  color: var(--ink-1);
  border: 1px solid var(--line);
}
.btn-ghost:hover { background: var(--bg-2); color: var(--ink-0); }
.btn-yellow {
  background: var(--yellow);
  color: #1a1300;
  box-shadow: 0 4px 14px -4px rgba(250,204,21,.5);
}
.btn-yellow:hover { background: var(--yellow-soft); }
.btn-yellow:disabled { background: var(--ink-3); color: var(--ink-2); cursor: not-allowed; box-shadow: none; }

/* ============== WORKSPACE ============== */
.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 75px);
  max-width: 1700px;
  margin: 0 auto;
}
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 1fr; height: auto; padding: 12px; }
}

.pitch-panel {
  display: grid;
  grid-template-rows: 1fr auto;
  gap: 14px;
  min-height: 0;
}

/* ============== PITCH ============== */
.pitch {
  position: relative;
  background:
    repeating-linear-gradient(180deg,
      var(--green-1) 0 8%,
      var(--green-2) 8% 16%);
  border-radius: var(--radius-lg);
  border: 2px solid rgba(255,255,255,.08);
  box-shadow:
    inset 0 0 80px rgba(0,0,0,.3),
    var(--shadow-lg);
  overflow: hidden;
  min-height: 540px;
  aspect-ratio: 68 / 105;
  max-height: calc(100vh - 280px);
  margin: 0 auto;
  width: 100%;
  max-width: min(720px, calc((100vh - 280px) * 0.647));
}
.pitch::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse at 50% 50%, transparent 50%, rgba(0,0,0,.35) 100%);
  pointer-events: none;
}
.pitch-lines { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.pitch-slots { position: absolute; inset: 0; }

.slot {
  position: absolute;
  width: 18%;
  max-width: 110px;
  aspect-ratio: 1 / 1.25;
  transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.slot-circle {
  width: 64%;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 2px dashed rgba(255,255,255,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.18);
  font-family: 'Bebas Neue', sans-serif;
  font-size: 14px;
  letter-spacing: .1em;
  color: rgba(255,255,255,.7);
  position: relative;
  cursor: grab;
  transition: transform .12s, background .12s, border-color .12s;
}
.slot.empty .slot-circle:hover { background: rgba(0,0,0,.32); border-color: rgba(250,204,21,.7); color: var(--yellow); }
.slot.drag-over .slot-circle { background: rgba(250,204,21,.18); border-color: var(--yellow); border-style: solid; transform: scale(1.06); }
.slot.filled .slot-circle {
  border-style: solid;
  border-color: rgba(0,0,0,.4);
  background: var(--bg-2);
  background-size: cover;
  background-position: center top;
  cursor: grab;
  overflow: hidden;
}
.slot.filled .slot-circle::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, transparent 50%, rgba(0,0,0,.5) 100%);
  pointer-events: none;
}
.slot-init {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 22px;
  letter-spacing: .04em;
  color: rgba(255,255,255,.7);
}
.slot.filled .slot-circle.has-photo .slot-init { display: none; }
.slot-name {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 14px;
  letter-spacing: .04em;
  text-align: center;
  background: rgba(0,0,0,.78);
  padding: 2px 8px;
  border-radius: 3px;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
}
.slot-value {
  font-size: 10px;
  font-weight: 700;
  color: var(--yellow);
  letter-spacing: .04em;
  background: rgba(0,0,0,.78);
  padding: 1px 6px;
  border-radius: 3px;
  margin-top: -2px;
}
.slot-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2;
  border: 2px solid var(--green-1);
}
.slot.filled:hover .slot-remove { display: flex; }
.slot.filled .slot-circle:hover { transform: scale(1.04); }

/* ============== BOTTOM BAR (BENCH + COACH) ============== */
.bottom-bar {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 14px;
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
}
@media (max-width: 760px) {
  .bottom-bar { grid-template-columns: 1fr; }
}
.block-label {
  font-size: 10px;
  letter-spacing: .2em;
  color: var(--ink-2);
  font-weight: 700;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.block-count { color: var(--yellow); }
.coach-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}
.coach-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--bg-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 18px;
  color: var(--ink-2);
  flex: 0 0 40px;
}
.coach-input {
  flex: 1;
  background: transparent;
  border: 0;
  color: var(--ink-0);
  font-size: 14px;
  font-weight: 600;
  outline: none;
  padding: 4px 0;
  min-width: 0;
}
.coach-input::placeholder { color: var(--ink-3); }

.bench-list {
  list-style: none;
  margin: 0; padding: 0;
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
  min-height: 60px;
}
@media (max-width: 760px) { .bench-list { grid-template-columns: repeat(4, 1fr); } }
.bench-slot {
  background: var(--bg-2);
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 8px 6px;
  min-height: 60px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  text-align: center;
  cursor: grab;
  transition: border-color .12s, background .12s, transform .12s;
}
.bench-slot.empty { color: var(--ink-3); justify-content: center; font-size: 11px; letter-spacing: .15em; }
.bench-slot.drag-over { border-color: var(--yellow); border-style: solid; background: rgba(250,204,21,.08); }
.bench-slot.filled { border-style: solid; border-color: var(--bg-3); background: var(--bg-2); }
.bench-photo {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--bg-3);
  background-size: cover;
  background-position: center top;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Bebas Neue', sans-serif;
  font-size: 12px;
  color: var(--ink-1);
}
.bench-photo.has-photo .bench-init { display: none; }
.bench-name {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}
.bench-value {
  font-size: 10px;
  color: var(--yellow);
  font-weight: 700;
}
.bench-slot.filled:hover .slot-remove { display: flex; }
.bench-slot { position: relative; }

/* ============== SIDE PANEL ============== */
.side-panel {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.tab {
  flex: 1;
  padding: 14px 12px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .2em;
  color: var(--ink-2);
  position: relative;
  transition: color .12s;
}
.tab:hover { color: var(--ink-1); }
.tab.active { color: var(--yellow); }
.tab.active::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 16px; right: 16px;
  height: 2px;
  background: var(--yellow);
}
.tab-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  flex: 1;
}
.tab-pane[hidden] { display: none; }

.pool-toolbar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--bg-1);
}
.input-thin, .select-thin {
  flex: 1;
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--ink-0);
  padding: 8px 10px;
  font-size: 13px;
  border-radius: 6px;
  outline: none;
  min-width: 0;
}
.select-thin {
  flex: 0 0 110px;
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' fill='none' stroke='%23c9d2dd' stroke-width='1.5'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 10px;
  padding-right: 26px;
}
.input-thin:focus { border-color: var(--yellow); }
.search-hint {
  padding: 16px 14px;
  font-size: 12px;
  color: var(--ink-3);
  text-align: center;
}

.player-pool {
  list-style: none;
  margin: 0; padding: 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-height: 200px;
}
.player-card {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 10px;
  align-items: center;
  background: var(--bg-2);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: grab;
  transition: background .1s, border-color .1s, transform .08s;
}
.player-card:hover { background: var(--bg-3); border-color: var(--line); }
.player-card.in-pitch { opacity: .35; }
.player-card.in-pitch::before {
  content: '◉';
  position: absolute;
  margin-left: -4px;
  margin-top: -2px;
  color: var(--yellow);
}
.player-photo {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: var(--bg-3);
  background-size: cover;
  background-position: center top;
  flex: 0 0 36px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.photo-init {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 14px;
  color: var(--ink-1);
  letter-spacing: .03em;
}
.player-photo.has-photo .photo-init { display: none; }
.player-photo .pos-badge {
  position: absolute;
  bottom: -2px; left: 50%;
  transform: translateX(-50%);
  background: var(--bg-0);
  color: var(--yellow);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .05em;
  padding: 1px 4px;
  border-radius: 3px;
  border: 1px solid var(--line);
  white-space: nowrap;
}
.player-info { min-width: 0; }
.player-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.player-sub {
  font-size: 11px;
  color: var(--ink-2);
  margin-top: 2px;
}
.player-value {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 18px;
  color: var(--yellow);
  letter-spacing: .03em;
  text-align: right;
}

/* ============== TOAST ============== */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(120%);
  background: var(--bg-3);
  border: 1px solid var(--line);
  color: var(--ink-0);
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 100;
  opacity: 0;
  transition: transform .25s, opacity .25s;
  box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { border-color: var(--red); }

/* ============== MODAL ============== */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--bg-1);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 32px;
  max-width: 460px;
  width: 100%;
  position: relative;
  box-shadow: var(--shadow-lg);
}
.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  width: 32px; height: 32px;
  font-size: 22px;
  color: var(--ink-2);
  border-radius: 50%;
}
.modal-close:hover { color: var(--ink-0); background: var(--bg-3); }
.modal-eyebrow {
  font-size: 11px;
  letter-spacing: .25em;
  color: var(--yellow);
  font-weight: 700;
}
.modal-title {
  font-family: 'Bebas Neue', sans-serif;
  font-size: 36px;
  margin: 4px 0 20px;
  letter-spacing: .02em;
}
.share-url-wrap {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.share-url {
  flex: 1;
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--ink-0);
  padding: 12px;
  font-size: 13px;
  border-radius: 6px;
  font-family: ui-monospace, 'SF Mono', Consolas, monospace;
}
.share-foot {
  font-size: 11px;
  color: var(--ink-3);
  margin-top: 10px;
}

/* ============== READ-ONLY BANNER ============== */
.ro-banner {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-2);
  border: 1px solid var(--yellow);
  border-radius: 10px;
  padding: 12px 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  z-index: 60;
  box-shadow: var(--shadow-lg);
}
.ro-banner[hidden] { display: none; }
.ro-text { font-size: 13px; color: var(--ink-1); }

body.read-only .pool-toolbar,
body.read-only .side-panel .tabs,
body.read-only .sb-actions,
body.read-only #autofill-btn,
body.read-only #reset-btn,
body.read-only #share-btn,
body.read-only #formation,
body.read-only .coach-input { pointer-events: none; }
body.read-only .slot-remove { display: none !important; }
body.read-only .player-pool .player-card { cursor: default; opacity: .7; }

/* ============== DRAG GHOST ============== */
.sortable-ghost { opacity: .35; }
.sortable-chosen { cursor: grabbing; }
.sortable-drag {
  cursor: grabbing;
  transform: rotate(2deg);
  box-shadow: var(--shadow-lg) !important;
}

/* ============== SMALL SCREENS ============== */
@media (max-width: 760px) {
  .scorebug { grid-template-columns: auto auto 1fr auto; gap: 10px; padding: 10px 14px; flex-wrap: wrap; }
  .sb-divider, .sb-form, .sb-value { display: none; }
  .sb-name { font-size: 22px; }
  .sb-actions .btn { padding: 8px 10px; font-size: 11px; }
  .pitch { min-height: 480px; }
}
