:root {
  --bg: #101112;
  --panel: #161718;
  --raised: #1e2021;
  --line: #2b2d2e;
  --control-border: #65696b;
  --text: #f2f1ed;
  --soft: #c4c6c3;
  --muted: #929596;
  --accent: #f0a065;
  --danger: #e4a08b;
  --focus: #f0a065;
  --on-primary: #101112;
  --primary: #f2f1ed;
  --scrim: rgba(0, 0, 0, 0.66);
  --sidebar-width: 220px;
  --header-height: 65px;
  --page-padding: 38px;
  --radius-control: 7px;
  --radius-card: 9px;
  --radius-panel: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Consolas, monospace;
}

:root[data-theme="light"] {
  --bg: #f4f4f1;
  --panel: #ffffff;
  --raised: #ebeae7;
  --line: #d8d6d1;
  --control-border: #8b8780;
  --text: #272623;
  --soft: #53514c;
  --muted: #66645f;
  --accent: #a45423;
  --danger: #a63e27;
  --focus: #a45423;
  --on-primary: #ffffff;
  --primary: #272623;
  --scrim: rgba(0, 0, 0, 0.42);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.42; cursor: not-allowed; }
a { color: inherit; text-decoration: none; }
h1, h2, p { margin: 0; }
h1 { font-size: 34px; font-weight: 500; line-height: 1.35; }
h2 { font-size: 18px; font-weight: 500; line-height: 1.45; }
:root:lang(zh-Hans) h1, :root:lang(zh-Hant) h1,
:root:lang(zh-Hans) h2, :root:lang(zh-Hant) h2 { letter-spacing: normal; }
.muted { color: var(--muted); }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
.skip-link {
  position: absolute;
  left: 16px;
  top: 8px;
  z-index: 50;
  transform: translateY(-140%);
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--control-border);
  border-radius: var(--radius-control);
  padding: 8px 12px;
}
.skip-link:focus { transform: none; }

button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

.app-header {
  position: fixed;
  z-index: 40;
  inset: 0 0 auto;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.header-left, .header-right { display: flex; align-items: center; gap: 12px; min-width: 0; }
.logo {
  color: var(--text);
  font-size: 27px;
  font-weight: 700;
  letter-spacing: -0.04em;
  padding: 0 8px;
}
.header-context { font-size: 12px; line-height: 1.5; color: var(--muted); }
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--soft);
}
.icon-button:hover { background: var(--raised); color: var(--text); }
.icon-button svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 1.5; fill: none; }
.preferences { display: flex; gap: 8px; }
.preference {
  border: 1px solid var(--control-border);
  border-radius: var(--radius-control);
  background: var(--panel);
  color: var(--soft);
  height: 34px;
  max-width: 134px;
  padding: 0 8px;
  font-size: 12px;
}
.who { font-size: 13px; color: var(--soft); white-space: nowrap; }

.sidebar {
  width: var(--sidebar-width);
  position: fixed;
  z-index: 30;
  left: 0;
  top: var(--header-height);
  bottom: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 24px 12px 16px;
  display: flex;
  flex-direction: column;
  transition: transform 160ms ease;
}
.sidebar-hidden .sidebar { transform: translateX(-100%); }
.sidebar-hidden .app-main { margin-left: 0; }
.signed-out .app-main { margin-left: 0; }
.app-main {
  margin: var(--header-height) 0 0 var(--sidebar-width);
  min-height: calc(100vh - var(--header-height));
}
.nav { display: flex; flex-direction: column; gap: 8px; flex: 1; min-height: 0; }
.nav-link[data-view="systemParameters"] { margin-top: auto; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 42px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--soft);
  text-align: left;
}
.nav-link:hover { background: var(--raised); color: var(--text); }
.nav-link[aria-current="page"] {
  color: var(--text);
  background: var(--raised);
  border-color: var(--accent);
}
.nav-link svg { width: 18px; height: 18px; stroke: currentColor; stroke-width: 1.5; fill: none; flex: none; }
.drawer-scrim { display: none; }

.page { max-width: 1380px; margin: 0 auto; padding: var(--page-padding); }
.auth-wrap { display: grid; place-items: center; min-height: calc(100vh - var(--header-height)); }
.auth-card {
  width: min(100%, 420px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  padding: 32px;
}
.auth-card h1 { margin-bottom: 12px; }
.auth-card .muted { margin-bottom: 24px; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--control-border);
  border-radius: var(--radius-control);
  color: var(--text);
  background: transparent;
}
.button:hover { background: var(--raised); }
.button.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 600; }
.button.compact { min-height: 34px; padding: 0 12px; font-size: 13px; }
.button.danger { color: var(--danger); border-color: var(--danger); }
.field input,
.field select,
.field textarea {
  width: 100%;
  color: var(--text);
  background: var(--raised);
  border: 1px solid var(--control-border);
  border-radius: var(--radius-control);
  font-size: 16px;
  line-height: 1.6;
}
.field input,
.field select {
  height: 42px;
  min-height: 42px;
  padding: 0 12px;
}
.field textarea {
  min-height: 96px;
  padding: 10px 12px;
  resize: vertical;
}
.field { display: grid; gap: 8px; margin-bottom: 16px; }
.field label { font-size: 13px; line-height: 1.4; color: var(--soft); }
.field-error { color: var(--danger); font-size: 13px; min-height: 1.5em; }
.toolbar { display: flex; align-items: flex-end; flex-wrap: wrap; gap: 12px; margin: 24px 0; }
.toolbar .field { margin: 0; min-width: min(100%, 180px); }
.grow { flex: 1; min-width: min(100%, 180px); }

.detail-grid { display: grid; grid-template-columns: minmax(140px, 180px) 1fr; gap: 8px 16px; margin-top: 16px; }
.detail-grid dt { color: var(--soft); font-size: 13px; line-height: 1.4; }
.detail-grid dd { margin: 0; }
.facts { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.fact {
  flex: 1 1 160px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--raised);
}
.fact span { display: block; color: var(--soft); font-size: 12px; line-height: 1.4; }
.fact strong { display: block; margin-top: 4px; font-size: 14px; font-weight: 500; line-height: 1.45; word-break: break-word; }
.method-list { margin: 0; padding: 0; list-style: none; }
.method-list li + li { margin-top: 4px; }
#attribution h2, #refunds h2 { margin: 28px 0 8px; }
#refunds .toolbar { margin-bottom: 8px; }
#refunds .pager { display: flex; align-items: center; gap: 12px; margin: 12px 0; }
#refunds .pager span { color: var(--soft); font-size: 14px; }
#refunds .refund-orders { display: grid; gap: 16px; margin-top: 16px; }
#refunds .refund-order {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}
#refunds .refund-order header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
#refunds .refund-order .order-no { display: block; font-weight: 600; }
#refunds .refund-order .pi { display: block; margin-top: 4px; color: var(--soft); font-size: 12px; word-break: break-all; }
#refunds .refund-order .pill {
  display: inline-block;
  margin: 12px 0 0;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--raised);
  color: var(--text);
  font-size: 12px;
}
#refunds .refund-order .pill.no { color: var(--danger); }
#refunds .refund-order dl { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 16px; margin: 12px 0 0; }
#refunds .refund-order dt { color: var(--soft); font-size: 12px; }
#refunds .refund-order dd { margin: 4px 0 0; }
#refunds .refund-order .wide { grid-column: 1 / -1; padding: 10px 12px; border-radius: 8px; background: var(--raised); }
#refunds .refund-order form { margin-top: 16px; }
#refunds .refund-feedback { margin: 12px 0 0; font-size: 14px; line-height: 1.5; }
#refunds .refund-feedback.ok { color: var(--text); }
#refunds .refund-feedback.no { color: var(--danger); }
#refunds .recorded { margin-top: 12px; }
#refundConfirmBody { white-space: pre-line; }
#refunds .refund-note { margin: 12px 0 0; color: var(--soft); }
@media (max-width: 720px) {
  #refunds .refund-order dl { grid-template-columns: 1fr; }
}
#attribution .cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 16px 0; }
#attribution .table-wrap + .table-wrap { margin-top: 12px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-card); padding: 16px; }
.card .muted { font-size: 12px; line-height: 1.5; }
.plan-list {
  border: 0;
  margin: 16px 0 0;
  padding: 0;
  min-inline-size: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.plan-list .card:first-child { grid-column: 1 / -1; }
.plan-list h2 { margin: 0 0 12px; font-size: 16px; }
.plan-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 16px; }
.plan-grid .field { margin: 0; }
.plan-grid .plan-span { grid-column: 1 / -1; margin: 0; }
.system-parameter-layout {
  display: grid;
  grid-template-columns: minmax(190px, 220px) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  margin-top: 16px;
}
.system-parameter-menu {
  display: grid;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  background: var(--panel);
}
.system-parameter-menu-item {
  display: flex;
  align-items: center;
  min-height: 42px;
  padding: 9px 12px;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  background: transparent;
  color: var(--soft);
  font: inherit;
  line-height: 1.4;
  text-align: left;
  text-decoration: none;
}
.system-parameter-menu-item:hover { background: var(--raised); color: var(--text); }
.system-parameter-menu-item[aria-current="page"] {
  border-color: var(--accent);
  background: var(--raised);
  color: var(--text);
}
.system-parameter-content { min-width: 0; }
.system-parameter-card h2 { margin: 0 0 8px; font-size: 18px; }
.system-parameter-card > .muted + .muted { margin-top: 4px; }
.system-parameter-fields { min-inline-size: 0; margin: 20px 0 0; padding: 0; border: 0; }
.card strong { display: block; margin-top: 8px; font-size: 24px; font-weight: 500; line-height: 1.35; }
.overview-board {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.overview-group h2 { margin: 0 0 12px; font-size: 16px; }
.overview-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(108px, 1fr));
  gap: 12px 16px;
  margin: 0;
}
.overview-metrics dt { color: var(--soft); font-size: 12px; line-height: 1.4; }
.overview-metrics dd { margin: 4px 0 0; font-size: 22px; font-weight: 500; line-height: 1.3; }
.overview-group .muted { margin: 12px 0 0; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius-card); background: var(--panel); }
table { width: 100%; border-collapse: collapse; }
th, td { border-bottom: 1px solid var(--line); text-align: left; padding: 12px 16px; font-size: 14px; vertical-align: middle; }
th { color: var(--soft); font-size: 13px; font-weight: 500; }
tr:last-child td { border-bottom: 0; }
.mono { font-family: var(--mono); font-size: 12px; }
.empty-state {
  text-align: center;
  padding: 48px 24px;
  margin-top: 16px;
  border: 1px dashed var(--control-border);
  border-radius: var(--radius-panel);
  color: var(--muted);
}
dialog {
  width: min(100% - 32px, 440px);
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--panel);
  color: var(--text);
  padding: 24px;
}
dialog::backdrop { background: var(--scrim); }
#web-version-dialog {
  position: fixed;
  inset: auto 24px 24px auto;
  margin: 0;
  width: min(360px, calc(100vw - 48px));
  height: fit-content;
  max-height: none;
}
#web-version-dialog::backdrop { background: transparent; backdrop-filter: none; }
#web-version-dialog h2 { font-size: 16px; line-height: 1.45; }
#web-version-dialog .dialog-actions { margin-top: 16px; }
dialog p { margin: 12px 0 24px; color: var(--soft); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

@media (min-width: 1600px) {
  :root { --sidebar-width: 236px; --page-padding: 46px; }
}
@media (max-width: 1180px) {
  :root { --sidebar-width: 204px; --page-padding: 29px; }
}
@media (max-width: 1100px) {
  .plan-list { grid-template-columns: 1fr; }
  .plan-list .card:first-child { grid-column: auto; }
}
@media (max-width: 980px) {
  :root { --sidebar-width: 190px; --page-padding: 25px; }
  .header-context, .who { display: none; }
}
@media (max-width: 760px) {
  :root { --header-height: 60px; --sidebar-width: 280px; --page-padding: 20px; }
  .overview-board { grid-template-columns: 1fr; }
  .system-parameter-layout { grid-template-columns: 1fr; }
  .system-parameter-menu-item { min-height: 44px; }
  h1 { font-size: 28px; }
  #web-version-dialog { right: 16px; bottom: 16px; left: 16px; width: auto; }
  .app-header { padding: 0 12px; }
  .app-main { margin-left: 0; }
  .sidebar { width: min(280px, 85vw); transform: translateX(-100%); z-index: 45; }
  .drawer-open .sidebar { transform: translateX(0); }
  .drawer-open .drawer-scrim { display: block; position: fixed; inset: var(--header-height) 0 0; background: var(--scrim); z-index: 44; }
  .preference { max-width: 108px; }
  .button, .field input, .field select { height: 44px; min-height: 44px; }
}
@media (max-width: 600px) {
  .plan-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}
.editor-toolbar { border-radius: 7px 7px 0 0; background: var(--panel); border-color: var(--control-border); }
.editor-toolbar button { color: var(--text) !important; }
.editor-toolbar button:hover, .editor-toolbar button.active { background: var(--bg); border-color: var(--control-border); }
.editor-toolbar i.separator { border-left-color: var(--line); border-right-color: transparent; }
.EasyMDEContainer .CodeMirror {
  background: var(--raised);
  color: var(--text);
  border-color: var(--control-border);
  border-radius: 0 0 7px 7px;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  min-height: 280px;
}
.CodeMirror-cursor { border-left-color: var(--text) !important; }
.editor-preview, .editor-preview-side { background: var(--panel); color: var(--text); }
.editor-preview-side { border-color: var(--control-border); }
