:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --radius: 12px;
  --font: system-ui, -apple-system, 'Segoe UI', Roboto, 'PingFang SC', sans-serif;
  --page-x: max(1rem, env(safe-area-inset-left, 0px));
  --page-x-right: max(1rem, env(safe-area-inset-right, 0px));
  --page-top: max(0.75rem, env(safe-area-inset-top, 0px));
  --page-bottom: max(1rem, env(safe-area-inset-bottom, 0px));
  --touch-min: 44px;
  --content-narrow: 32rem;
  --content-md: 42rem;
  --content-wide: 56rem;
  --content-docs: 48rem;
  --content-docs-wide: 72rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body.page {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  -webkit-text-size-adjust: 100%;
}

.header {
  padding: calc(1rem + var(--page-top)) var(--page-x) 0.5rem var(--page-x-right);
  text-align: center;
  background: linear-gradient(180deg, #1e3a8a 0%, var(--bg) 100%);
  flex-shrink: 0;
}

.header h1 {
  margin: 0;
  font-size: clamp(1.25rem, 4vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.subtitle {
  margin: 0.35rem auto 0;
  max-width: 28rem;
  font-size: clamp(0.78rem, 2.5vw, 0.9rem);
  color: var(--muted);
  line-height: 1.4;
  padding: 0 0.5rem;
}

.tabs {
  display: flex;
  justify-content: center;
  gap: 0.35rem;
  margin-top: 1rem;
  padding: 0.25rem;
  background: rgba(15, 23, 42, 0.55);
  border-radius: 10px;
  width: min(100%, 16rem);
  margin-left: auto;
  margin-right: auto;
}

.tab {
  flex: 1;
  min-height: var(--touch-min);
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.tab.active {
  background: var(--primary);
  color: #fff;
}

.container {
  width: 100%;
  max-width: var(--content-narrow);
  margin: 0 auto;
  padding: 1rem var(--page-x) calc(1.5rem + var(--page-bottom)) var(--page-x-right);
  flex-direction: column;
  gap: 1rem;
}

#panel-docs.container {
  max-width: var(--content-docs);
}

main.tab-panel {
  display: none;
}

main.tab-panel.active#panel-demo {
  display: flex;
  flex-direction: column;
}

main.tab-panel.active#panel-docs {
  display: block;
}

.demo-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(1rem, 3vw, 1.35rem);
}

.card h2 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
}

.hint {
  margin: 0 0 1rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.status-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.35rem 1rem;
  margin: 0 0 1rem;
  font-size: 0.9rem;
}

.status-grid dt {
  color: var(--muted);
}

.status-grid dd {
  margin: 0;
  word-break: break-all;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.btn {
  border: none;
  border-radius: 8px;
  min-height: var(--touch-min);
  padding: 0.65rem 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn.primary {
  background: var(--primary);
  color: #fff;
}

.btn.primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn.secondary {
  background: var(--border);
  color: var(--text);
}

.btn.danger {
  background: var(--danger);
  color: #fff;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.field input {
  padding: 0.65rem 0.75rem;
  min-height: var(--touch-min);
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  width: 100%;
}

.log {
  margin: 1rem 0 0;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: 8px;
  font-size: 0.75rem;
  overflow-x: auto;
  max-height: min(12rem, 28vh);
  white-space: pre-wrap;
  color: var(--muted);
  -webkit-overflow-scrolling: touch;
}

.footer {
  text-align: center;
  padding: 1rem var(--page-x) calc(1rem + var(--page-bottom)) var(--page-x-right);
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: auto;
  flex-shrink: 0;
}

.footer a {
  color: #60a5fa;
}

.docs-layout {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
}

.docs-content {
  min-width: 0;
}

.docs-nav {
  display: flex;
  flex-wrap: nowrap;
  gap: 0.35rem;
  margin-bottom: 0.25rem;
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 0.5rem 0;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.docs-nav::-webkit-scrollbar {
  display: none;
}

.docs-nav-link {
  flex-shrink: 0;
  font-size: 0.8rem;
  color: var(--muted);
  text-decoration: none;
  padding: 0.45rem 0.75rem;
  min-height: 2.25rem;
  display: inline-flex;
  align-items: center;
  border-radius: 6px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.docs-nav-link:hover {
  color: var(--text);
  border-color: var(--border);
}

.docs-nav-link.active {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}

.doc.prose {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: clamp(1rem, 3vw, 1.35rem);
  margin-bottom: 1rem;
  scroll-margin-top: 5rem;
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0.5rem 0 1rem;
  max-width: 100%;
  border-radius: 8px;
}

.doc.prose h2 {
  margin: 0 0 0.75rem;
  font-size: 1.15rem;
}

.doc.prose h3 {
  margin: 1.25rem 0 0.5rem;
  font-size: 1rem;
  color: #cbd5e1;
}

.doc.prose p,
.doc.prose li {
  font-size: 0.9rem;
  color: #cbd5e1;
}

.doc.prose ul,
.doc.prose ol {
  margin: 0.5rem 0;
  padding-left: 1.25rem;
}

.doc.prose code {
  font-size: 0.82em;
  background: var(--bg);
  padding: 0.1em 0.35em;
  border-radius: 4px;
  color: #93c5fd;
}

.doc.prose a {
  color: #60a5fa;
}

.doc-flow {
  padding-left: 1.25rem;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  margin: 0.5rem 0 1rem;
}

.doc-table th,
.doc-table td {
  border: 1px solid var(--border);
  padding: 0.45rem 0.55rem;
  text-align: left;
  vertical-align: top;
}

.doc-table th {
  background: var(--bg);
  color: var(--muted);
  font-weight: 600;
}

.doc-code {
  margin: 0.5rem 0 1rem;
  padding: 0.85rem 1rem;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow-x: auto;
  font-size: 0.78rem;
  line-height: 1.45;
  color: #a5b4fc;
}

.doc-code code {
  background: none;
  padding: 0;
}

/* —— 手机横屏 / 大屏手机 (≥480px) —— */
@media (min-width: 480px) {
  .actions {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .btn {
    width: auto;
    flex: 1 1 auto;
    min-width: 8rem;
  }

  #btn-refresh {
    width: auto;
  }
}

/* —— iPad / 平板竖屏 (≥768px) —— */
@media (min-width: 768px) {
  .container {
    max-width: var(--content-md);
    padding-top: 1.25rem;
    padding-bottom: 2.5rem;
  }

  #panel-docs.container {
    max-width: var(--content-docs-wide);
  }

  .demo-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
    align-items: start;
  }

  #section-send {
    grid-column: 1 / -1;
  }

  .status-grid {
    font-size: 0.95rem;
  }

  .log {
    max-height: 14rem;
  }

  .docs-layout {
    display: grid;
    grid-template-columns: 11rem minmax(0, 1fr);
    gap: 1.25rem;
    align-items: start;
  }

  .docs-nav {
    flex-direction: column;
    flex-wrap: nowrap;
    overflow-x: visible;
    position: sticky;
    top: 1rem;
    padding: 0.75rem 0;
    margin-bottom: 0;
    border-bottom: none;
    border-right: 1px solid var(--border);
    padding-right: 1rem;
    max-height: calc(100dvh - 8rem);
    overflow-y: auto;
  }

  .docs-nav-link {
    white-space: normal;
    text-align: left;
    width: 100%;
  }

  .doc.prose {
    scroll-margin-top: 1.5rem;
  }
}

/* —— PC / iPad 横屏 (≥1024px) —— */
@media (min-width: 1024px) {
  .container {
    max-width: var(--content-wide);
    padding-left: max(1.5rem, var(--page-x));
    padding-right: max(1.5rem, var(--page-x-right));
  }

  .header {
    padding-top: calc(1.5rem + var(--page-top));
  }

  .tabs {
    width: 18rem;
  }

  .demo-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  #section-status,
  #section-subscribe {
    grid-column: span 1;
  }

  #section-send {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 1rem 1.25rem;
    align-items: end;
  }

  #section-send h2 {
    grid-column: 1 / -1;
    margin-bottom: 0;
  }

  #section-send .hint,
  #section-send .field {
    margin-bottom: 0;
  }

  #section-send .field:nth-of-type(1) {
    grid-column: 1;
  }

  #section-send .field:nth-of-type(2) {
    grid-column: 2;
  }

  #section-send #btn-push {
    grid-column: 3;
    align-self: end;
    min-width: 10rem;
  }

  #section-send .log {
    grid-column: 1 / -1;
    margin-top: 0;
    max-height: 11rem;
  }

  .docs-layout {
    grid-template-columns: 13rem minmax(0, 1fr);
    gap: 2rem;
  }

  .doc.prose h2 {
    font-size: 1.25rem;
  }

  .doc-table {
    font-size: 0.88rem;
  }
}

/* —— 宽屏 PC (≥1280px) —— */
@media (min-width: 1280px) {
  #panel-docs.container {
    max-width: 80rem;
  }

  .docs-layout {
    grid-template-columns: 14rem minmax(0, 1fr);
  }
}

/* 减少动效（无障碍） */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
}
