:root {
  --bg: #f3f4f8; --surface: #ffffff; --surface-2: #f7f8fb; --fg: #0f1630; --muted: #5d6680; --line: #e3e6ef; --line-strong: #c9cfde;
  --primary: #1d3fbf; --primary-fg: #ffffff; --ball: #ffc531; --ball-fg: #2a1f00;
  --danger: #c0352b; --ok: #13804f; --warn-bg: #fff4d6; --warn-fg: #6b4b00;
  --up: #b8530b; --down: #1d3fbf;
  --shadow: 0 1px 2px rgba(15, 22, 48, .06), 0 4px 16px rgba(15, 22, 48, .06);
  --display: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --body: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020; --surface: #141b30; --surface-2: #1a2238; --fg: #eef1f8; --muted: #9aa3bb; --line: #26304a; --line-strong: #3a4664;
    --primary: #6f93ff; --primary-fg: #0b1020;
    --danger: #ff7a6e; --ok: #3cc488; --warn-bg: #3a2e0d; --warn-fg: #ffd98a;
    --up: #ffa463; --down: #8fb0ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.5 var(--body); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- header ---------- */
.top { position: sticky; top: 0; z-index: 10; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px;
  padding: 10px max(16px, calc((100vw - 1100px) / 2)); background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--fg); }
.brand svg { width: 30px; height: 30px; flex: none; }
.brand h1 { margin: 0; font: 700 1.7rem/1 var(--display); letter-spacing: .01em; }
.brand h1 span { color: var(--primary); }
#nav { display: flex; gap: 4px; flex: 1; }
#nav a { padding: 8px 14px; border-radius: 999px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: .92rem; white-space: nowrap; }
#nav a:hover { color: var(--fg); background: var(--surface-2); }
#nav a.on { background: var(--fg); color: var(--bg); }
#who { display: flex; align-items: center; gap: 10px; }
.me { display: flex; align-items: center; gap: 8px; font-size: .88rem; }
.me b { display: block; line-height: 1.2; }
.me small { display: block; color: var(--muted); font-size: .75rem; text-transform: capitalize; line-height: 1.1; }

/* ---------- layout ---------- */
main { max-width: 1100px; margin: 0 auto; padding: 24px 16px 80px; }
.page-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 8px 16px; margin-bottom: 16px; }
.page-head h2 { margin: 0; font: 700 2.2rem/1 var(--display); text-transform: uppercase; letter-spacing: .01em; }
.page-head p { margin: 6px 0 0; color: var(--muted); }
h3 { margin: 0; font: 700 1.3rem/1.1 var(--display); text-transform: uppercase; letter-spacing: .02em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px; margin: 0 0 14px; box-shadow: var(--shadow); }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.card-head .actions { display: flex; gap: 8px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.grow { flex: 1; }
.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 320px), 1fr)); }
.grid > .card { margin: 0; }
.scroll { overflow-x: auto; }

/* ---------- controls ---------- */
input[type=text], input[type=date], input[type=email], input[type=password], input[type=search], select {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; min-width: 0; min-height: 44px; }
input:focus, select:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent); }
button { background: var(--primary); color: var(--primary-fg); border: 0; border-radius: 10px; padding: 9px 16px; min-height: 44px; font-weight: 600; cursor: pointer; transition: transform .05s, filter .15s, background .15s; }
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button.ghost { background: transparent; color: var(--fg); border: 1px solid var(--line-strong); }
button.danger { background: transparent; color: var(--danger); border: 1px solid var(--line-strong); }
button.ball { background: var(--ball); color: var(--ball-fg); }
button.big { min-height: 52px; padding: 12px 28px; font-size: 1.05rem; }
button.sm { min-height: 34px; padding: 4px 12px; font-size: .85rem; }
button:disabled { opacity: .55; cursor: default; filter: none; }

/* Toggle switch: the whole label is the tap target. */
.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; user-select: none; font-weight: 600; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { position: relative; width: 52px; height: 32px; border-radius: 999px; background: var(--line-strong); transition: background .2s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .2s; }
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Segmented buttons for picking one value. */
.seg { display: inline-flex; gap: 2px; padding: 3px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 11px; }
.seg button { flex: 1 0 auto; min-width: 40px; min-height: 36px; padding: 4px 8px; border-radius: 8px; background: transparent; color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.seg button:hover { color: var(--fg); filter: none; background: color-mix(in srgb, var(--fg) 7%, transparent); }
.seg button[aria-pressed=true] { background: var(--primary); color: var(--primary-fg); box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.seg button.u[aria-pressed=true] { background: var(--line-strong); color: var(--fg); }

/* ---------- bits ---------- */
.avatar { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: 50%; flex: none; font: 700 .82rem/1 var(--body); color: #fff; letter-spacing: .02em; }
.badge { display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 999px; font-size: .7rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.set { background: var(--ball); color: var(--ball-fg); border-color: transparent; }
.badge.backup { background: transparent; color: var(--fg); border-color: var(--ball); }
.badge.on { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); border-color: transparent; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 3px 3px 12px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); font-weight: 600; font-size: .9rem; }
.chip.off { opacity: .55; text-decoration: line-through; }
.chip.apart { border-color: color-mix(in srgb, var(--danger) 45%, transparent); background: color-mix(in srgb, var(--danger) 8%, var(--surface-2)); }
.combo-section { margin-top: 14px; }
/* Consistency sits apart from the skills: it doesn't count toward the total. */
.skill-row.trait { margin-top: 4px; padding-top: 10px; border-top: 1px dashed var(--line); }
.combo-section h4 { margin: 0 0 8px; font-size: .72rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.chip.plain { padding: 5px 12px; }
.chip.plain.off { text-decoration: none; }
textarea { width: 100%; background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: inherit; color: inherit; resize: vertical; }
textarea:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 22%, transparent); }
.chip button { min-height: 30px; width: 30px; padding: 0; border-radius: 50%; background: transparent; color: var(--muted); font-size: 1.1rem; line-height: 1; }
.chip button:hover { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); filter: none; }
.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--line); }
.progress span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--ball)); border-radius: inherit; transition: width .3s; }
.stat { font: 700 1.6rem/1 var(--display); }
.stat small { font: 600 .75rem var(--body); color: var(--muted); margin-left: 4px; }
.warn { background: var(--warn-bg); color: var(--warn-fg); border-radius: 10px; padding: 10px 14px; margin: 8px 0; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.link { word-break: break-all; font-family: ui-monospace, monospace; font-size: .85rem; background: var(--surface-2); padding: 10px; border-radius: 10px; border: 1px dashed var(--line-strong); margin: 10px 0; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; box-shadow: var(--shadow); z-index: 20; }

/* ---------- rate ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .85rem; color: var(--muted); }
.legend b { color: var(--fg); }
/* Rating guide: on desktop a full-height drawer slides in from the right and pushes the whole page (header too) left;
   on phones it slides up from the bottom. */
body, .top { transition: padding .28s ease; }
.guide-panel { position: fixed; z-index: 15; background: var(--surface); border: 1px solid var(--line); box-shadow: var(--shadow);
  padding: 0 14px 14px; overflow-y: auto; overscroll-behavior: contain; visibility: hidden;
  transition: transform .28s ease, visibility 0s linear .28s; }
.guide-panel.open { transform: none; visibility: visible; transition: transform .28s ease, visibility 0s; }
.guide-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 0 8px; background: var(--surface); }
.guide-head h3 { margin: 0; }
.guide-head button { font-size: 1.2rem; width: 36px; padding: 0; }
.guide-panel > p { margin: 0 0 10px; }
.guide-panel .guide-item { margin-top: 10px; transition: border-color .2s, background .2s; }
.guide-panel .guide-item.on { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, var(--surface-2)); }
.guide-fab { position: fixed; right: 16px; bottom: 16px; z-index: 15; border-radius: 999px; padding: 10px 18px; box-shadow: var(--shadow); }
.guide-fab[hidden] { display: none; }
@media (min-width: 900px) {
  .guide-panel { top: 0; right: 0; bottom: 0; width: 360px; border: 0; border-left: 1px solid var(--line); border-radius: 0; transform: translateX(100%); }
  body.guide-open { padding-right: 360px; }
  body.guide-open .top { padding-inline: max(16px, calc((100vw - 360px - 1100px) / 2)); }
}
@media (max-width: 899px) {
  .guide-panel { left: 0; right: 0; bottom: 0; max-height: 48vh; border-bottom: 0; border-radius: 16px 16px 0 0;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, .3); transform: translateY(100%); }
  body.guide-open main { padding-bottom: 48vh; }
}
@media (prefers-reduced-motion: reduce) {
  .guide-panel, .guide-panel.open, body, .top { transition: none; }
}
.guide-item { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.guide-item h4 { margin: 0 0 2px; font-size: .9rem; }
.guide-item p { margin: 0 0 8px; font-size: .85rem; color: var(--muted); }
.guide-item dl { display: grid; grid-template-columns: 2.2em 1fr; gap: 3px 6px; margin: 0; font-size: .85rem; }
.guide-item dt { font-weight: 700; }
.guide-item dd { margin: 0; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.toolbar input[type=search] { flex: 1 1 200px; }
.player-card { display: grid; gap: 8px; min-width: 0; }
.player-card header { display: flex; align-items: center; gap: 10px; margin-bottom: 2px; }
.player-card header b { flex: 1; font-size: 1.02rem; }
.skill-row { display: grid; grid-template-columns: 88px minmax(0, 1fr); align-items: center; gap: 8px; }
.skill-row > span { font-size: .8rem; font-weight: 700; color: var(--muted); }
.skill-row .seg { width: 100%; min-width: 0; }
.totals { display: flex; gap: 18px; border-top: 1px solid var(--line); padding-top: 10px; margin-top: 2px; }
.totals span { display: flex; align-items: baseline; gap: 6px; }
.totals small { font-size: .7rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.totals b { font: 700 1.35rem/1 var(--display); font-variant-numeric: tabular-nums; }
.skill-row .seg button { flex: 1 1 0; min-width: 0; padding: 4px 2px; }

/* ---------- players ---------- */
.roster-card { display: grid; gap: 12px; min-width: 0; }
.roster-card header { display: flex; align-items: center; gap: 10px; }
.roster-card header input { flex: 1; font-weight: 600; }
.roster-card header .grow { min-width: 0; overflow-wrap: anywhere; }
.fields { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: end; }
.field { display: grid; gap: 4px; }
.field > span { font-size: .7rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.fields .seg button { flex: 1 0 auto; padding: 4px 12px; }
.add-player { display: grid; gap: 12px; }
.add-player .row input { flex: 1; }
.add-player .seg button, .new-player .seg button { padding: 4px 12px; }
.new-players { display: grid; gap: 8px; }
.new-player { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 12px; }

/* ---------- teams ---------- */
.build-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px; }
/* Super's "Ratings from" chips: on = filled with a tick, off = faded and crossed out. */
.build-bar .raters { flex: 1 1 100%; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
.rater-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.rater-chips > button.sm { min-height: 36px; }
.build-bar .need-rater { flex: 1 1 100%; margin: 0; }
.need-rater[hidden] { display: none; }
.rater-chip { display: inline-flex; align-items: center; gap: 8px; min-height: 36px; padding: 4px 12px 4px 5px; border-radius: 999px;
  background: color-mix(in srgb, var(--primary) 14%, var(--surface)); color: var(--fg); border: 1px solid color-mix(in srgb, var(--primary) 45%, transparent); font-weight: 600; }
.rater-chip .tick { color: var(--primary); font-weight: 800; }
.rater-chip[aria-pressed=false] { background: transparent; border-color: var(--line-strong); border-style: dashed; color: var(--muted); }
.rater-chip[aria-pressed=false] > span:not(.tick) { text-decoration: line-through; }
.rater-chip[aria-pressed=false] .avatar { filter: grayscale(1); opacity: .5; }
.rater-chip[aria-pressed=false] .tick { visibility: hidden; }
.option { margin: 22px 0 8px; }
.team-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 235px), 1fr)); }
.team { --tc: var(--primary); background: var(--surface); border: 1px solid var(--line); border-top: 5px solid var(--tc); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); display: grid; gap: 10px; align-content: start; }
.team header { display: flex; align-items: baseline; justify-content: space-between; }
.team h4 { margin: 0; font: 700 1.4rem/1 var(--display); text-transform: uppercase; color: var(--tc); }
.team .total { font: 700 1.4rem/1 var(--display); font-variant-numeric: tabular-nums; }
.team .total small { font: 700 .66rem var(--body); color: var(--muted); letter-spacing: .05em; margin-right: 4px; }
.team ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; }
.team li { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.team li span:nth-child(2) { flex: 1; }
.team li .avatar { width: 28px; height: 28px; font-size: .7rem; }
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; border-top: 1px solid var(--line); padding-top: 8px; text-align: center; font-variant-numeric: tabular-nums; }
.stats small { display: block; font-size: .64rem; color: var(--muted); font-weight: 700; letter-spacing: .04em; text-transform: uppercase; }
.stats b { font-size: .88rem; }

/* ---------- tables (ratings, users) ---------- */
table { border-collapse: collapse; width: 100%; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-weight: 700; font-size: .7rem; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; }
td.num, th.num { text-align: center; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover, th[aria-sort=ascending], th[aria-sort=descending] { color: var(--fg); }
th .arrow { color: var(--primary); }
.sort { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; }
.sort > span { font-size: .7rem; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.sort-dir { min-height: 44px; }

/* Rater leans and disagreements (All ratings page). */
.lean-up { color: var(--up); font-weight: 700; }
.lean-down { color: var(--down); font-weight: 700; }
td.muted { color: var(--muted); }
.disagree { display: grid; }
.disagree-item { display: grid; gap: 8px; padding: 12px 0; border-top: 1px solid var(--line); }
.disagree-item:first-child { border-top: 0; padding-top: 4px; }
.disagree-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chip.hi { border-color: var(--up); color: var(--up); }
.chip.lo { border-color: var(--down); color: var(--down); }
.disagree details summary { cursor: pointer; color: var(--muted); font-size: .85rem; font-weight: 600; }
table.mini { margin-top: 6px; font-size: .9rem; }
table.mini th, table.mini td { padding: 5px 6px; }
tbody tr:hover { background: var(--surface-2); }

/* ---------- login ---------- */
.login { max-width: 400px; margin: 8vh auto 0; display: grid; gap: 12px; padding: 30px 26px; }
.login .brand { justify-content: center; }
.login .brand svg { width: 48px; height: 48px; }
.login .brand h1 { font-size: 2.8rem; }
.login .tag { text-align: center; margin: -4px 0 10px; color: var(--muted); }
.login button { min-height: 50px; }

/* ---------- phones ---------- */
@media (max-width: 640px) {
  .top { padding: 8px 12px; gap: 6px 10px; }
  #nav { order: 3; flex: 1 1 100%; overflow-x: auto; scrollbar-width: none; margin: 0 -12px; padding: 0 12px 2px; }
  #nav::-webkit-scrollbar { display: none; }
  .me .who-text { display: none; }
  main { padding: 16px 12px 80px; }
  .page-head h2 { font-size: 1.9rem; }
  .card { padding: 14px; border-radius: 12px; }
  input[type=text], input[type=date], input[type=email], input[type=password], input[type=search], select, textarea { font-size: 16px; }
  form.row > input, form.row > select { flex: 1 1 140px; }
  form.row > button, .build-bar > button { flex: 1 1 100%; }
  .combo-add .seg { flex: 1 1 100%; }
  .combo-add .seg button { flex: 1 1 0; }
  .seg button { min-height: 42px; }
  .skill-row .seg button, .fields .seg button { flex: 1 1 0; min-width: 0; padding: 4px 2px; }
  .skill-row { grid-template-columns: 1fr; gap: 4px; }
  .fields { display: grid; grid-template-columns: 1fr 1.7fr; }
  .fields .seg { width: 100%; }
  table.stack, table.stack tbody { display: block; width: 100%; }
  table.stack thead { display: none; }
  table.stack tr { display: grid; grid-template-columns: repeat(auto-fit, minmax(3.8rem, 1fr)); gap: 6px 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  table.stack td { border: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; min-width: 0; overflow-wrap: anywhere; }
  table.stack td.num { text-align: left; }
  table.stack td::before { content: attr(data-label); font-size: .68rem; color: var(--muted); font-weight: 700; text-transform: uppercase; }
  table.stack td:first-child { grid-column: 1 / -1; font-weight: 600; }
  table.stack td:first-child::before, table.stack td:empty::before, table.stack td:not([data-label])::before { content: none; }
  table.stack td:empty { display: none; }
}
