:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --surface: #fff;
  --subtle: #eff1ee;
  --text: #192623;
  --muted: #4f605c;
  --line: #d8dfdb;
  --input-line: #788a84;
  --accent: #086654;
  --accent-hover: #054e40;
  --on-accent: #fff;
  --tint: #e6f3ed;
  --progress-track: #c6d7d0;
  --error: #912c27;
  --error-bg: #fbefed;
  --focus: #08755f;
  --radius: 16px;
  --header-height: 68px;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.55;
}

:root:lang(zh) {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei",
    "Noto Sans CJK SC", "WenQuanYi Micro Hei", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #151b19;
    --surface: #1d2522;
    --subtle: #27312d;
    --text: #edf3f0;
    --muted: #b0c0b9;
    --line: #384640;
    --input-line: #82978d;
    --accent: #81d7be;
    --accent-hover: #a5e6d3;
    --on-accent: #10251e;
    --tint: #213a31;
    --progress-track: #456057;
    --error: #ffb4ac;
    --error-bg: #3b2624;
    --focus: #8edfc6;
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #151b19;
  --surface: #1d2522;
  --subtle: #27312d;
  --text: #edf3f0;
  --muted: #b0c0b9;
  --line: #384640;
  --input-line: #82978d;
  --accent: #81d7be;
  --accent-hover: #a5e6d3;
  --on-accent: #10251e;
  --tint: #213a31;
  --progress-track: #456057;
  --error: #ffb4ac;
  --error-bg: #3b2624;
  --focus: #8edfc6;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-size: .9375rem;
}

a { color: var(--accent); text-underline-offset: .2em; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
:target { scroll-margin-top: calc(var(--header-height) + 16px); }

h1, h2, h3, p, dl, dd { margin: 0; }
p { color: var(--muted); }
h1, h2, h3 { line-height: 1.2; font-weight: 650; }
h1 { font-size: clamp(1.9rem, 3.2vw, 2.75rem); letter-spacing: -.045em; }
h2 { font-size: 1.12rem; letter-spacing: -.018em; }
h3 { font-size: 1rem; }
:lang(zh) :is(h1, h2, h3) { letter-spacing: 0; }
pre {
  padding: 14px;
  border-radius: 9px;
  margin: 0;
  overflow: auto;
  background: var(--subtle);
  color: var(--text);
  font-size: .8125rem;
}
pre:empty, p[role="status"]:empty { display: none; }
code { overflow-wrap: anywhere; }
.checksum { overflow-wrap: anywhere; }
.flow { display: grid; gap: 20px; }

.skip-link {
  position: fixed;
  inset: 12px auto auto 12px;
  z-index: 5;
  transform: translateY(-150%);
  background: var(--surface);
  padding: 9px 13px;
}
.skip-link:focus { transform: none; }

.topbar {
  position: sticky;
  z-index: 2;
  top: 0;
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px clamp(16px, 3vw, 36px);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.brand, .topbar-actions, .language-link {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand { text-decoration: none; color: var(--text); font-size: 1.15rem; font-weight: 700; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: 1.2rem;
  line-height: 1;
}
.brand-context {
  color: var(--muted);
  border-inline-start: 1px solid var(--line);
  padding-inline-start: 10px;
  font-size: .85rem;
  font-weight: 500;
}
.topbar-actions { flex-shrink: 0; }
.language-link { min-height: 44px; padding-inline: 8px; font-weight: 600; }
.theme-icon {
  position: relative;
  box-sizing: content-box;
  width: 13px;
  height: 13px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
  overflow: hidden;
}
.theme-icon::before {
  content: "";
  position: absolute;
  inset: 0 50% 0 0;
  background: currentColor;
}

.shell { display: flex; flex: 1 0 auto; min-width: 0; }
.sidebar {
  flex: 0 0 224px;
  align-self: stretch;
  padding: 34px 16px 24px;
  border-inline-end: 1px solid var(--line);
  background: var(--surface);
}
.site-nav {
  display: grid;
  gap: 5px;
}
.site-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
  padding: 8px 12px;
  border-radius: 9px;
  color: var(--muted);
  font-weight: 600;
  text-decoration: none;
}
.site-nav a:hover { background: var(--subtle); color: var(--text); }
.site-nav a[aria-current="page"] { background: var(--tint); color: var(--accent); }
.sidebar-account {
  margin: 26px 12px 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  overflow-wrap: anywhere;
  font-size: .8125rem;
  color: var(--muted);
}

.nav-icon {
  position: relative;
  display: inline-block;
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
}
.nav-icon::before, .nav-icon::after {
  content: "";
  position: absolute;
}
.icon-overview::before {
  inset: 2px;
  border: 1.5px solid currentColor;
  border-radius: 3px;
  background: linear-gradient(90deg, transparent 45%, currentColor 45% 55%, transparent 55%);
}
.icon-usage::before {
  inset: 2px;
  border: 1.5px solid currentColor;
  border-radius: 50%;
}
.icon-usage::after { inset: 5px 5px 8px 8px; border-left: 1.5px solid; border-bottom: 1.5px solid; }
.icon-plans::before { inset: 3px 1px; border: 1.5px solid; border-radius: 3px; }
.icon-plans::after { inset: 7px 1px auto; border-top: 1.5px solid; }
.icon-projects::before { inset: 5px 1px 2px; border: 1.5px solid; border-radius: 3px; }
.icon-projects::after { inset: 2px 9px 12px 3px; border: 1.5px solid; border-bottom: 0; border-radius: 3px 3px 0 0; }
.icon-devices::before { inset: 2px 2px 6px; border: 1.5px solid; border-radius: 3px; }
.icon-devices::after { inset: 14px 0 auto; border-bottom: 1.5px solid; }
.icon-account::before { inset: 1px 5px 9px; border: 1.5px solid; border-radius: 50%; }
.icon-account::after { inset: 10px 2px 1px; border: 1.5px solid; border-radius: 8px 8px 3px 3px; }

main {
  width: min(100%, 1180px);
  min-width: 0;
  margin-inline: auto;
  padding: clamp(28px, 4.8vw, 68px) clamp(20px, 5vw, 70px) 56px;
}
.page { gap: 24px; }
.page-heading { display: grid; gap: 8px; padding-bottom: 4px; }
.page-heading p { font-size: 1rem; }
#main[data-view="auth"] {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-block: 38px;
}
#main[data-view="guide"] #devices > :not(#gettingStarted) { display: none; }
#main[data-view="auth"] #operationResult { width: min(100%, 440px); }

.card {
  min-width: 0;
  padding: clamp(16px, 2.5vw, 26px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow-wrap: anywhere;
}
.card > :is(h2, h3) + *, .card > :is(p, form, pre) + :not(:empty) { margin-top: 12px; }
.card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-bottom: 14px;
}
.card-heading > div { min-width: 0; }
.card-heading h2 + p { margin-top: 4px; }
.card-heading:has(> button) { margin-top: -4px; }
.group-heading { margin-bottom: 12px; }
.overview-grid, .tier-grid {
  display: grid;
  gap: 14px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.plan-summary { background: var(--tint); }
.plan-name, .usage-number strong, .tier-number {
  color: var(--text);
  font-size: clamp(1.9rem, 3vw, 2.65rem);
  line-height: 1.07;
  font-weight: 650;
  letter-spacing: -.05em;
  font-variant-numeric: tabular-nums;
}
.plan-description { min-height: 1.5em; }
.text-action { font-size: .875rem; font-weight: 650; white-space: nowrap; }
.usage-number { margin-top: 20px; }
.usage-card progress {
  width: 100%;
  height: 10px;
  display: block;
  margin-block: 14px 10px;
  appearance: none;
  border: 0;
  border-radius: 12px;
  background: var(--progress-track);
  color: var(--accent);
}
.usage-card progress::-webkit-progress-bar { border-radius: inherit; background: var(--progress-track); }
.usage-card progress::-webkit-progress-value { border-radius: inherit; background: var(--accent); }
.usage-card progress::-moz-progress-bar { border-radius: inherit; background: var(--accent); }
.reset-line { font-size: .875rem; }
[data-usage-extra] { margin-top: 6px; }
.state-message { padding-top: 8px; }
.fact-list { display: grid; gap: 13px; }
.fact-list div { display: grid; gap: 2px 18px; grid-template-columns: minmax(130px, 1fr) 2fr; }
.fact-list dt { font-weight: 600; }
.fact-list dd { color: var(--muted); }

.destination {
  display: flex;
  gap: 13px;
  align-items: center;
  color: var(--text);
  text-decoration: none;
}
.destination:hover { border-color: var(--accent); }
.destination > span:nth-child(2) { display: grid; gap: 3px; }
.destination span span { color: var(--muted); font-size: .875rem; }
.destination .nav-icon, .empty-state .nav-icon { color: var(--accent); }
.arrow { margin-inline-start: auto; color: var(--accent); }

.tier-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.tier { display: grid; gap: 8px; }
.tier .tier-number { margin-top: 8px; }
.tier > p + :not(:empty) { margin: 0; }
.tier h3 { color: var(--accent); }
.tier-bar {
  position: relative;
  height: 5px;
  background: var(--progress-track);
  border-radius: 6px;
}
.tier-bar::before {
  content: "";
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}
.tier-bar[data-tier="1"]::before { width: 8.333%; }
.tier-bar[data-tier="4"]::before { width: 33.333%; }
#membershipPlans { display: grid; gap: 8px; }
#membershipPlans:not(:empty) { margin-block: 12px; }

.empty-state { display: grid; justify-items: center; text-align: center; gap: 10px; padding: 28px 0 18px; }
.empty-state > .nav-icon { transform: scale(1.25); margin: 6px; }
.empty-state p { max-width: 42ch; }
.project-list, .device-list { display: grid; gap: 12px; }
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px 18px;
  flex-wrap: wrap;
  padding: 14px;
  border-radius: 10px;
  border: 1px solid var(--line);
}
.project-list .list-item { align-items: start; }
.list-item div { min-width: 0; }
.list-item h3 + p, #releaseList article p { margin-top: 5px; }
.list-item .fact-list { width: 100%; padding-top: 8px; }
#releaseList article { margin-top: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; }
#deviceClientName:not(:empty) { margin-block: 10px; }
#deviceClientName + form:not([hidden]), #deviceApprove:not([hidden]) {
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
#revokeDevice { margin-top: 12px; }
#clientPanel p code { color: var(--text); }

form {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
}
form + form { margin-top: 12px; }
label {
  display: grid;
  flex: 1 1 180px;
  gap: 5px;
  font-size: .875rem;
  font-weight: 600;
  min-width: 0;
}
label:has(input[type="checkbox"]) {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  width: 100%;
  flex-basis: 100%;
}
input, select, textarea, button, .button { font: inherit; }
input:not([type="checkbox"]), select, textarea {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 8px 11px;
  border: 1px solid var(--input-line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
}
input[type="checkbox"] { accent-color: var(--accent); margin: 3px 0 0; min-width: 17px; min-height: 17px; }
textarea { resize: vertical; }
.wide { flex-basis: 100%; width: 100%; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

button, .button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 13px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  font-size: .875rem;
  font-weight: 650;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}
button:not(:disabled):hover, .button:hover { background: var(--accent-hover); color: var(--on-accent); }
button.secondary, .button.secondary {
  color: var(--text);
  background: var(--surface);
  border-color: var(--input-line);
}
button.secondary:not(:disabled):hover, .button.secondary:hover { color: var(--accent-hover); background: var(--subtle); }
button:disabled { opacity: .58; cursor: default; }
button[aria-busy="true"]::before {
  content: "";
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-inline-end-color: transparent;
  border-radius: 50%;
  animation: spin .75s linear infinite;
}
@keyframes spin { to { transform: rotate(1turn); } }

.auth-card { width: min(100%, 440px); padding: clamp(20px, 4vw, 36px); }
.auth-card h1 { font-size: clamp(1.65rem, 4vw, 2rem); }
.auth-card .auth-description { margin: 10px 0 24px; }
.auth-card form { display: grid; gap: 12px; }
.auth-card form + form { margin-top: 18px; }
.auth-card .button, .auth-card button { width: 100%; }
.auth-card .flow { gap: 14px; }
.auth-card .auth-footer { border-top: 1px solid var(--line); margin-top: 22px; padding-top: 15px; }
.auth-card .auth-help { margin-top: 8px; }
.auth-card :is(.auth-footer, .auth-help) { text-align: center; font-size: .875rem; }
.auth-card :is(.auth-footer, .auth-help) a { font-weight: 650; }
.divider { display: flex; gap: 10px; align-items: center; color: var(--muted); font-size: .8125rem; }
.divider::before, .divider::after { flex: 1; content: ""; height: 1px; background: var(--line); }

.disclosure { padding-block: 0; }
summary { cursor: pointer; font-weight: 650; }
.disclosure > summary { min-height: 46px; padding-block: 11px; }
.disclosure-body { border-top: 1px solid var(--line); padding-block: 16px; gap: 12px; }
.disclosure-body > button { justify-self: start; }
#operationResult { margin-top: 20px; }
#operationResult pre { margin-bottom: 12px; }
#gettingStarted nav, #gettingStarted details { margin-top: 12px; }
#gettingStarted pre { margin-block: 10px; }
#gettingStarted p:not(:first-child) { margin-block: 10px; }

.site-footer { padding: 14px clamp(18px, 3vw, 36px); border-top: 1px solid var(--line); font-size: .8125rem; }
.service-status { color: var(--muted); }
.service-status p { margin-block: 8px; }
#mode { margin-block: 5px; }
.session-loading { text-align: center; }
.callout, .inline-error {
  width: min(100%, 440px);
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--tint);
  color: var(--text);
  overflow-wrap: anywhere;
}
.session-error, .inline-error { background: var(--error-bg); color: var(--error); }
.session-error, .auth-intent { margin-bottom: 12px; }
.inline-error { margin-top: 8px; font-size: .875rem; }
.toast {
  position: fixed;
  z-index: 3;
  inset: auto 18px 18px auto;
  max-width: min(350px, calc(100% - 36px));
  pointer-events: none;
}
.toast:not(:empty) {
  padding: 11px 15px;
  border: 1px solid var(--input-line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
}

@media (max-width: 820px) {
  .shell { flex-direction: column; }
  .sidebar { flex: none; padding: 9px 16px; border-inline-end: 0; border-bottom: 1px solid var(--line); }
  .site-nav { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
  .site-nav a { justify-content: center; padding-inline: 4px; gap: 6px; }
  .sidebar-account { display: none; }
}

@media (max-width: 560px) {
  :root { --header-height: 60px; }
  main { padding: 24px 16px 32px; }
  .topbar-actions { gap: 4px; }
  .brand-context { display: none; }
  .site-nav a { font-size: .78rem; }
  .site-nav .nav-icon { transform: scale(.84); }
  .page { gap: 18px; }
  .overview-grid, .tier-grid { grid-template-columns: 1fr; gap: 10px; }
  .tier { grid-template-columns: 1fr auto; gap: 2px 8px; align-items: center; }
  .tier .tier-number { grid-column: 2; grid-row: 1 / 3; margin: 0; }
  .tier-bar { grid-column: 1 / -1; margin-top: 8px !important; }
  .fact-list div { grid-template-columns: 1fr; }
  #main[data-view="auth"] { padding-block: 24px; }
  #deviceReview { align-items: end; }
  #deviceReview label { flex-basis: 130px; }
  .card-heading { margin-bottom: 10px; }
  .usage-number { margin-top: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  button[aria-busy="true"]::before { animation: none; }
}

.guide-return { display: none; }
#main[data-view="guide"] .guide-return { display: inline-block; margin-bottom: 12px; }
.legacy-login { margin-top: 10px; color: var(--muted); font-size: .875rem; }
.auth-card #loginHint:not([hidden]), .auth-card #loginRestart:not([hidden]),
.auth-card #registerResend:not([hidden]) { margin-top: 12px; }
