:root {
  --bg: #0b1220;
  --bg2: #121a2e;
  --panel: #182338;
  --card: #1c2a45;
  --line: #2a3b5c;
  --text: #eef3ff;
  --muted: #93a4c3;
  --accent: #e0b12a;
  --accent2: #3dd68c;
  --danger: #ff6b6b;
  --wish: #7eb6ff;
  --radius: 16px;
  --font: "Segoe UI", "Trebuchet MS", sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(900px 420px at 0% -10%, #1a3d2e 0%, transparent 55%),
    radial-gradient(700px 360px at 100% 0%, #3a2e10 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
}

.app {
  max-width: 980px;
  margin: 0 auto;
  padding: 14px 12px calc(28px + var(--safe-bottom));
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}
.brand {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: 0.01em;
}
.sub { margin: 4px 0 0; color: var(--muted); font-size: 0.82rem; line-height: 1.35; }
.top-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }

.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 999px;
  padding: 9px 12px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}
.btn.primary { background: var(--accent); color: #1a1400; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn:active { transform: scale(0.98); }

.credits, .gaps {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 10px;
  scrollbar-width: thin;
}
.credit-card, .gap-pill {
  flex: 0 0 auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  min-width: 104px;
}
.credit-card {
  display: block;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.credit-card:hover { border-color: var(--accent); }
.credit-card.owner { border-color: #8a7340; }
.credit-card.selected {
  border-color: var(--accent);
  background: #2a2410;
  box-shadow: 0 0 0 1px rgba(224, 177, 42, 0.35);
}
.credit-card .name { font-size: 0.8rem; color: var(--muted); }
.credit-card .val { font-size: 1.2rem; font-weight: 800; }
.gap-pill { min-width: 60px; text-align: center; }
.gap-pill strong { display: block; font-size: 1.15rem; }
.gap-pill span { color: var(--muted); font-size: 0.72rem; }

.search-panel {
  background: rgba(18, 26, 46, 0.92);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 12px;
  margin-bottom: 14px;
  overflow: hidden;
}
#searchInput {
  width: 100%;
  border: 1px solid var(--line);
  background: #0d1424;
  color: var(--text);
  border-radius: 14px;
  padding: 13px 14px;
  font-size: 1rem;
  outline: none;
}
#searchInput:focus {
  border-color: var(--accent2);
  box-shadow: 0 0 0 2px rgba(61, 214, 140, 0.18);
}

.filters {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  margin-top: 10px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.filters::-webkit-scrollbar { display: none; }
.filters.roles { flex-wrap: wrap; }
.filters.availability {
  margin-top: 8px;
}
.filters.availability .chip {
  flex: 1 1 0;
  text-align: center;
  min-width: 0;
}
.team-bar {
  margin-top: 8px;
  margin-left: -12px;
  margin-right: -12px;
  padding: 0 12px;
}
.filters.teams {
  margin-top: 0;
  max-height: none;
  overflow-x: auto;
  overflow-y: hidden;
  flex-wrap: nowrap;
  padding-bottom: 4px;
}

.chip {
  border: 1px solid var(--line);
  background: #141e33;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 12px;
  cursor: pointer;
  flex: 0 0 auto;
  white-space: nowrap;
  font-size: 0.86rem;
}
.chip.role-chip {
  width: 38px;
  height: 38px;
  padding: 0;
  display: grid;
  place-items: center;
  font-weight: 800;
}
.chip.active {
  background: var(--accent2);
  color: #062416;
  border-color: transparent;
  font-weight: 700;
}
.chip.team {
  padding: 7px 11px;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  font-weight: 700;
}

/* Desktop / wide: table-like rows */
.listone-head {
  display: none;
  margin-top: 12px;
  padding: 0 8px 8px;
  color: #a9b8d6;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  grid-template-columns: minmax(160px, 1.7fr) 48px 44px 44px 56px 88px;
  gap: 8px;
  align-items: center;
}
.listone-head .col-sq,
.listone-head .col-num,
.listone-head .col-fvm { text-align: center; }

.results {
  margin-top: 10px;
  display: grid;
  gap: 10px;
}

.player-row {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas:
    "main actions"
    "stats stats";
  gap: 10px;
  align-items: center;
}
.player-row.taken { opacity: 0.78; }
.player-main {
  grid-area: main;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.player-text { min-width: 0; }
.player-stats {
  grid-area: stats;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  background: rgba(0, 0, 0, 0.18);
  border-radius: 12px;
  padding: 8px 6px;
}
.col-actions {
  grid-area: actions;
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex: 0 0 auto;
}
.role {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 0.78rem;
  color: #fff;
  flex: 0 0 auto;
}
.role.P { background: #e0a800; color: #1a1400; }
.role.D { background: #2f9e44; }
.role.C { background: #2f6fed; }
.role.A { background: #e03131; }
.pname {
  font-weight: 750;
  font-size: 1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pmeta { color: var(--muted); font-size: 0.74rem; margin-top: 2px; }

.stat {
  text-align: center;
  min-width: 0;
}
.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 2px;
}
.stat-value {
  display: block;
  font-variant-numeric: tabular-nums;
  font-weight: 750;
  font-size: 0.95rem;
}

.icon-btn {
  border: 1px solid var(--line);
  background: #121c33;
  color: var(--text);
  border-radius: 12px;
  width: 42px;
  height: 42px;
  min-width: 42px;
  min-height: 42px;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 1.05rem;
  padding: 0;
}
.icon-btn.wish.on { border-color: var(--wish); color: var(--wish); }
.icon-btn.take {
  background: var(--accent);
  color: #1a1400;
  border: none;
  font-weight: 800;
  font-size: 1.25rem;
}

/* Desktop table layout */
@media (min-width: 760px) {
  .listone-head { display: grid; }
  .player-row {
    grid-template-columns: minmax(160px, 1.7fr) 48px 44px 44px 56px 88px;
    grid-template-areas: none;
    gap: 8px;
    align-items: center;
    padding: 10px 12px;
  }
  .player-main,
  .player-stats,
  .col-actions {
    grid-area: auto;
  }
  .player-stats {
    display: contents;
    background: none;
    padding: 0;
  }
  .stat { display: contents; }
  .stat-label { display: none; }
  .stat-value {
    display: block;
    text-align: center;
  }
  .filters.roles { flex-wrap: wrap; }
}

@media (max-width: 759px) {
  .app { padding-left: 10px; padding-right: 10px; }
  .brand { font-size: 1.35rem; }
  .top-actions .btn { padding: 8px 10px; font-size: 0.78rem; }
  .search-panel { padding: 10px; border-radius: 18px; }
}

.panels { display: grid; gap: 12px; }
@media (min-width: 840px) {
  .panels { grid-template-columns: repeat(3, 1fr); }
}
.panel {
  background: rgba(24, 35, 56, 0.85);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
}
.panel h2 { margin: 0 0 10px; font-size: 0.95rem; }
.list { display: grid; gap: 8px; max-height: 360px; overflow: auto; }
.list-item {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 10px;
  background: #121a2e;
  font-size: 0.9rem;
}
.list-item .muted, .muted { color: var(--muted); }
.tag-taken { color: var(--danger); font-weight: 700; }
.tag-free { color: var(--accent2); }

dialog {
  border: none;
  border-radius: 18px;
  padding: 0;
  background: transparent;
  width: min(92vw, 420px);
  color-scheme: dark;
}
dialog::backdrop { background: rgba(0,0,0,0.55); }
.dialog-card {
  background: #15281d;
  color: var(--text);
  border: 1px solid #2f5a40;
  border-radius: 18px;
  padding: 16px;
  display: grid;
  gap: 10px;
}
.dialog-card h3 { margin: 0; font-size: 1.35rem; }
.dialog-card label {
  display: grid;
  gap: 8px;
  font-size: 0.9rem;
  color: #9bb5a4;
  font-weight: 600;
}
.dialog-card input,
.dialog-card select,
.dialog-card textarea {
  width: 100%;
  border-radius: 12px;
  border: 1px solid #314872;
  background: #0f1a2e;
  color: #e8f2ea;
  padding: 12px 14px;
  font: inherit;
  font-weight: 700;
  outline: none;
}
.dialog-card select {
  appearance: none;
  -webkit-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, #e8f2ea 50%),
    linear-gradient(135deg, #e8f2ea 50%, transparent 50%),
    linear-gradient(to right, #1a2744, #1a2744);
  background-position:
    calc(100% - 18px) calc(50% - 3px),
    calc(100% - 12px) calc(50% - 3px),
    0 0;
  background-size: 6px 6px, 6px 6px, 100% 100%;
  background-repeat: no-repeat;
  padding-right: 40px;
  cursor: pointer;
}
.dialog-card select:focus,
.dialog-card input:focus,
.dialog-card textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(224, 177, 42, 0.25);
}
.dialog-card select option {
  background: #0f1a2e;
  color: #e8f2ea;
  font-weight: 600;
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + var(--safe-bottom));
  transform: translateX(-50%);
  background: #102018;
  border: 1px solid var(--line);
  padding: 10px 14px;
  border-radius: 999px;
  z-index: 30;
  max-width: calc(100vw - 24px);
}
