:root {
  --bg: #0f1218;
  --panel: #171b23;
  --panel-2: #1e232d;
  --line: #2a3140;
  --text: #e6e9ef;
  --muted: #9aa3b2;
  --primary: #2f7cf6;
  --primary-2: #1f63cc;
  --danger: #ff6b6b;
  --purple: #a86cff;
  --red: #ff5c5c;
  --yellow: #ffcc4d;
  --radius: 10px;
  --focus: 0 0 0 3px rgba(47, 124, 246, 0.55);
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus); }
.muted { color: var(--muted); font-weight: normal; }
.hint { color: var(--muted); font-size: .85rem; }
.error { color: var(--danger); font-size: .85rem; min-height: 1.1em; display: block; }
.mobile-only { display: none; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--primary); color: #fff; padding: .4rem .7rem; border-radius: 0 0 var(--radius) 0; z-index: 30; }
.skip-link:focus { left: 0; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(15, 18, 24, .95); border-bottom: 1px solid var(--line); backdrop-filter: blur(6px); }
.topbar-inner { max-width: 1440px; margin: 0 auto; padding: .6rem 1rem; display: flex; gap: 1.2rem; align-items: center; flex-wrap: wrap; }
.brand { display: flex; flex-direction: column; }
.brand-name { font-weight: 700; letter-spacing: .02em; }
.brand-sub { color: var(--muted); font-size: .8rem; }
.summary { display: flex; gap: .6rem; margin: 0; flex-wrap: wrap; }
.summary div { display: flex; gap: .35rem; align-items: baseline; padding: .25rem .6rem; border: 1px solid var(--line); border-radius: 999px; background: var(--panel); }
.summary dt { color: var(--muted); font-size: .8rem; }
.summary dd { margin: 0; font-weight: 600; }
.pill-purple { border-color: var(--purple) !important; }
.pill-red { border-color: var(--red) !important; }
.pill-yellow { border-color: var(--yellow) !important; }

/* ---------- layout ---------- */
.layout { max-width: 1440px; margin: 0 auto; padding: 1rem; display: grid; grid-template-columns: 380px 1fr; gap: 1rem; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.left { position: sticky; top: 4.5rem; max-height: calc(100vh - 5.5rem); overflow: auto; display: flex; flex-direction: column; gap: 1rem; }

/* ---------- form ---------- */
.form { display: flex; flex-direction: column; gap: .5rem; }
.field { display: flex; flex-direction: column; gap: .2rem; }
.field label { font-size: .9rem; }
.field input { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .6rem; }
.field input[aria-invalid="true"] { border-color: var(--danger); }

/* ---------- roster ---------- */
.progress-group { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .5rem; }
.progress { display: grid; grid-template-columns: 3rem 1fr 3.2rem; gap: .5rem; align-items: center; font-size: .85rem; }
.bar { height: 8px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.bar > div { width: 0; height: 100%; background: var(--primary); transition: width .2s; }
.roster-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .3rem; }
.roster-item { display: grid; grid-template-columns: 2.4rem 1fr auto auto; gap: .5rem; align-items: center; padding: .35rem .5rem; background: var(--panel-2); border-radius: 8px; border-left: 4px solid var(--line); }
.roster-item.c-purple { border-left-color: var(--purple); }
.roster-item.c-red { border-left-color: var(--red); }
.roster-item.c-yellow { border-left-color: var(--yellow); }
.roster-item .pos { font-weight: 700; font-size: .85rem; }
.roster-item .who { display: flex; flex-direction: column; }
.roster-item .who small { color: var(--muted); }
.roster-item .color-tag { font-size: .75rem; padding: .1rem .4rem; border-radius: 999px; border: 1px solid currentColor; }
.empty { color: var(--muted); font-size: .9rem; }
.submit-row { display: flex; flex-direction: column; gap: .3rem; }

/* ---------- buttons ---------- */
.btn { border: 1px solid var(--line); background: var(--panel-2); border-radius: 8px; padding: .5rem .9rem; cursor: pointer; }
.btn:hover { border-color: #3a4356; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--primary-2); }
.btn-primary[disabled] { opacity: .6; cursor: progress; }
.btn-ghost { background: transparent; }
.btn-small { padding: .2rem .5rem; font-size: .8rem; }

/* ---------- picker ---------- */
.picker-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.stage-tabs { display: flex; gap: .3rem; }
.tab { border: 1px solid var(--line); background: var(--panel-2); border-radius: 999px; padding: .35rem .9rem; cursor: pointer; }
.tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .5rem; margin: .8rem 0; align-items: end; }
.filters label { display: flex; flex-direction: column; gap: .2rem; font-size: .8rem; color: var(--muted); }
.filters input, .filters select { background: var(--panel-2); border: 1px solid var(--line); border-radius: 8px; padding: .4rem .5rem; color: var(--text); }
.status { color: var(--muted); font-size: .9rem; margin: .2rem 0 .6rem; min-height: 1.2em; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .7rem; }
.card { text-align: left; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 0; overflow: hidden; cursor: pointer; display: flex; flex-direction: column; transition: transform .08s, border-color .08s; }
.card:hover { transform: translateY(-1px); border-color: #3a4356; }
.card[aria-pressed="true"] { border-color: var(--primary); box-shadow: inset 0 0 0 2px var(--primary); }
.card[disabled] { opacity: .45; cursor: not-allowed; }
.card-top { height: 6px; }
.c-purple .card-top { background: var(--purple); }
.c-red .card-top { background: var(--red); }
.c-yellow .card-top { background: var(--yellow); }
.card-body { padding: .6rem .7rem; display: flex; gap: .6rem; }
.portrait { width: 56px; height: 72px; border-radius: 6px; background: linear-gradient(160deg, #2a3140, #1b2029); display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-weight: 700; color: var(--muted); border: 1px solid var(--line); }
.portrait img { width: 100%; height: 100%; object-fit: cover; border-radius: 6px; }
.card-main { display: flex; flex-direction: column; gap: .15rem; min-width: 0; flex: 1; }
.card-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { color: var(--muted); font-size: .8rem; }
.card-tags { display: flex; gap: .3rem; flex-wrap: wrap; font-size: .75rem; }
.tag { padding: .05rem .4rem; border-radius: 999px; border: 1px solid var(--line); }
.tag-color { border-color: currentColor; }
.c-purple .tag-color { color: var(--purple); }
.c-red .tag-color { color: var(--red); }
.c-yellow .tag-color { color: var(--yellow); }
.card-stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: .2rem; padding: 0 .7rem .6rem; font-size: .72rem; color: var(--muted); }
.card-stats div { display: flex; flex-direction: column; align-items: center; }
.card-stats b { color: var(--text); font-size: .85rem; }
.card-state { padding: .35rem .7rem; font-size: .8rem; border-top: 1px solid var(--line); color: var(--muted); }
.card[aria-pressed="true"] .card-state { color: #fff; background: var(--primary); }

.pager { display: flex; justify-content: center; gap: 1rem; align-items: center; margin-top: 1rem; }

/* ---------- modal / toast ---------- */
.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center; z-index: 40; padding: 1rem; }
.modal[hidden] { display: none; }
.modal-box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; max-width: 460px; width: 100%; }
.modal-box ul { padding-left: 1.2rem; }
.modal-box li { margin: .3rem 0; }
.modal-actions { display: flex; justify-content: flex-end; margin-top: 1rem; }
.success-detail div { display: flex; gap: .6rem; margin: .3rem 0; }
.success-detail dt { color: var(--muted); min-width: 6rem; }
.success-detail dd { margin: 0; font-weight: 600; word-break: break-all; }
.toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: #2b1e1e; border: 1px solid var(--danger); color: #fff; padding: .6rem 1rem; border-radius: 8px; z-index: 50; max-width: 90vw; }
.toast.ok { background: #1c2b1f; border-color: #4caf50; }

/* ---------- mobile ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: .6rem; }
  .left { position: static; max-height: none; display: none; }
  .left.open { display: flex; }
  .mobile-only { display: inline-block; }
  .summary { gap: .35rem; }
  .summary div { padding: .15rem .45rem; font-size: .85rem; }
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .filters { grid-template-columns: repeat(2, 1fr); }
}
