/* 承天之弈 · 授权页与开发者平台 —— Material Design 3
   令牌来自 md3-tokens.css（HCT 动态配色、字阶、形状、弹簧动效），深浅色跟随系统。
   两个页面共用这里的组件：按钮、文本框、卡片、纸片、标签页、对话框、提示条。 */

*, *::before, *::after { box-sizing: border-box; }
html { background: var(--md-sys-color-surface-container); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--md-sys-color-surface-container);
  color: var(--md-sys-color-on-surface);
  font: var(--md-sys-typescale-body-medium);
  letter-spacing: var(--md-sys-typescale-body-medium-tracking);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p { margin: 0; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--md-sys-color-primary); }
[hidden] { display: none !important; }
:focus { outline: none; }
:focus-visible { outline: 3px solid var(--md-sys-color-secondary); outline-offset: 2px; }
::selection { background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); }
code, pre, .op-mono { font-family: var(--md-ref-typeface-mono); }

.md-icon { width: 24px; height: 24px; flex: none; fill: currentColor; }

/* ---- 按钮 ---- */
.md-button {
  --bg: transparent;
  --fg: var(--md-sys-color-primary);
  --outline: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 24px;
  border: 1px solid var(--outline);
  border-radius: var(--md-sys-shape-corner-full);
  background: var(--bg);
  color: var(--fg);
  font: var(--md-sys-typescale-label-large);
  letter-spacing: var(--md-sys-typescale-label-large-tracking);
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: border-radius var(--md-sys-motion-spring-fast-spatial-duration) var(--md-sys-motion-spring-fast-spatial), background-color var(--md-sys-motion-spring-fast-effects-duration) var(--md-sys-motion-spring-effects);
}
.md-button .md-icon { width: 18px; height: 18px; margin-left: -8px; }
.md-button:hover { background-color: color-mix(in srgb, var(--fg) 8%, var(--bg)); }
.md-button:active { background-color: color-mix(in srgb, var(--fg) 12%, var(--bg)); border-radius: var(--md-sys-shape-corner-small); }
.md-button:disabled { --bg: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent); --fg: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent); --outline: transparent; cursor: default; }
.md-button--filled { --bg: var(--md-sys-color-primary); --fg: var(--md-sys-color-on-primary); }
.md-button--tonal { --bg: var(--md-sys-color-secondary-container); --fg: var(--md-sys-color-on-secondary-container); }
.md-button--outlined { --outline: var(--md-sys-color-outline-variant); }
.md-button--text { padding: 0 12px; }
.md-button--large { min-height: 56px; padding: 0 28px; font: var(--md-sys-typescale-title-medium); border-radius: var(--md-sys-shape-corner-large); }
.md-button.is-danger { --fg: var(--md-sys-color-error); }
.md-button--filled.is-danger { --bg: var(--md-sys-color-error); --fg: var(--md-sys-color-on-error); }

.md-icon-button {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: var(--md-sys-shape-corner-full);
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  text-decoration: none;
  cursor: pointer;
  transition: border-radius var(--md-sys-motion-spring-fast-spatial-duration) var(--md-sys-motion-spring-fast-spatial);
}
.md-icon-button:hover { background: color-mix(in srgb, var(--md-sys-color-on-surface-variant) 8%, transparent); }
.md-icon-button:active { background: color-mix(in srgb, var(--md-sys-color-on-surface-variant) 12%, transparent); border-radius: var(--md-sys-shape-corner-medium); }
.md-icon-button .md-icon { width: 20px; height: 20px; }

/* ---- 纸片 ---- */
.md-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  padding: 0 12px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-small);
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-label-medium);
  white-space: nowrap;
}
.md-chip .md-icon { width: 16px; height: 16px; }
.md-chip--success { border-color: transparent; background: color-mix(in srgb, var(--md-chart-3) 18%, transparent); color: var(--md-sys-color-on-surface); }
.md-chip--error { border-color: transparent; background: var(--md-sys-color-error-container); color: var(--md-sys-color-on-error-container); }
.md-chip--tonal { border-color: transparent; background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }

/* ---- 文本框（填充式） ---- */
.md-field { display: grid; gap: 4px; }
.md-field > span { color: var(--md-sys-color-on-surface-variant); font: var(--md-sys-typescale-body-small); }
.md-field input,
.md-field textarea {
  width: 100%;
  min-height: 52px;
  padding: 14px 16px;
  border: 0;
  border-bottom: 1px solid var(--md-sys-color-on-surface-variant);
  border-radius: var(--md-sys-shape-corner-extra-small) var(--md-sys-shape-corner-extra-small) 0 0;
  background: var(--md-sys-color-surface-container-highest);
  font: var(--md-sys-typescale-body-large);
}
.md-field textarea { min-height: 96px; resize: vertical; font-family: var(--md-ref-typeface-mono); font-size: 14px; }
.md-field input:focus,
.md-field textarea:focus { border-bottom: 2px solid var(--md-sys-color-primary); padding-bottom: 13px; outline: none; }
.md-field small { color: var(--md-sys-color-on-surface-variant); font: var(--md-sys-typescale-body-small); }
.op-fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.md-field.is-required > span::after { content: " *"; color: var(--md-sys-color-error); }

.md-segmented { display: inline-flex; justify-self: start; border: 1px solid var(--md-sys-color-outline); border-radius: var(--md-sys-shape-corner-full); overflow: hidden; }
.md-segmented > button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-left: 1px solid var(--md-sys-color-outline);
  background: transparent;
  font: var(--md-sys-typescale-label-large);
  cursor: pointer;
}
.md-segmented > button:first-child { border-left: 0; }
.md-segmented > button[aria-checked="true"] { background: var(--md-sys-color-secondary-container); color: var(--md-sys-color-on-secondary-container); }
.md-segmented > button[aria-checked="true"]::before { content: ""; width: 10px; height: 5px; margin-top: -3px; border: solid currentColor; border-width: 0 0 2px 2px; transform: rotate(-45deg); }
.md-segmented > button:disabled { opacity: 0.38; cursor: default; }

.md-check { display: flex; align-items: flex-start; gap: 12px; padding: 8px 0; cursor: pointer; }
.md-check input { width: 18px; height: 18px; margin: 3px 0 0; accent-color: var(--md-sys-color-primary); }
.md-check strong { display: block; font: var(--md-sys-typescale-body-large); }
.md-check small { color: var(--md-sys-color-on-surface-variant); font: var(--md-sys-typescale-body-small); }

/* ---- 对话框与提示条 ---- */
.md-dialog {
  width: min(560px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  padding: 0;
  border: 0;
  border-radius: var(--md-sys-shape-corner-extra-large);
  background: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  box-shadow: var(--md-sys-elevation-level3);
}
.md-dialog::backdrop { background: color-mix(in srgb, var(--md-sys-color-scrim) 40%, transparent); }
.md-dialog form { display: flex; flex-direction: column; max-height: inherit; margin: 0; }
.md-dialog__head { padding: 24px 24px 16px; }
.md-dialog__head h2 { font: var(--md-sys-typescale-headline-small); }
.md-dialog__head p { margin-top: 8px; color: var(--md-sys-color-on-surface-variant); }
.md-dialog__body { display: grid; gap: 16px; padding: 0 24px 8px; overflow-y: auto; }
.md-dialog__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 16px 24px 24px; }
.md-dialog__error { padding: 12px 16px; border-radius: var(--md-sys-shape-corner-medium); background: var(--md-sys-color-error-container); color: var(--md-sys-color-on-error-container); }

.md-snackbar {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 100;
  max-width: min(560px, calc(100vw - 32px));
  padding: 14px 16px;
  border-radius: var(--md-sys-shape-corner-extra-small);
  background: var(--md-sys-color-inverse-surface);
  color: var(--md-sys-color-inverse-on-surface);
  box-shadow: var(--md-sys-elevation-level3);
  transform: translateX(-50%);
}

/* ---- 应用头像：取名字第一个字，色调容器 ---- */
.op-app-mark {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 48px;
  height: 48px;
  border-radius: var(--md-sys-shape-corner-large);
  background: var(--md-sys-color-tertiary-container);
  color: var(--md-sys-color-on-tertiary-container);
  font: 600 22px/1 var(--md-ref-typeface-brand);
}
.op-app-mark--site { background: var(--md-sys-color-primary-container); color: var(--md-sys-color-on-primary-container); font-family: "Songti SC", "Noto Serif SC", serif; }
.op-avatar {
  display: inline-grid;
  place-items: center;
  flex: none;
  width: 40px;
  height: 40px;
  overflow: hidden;
  border-radius: 50%;
  background: var(--md-sys-color-secondary-container);
  color: var(--md-sys-color-on-secondary-container);
  font: var(--md-sys-typescale-title-medium);
}
.op-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ============ 授权同意页 ============ */
.op-consent-page { display: grid; place-items: start center; min-height: 100dvh; padding: 48px 16px; }
.op-consent {
  width: min(460px, 100%);
  padding: 32px 28px 24px;
  border-radius: var(--md-sys-shape-corner-extra-large);
  background: var(--md-sys-color-surface-container-lowest);
  box-shadow: var(--md-sys-elevation-level1);
}
.op-consent__brand { display: flex; align-items: center; gap: 8px; color: var(--md-sys-color-on-surface-variant); font: var(--md-sys-typescale-label-large); }
.op-consent__brand .md-icon { width: 18px; height: 18px; color: var(--md-sys-color-primary); }
.op-consent__marks { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 28px 0 20px; }
.op-consent__marks .op-app-mark { width: 64px; height: 64px; border-radius: var(--md-sys-shape-corner-extra-large); font-size: 28px; }
.op-consent__link { display: inline-flex; gap: 4px; color: var(--md-sys-color-outline); }
.op-consent__link i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.op-consent h1 { font: var(--md-sys-typescale-headline-small); text-align: center; text-wrap: balance; }
.op-consent__dev { margin-top: 8px; color: var(--md-sys-color-on-surface-variant); text-align: center; }
.op-consent__desc { margin-top: 12px; color: var(--md-sys-color-on-surface-variant); text-align: center; font: var(--md-sys-typescale-body-small); }
.op-consent__account {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 24px 0 8px;
  padding: 12px 12px 12px 16px;
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: var(--md-sys-shape-corner-full);
}
.op-consent__account > span:nth-child(2) { flex: 1; min-width: 0; }
.op-consent__account strong { display: block; overflow: hidden; font: var(--md-sys-typescale-title-small); white-space: nowrap; text-overflow: ellipsis; }
.op-consent__account small { color: var(--md-sys-color-on-surface-variant); font: var(--md-sys-typescale-body-small); }
.op-consent__section { margin-top: 20px; color: var(--md-sys-color-on-surface-variant); font: var(--md-sys-typescale-title-small); }
.op-scope-list { display: grid; gap: 4px; margin: 8px 0 0; padding: 0; list-style: none; }
.op-scope-list li { display: flex; align-items: center; gap: 16px; min-height: 56px; padding: 8px 4px; }
.op-scope-list li + li { border-top: 1px solid var(--md-sys-color-surface-variant); }
.op-scope-list .op-scope-icon { display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 50%; background: var(--md-sys-color-surface-container-high); color: var(--md-sys-color-primary); }
.op-scope-list .op-scope-icon .md-icon { width: 20px; height: 20px; }
.op-scope-list span:nth-child(2) { flex: 1; font: var(--md-sys-typescale-body-large); }
.op-consent__notes { display: grid; gap: 10px; margin-top: 20px; padding: 16px; border-radius: var(--md-sys-shape-corner-large); background: var(--md-sys-color-surface-container); color: var(--md-sys-color-on-surface-variant); font: var(--md-sys-typescale-body-small); }
.op-consent__notes p { display: flex; gap: 10px; }
.op-consent__notes .md-icon { width: 18px; height: 18px; color: var(--md-sys-color-on-surface-variant); }
.op-consent__notes strong { color: var(--md-sys-color-on-surface); font-weight: 500; word-break: break-all; }
.op-consent__actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 24px; }
.op-consent__actions .md-button { min-height: 48px; }
.op-consent__footer { margin-top: 20px; color: var(--md-sys-color-on-surface-variant); text-align: center; font: var(--md-sys-typescale-body-small); }
.op-consent__state { display: grid; justify-items: center; gap: 12px; padding: 32px 0 8px; text-align: center; }
.op-consent__state .md-icon { width: 40px; height: 40px; color: var(--md-sys-color-primary); }
.op-consent__state.is-error .md-icon { color: var(--md-sys-color-error); }
.op-consent__state h1 { font: var(--md-sys-typescale-title-large); }
.op-consent__state p { color: var(--md-sys-color-on-surface-variant); }
@media (max-width: 480px) {
  .op-consent-page { padding: 16px; }
  .op-consent { padding: 24px 20px 20px; }
}

/* ============ 开发者平台 ============ */
.op-app { display: grid; grid-template-rows: auto auto minmax(0, 1fr); min-height: 100dvh; }
.op-topbar { display: flex; align-items: center; gap: 4px; min-height: 64px; padding: 0 12px 0 8px; }
.op-topbar h1 { flex: 1; padding-left: 8px; font: var(--md-sys-typescale-title-large); }
.op-topbar .op-avatar { width: 32px; height: 32px; font: var(--md-sys-typescale-label-large); }
.op-tabs { display: flex; gap: 0; padding: 0 16px; border-bottom: 1px solid var(--md-sys-color-surface-variant); overflow-x: auto; scrollbar-width: none; }
.op-tabs > button {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border: 0;
  background: none;
  color: var(--md-sys-color-on-surface-variant);
  font: var(--md-sys-typescale-title-small);
  white-space: nowrap;
  cursor: pointer;
}
.op-tabs > button .md-icon { width: 20px; height: 20px; }
.op-tabs > button:hover { background: color-mix(in srgb, var(--md-sys-color-on-surface) 8%, transparent); }
.op-tabs > button[aria-selected="true"] { color: var(--md-sys-color-primary); }
.op-tabs > button[aria-selected="true"]::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: 0; height: 3px; border-radius: 3px 3px 0 0; background: var(--md-sys-color-primary); }
.op-main { width: min(1040px, 100%); margin: 0 auto; padding: 24px 16px 96px; }
.op-panel-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.op-panel-head h2 { font: var(--md-sys-typescale-headline-small); }
.op-panel-head p { margin-top: 4px; color: var(--md-sys-color-on-surface-variant); }

.op-card-list { display: grid; gap: 16px; }
.op-card {
  display: grid;
  gap: 16px;
  padding: 20px 20px 16px;
  border-radius: var(--md-sys-shape-corner-extra-large);
  background: var(--md-sys-color-surface-container-lowest);
}
.op-card.is-suspended { outline: 1px solid var(--md-sys-color-error); }
.op-card__head { display: flex; align-items: flex-start; gap: 16px; }
.op-card__title { flex: 1; min-width: 0; }
.op-card__title h3 { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font: var(--md-sys-typescale-title-large); }
.op-card__title p { margin-top: 4px; color: var(--md-sys-color-on-surface-variant); }
.op-card__meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 24px; }
.op-card__meta dt { color: var(--md-sys-color-on-surface-variant); font: var(--md-sys-typescale-label-medium); }
.op-card__meta dd { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 4px 0 0; min-width: 0; font: var(--md-sys-typescale-body-medium); }
.op-card__meta dd code { overflow-wrap: anywhere; font-size: 13px; }
.op-card__meta dd .md-icon-button { flex: none; width: 32px; height: 32px; }
.op-card__meta dd:has(> .md-icon-button) { flex-wrap: nowrap; }
.op-card__meta ul { display: grid; gap: 2px; margin: 0; padding: 0; list-style: none; }
.op-card__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding-top: 12px; border-top: 1px solid var(--md-sys-color-surface-variant); }
.op-card__notice { padding: 10px 14px; border-radius: var(--md-sys-shape-corner-medium); background: var(--md-sys-color-error-container); color: var(--md-sys-color-on-error-container); }

.op-empty { display: grid; justify-items: center; gap: 12px; padding: 56px 24px; border-radius: var(--md-sys-shape-corner-extra-large); background: var(--md-sys-color-surface-container-lowest); text-align: center; }
.op-empty .md-icon { width: 48px; height: 48px; color: var(--md-sys-color-primary); }
.op-empty h3 { font: var(--md-sys-typescale-title-large); }
.op-empty p { max-width: 420px; color: var(--md-sys-color-on-surface-variant); }

.op-secret {
  display: grid;
  gap: 12px;
  padding: 16px;
  border-radius: var(--md-sys-shape-corner-large);
  background: var(--md-sys-color-surface-container);
}
.op-secret > div { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; }
.op-secret dt { grid-column: 1 / -1; color: var(--md-sys-color-on-surface-variant); font: var(--md-sys-typescale-label-medium); }
.op-secret code { overflow-wrap: anywhere; font-size: 14px; }
.op-secret-warning { display: flex; gap: 10px; padding: 12px 16px; border-radius: var(--md-sys-shape-corner-medium); background: var(--md-sys-color-tertiary-container); color: var(--md-sys-color-on-tertiary-container); }
.op-secret-warning .md-icon { width: 20px; height: 20px; }

/* 接入文档 */
.op-docs { display: grid; gap: 16px; }
.op-docs section { padding: 24px; border-radius: var(--md-sys-shape-corner-extra-large); background: var(--md-sys-color-surface-container-lowest); }
.op-docs h3 { margin-bottom: 12px; font: var(--md-sys-typescale-title-large); }
.op-docs h4 { margin: 20px 0 8px; font: var(--md-sys-typescale-title-medium); }
.op-docs p, .op-docs li { line-height: 1.7; }
.op-docs p + p { margin-top: 8px; }
.op-docs ol, .op-docs ul { margin: 8px 0; padding-left: 22px; }
.op-docs pre {
  margin: 12px 0;
  padding: 16px;
  overflow-x: auto;
  border-radius: var(--md-sys-shape-corner-medium);
  background: var(--md-sys-color-surface-container-highest);
  font-size: 13px;
  line-height: 1.6;
}
.op-docs :not(pre) > code { padding: 1px 6px; border-radius: 4px; background: var(--md-sys-color-surface-container-high); font-size: 13px; }
.op-docs table { width: 100%; margin: 12px 0; border-collapse: collapse; }
.op-docs th, .op-docs td { padding: 10px 12px; border-bottom: 1px solid var(--md-sys-color-surface-variant); text-align: left; vertical-align: top; }
.op-docs th { color: var(--md-sys-color-on-surface-variant); font: var(--md-sys-typescale-label-large); }
.op-docs .op-table-wrap { overflow-x: auto; }

@media (max-width: 600px) {
  .op-main { padding: 16px 16px 96px; }
  .op-card { padding: 16px; }
  .op-card__head .op-app-mark { width: 40px; height: 40px; font-size: 18px; }
  .op-card__actions .md-button { flex: 1 1 auto; }
  .op-docs section { padding: 20px 16px; }
  .op-tabs { padding: 0 4px; }
  .op-tabs > button { padding: 0 14px; }
}
