:root {
  color: #172233;
  background: #edf2f5;
  font-family: "PingFang SC", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: linear-gradient(145deg, #edf3f6, #f4f1e9); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.page-shell { display: grid; grid-template-columns: 270px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 20px; color: #f5f7f9; background: linear-gradient(180deg, #13374f, #0b2236); }
.brand-card { padding: 18px; border-radius: 16px; background: rgba(255,255,255,.08); }
.brand-card h1, .topbar h2, .panel h2, .panel h3 { margin: 6px 0 10px; }
.brand-card p:last-child { margin-bottom: 0; color: #bdd0dc; line-height: 1.65; }
.eyebrow { margin: 0; color: #9bb6c7; font-size: 11px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.game-list { margin-top: 18px; }
.game-item { width: 100%; padding: 13px; border: 1px solid #e7bd69; border-radius: 13px; color: #fff; text-align: left; background: rgba(230,184,91,.14); }
.game-item strong, .game-item small { display: block; }
.game-item small { margin-top: 4px; color: #c7d6df; }
.subnav { display: grid; gap: 6px; margin: 10px 0 18px 12px; padding-left: 12px; border-left: 1px solid rgba(255,255,255,.16); }
.subnav button { min-height: 38px; padding: 8px 11px; border: 0; border-radius: 9px; color: #bcd0dc; text-align: left; background: transparent; }
.subnav button:hover, .subnav button.active { color: #fff; background: rgba(255,255,255,.11); }
.side-note { display: grid; gap: 5px; padding: 13px; border-radius: 12px; color: #bfd0db; background: rgba(0,0,0,.14); font-size: 12px; }
.side-note strong { color: #fff; }

.content { min-width: 0; padding: 22px; }
.topbar { display: flex; justify-content: space-between; gap: 18px; padding: 22px; margin-bottom: 16px; border-radius: 18px; background: linear-gradient(135deg, #fff8e9, #fff, #e3edf2); box-shadow: 0 14px 40px rgba(22,42,58,.07); }
.topbar p:last-child { margin: 0; color: #687486; }
.connection { display: flex; align-items: center; gap: 12px; min-width: 260px; padding: 12px 14px; border-radius: 14px; background: rgba(255,255,255,.82); }
.connection i { width: 10px; height: 10px; border-radius: 50%; background: #e2a13f; box-shadow: 0 0 0 5px rgba(226,161,63,.17); }
.connection.ready i { background: #299369; box-shadow: 0 0 0 5px rgba(41,147,105,.17); }
.connection.error i { background: #bb4657; box-shadow: 0 0 0 5px rgba(187,70,87,.17); }
.connection div { display: grid; gap: 3px; }
.connection span { color: #6c7787; font-size: 12px; }

.panel { padding: 18px; margin-bottom: 16px; border: 1px solid rgba(208,219,228,.7); border-radius: 16px; background: #fff; box-shadow: 0 12px 36px rgba(21,39,54,.06); }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 13px; }
.login-panel { display: grid; grid-template-columns: .85fr 1.15fr; gap: 18px; }
.login-copy { padding: 20px; border-radius: 14px; color: #eef5f9; background: linear-gradient(150deg, #1a536d, #153448); }
.login-copy .eyebrow { color: #bcd5e2; }
.warning-copy { padding: 10px 12px; border-radius: 10px; color: #fff1bf; background: rgba(255,214,119,.13); line-height: 1.65; }
.login-form, .captcha-fields, .candidate-list { display: grid; gap: 10px; }

label { display: grid; gap: 6px; color: #465365; font-size: 13px; font-weight: 700; }
input, textarea { width: 100%; min-height: 42px; padding: 10px 11px; border: 1px solid #d4dee6; border-radius: 10px; color: #172233; background: #fbfdfe; outline: none; }
input:focus, textarea:focus { border-color: #3b7ca6; box-shadow: 0 0 0 3px rgba(59,124,166,.12); }
input[readonly] { color: #596779; background: #f3f6f8; }
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; line-height: 1.55; }
button { min-height: 38px; padding: 9px 13px; border: 1px solid #cfd9e2; border-radius: 10px; color: #243345; background: #fff; font-weight: 700; }
button:hover:not(:disabled) { border-color: #7a9bae; }
button:disabled { cursor: not-allowed; opacity: .58; }
button.primary { border-color: #0f7095; color: #fff; background: #0f7095; }
button.danger { border-color: #b84556; color: #fff; background: #b84556; }
.button-row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.button-row.compact { justify-content: flex-end; }
.remember-row { display: flex; align-items: center; gap: 9px; font-weight: 500; }
.remember-row input { width: 17px; min-height: 17px; }
.captcha-toolbar { display: flex; align-items: center; gap: 10px; }
.captcha-grid { display: grid; grid-template-columns: 190px 1fr; gap: 12px; }
.captcha-preview { display: grid; place-items: center; min-height: 126px; padding: 10px; border: 1px dashed #cbd7e0; border-radius: 12px; background: #f6f9fa; }
.captcha-preview img { max-width: 170px; max-height: 100px; }
.placeholder-box, .muted { color: #6c7889; }

.workspace-toolbar { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 10px; }
.summary-strip { display: grid; grid-template-columns: repeat(4, minmax(120px, 1fr)); gap: 8px; }
.summary-strip span { display: grid; gap: 4px; padding: 9px 11px; border-radius: 10px; background: #f5f8fa; }
.summary-strip small { color: #7c8795; }
.summary-strip strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.workspace-toolbar > .muted { grid-column: 1 / -1; font-size: 12px; }
.token-row { display: grid; grid-template-columns: minmax(180px,.35fr) minmax(320px,1fr) auto; align-items: end; gap: 10px; }
.token-row .wide { grid-column: auto; }

.preset-guide-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 10px; }
.preset-guide-grid article { display: grid; grid-template-columns: 130px 1fr; gap: 13px; min-height: 140px; padding: 12px; border: 1px solid #e0e6eb; border-radius: 13px; background: #fafcfd; }
.preset-guide-grid img { width: 130px; height: 110px; object-fit: contain; border-radius: 10px; background: #f2f6f8; }
.preset-guide-grid p { margin: 7px 0; color: #4f5d6d; line-height: 1.55; }
.preset-guide-grid small { color: #7b6535; }
.plain-explanation { border-left: 4px solid #d5a143; }
.plain-explanation p { margin-bottom: 0; line-height: 1.7; }

.candidate-layout { display: grid; grid-template-columns: 320px minmax(0,1fr); gap: 14px; }
.candidate-item { display: grid; gap: 6px; padding: 12px; border: 1px solid #dce4ea; text-align: left; background: #f9fbfc; }
.candidate-item.active { border-color: #bd8b2c; background: #fff6df; }
.candidate-item small { color: #687587; line-height: 1.45; }
.badge { justify-self: start; padding: 3px 7px; border-radius: 999px; color: #236c54; background: #e8f5ef; font-size: 11px; }
.badge.official { color: #79551b; background: #fff0c9; }
.candidate-detail { display: grid; grid-template-columns: 190px 1fr; gap: 16px; align-items: center; padding: 14px; border-radius: 13px; background: #f5f8fa; }
.candidate-detail img { width: 190px; height: 135px; object-fit: contain; border-radius: 11px; background: #fff; }
.candidate-detail p { line-height: 1.65; }
.lead { color: #22465d; font-weight: 700; }
.process-banner { padding: 10px 12px; margin-bottom: 12px; border-radius: 10px; color: #31596c; background: #eaf4f7; }
.process-banner.success { color: #226346; background: #e9f7ef; }
.process-banner.error { color: #8d2f40; background: #fbecee; }

.toolbar-row { display: flex; align-items: center; justify-content: flex-end; gap: 9px; flex-wrap: wrap; }
.segmented { display: flex; padding: 3px; border-radius: 999px; background: #edf2f5; }
.segmented button { min-height: 32px; border: 0; border-radius: 999px; background: transparent; }
.segmented button.active { color: #0f7095; background: #fff; box-shadow: 0 3px 10px rgba(20,40,56,.08); }
.table-editor { max-height: 680px; overflow: auto; border: 1px solid #dce5eb; border-radius: 12px; }
.table-editor table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.table-editor th, .table-editor td { padding: 10px; border-bottom: 1px solid #e7edf1; vertical-align: top; text-align: left; }
.table-editor th { position: sticky; top: 0; z-index: 1; background: #f1f5f7; }
.table-editor th:nth-child(1) { width: 36%; }
.table-editor th:nth-child(2) { width: 20%; }
.table-editor td p { margin: 5px 0 0; line-height: 1.5; }
.priority-row { background: #fff9e9; }
.priority-row code, .priority-row strong { color: #8c5f12; }
.undocumented-row { background: #fff0f1; }
.undocumented-row code, .undocumented-row strong { color: #a83447; }
.table-editor code, .code-block, .definition-grid code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.remote-meta { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; color: #5e6b7a; font-size: 12px; }
.code-block { overflow: auto; max-height: 500px; padding: 14px; border-radius: 12px; color: #eef4f8; background: #112332; line-height: 1.55; white-space: pre-wrap; overflow-wrap: anywhere; }

.definition-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 11px; }
.definition-grid article { display: grid; gap: 7px; padding: 14px; border: 1px solid #dfe7ec; border-radius: 12px; background: #f9fbfc; }
.definition-grid code { color: #0d6789; font-size: 12px; }
.definition-grid p { margin: 0; color: #596676; line-height: 1.65; }
.game-info-grid { display: grid; grid-template-columns: 1fr 240px; gap: 11px; }
.game-info-grid .wide { grid-column: 1 / -1; }
.readback-card { display: grid; gap: 6px; min-width: 0; padding: 10px 12px; border-radius: 11px; background: #f2f6f8; }
.readback-card small { color: #74808f; }
.readback-card strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

dialog { width: min(720px,calc(100% - 24px)); border: 0; border-radius: 17px; box-shadow: 0 26px 80px rgba(9,23,36,.3); }
dialog::backdrop { background: rgba(10,18,25,.5); }
.dialog-header { margin-bottom: 12px; }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 20; max-width: 480px; padding: 12px 14px; border-radius: 11px; color: #fff; background: #1c5369; box-shadow: 0 16px 40px rgba(18,36,50,.2); }
.toast.error { background: #a63f50; }

@media (max-width: 1120px) {
  .page-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .subnav { grid-template-columns: repeat(2,minmax(0,1fr)); margin-left: 0; border-left: 0; }
  .summary-strip, .preset-guide-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .login-panel, .candidate-layout { grid-template-columns: 1fr; }
  .token-row { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .content, .sidebar { padding: 14px; }
  .topbar, .panel-heading { flex-direction: column; }
  .connection { min-width: 0; width: 100%; }
  .subnav, .summary-strip, .preset-guide-grid, .definition-grid, .game-info-grid, .captcha-grid { grid-template-columns: 1fr; }
  .workspace-toolbar { grid-template-columns: 1fr; }
  .candidate-detail, .preset-guide-grid article { grid-template-columns: 1fr; }
  .candidate-detail img, .preset-guide-grid img { width: 100%; height: 120px; }
}
