:root {
  --bg: #0e1116;
  --sheet: #14181f;
  --head: #1b2029;
  --line: #2a3140;
  --text: #e7ebf2;
  --muted: #8b93a3;
  --faint: #5d6573;
  --on: #243044;
  --add: #3dbe78;
  --del: #e85d75;
  --warn: #e2a84a;
  --accent: #7c8cff;
  --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --ease: cubic-bezier(.22, 1, .36, 1);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 13px/1.4 var(--font); }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; background: transparent; border: 1px solid var(--line); border-radius: 6px; min-height: 28px; padding: 2px 8px; color: var(--text); }
button:hover { border-color: #445066; }
button:disabled { opacity: .4; cursor: default; }
button.primary { border-color: var(--accent); color: #fff; background: #2a3160; }
.muted, .keys { color: var(--muted); }
.grow { flex: 1; }
main { max-width: 1180px; margin: 0 auto; padding: 12px 16px 64px; display: flex; flex-direction: column; gap: 10px; }

.top { position: sticky; top: 0; z-index: 5; height: 40px; display: flex; align-items: center; gap: 12px;
  padding: 0 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
.top strong { font-weight: 650; letter-spacing: -.01em; }
.meta { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meta b { color: var(--text); font-weight: 600; }

details { border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; background: var(--sheet); }
summary { cursor: pointer; color: var(--muted); }
.columns, .prefs { display: grid; gap: 10px; margin-top: 8px; }
.columns { grid-template-columns: 1fr 1fr; }
.prefs { grid-template-columns: 1fr 1fr auto auto; align-items: end; }
label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); }
textarea, input[type="password"], select { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; }
textarea { font-family: var(--mono); font-size: 12px; resize: vertical; }
.file input { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.file span { display: flex; align-items: center; justify-content: center; min-height: 32px; border: 1px dashed var(--line); border-radius: 6px; }
.error { margin: 0; color: #ffb4c0; }
#steps, #sheet-note, #done-line { margin: 0; }
#steps:empty, #queue:empty, #ranks:empty { display: none; }

.doubt { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 10px; border: 1px solid #5a4a28; border-radius: 8px; background: #1a170f; }
.doubt .k { color: var(--warn); font-weight: 700; font-variant-numeric: tabular-nums; }
.doubt .who { border: 0; padding: 0; min-height: 0; font-weight: 650; }
.doubt .who mark { background: rgba(226, 168, 74, .25); color: #ffe0a8; border-radius: 2px; }
.reason { margin: 4px 0 0; color: var(--muted); }
.doubt .reason { margin: 0; flex-basis: 100%; }
#ranks h2 { color: var(--warn); }

#desk { display: grid; grid-template-columns: 1.4fr .8fr; gap: 12px; align-items: start; }
.sheet { background: var(--sheet); border: 1px solid var(--line); border-radius: 8px; min-width: 0; }
.sheet.add.active { border-color: #2c6b49; }
.sheet.del.active { border-color: #6e3a46; }
.sheet-head { display: flex; align-items: baseline; gap: 8px; padding: 8px 10px 6px; }
.sheet-head h2 { margin: 0; font-size: 12px; letter-spacing: .08em; text-transform: uppercase; }
.sheet.add h2 { color: var(--add); }
.sheet.del h2 { color: var(--del); }
.sheet-head .count { font-variant-numeric: tabular-nums; color: var(--muted); }
.sheet-head button { margin-left: auto; }
.sheet-head button + button { margin-left: 0; }
table { width: 100%; border-collapse: collapse; }
th { position: sticky; top: 40px; text-align: left; font-weight: 600; font-size: 11px; letter-spacing: .04em; text-transform: uppercase;
  color: var(--faint); background: var(--head); padding: 4px 8px; border-bottom: 1px solid var(--line); }
td { padding: 5px 8px; border-top: 1px solid #222833; vertical-align: middle; }
td.gutter { width: 2.4rem; text-align: right; color: var(--faint); font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 11px; }
td.rank { width: 7.5rem; color: var(--muted); white-space: nowrap; }
td.name { font-weight: 600; }
tr { cursor: pointer; }
tr:hover td { background: #1a2030; }
tr.on td { background: var(--on); }
.sheet.add tr.on td.gutter { box-shadow: inset 2px 0 0 var(--add); }
.sheet.del tr.on td.gutter { box-shadow: inset 2px 0 0 var(--del); }
tr.done td { color: var(--faint); }
tr.done td.name { font-weight: 500; text-decoration: line-through; text-decoration-color: rgba(255,255,255,.28); }
tr.empty td { color: var(--faint); cursor: default; }
tr.empty:hover td { background: transparent; }

.done-line { padding: 28px 4px; color: var(--add); font-size: 28px; font-weight: 750; letter-spacing: -.03em; animation: rise .45s var(--ease); }
#ranks { background: var(--sheet); border: 1px solid var(--line); border-radius: 8px; }
.rank-table tr, .plain tr { cursor: default; }
.rank-table td, .plain td { cursor: default; }
.rank-table button, .plain button { margin-right: 4px; }
.rank-table .who, .plain .who { border: 0; padding: 0 2px; min-height: 0; font-weight: 650; }
.bulk { display: flex; gap: 6px; padding: 0 10px 8px; }

#toolbar { display: flex; gap: 8px; align-items: flex-start; }
#toolbar details { flex: 1; }
.decision { display: flex; gap: 8px; align-items: center; padding: 4px 0; }
.decision span { flex: 1; }
.tabs { display: flex; gap: 6px; margin: 8px 0; }
.tabs button[aria-selected="true"] { border-color: var(--accent); color: #fff; }
.line { padding: 6px 0; border-bottom: 1px solid #222833; color: var(--muted); }
pre { white-space: pre-wrap; max-height: 200px; overflow: auto; background: var(--bg); padding: 8px; border-radius: 6px; }

.clip { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; height: 44px; display: flex; align-items: center; gap: 12px;
  padding: 0 16px; background: #10141b; border-top: 1px solid var(--line); }
#clip-state { color: var(--muted); white-space: nowrap; }
#clip.ready #clip-state { color: var(--add); }
#clip-text { display: flex; gap: 0; min-width: 0; overflow: hidden; }
.cell { font-family: var(--mono); font-size: 13px; padding: 3px 8px; background: #0c0f14; border: 1px solid #323a4a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 28rem; }
.cell + .cell { border-left: 0; }
.keys { margin-left: auto; font-size: 12px; white-space: nowrap; }
#toast { position: fixed; top: 48px; right: 16px; z-index: 7; background: var(--head); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px 10px; opacity: 0; pointer-events: none; }
#toast.show { opacity: 1; }

#rail { display: flex; gap: 8px; list-style: none; margin: 0; padding: 0; flex-wrap: wrap; }
#rail li { padding: 6px 12px; border-radius: 999px; background: #1b2029; color: var(--muted); font-weight: 700; font-size: 12px; letter-spacing: .02em; }
#rail li.now { background: #f4f6fb; color: #12141a; }
#rail li.done { color: var(--add); background: #14261c; }
#rail li.wait { opacity: .45; }

.lead { display: flex; gap: 14px; align-items: center; padding: 16px 18px; border-radius: 18px; background: var(--sheet); border: 1px solid var(--line); animation: rise .4s var(--ease); }
.lead .n { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; background: #f4f6fb; color: #12141a; font-weight: 800; font-size: 18px; flex: none; }
.lead strong { font-size: 18px; letter-spacing: -.02em; }
.lead p { margin: 2px 0 0; color: var(--muted); }

.now-card { padding: 22px 22px 16px; border-radius: 22px; border: 1px solid #6a5424;
  background: radial-gradient(120% 90% at 0% 0%, rgba(226, 168, 74, .18), transparent 52%), #17140c;
  animation: rise .45s var(--ease); }
.now-card.leaving { animation: leave .2s var(--ease) forwards; }
.now-card h2 { margin: 2px 0 0; font-size: 32px; line-height: 1.05; font-weight: 750; letter-spacing: -.04em; }
.kicker { margin: 0; color: var(--warn); font-size: 12px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.versus { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: stretch; margin: 18px 0 8px; }
.plate { background: #0e1116; border-radius: 16px; padding: 16px 18px; min-width: 0; }
.plate small { display: block; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.plate .who { display: block; width: 100%; margin-top: 4px; border: 0; padding: 0; min-height: 0; text-align: left;
  font-size: 26px; line-height: 1.15; font-weight: 750; letter-spacing: -.03em; background: transparent; }
.plate .who mark { background: rgba(226, 168, 74, .28); color: #ffe0a8; border-radius: 3px; }
.plate .rankline { display: block; margin-top: 6px; color: var(--muted); }
.or { align-self: center; color: var(--faint); font-weight: 800; }
.choice { display: flex; gap: 10px; margin-top: 16px; }
.choice .go { flex: 1; }
.go { min-height: 56px; border: 0; border-radius: 14px; font-size: 17px; font-weight: 750; letter-spacing: -.02em;
  transition: transform .15s var(--ease), filter .15s ease; }
.go:hover { filter: brightness(1.08); }
.go:active { transform: scale(.97); }
.go.join { background: #3dbe78; color: #06210f; }
.go.split { background: #2a171c; color: #ffd0d8; border: 1px solid #6e3a46; }
button.quiet { border: 0; color: var(--muted); padding: 8px 0; }
button.quiet:hover { color: var(--text); }
.now-card .reason { margin: 8px 0 0; }
.issue-pick { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.issue-pick select { min-height: 44px; font-size: 16px; }

.guide { display: flex; align-items: center; gap: 16px; padding: 14px 14px 14px 18px; border-radius: 18px;
  background: var(--sheet); border: 1px solid var(--line); animation: rise .4s var(--ease); }
.guide .copy { flex: 1; min-width: 0; }
.guide strong { display: block; font-size: 22px; line-height: 1.15; font-weight: 750; letter-spacing: -.03em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.guide .go { min-width: 11.5rem; }
#guide:empty { display: none; }

#desk.arrive { animation: rise .5s var(--ease); }
tr.on td { animation: live 1.1s ease-in-out 2; }
tr.just td { animation: flash .5s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes leave { to { opacity: 0; transform: translateY(-16px) scale(.96); } }
@keyframes live { 0%, 100% { background-color: #243044; } 50% { background-color: #314864; } }
@keyframes flash { 0% { background-color: rgba(61, 190, 120, .45); } 100% { background-color: transparent; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

@media (max-width: 800px) {
  .columns, #desk, .prefs { grid-template-columns: 1fr; }
  .keys { display: none; }
  th { top: 40px; }
  .versus, .choice, .guide { grid-template-columns: 1fr; flex-direction: column; align-items: stretch; }
  .or { text-align: center; }
  .now-card h2 { font-size: 26px; }
  .plate .who, .guide strong { font-size: 22px; }
}
