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

:root {
  --bg: #12151c;
  --panel: #1a1f29;
  --panel2: #202634;
  --line: #2c3444;
  --text: #e8ecf3;
  --dim: #8b93a5;
  --mine: #4fc08d;
  --danger: #e05c5c;
  --star: #f4c542;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  overflow: hidden;
}

/* ---------- Top bar ---------- */
#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.brand { display: flex; flex-direction: column; line-height: 1.1; }
.brand-title { font-weight: 800; font-size: 15px; letter-spacing: 0.5px; }
.brand-sub { font-size: 11px; color: var(--dim); font-weight: 600; }

#search {
  flex: 0 1 220px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  padding: 7px 10px;
  outline: none;
}
#search:focus { border-color: #4a5670; }

.counts { flex: 1; display: flex; gap: 10px; justify-content: center; }
.counts .cnt { font-size: 12px; color: var(--dim); font-weight: 600; }
.counts .cnt b { color: var(--text); }

.toolbar { display: flex; gap: 8px; }
.toolbar button {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  cursor: pointer;
}
.toolbar button:active { background: #2a3242; }
.toolbar button.danger { color: var(--danger); }
.pill {
  background: var(--mine);
  color: #0b2418;
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 12px;
  font-weight: 800;
}

/* ---------- Board ---------- */
#board {
  flex: 1;
  display: flex;
  min-height: 0;
}

#order-rail {
  flex: 0 0 190px;
  overflow-y: auto;
  padding: 10px;
  border-right: 1px solid var(--line);
  background: var(--panel);
}
#order-rail h2 {
  font-size: 11px;
  letter-spacing: 1px;
  color: var(--dim);
  text-transform: uppercase;
  margin-bottom: 8px;
}
#order-list { list-style: none; }
#order-list li {
  display: flex;
  gap: 8px;
  padding: 7px 6px;
  border-radius: 8px;
  font-size: 12.5px;
  line-height: 1.3;
  margin-bottom: 2px;
}
#order-list li.current { background: #26304222; outline: 1px solid var(--line); }
#order-list li .onum {
  flex: 0 0 24px;
  font-weight: 800;
  color: var(--star);
  font-size: 12px;
}
#order-list li.done { opacity: 0.35; }
#order-list li.done .otext { text-decoration: line-through; }

.legend {
  margin-top: 14px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
  font-size: 11.5px;
  color: var(--dim);
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.lg.star { color: var(--star); }
.lg.reach { color: #6fd08c; }
.lg.fade { color: #d98a8a; }
.legend-tap { margin-top: 6px; line-height: 1.4; }

/* ---------- Columns ---------- */
#columns {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

.col {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  border-right: 1px solid var(--line);
}
.col:last-child { border-right: none; }

.col-head {
  flex: 0 0 auto;
  padding: 8px 10px 6px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.8px;
  border-bottom: 2px solid var(--pos-color);
  color: var(--pos-color);
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  background: var(--panel);
}
.col-head .left-cnt { font-size: 11px; color: var(--dim); font-weight: 600; }

.col-body { flex: 1; overflow-y: auto; padding-bottom: 30px; }

.tier-head {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 4px 10px;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--pos-color);
  background: color-mix(in srgb, var(--pos-color) 14%, var(--bg));
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
}
.tier-head .tier-left { color: var(--dim); font-weight: 600; letter-spacing: 0; text-transform: none; }
.tier-head.tier-done { opacity: 0.45; }

.player {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  font-size: 14.5px;
  border-bottom: 1px solid #1e2430;
  cursor: pointer;
  min-height: 38px;
}
.player .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player .mark { flex: 0 0 auto; font-size: 12px; }
.player .mark.star { color: var(--star); }
.player .mark.reach { color: #6fd08c; }
.player .mark.fade { color: #d98a8a; }
.player .note-dot { flex: 0 0 auto; font-size: 11px; color: #7fa7d8; }

.player.guy .nm { font-weight: 700; }
.player.fadep .nm { color: var(--dim); }

.player.taken { opacity: 0.32; }
.player.taken .nm { text-decoration: line-through; }

.player.mine {
  background: color-mix(in srgb, var(--mine) 16%, transparent);
  box-shadow: inset 3px 0 0 var(--mine);
}
.player.mine .nm { color: var(--mine); font-weight: 700; }
.player.mine .who { flex: 0 0 auto; font-size: 10px; font-weight: 800; color: var(--mine); letter-spacing: 0.5px; }

.player.search-hit {
  background: color-mix(in srgb, var(--star) 18%, transparent);
  box-shadow: inset 3px 0 0 var(--star);
}
.player.search-miss { opacity: 0.15; }

/* ---------- Sheets (panels) ---------- */
.sheet {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 360px;
  max-width: 90vw;
  background: var(--panel);
  border-left: 1px solid var(--line);
  z-index: 20;
  overflow-y: auto;
  padding: 14px 16px calc(20px + env(safe-area-inset-bottom));
  transition: transform 0.2s ease;
}
.sheet.hidden { transform: translateX(105%); }

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.sheet-head h2 { font-size: 16px; }
.sheet .close {
  background: var(--panel2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  font-size: 14px;
  padding: 6px 10px;
  cursor: pointer;
}

#scrim {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 15;
}
#scrim.hidden { display: none; }

.team-pos-head {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 1px;
  margin: 12px 0 4px;
}
.team-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 8px;
  font-size: 14px;
  border-bottom: 1px solid var(--line);
}
.team-row .tier-tag { color: var(--dim); font-size: 12px; }
.team-empty { color: var(--dim); font-size: 13px; padding: 4px 8px; }

#tips-list { list-style: none; }
#tips-list li {
  font-size: 13.5px;
  line-height: 1.45;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
  -webkit-user-select: text;
  user-select: text;
}

/* ---------- ADP badge ---------- */
.player .adp {
  flex: 0 0 auto;
  font-size: 10.5px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  min-width: 30px;
  text-align: right;
}

/* ---------- Sync ---------- */
.dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  margin-right: 2px;
}
.dot.off { background: #555e70; }
.dot.on { background: var(--mine); box-shadow: 0 0 6px var(--mine); }
.dot.err { background: var(--danger); }

.sync-form label {
  display: block;
  font-size: 12px;
  color: var(--dim);
  font-weight: 600;
  margin-bottom: 10px;
}
.sync-form input {
  display: block;
  width: 100%;
  margin-top: 4px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  padding: 8px 10px;
  outline: none;
}
.sync-buttons { display: flex; gap: 8px; margin: 6px 0 10px; }
.sync-buttons button {
  flex: 1;
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  padding: 10px;
  cursor: pointer;
}
.sync-buttons button:disabled { opacity: 0.4; }
.sync-buttons button.live { color: var(--mine); border-color: var(--mine); }
.sync-status {
  font-size: 12.5px;
  color: var(--dim);
  padding: 8px 10px;
  background: var(--panel2);
  border-radius: 8px;
  margin-bottom: 12px;
  line-height: 1.4;
}
.sync-help { font-size: 12px; color: var(--dim); line-height: 1.5; }
.sync-help p { margin-bottom: 8px; }
.sync-help code {
  background: var(--panel2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11px;
}

/* ---------- Note/tag modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.5);
}
.modal.hidden { display: none; }
.modal-card {
  width: 400px;
  max-width: 92vw;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}
.modal-card h3 { font-size: 16px; margin-bottom: 12px; }
.tag-row { display: flex; gap: 8px; margin-bottom: 12px; }
.tag-btn {
  flex: 1;
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  padding: 10px 6px;
  cursor: pointer;
}
.tag-btn.sel { border-color: var(--mine); color: var(--mine); }
#nm-note {
  width: 100%;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  padding: 8px 10px;
  outline: none;
  resize: none;
  margin-bottom: 12px;
  -webkit-user-select: text;
  user-select: text;
}
.add-player {
  display: block;
  width: calc(100% - 20px);
  margin: 10px auto 0;
  background: transparent;
  color: var(--dim);
  border: 1px dashed var(--line);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  padding: 9px;
  cursor: pointer;
}
.add-player:active { background: var(--panel2); }

.modal-buttons { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }
.modal-buttons .spacer { flex: 1; }
.modal-buttons button.remove {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, var(--line));
}
.modal-buttons button {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  padding: 9px 18px;
  cursor: pointer;
}
.modal-buttons button.primary {
  background: var(--mine);
  color: #0b2418;
  border-color: var(--mine);
}

/* Narrower screens (portrait fallback): 2 columns */
@media (max-width: 900px) {
  #columns { grid-template-columns: repeat(2, 1fr); }
  #order-rail { display: none; }
  .counts { display: none; }
}
