:root {
      --bg: #f3f6fb;
      --panel: #ffffff;
      --panel2: #f1f6ff;
      --text: #15285f;
      --muted: #6b7895;
      --line: #c7dbff;
      --blue: #2f66ee;
      --blue2: #174cc7;
      --blueSoft: #e5efff;
      --green: #13a361;
      --greenSoft: #e3f8ed;
      --red: #dc2626;
      --redSoft: #fee2e2;
      --shadow: 0 12px 32px rgba(30, 64, 175, .09);
    }
    * { box-sizing: border-box; }
    [hidden] { display: none !important; }
    body {
      margin: 0;
      min-height: 100vh;
      font-family: -apple-system, BlinkMacSystemFont, "Yu Gothic UI", "Hiragino Sans", sans-serif;
      color: var(--text);
      background: linear-gradient(180deg, #f8faff 0%, var(--bg) 100%);
    }
    header {
      position: sticky;
      top: 0;
      z-index: 30;
      display: flex;
      align-items: center;
      justify-content: space-between;
      height: 66px;
      padding: 0 22px;
      background: rgba(255,255,255,.88);
      border-bottom: 1px solid var(--line);
      backdrop-filter: blur(16px);
      box-shadow: 0 1px 12px rgba(30, 64, 175, .05);
    }
    .headerActions { display: flex; align-items: center; gap: 10px; }
    .authUser {
      display: flex;
      align-items: center;
      gap: 8px;
      color: var(--text);
      font-size: 13px;
    }
    .authAvatar {
      width: 32px;
      height: 32px;
      flex: 0 0 32px;
      border-radius: 50%;
      object-fit: cover;
      border: 1px solid var(--line);
      background: #fff;
    }
    .authAvatarFallback {
      display: grid;
      place-items: center;
      color: #fff;
      background: var(--blue);
    }
    .headerLink {
      color: var(--text); text-decoration: none; border: 1px solid var(--line);
      border-radius: 6px; padding: 8px 11px; background: #fff; font-size: 13px;
    }
    .headerLink.loginAction {
      color: #fff;
      border-color: var(--blue);
      background: var(--blue);
    }
    .accountMode {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: 11px;
      margin-bottom: 16px;
      padding: 12px;
      border: 1px solid var(--line);
      border-radius: 8px;
      background: #f7f9fd;
    }
    .accountModeIcon {
      display: grid;
      place-items: center;
      width: 34px;
      height: 34px;
      flex: 0 0 34px;
      border-radius: 7px;
      color: #fff;
      background: var(--blue);
    }
    .modeIcon { width: 18px; height: 18px; }
    .savedIcon { display: none; }
    .accountMode strong,
    .accountMode span { display: block; }
    .accountModeContent { flex: 1 1 240px; min-width: 0; }
    .accountMode strong { font-size: 13px; }
    .accountMode div > span { margin-top: 3px; color: var(--muted); font-size: 11px; line-height: 1.45; }
    .accountMode.savedMode { border-color: #b9e5cf; background: #f0fbf5; }
    .accountMode.savedMode .accountModeIcon { background: var(--green); }
    .accountMode.savedMode .guestIcon { display: none; }
    .accountMode.savedMode .savedIcon { display: block; }
    .accountModeLogin {
      flex: 1 0 100%;
      margin-top: 2px;
      padding: 9px 12px;
      border-radius: 6px;
      color: #fff;
      background: #101114;
      text-align: center;
      text-decoration: none;
      font-size: 13px;
    }
    .accountModeLogin:hover { background: #27282c; }
    .accountMode.savedMode .accountModeLogin { display: none; }
    h1 { margin: 0; font-size: 22px; letter-spacing: .01em; }
    .shell {
      display: grid;
      grid-template-columns: 390px minmax(0, 1fr);
      gap: 18px;
      padding: 18px;
      height: calc(100vh - 102px);
    }
    .card {
      background: rgba(255,255,255,.86);
      border: 1px solid var(--line);
      border-radius: 8px;
      box-shadow: var(--shadow);
      backdrop-filter: blur(18px);
    }
    .siteFooter {
      display: flex;
      align-items: center;
      justify-content: center;
      height: 36px;
      color: var(--muted);
      gap: 12px;
      font-size: 14px;
      opacity: .48;
    }
    .siteFooter::before,
    .siteFooter::after {
      width: 52px;
      height: 1px;
      content: "";
      background: currentColor;
    }
    aside {
      padding: 18px;
      overflow: auto;
    }
    .content {
      min-width: 0;
      display: grid;
      grid-template-rows: auto auto auto minmax(0, 1fr) auto;
      overflow: hidden;
    }
    .topline {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 14px;
      padding: 16px 18px 10px;
    }
    .tabs {
      display: flex;
      gap: 8px;
      padding: 0 18px 12px;
      border-bottom: 1px solid var(--line);
    }
    .tab {
      border: 1px solid var(--line);
      background: var(--panel2);
      color: var(--muted);
      padding: 10px 14px;
      border-radius: 8px;
      font-weight: 600;
      cursor: pointer;
      transition: color .16s ease, background-color .16s ease, border-color .16s ease, transform .16s ease;
    }
    .tab.active {
      background: var(--blue);
      border-color: var(--blue);
      color: #fff;
      box-shadow: 0 6px 16px rgba(47,102,238,.22);
    }
    label { display: block; margin: 14px 0 7px; font-size: 13px; font-weight: 800; }
    input, select, textarea, button {
      font: inherit;
      border-radius: 10px;
      border: 1px solid var(--line);
    }
    input, select, textarea {
      width: 100%;
      padding: 10px 12px;
      background: #fff;
      color: var(--text);
      outline: none;
    }
    input:focus, select:focus, textarea:focus {
      border-color: var(--blue);
      box-shadow: 0 0 0 3px rgba(47,102,238,.12);
    }
    textarea { min-height: 84px; resize: vertical; }
    button {
      padding: 10px 14px;
      font-weight: 900;
      cursor: pointer;
      transition: transform .14s ease, box-shadow .14s ease, background-color .14s ease;
    }
    button:not(:disabled):hover { transform: translateY(-1px); box-shadow: 0 7px 18px rgba(30,64,175,.12); }
    button:not(:disabled):active { transform: translateY(1px) scale(.99); box-shadow: none; }
    button.primary {
      color: #fff;
      background: linear-gradient(135deg, var(--blue), var(--blue2));
      border-color: var(--blue);
    }
    button.soft { background: var(--blueSoft); color: var(--blue2); }
    button.danger { background: var(--redSoft); color: var(--red); border-color: #fecaca; }
    button:disabled { opacity: .45; cursor: not-allowed; }
    .row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
    .check {
      display: flex;
      align-items: center;
      gap: 8px;
      margin-top: 13px;
      font-weight: 800;
    }
    .check input { width: auto; }
    .hint {
      color: var(--muted);
      font-size: 13px;
      line-height: 1.45;
    }
    .guide {
      margin: 14px 18px 12px;
      padding: 14px 16px;
      border: 1px solid var(--line);
      border-radius: 12px;
      background: linear-gradient(135deg, rgba(238,245,255,.95), rgba(248,251,255,.78));
      line-height: 1.95;
    }
    .guide strong { display: block; margin-bottom: 6px; }
    .guide div { margin: 2px 0; }
    .badges { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
    .badge {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 6px 10px;
      border-radius: 999px;
      background: #eef2ff;
      color: var(--muted);
      font-size: 12px;
      font-weight: 900;
    }
    .badge.blue { background: var(--blue); color: #fff; }
    .badge.green { background: var(--green); color: #fff; }
    .guide .blueText { color: var(--blue); }
    .guide .greenText { color: var(--green); }
    .guide .orangeText { color: #d97706; }
    .guide .redText { color: var(--red); }
    .status {
      min-height: 46px;
      padding: 12px 18px;
      color: var(--blue2);
      font-weight: 900;
      border-top: 1px solid var(--line);
      background: #fff;
    }
    .tableWrap { min-width: 0; overflow: auto; background: #fff; }
    .tableWrap table { isolation: isolate; }
    .resultStack {
      display: grid;
      gap: 16px;
      padding: 16px;
      min-width: 100%;
    }
    .resultBlock {
      border: 1px solid var(--line);
      border-radius: 12px;
      overflow: auto;
      background: #fff;
    }
    .panelPad {
      padding: 16px;
      min-width: min(760px, 100%);
    }
    .formGrid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 12px;
      align-items: end;
    }
    .toolbar {
      display: flex;
      flex-wrap: wrap;
      gap: 10px;
      align-items: center;
      padding: 12px 14px;
      border-bottom: 1px solid var(--line);
      background: #fff;
    }
    .toolbar select {
      width: min(360px, 100%);
    }
    .toolbarActions {
      display: flex;
      gap: 8px;
      margin-left: auto;
    }
    .toolbarButton {
      min-width: 104px;
      min-height: 40px;
      padding: 8px 14px;
      border-radius: 8px;
      border-color: var(--line);
      background: var(--blueSoft);
      color: var(--blue2);
      font-weight: 400;
    }
    .sectionTitle {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      padding: 12px 14px;
      background: var(--panel2);
      border-bottom: 1px solid var(--line);
      font-weight: 900;
    }
    .tinyButton {
      padding: 6px 10px;
      border-radius: 8px;
      background: var(--blueSoft);
      color: var(--blue2);
      border-color: var(--line);
      font-size: 12px;
    }
    tr.activeSession td {
      background: var(--blueSoft);
      font-weight: 900;
    }
    table {
      width: max-content;
      min-width: 100%;
      border-collapse: separate;
      border-spacing: 0;
      font-size: 13px;
    }
    th, td {
      border-right: 1px solid #e5edf9;
      border-bottom: 1px solid #e5edf9;
      padding: 10px 12px;
      min-width: 136px;
      max-width: 320px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      text-align: left;
    }
    th {
      position: sticky;
      top: 0;
      z-index: 2;
      background: #f1f6ff;
      color: var(--text);
      user-select: none;
      box-shadow: inset 0 -1px 0 #dce7f7;
    }
    .selectable [data-col] {
      cursor: pointer;
      transition: background-color .14s ease, box-shadow .14s ease;
    }
    .selectable [data-col]:hover {
      box-shadow: inset 0 0 0 2px rgba(47,102,238,.32);
    }
    .rowActionHead,
    .rowActionCell {
      min-width: 76px;
      width: 76px;
      text-align: center;
      color: var(--muted);
      background: rgba(248, 251, 255, .92);
      position: relative;
      z-index: 1;
    }
    .rowActionCell {
      font-size: 12px;
      font-weight: 800;
      color: var(--red);
      background: rgba(254, 242, 242, .68);
      cursor: pointer;
    }
    .rowActionCell:hover {
      background: rgba(254, 226, 226, .98);
    }
    th.idCol, td.idCol {
      background: linear-gradient(135deg, rgba(47,102,238,.22), rgba(255,255,255,.58));
      box-shadow: inset 0 0 0 1px rgba(47,102,238,.18);
      backdrop-filter: blur(10px);
    }
    th.idCol {
      background: linear-gradient(135deg, rgba(47,102,238,.94), rgba(89,139,255,.76));
      color: #fff;
    }
    th.displayCol, td.displayCol {
      background: linear-gradient(135deg, rgba(19,163,97,.22), rgba(255,255,255,.62));
      box-shadow: inset 0 0 0 1px rgba(19,163,97,.18);
      backdrop-filter: blur(10px);
    }
    th.displayCol {
      background: linear-gradient(135deg, rgba(19,163,97,.94), rgba(69,206,135,.76));
      color: #fff;
    }
    th.specialCol, td.specialCol {
      background: linear-gradient(135deg, rgba(217,119,6,.22), rgba(255,255,255,.62));
      box-shadow: inset 0 0 0 1px rgba(217,119,6,.18);
      backdrop-filter: blur(10px);
    }
    th.specialCol {
      background: linear-gradient(135deg, rgba(217,119,6,.94), rgba(251,191,36,.76));
      color: #fff;
    }
    .selectable tbody tr { cursor: pointer; }
    .selectable tbody tr:hover td {
      box-shadow: inset 0 0 0 9999px rgba(47,102,238,.045);
    }
    table.selectable tbody tr.excludedRow > td,
    table.selectable tbody tr.excludedRow > td.idCol,
    table.selectable tbody tr.excludedRow > td.displayCol,
    table.selectable tbody tr.excludedRow > td.specialCol {
      background: rgba(254, 226, 226, .96) !important;
      color: #991b1b !important;
      text-decoration: line-through;
      box-shadow: inset 4px 0 0 #ef4444 !important;
    }
    table.selectable tbody tr.excludedRow > td.rowActionCell {
      background: #ef4444 !important;
      color: #fff !important;
      text-decoration: none;
    }
    table.selectable tbody tr.excludedRow:hover > td {
      box-shadow: inset 4px 0 0 #ef4444, inset 0 0 0 9999px rgba(239,68,68,.08) !important;
    }
    tr.winner td { background: #fff7ed; font-weight: 900; }
    .empty {
      height: 100%;
      min-height: 320px;
      display: grid;
      place-items: center;
      color: var(--muted);
      text-align: center;
      padding: 30px;
      font-weight: 800;
    }
    .miniStats {
      display: grid;
      grid-template-columns: repeat(3, minmax(0, 1fr));
      gap: 10px;
      margin-top: 14px;
    }
    .mini {
      padding: 12px;
      border-radius: 12px;
      background: var(--panel2);
      border: 1px solid var(--line);
    }
    .mini span { display: block; color: var(--muted); font-size: 12px; font-weight: 800; }
    .mini strong { display: block; margin-top: 4px; font-size: 20px; }
    .modalOverlay {
      position: fixed;
      inset: 0;
      z-index: 100;
      display: none;
      align-items: center;
      justify-content: center;
      padding: 24px;
      background: rgba(15, 23, 42, .30);
      backdrop-filter: blur(10px);
    }
    .modalOverlay.open { display: flex; }
    .modal {
      width: min(520px, 100%);
      padding: 20px;
      border-radius: 16px;
      background: #fff;
      border: 1px solid var(--line);
      box-shadow: 0 24px 70px rgba(15, 23, 42, .22);
    }
    .modal h2 { margin: 0 0 8px; font-size: 20px; }
    .modalActions { display: flex; gap: 10px; margin-top: 16px; }
    .modalActions button { flex: 1; }
    .historyModal {
      width: min(1100px, 96vw);
      max-height: 92vh;
      overflow: auto;
    }
    .historyControls {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 12px;
    }
    .historyGuide {
      display: flex;
      flex-wrap: wrap;
      gap: 8px;
      margin: 12px 0;
      font-size: 13px;
    }
    .historyGuide span {
      padding: 6px 10px;
      border-radius: 999px;
      color: #fff;
    }
    .syncWeightNote {
      margin: -2px 0 12px;
      padding: 10px 12px;
      border-left: 3px solid #8b5cf6;
      color: var(--muted);
      background: #f7f5ff;
      font-size: 13px;
      line-height: 1.65;
    }
    .historyIdLegend { background: var(--blue); }
    .historyJoinLegend { background: #7c3aed; }
    .historyWinLegend { background: var(--green); }
    .historyPreview {
      max-height: 360px;
      overflow: auto;
      border: 1px solid var(--line);
      border-radius: 10px;
    }
    .modalStatus {
      min-height: 42px;
      margin-top: 12px;
      padding: 10px 12px;
      border: 1px solid #bfdbfe;
      border-radius: 8px;
      color: var(--blue2);
      background: #eff6ff;
      line-height: 1.5;
      font-size: 13px;
    }
    .modalStatus.busy { background: #eef2ff; }
    .modalStatus.error { color: #b91c1c; border-color: #fecaca; background: #fff1f2; }
    .historyPreview th[data-history-col] { cursor: pointer; }
    .historyPreview th[data-history-col]:hover { box-shadow: inset 0 0 0 2px rgba(47,102,238,.35); }
    .historyPreview th.historyIdCol,
    .historyPreview td.historyIdCol {
      background: rgba(47,102,238,.16);
    }
    .historyPreview th.historyJoinCol,
    .historyPreview td.historyJoinCol {
      background: rgba(124,58,237,.16);
    }
    .historyPreview th.historyWinCol,
    .historyPreview td.historyWinCol {
      background: rgba(19,163,97,.16);
    }
    .historyPreview th.historyIdCol { background: var(--blue); color: #fff; }
    .historyPreview th.historyJoinCol { background: #7c3aed; color: #fff; }
    .historyPreview th.historyWinCol { background: var(--green); color: #fff; }
    .historyBatches {
      margin-top: 16px;
      border-top: 1px solid var(--line);
      padding-top: 12px;
    }
    .historyBatch {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      padding: 8px 0;
      border-bottom: 1px solid #e5edf9;
      font-size: 13px;
    }
    @media (max-width: 980px) {
      .shell { grid-template-columns: 1fr; height: auto; }
      .content { min-height: 640px; }
      .historyControls { grid-template-columns: 1fr; }
      .toolbarActions { width: 100%; margin-left: 0; }
      .toolbarButton { flex: 1; }
    }
