/* LocalsLadder UI: utilitarian, dense, bordered. One accent, 4px spacing scale, 4/6px radii. */
:root {
  --bg: #111417;
  --surface: #1B2024;
  --text: #E6E9E8;
  --muted: #929DA1;
  --accent: #89AA97;
  --border: #303A3E;

  --accent-bg: rgba(137,170,151,.12);
  --warn: #C4B07E;
  --danger: #D08F89;
  --danger-bg: rgba(208,143,137,.12);

  --r: 4px;
  --r-lg: 6px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;

  --sans: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0 auto; padding: 0 var(--s4) var(--s6); max-width: 720px; min-height: 100vh;
  background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased;
}
b { font-weight: 600; }

/* ---------- header ---------- */
header {
  display: flex; justify-content: space-between; align-items: center; gap: var(--s3);
  padding: var(--s3) 0; margin-bottom: var(--s4); border-bottom: 1px solid var(--border);
}
h1 { margin: 0; font-size: 15px; font-weight: 600; line-height: 24px; letter-spacing: -.005em; }
h2 {
  display: flex; align-items: baseline; gap: var(--s2); margin: 0; padding: var(--s2) var(--s3);
  font-size: 11px; font-weight: 600; line-height: 16px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
h2 .muted { font-family: var(--mono); letter-spacing: 0; }

.conn { display: inline-flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 12px; white-space: nowrap; color: var(--muted); }
.conn::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.conn.live { color: var(--text); }
.conn.live::before { background: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }

/* ---------- sections ---------- */
.card { margin-bottom: var(--s4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: clip; }
.card > :not(h2):not(.list):not(.setups):not(.tabs) { margin-left: var(--s3); margin-right: var(--s3); }
.card > h2 + * { margin-top: var(--s3); }
.card > :last-child { margin-bottom: var(--s3); }
.card > .list, .card > .setups { margin-left: 0; margin-right: 0; }
.card > h2 + .list { margin-top: 0; }
.card > .list:last-child { margin-bottom: 0; }
.card > .setups { padding: var(--s3); margin-top: 0; }
.card.hero { background: var(--surface); }

.big { font-size: 20px; font-weight: 600; line-height: 28px; letter-spacing: -.01em; margin: 0; }
.sub { color: var(--muted); font-size: 13px; line-height: 20px; }
.row { display: flex; gap: var(--s2); flex-wrap: wrap; align-items: center; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.center { text-align: center; }
.hidden { display: none !important; }
#me-card { padding: var(--s3); }
#me-card > * { margin-left: 0; margin-right: 0; }
#me-card .big { margin: 0; }
#me-card > .row .sub:last-child { font-family: var(--mono); font-size: 12px; }

/* ---------- buttons ---------- */
button {
  appearance: none; display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 32px; padding: 0 var(--s3); border: 1px solid var(--border); border-radius: var(--r);
  background: var(--surface); color: var(--text); font: 500 13px/20px var(--sans); cursor: pointer;
  transition: background-color .1s, border-color .1s, color .1s;
}
button:hover:not(:disabled) { background: #232A2F; border-color: #3C484D; }
button:active:not(:disabled) { background: var(--bg); }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #0E1511; font-weight: 600; }
button.primary:hover:not(:disabled) { background: #9BBAA8; border-color: #9BBAA8; }
button.primary:active:not(:disabled) { background: #7A9A88; border-color: #7A9A88; }
button.secondary { background: var(--surface); border-color: #46545A; }
button.danger { color: var(--danger); }
button.danger:hover:not(:disabled) { background: var(--danger-bg); border-color: var(--danger); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover:not(:disabled) { background: var(--surface); border-color: var(--border); color: var(--text); }
button.small { min-height: 28px; padding: 0 var(--s2); font-size: 12px; }
button:disabled { opacity: .4; cursor: not-allowed; }
button[aria-busy="true"] { opacity: .6; cursor: progress; }
/* thumb-sized actions inside the player panel and join form */
#me-card button, #join button, .actions.stack button { width: 100%; min-height: 40px; font-size: 14px; }
#me-card .row button { width: auto; }

input, select {
  width: 100%; min-height: 32px; padding: 0 var(--s2); border: 1px solid var(--border); border-radius: var(--r);
  background: var(--bg); color: var(--text); font: 14px/20px var(--sans);
}
input::placeholder { color: #66737A; }
input:hover, select:hover { border-color: #3C484D; }
input:focus, select:focus { border-color: var(--accent); outline: none; }
input:disabled, select:disabled { opacity: .4; cursor: not-allowed; }
/* checkboxes and radios: same border, radius and accent as the rest of the UI */
input[type=checkbox], input[type=radio] {
  appearance: none; -webkit-appearance: none; flex: none; width: 18px; height: 18px; min-height: 0; padding: 0; margin: 0;
  border: 1px solid #46545A; background: var(--bg) center / 14px no-repeat; cursor: pointer;
}
input[type=checkbox] { border-radius: var(--r); }
input[type=radio] { border-radius: 50%; }
input[type=checkbox]:checked, input[type=radio]:checked { background-color: var(--accent); border-color: var(--accent); }
input[type=checkbox]:checked {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 8.5l3 3 6-7' fill='none' stroke='%230E1511' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
input[type=radio]:checked { background-image: radial-gradient(circle, #0E1511 0 3px, transparent 3.5px); background-size: 100% 100%; }
input[type=checkbox]:hover:not(:disabled):not(:checked), input[type=radio]:hover:not(:disabled):not(:checked) { border-color: var(--accent); }
input[type=checkbox]:disabled, input[type=radio]:disabled { cursor: not-allowed; }

/* number inputs: no browser spinner arrows */
input[type=number] { appearance: textfield; -moz-appearance: textfield; }
input[type=number]::-webkit-inner-spin-button, input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

/* selects: custom caret instead of the OS arrow */
select {
  appearance: none; -webkit-appearance: none; padding-right: 28px; cursor: pointer;
  background: var(--bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%23929DA1' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") right 8px center / 14px no-repeat;
}
#join input { min-height: 40px; }
label { display: block; margin: var(--s3) 0 var(--s1); font-size: 12px; font-weight: 500; line-height: 16px; color: var(--muted); }
.err { min-height: 20px; margin-top: var(--s2); color: var(--danger); font-size: 13px; line-height: 20px; }

/* ---------- lists ---------- */
.list { display: flex; flex-direction: column; }
.list > .muted { padding: var(--s3); font-size: 13px; }
.item { display: flex; align-items: center; gap: var(--s3); min-height: 36px; padding: var(--s1) var(--s3); border-bottom: 1px solid var(--border); font-size: 14px; }
.item:last-child { border-bottom: 0; }
.item .n { width: 24px; flex: none; text-align: right; color: var(--muted); font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums; }
.item .name { flex: 1; min-width: 0; font-weight: 500; overflow-wrap: anywhere; }
.item .muted { font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.item .name .muted, .item .name.muted { font-family: var(--sans); font-size: 13px; white-space: normal; }
.item .elo { min-width: 40px; text-align: right; font-family: var(--mono); font-size: 13px; font-weight: 500; font-variant-numeric: tabular-nums; }
.item.me { background: var(--accent-bg); box-shadow: inset 2px 0 0 var(--accent); }
.item select { width: auto; min-height: 28px; font-size: 12px; }

.setups { display: grid; grid-template-columns: repeat(auto-fill, minmax(176px, 1fr)); gap: var(--s2); }
.setup { padding: var(--s2) var(--s3); min-height: 80px; border: 1px solid var(--border); border-radius: var(--r); background: var(--bg); }
.setup .t { margin-bottom: var(--s1); font-family: var(--mono); font-size: 11px; line-height: 16px; letter-spacing: .02em; text-transform: uppercase; color: var(--muted); }
.setup .vs { font-size: 13px; font-weight: 500; line-height: 20px; }
.setup .vs small { font-family: var(--mono); font-size: 11px; color: var(--muted); font-weight: 400; }
.setup.free { background: transparent; border-style: dashed; }
.setup.mine { border-color: var(--accent); background: var(--accent-bg); }
.setup .status { margin-top: var(--s1); font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--warn); }

.tag { display: inline-block; margin-left: var(--s1); padding: 0 6px; border: 1px solid var(--border); border-radius: var(--r); font-size: 11px; font-weight: 500; line-height: 16px; vertical-align: middle; color: var(--warn); white-space: nowrap; }
.tag.danger { color: var(--danger); }
.tag.ok { color: var(--muted); }
a.tag { text-decoration: none; }
a.tag:hover { color: var(--text); border-color: #3C484D; }
.result-win { font-weight: 600; }
.result-loss { color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: var(--s4); transform: translateX(-50%); max-width: calc(100vw - 32px); z-index: 50;
  padding: var(--s2) var(--s3); background: var(--surface); color: var(--text);
  border: 1px solid var(--accent); border-radius: var(--r); font-size: 13px; font-weight: 500; animation: pop .15s ease-out;
}
@keyframes pop { from { opacity: 0; } }

.vsline { display: flex; justify-content: space-between; align-items: center; gap: var(--s3); margin: var(--s3) 0; padding: var(--s3) 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.vsline .p { flex: 1; min-width: 0; text-align: center; }
.vsline .p .nm { font-size: 18px; font-weight: 600; line-height: 24px; overflow-wrap: anywhere; }
.vsline .p .el { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.vsline .v { font-family: var(--mono); font-size: 11px; letter-spacing: .08em; color: var(--muted); }

.tabs { display: flex; gap: var(--s1); margin-bottom: var(--s4); border-bottom: 1px solid var(--border); }
.tabs button { min-height: 32px; margin-bottom: -1px; padding: 0 var(--s3); border: 0; border-bottom: 2px solid transparent; border-radius: 0; background: transparent; color: var(--muted); }
.tabs button:hover:not(:disabled) { background: transparent; color: var(--text); }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); }

/* ---------- admin ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2) var(--s3); }
@media (max-width: 600px) {
  .grid2 { grid-template-columns: 1fr; }
  input, select { font-size: 16px; }
}
.field { padding: var(--s2) var(--s3); border: 1px solid var(--border); border-radius: var(--r); }
.field label { margin: 0 0 var(--s1); color: var(--text); font-size: 13px; font-weight: 500; }
.field label .muted { font-family: var(--mono); font-size: 11px; font-weight: 400; }
.field .help { margin-top: var(--s1); font-size: 12px; line-height: 16px; color: var(--muted); }
.field input[type=checkbox] { margin: 0; }
.actions { display: flex; gap: var(--s2); flex-wrap: wrap; }
.sticky { position: sticky; top: 0; z-index: 5; background: var(--bg); padding-top: var(--s1); }

/* ---------- admin settings form ---------- */
#tab-settings .item .name > .muted { display: block; font-family: var(--sans); font-size: 12px; font-weight: 400; }
.groups { margin: 0 !important; }
.group { border-top: 1px solid var(--border); }
.group:first-child { border-top: 0; }
.group > summary {
  display: flex; align-items: baseline; gap: var(--s3); padding: var(--s2) var(--s3); cursor: pointer; list-style: none;
  font-size: 13px; font-weight: 600; user-select: none;
}
.group > summary::-webkit-details-marker { display: none; }
.group > summary::before { content: "▸"; color: var(--muted); font-size: 10px; width: 10px; }
.group[open] > summary::before { content: "▾"; }
.group > summary .muted { font-size: 12px; font-weight: 400; }
.group > summary:hover { background: #232A2F; }
.group > .grid2 { padding: var(--s1) var(--s3) var(--s3); }
.field.toggle label { display: flex; align-items: center; gap: var(--s2); cursor: pointer; }
.field.changed { border-color: var(--accent); background: var(--accent-bg); }
.field.inactive { opacity: .5; }
.field.inactive:focus-within, .field.inactive:hover { opacity: 1; }
.savebar {
  position: sticky; bottom: 0; display: flex; align-items: center; justify-content: flex-end; gap: var(--s2);
  margin: 0 !important; padding: var(--s2) var(--s3); background: var(--surface); border-top: 1px solid var(--border);
}
.savestate { margin-right: auto; font-size: 12px; color: var(--muted); }
.savestate.dirty { color: var(--warn); }
@media (max-width: 600px) { .savebar button { flex: 1; } .savestate { flex-basis: 100%; } }

/* ---------- result feedback ---------- */
.delta { font-weight: 600; }
.delta.up { color: var(--accent); }
.delta.down { color: var(--muted); }
.delta:not(:empty) { animation: rise .3s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(3px); } }
.note { margin-top: var(--s1); padding-left: var(--s2); border-left: 2px solid var(--accent); font-size: 12px; line-height: 16px; color: var(--text); }
.tag.streak { color: var(--accent); border-color: var(--accent); font-family: var(--mono); }
.mv { margin-left: var(--s1); font-family: var(--mono); font-size: 11px; font-weight: 500; }
.mv.up { color: var(--accent); }
.mv.down { color: var(--muted); }
@media (prefers-reduced-motion: reduce) { .delta:not(:empty), .toast { animation: none; } }

.score-row { gap: 8px; margin-bottom: 4px; }
.score-row label { font-size: 12px; color: var(--muted, #8a979d); display: flex; flex-direction: column; gap: 4px; }

.item.pick { cursor: pointer; }
.item.pick:hover { background: var(--accent-bg); }
.challenge-row { display: flex; align-items: center; gap: var(--s2); padding: var(--s2) var(--s3); border-bottom: 1px solid var(--border); }

/* rank badges: Wood -> Diamond */
.tag.rank { font-weight: 600; }
.rank-0 { color: #A98562; }   /* Wood */
.rank-1 { color: #9AA5AB; }   /* Iron */
.rank-2 { color: #C98A4B; }   /* Bronze */
.rank-3 { color: #C9D1D4; }   /* Silver */
.rank-4 { color: #DDB84F; }   /* Gold */
.rank-5 { color: #5CC9CF; }   /* Platinum */
.rank-6 { color: #86C5FF; }   /* Diamond */

/* top-bar links */
a.tag.nav { margin-left: 0; padding: 2px 8px; color: var(--muted); }
a.tag.nav:hover { color: var(--text); }

/* admin: edit-result dialog */
dialog { width: min(420px, calc(100vw - 32px)); padding: var(--s4); background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--r-lg); }
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin-top: 0; }
label.radio { display: inline-flex; align-items: center; gap: var(--s2); margin: 0; font-size: 14px; line-height: 20px; color: var(--text); cursor: pointer; }
label.radio:has(input:disabled) { cursor: not-allowed; opacity: .6; }

/* practice mode switch row in the player card: reads like an admin settings field */
#practice-box { padding: var(--s2) var(--s3); border: 1px solid var(--border); border-radius: var(--r); }
#practice-box label.radio { display: flex; min-height: 28px; font-weight: 500; }
#practice-box .sub { margin: 2px 0 0 26px; font-size: 12px; line-height: 16px; }
#practice-box:has(input:checked) { border-color: var(--accent); background: var(--accent-bg); }

/* online mode: the Setups card is a joke */
.joke { padding: var(--s4) var(--s3); text-align: center; border-bottom: 1px solid var(--border); }
.joke .big { font-size: 18px; font-weight: 600; line-height: 24px; }
.joke .sub { margin-top: var(--s1); }
