:root {
  color-scheme: light dark;
  --bg: #f5f8fb;
  --surface: #ffffff;
  --surface-soft: #eef6f4;
  --surface-elevated: #fbfdff;
  --ink: #121926;
  --muted: #5c6b7d;
  --line: #dbe6ee;
  --blue: #1f6feb;
  --blue-dark: #1859bd;
  --accent: var(--blue);
  --green: #13a878;
  --green-dark: #0a7d5a;
  --coral: #e85d4f;
  --amber: #f3b83f;
  --glass: rgba(255, 255, 255, 0.74);
  --shadow: 0 24px 70px rgba(18, 25, 38, 0.12);
  --shadow-soft: 0 10px 28px rgba(18, 25, 38, 0.08);
  --radius: 8px;
  --max: 1180px;
  --z-header: 20;
  --z-tabbar: 30;
  --z-toast: 40;
  --z-skip: 50;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.6;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

img {
  display: block;
  max-width: 100%;
}

a {
  color: inherit;
  text-decoration: none;
}

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(31, 111, 235, 0.3);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: var(--z-skip);
  transform: translateY(-150%);
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-weight: 800;
}

.skip-link:focus {
  transform: translateY(0);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 72px;
  padding: 0 max(24px, calc((100vw - var(--max)) / 2));
  border-bottom: 1px solid rgba(219, 230, 238, 0.88);
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.brand,
.desktop-nav,
.header-actions,
.hero-actions,
.button-row {
  display: flex;
  align-items: center;
}

.brand {
  gap: 10px;
  min-height: 44px;
  font-weight: 850;
}

.brand-mark {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  font-size: 14px;
}

.desktop-nav {
  gap: 4px;
}

.desktop-nav a,
.ghost-button,
.primary-button,
.secondary-button,
.tool-tab {
  min-height: 44px;
  border-radius: var(--radius);
  font-weight: 780;
  font-size: 14px;
  transition:
    background-color 200ms ease,
    border-color 200ms ease,
    color 200ms ease,
    transform 180ms ease,
    box-shadow 200ms ease;
}

.desktop-nav a {
  padding: 10px 13px;
  color: var(--muted);
}

.desktop-nav a:hover {
  background: #eaf1f6;
  color: var(--ink);
}

.header-actions,
.hero-actions,
.button-row {
  gap: 10px;
  flex-wrap: wrap;
}

.primary-button,
.secondary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
}

.primary-button {
  padding: 11px 18px;
  background: var(--blue);
  color: #fff;
  box-shadow: 0 12px 26px rgba(31, 111, 235, 0.22);
}

.primary-button:hover {
  background: var(--blue-dark);
}

.secondary-button,
.ghost-button {
  padding: 10px 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.secondary-button.danger {
  border-color: rgba(199, 53, 53, 0.35);
  color: #a4262c;
}

.small {
  min-height: 44px;
  padding: 9px 14px;
}

.primary-button:active,
.secondary-button:active,
.ghost-button:active,
.tool-tab:active {
  transform: scale(0.98);
}

.primary-button[disabled],
.secondary-button[disabled],
.ghost-button[disabled] {
  cursor: not-allowed;
  opacity: 0.58;
}

.hero-section,
.workspace-section,
.cards-section,
.commerce-grid,
.history-section,
.admin-section,
.account-section,
.legal-section {
  width: min(var(--max), calc(100% - 48px));
  margin: 0 auto;
}

.hero-section {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(420px, 1.05fr);
  gap: 40px;
  align-items: center;
  min-height: calc(100dvh - 72px);
  padding: 52px 0 40px;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--green-dark);
  font-size: 13px;
  font-weight: 850;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hero-section h1,
.section-heading h2 {
  margin: 0;
  line-height: 1.08;
  letter-spacing: 0;
}

.hero-section h1 {
  font-size: clamp(42px, 6vw, 72px);
}

.hero-lede,
.section-heading p,
.tool-card p,
.template-card p,
.credit-card p,
.wechat-card p,
.ad-card p,
.history-card p {
  color: var(--muted);
}

.hero-lede {
  max-width: 680px;
  margin: 22px 0 0;
  font-size: 19px;
}

.hero-actions {
  margin-top: 28px;
}

.hero-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-top: 28px;
}

.metric-card,
.status-strip article,
.tool-panel,
.result-panel,
.tool-sidebar,
.template-card,
.credit-card,
.wechat-card,
.ad-card,
.history-card,
.dashboard-card,
.admin-table-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.metric-card {
  min-height: 94px;
  padding: 15px;
}

.metric-card span,
.card-label,
.panel-header span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}

.metric-card strong {
  display: block;
  margin-top: 6px;
  font-size: 26px;
  line-height: 1;
}

.hero-visual img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1px;
  width: min(var(--max), calc(100% - 48px));
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--line);
}

.status-strip article {
  min-height: 116px;
  padding: 20px;
  border: 0;
  border-radius: 0;
}

.status-strip span {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 14px;
}

.workspace-section,
.cards-section,
.history-section,
.admin-section,
.account-section,
.legal-section {
  margin-top: 88px;
}

.section-heading {
  max-width: 760px;
  margin-bottom: 28px;
}

.section-heading h2 {
  font-size: clamp(30px, 4vw, 48px);
}

.workspace-grid {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr) 340px;
  gap: 14px;
  align-items: stretch;
}

.tool-sidebar {
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 12px;
}

.tool-tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  text-align: left;
}

.tool-tab.active {
  border-color: rgba(31, 111, 235, 0.26);
  background: #eaf2ff;
  color: var(--blue);
}

.tool-panel,
.result-panel {
  min-height: 540px;
  padding: 18px;
}

.tool-form {
  display: none;
}

.tool-form.active {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-weight: 760;
}

label span {
  font-size: 14px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-elevated);
  color: var(--ink);
}

input,
select {
  padding: 0 12px;
}

textarea {
  resize: vertical;
  padding: 14px;
  line-height: 1.65;
}

.form-row.split {
  display: grid;
  grid-template-columns: 1fr 160px;
  gap: 12px;
}

.template-fields {
  display: grid;
  gap: 14px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.panel-header h3 {
  margin: 0;
}

.result-output {
  display: grid;
  gap: 12px;
  padding-top: 16px;
  white-space: pre-wrap;
}

.empty-state {
  color: var(--muted);
}

.result-image {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.result-media-card {
  margin: 0;
}

.result-media-card figcaption {
  margin-top: 10px;
}

.template-grid,
.history-list,
.dashboard-grid,
.account-grid,
.legal-grid {
  display: grid;
  gap: 14px;
}

.history-tools {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) repeat(3, auto);
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
}

.history-tools input {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 12px;
  background: var(--surface);
}

.history-list.compact {
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  margin-bottom: 14px;
}

.conversation-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(31, 111, 235, 0.12);
}

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

.template-card {
  min-height: 230px;
  padding: 22px;
}

.template-card h3,
.history-card h3 {
  margin: 12px 0 8px;
}

.commerce-grid {
  display: grid;
  grid-template-columns: 1fr 0.8fr 0.8fr;
  gap: 14px;
  margin-top: 88px;
}

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

.account-card,
.legal-grid article {
  min-height: 230px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.account-card strong {
  display: block;
  margin-top: 6px;
  font-size: 26px;
  line-height: 1.2;
}

.credit-card,
.wechat-card,
.ad-card {
  min-height: 250px;
  padding: 22px;
}

.credit-card {
  background: var(--surface-soft);
}

.credit-card strong,
.wechat-card strong,
.ad-card strong {
  display: block;
  margin-top: 6px;
  font-size: 32px;
  line-height: 1;
}

.meter {
  height: 10px;
  margin: 16px 0;
  overflow: hidden;
  border-radius: 999px;
  background: #dbe6ee;
}

.meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}

.qr-box {
  display: flex;
  width: 118px;
  min-height: 118px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  place-items: center;
  padding: 10px;
  border: 1px solid #bd7c13;
  border-radius: var(--radius);
  background: #fff;
  color: #865400;
  font-weight: 900;
  text-align: center;
  overflow-wrap: anywhere;
}

.qr-box img {
  width: 86px;
  height: 86px;
  object-fit: contain;
}

.qr-box span {
  font-size: 12px;
  line-height: 1.3;
}

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

.history-card {
  min-height: 170px;
  padding: 18px;
}

.history-card code {
  display: inline-block;
  margin-bottom: 10px;
  color: var(--blue);
  font-weight: 800;
}

.admin-section {
  margin-bottom: 96px;
}

.admin-auth-panel {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 12px;
  align-items: end;
  margin-bottom: 18px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.legal-section {
  margin-bottom: 88px;
}

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

.legal-grid h3 {
  margin: 0 0 8px;
}

.legal-grid p,
.account-card p {
  color: var(--muted);
}

.dashboard-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 18px;
}

.dashboard-card {
  min-height: 130px;
  padding: 18px;
}

.dashboard-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 760;
}

.dashboard-card strong {
  display: block;
  margin-top: 8px;
  font-size: 32px;
  line-height: 1;
}

.integration-panel {
  margin-bottom: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.integration-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.integration-item {
  min-height: 92px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fbfd;
}

.integration-item strong {
  display: block;
  color: var(--ink);
}

.integration-item span {
  display: inline-block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.integration-item.ready {
  border-color: rgba(33, 150, 105, 0.35);
  background: #effaf5;
}

.integration-item.missing {
  border-color: rgba(189, 124, 19, 0.35);
  background: #fff8e8;
}

.admin-ops-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.admin-form {
  display: grid;
  gap: 12px;
  min-height: 280px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.admin-form h3 {
  margin: 0;
  color: var(--ink);
  font-size: 18px;
}

.admin-form textarea {
  min-height: 110px;
}

.admin-table-wrap {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

.admin-table caption {
  padding: 16px;
  text-align: left;
  font-weight: 850;
}

.admin-table th,
.admin-table td {
  padding: 13px 16px;
  border-top: 1px solid var(--line);
  text-align: left;
  font-size: 14px;
}

.toast-region {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: var(--z-toast);
  display: grid;
  gap: 8px;
}

.toast {
  max-width: 360px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
}

.desktop-only {
  display: inline-flex;
}

.legal-page {
  min-height: 100vh;
  padding: 48px 18px;
  background: linear-gradient(180deg, #f7fafc 0%, #edf5f1 100%);
}

.legal-document {
  width: min(860px, 100%);
  margin: 0 auto;
  padding: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow-soft);
}

.legal-document h1 {
  margin: 28px 0 14px;
  color: var(--ink);
  font-size: 36px;
  line-height: 1.12;
}

.legal-document h2 {
  margin: 26px 0 10px;
  color: var(--ink);
  font-size: 22px;
}

.legal-document p {
  margin: 0 0 14px;
  color: var(--muted);
  line-height: 1.78;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media (prefers-contrast: more) {
  :root {
    --muted: #354455;
    --line: #aab8c4;
    --glass: rgba(255, 255, 255, 0.96);
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-soft: #17332e;
    --surface-elevated: #2c2c2e;
    --ink: #f2f2f7;
    --muted: #aeaeb2;
    --line: rgba(235, 235, 245, 0.18);
    --blue: #0a84ff;
    --blue-dark: #409cff;
    --green: #30d158;
    --green-dark: #63e6a0;
    --glass: rgba(28, 28, 30, 0.78);
    --shadow: 0 18px 52px rgba(0, 0, 0, 0.42);
    --shadow-soft: 0 8px 22px rgba(0, 0, 0, 0.3);
  }

  .tool-tab.active {
    border-color: rgba(10, 132, 255, 0.56);
    background: rgba(10, 132, 255, 0.2);
  }

  .desktop-nav a:hover {
    background: rgba(235, 235, 245, 0.12);
  }

  .meter {
    background: rgba(235, 235, 245, 0.18);
  }

  .qr-box {
    border-color: #dba64b;
    background: var(--surface-elevated);
    color: #ffd089;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .app-header {
    background: #fff;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

@supports not ((backdrop-filter: blur(16px)) or (-webkit-backdrop-filter: blur(16px))) {
  .app-header {
    background: rgba(255, 255, 255, 0.96);
  }
}

@media (max-width: 1050px) {
  .app-header {
    padding: 0 18px;
  }

  .hero-section,
  .workspace-grid,
  .commerce-grid {
    grid-template-columns: 1fr;
  }

  .hero-visual {
    order: -1;
  }

  .tool-sidebar {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .template-grid,
  .history-list,
  .dashboard-grid,
  .integration-grid,
  .admin-ops-grid,
  .account-grid,
  .legal-grid,
  .status-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  :root {
    --bg: #f7f7fb;
    --surface: #ffffff;
    --surface-soft: #f1f4fb;
    --ink: #111827;
    --muted: #687386;
    --blue: #007aff;
    --blue-dark: #0066d6;
    --radius: 18px;
  }

  body {
    padding-bottom: calc(78px + env(safe-area-inset-bottom));
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
  }

  .desktop-nav,
  .header-actions .ghost-button,
  .desktop-only,
  .demo-only,
  .hero-section,
  .status-strip,
  .legal-section,
  .admin-section {
    display: none;
  }

  .app-header {
    min-height: calc(58px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 18px 0;
    border-bottom: 0;
    background: rgba(247, 247, 251, 0.88);
  }

  .brand {
    min-height: 52px;
    font-size: 18px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 11px;
    background: linear-gradient(135deg, #007aff, #5e5ce6);
  }

  .header-actions .primary-button {
    min-height: 44px;
    padding: 8px 13px;
    border-radius: 999px;
    font-size: 13px;
  }

  main {
    padding-top: 8px;
  }

  .workspace-section,
  .cards-section,
  .commerce-grid,
  .history-section,
  .account-section {
    width: calc(100% - 28px);
    display: none;
  }

  body[data-mobile-screen="create"] [data-mobile-screen="create"],
  body[data-mobile-screen="templates"] [data-mobile-screen="templates"],
  body[data-mobile-screen="works"] [data-mobile-screen="works"],
  body[data-mobile-screen="account"] [data-mobile-screen="account"] {
    display: block;
  }

  .hero-metrics,
  .tool-sidebar,
  .template-grid,
  .history-list,
  .dashboard-grid,
  .integration-grid,
  .admin-ops-grid,
  .admin-auth-panel,
  .account-grid,
  .legal-grid,
  .history-tools,
  .form-row.split {
    grid-template-columns: 1fr;
  }

  .tool-panel,
  .result-panel {
    min-height: auto;
  }

  .workspace-section,
  .cards-section,
  .commerce-grid,
  .history-section,
  .account-section {
    margin-top: 14px;
    padding: 18px;
    border-radius: 28px;
    box-shadow: none;
  }

  .section-heading {
    margin-bottom: 16px;
  }

  .section-heading h2 {
    font-size: 26px;
    letter-spacing: -0.03em;
  }

  .section-heading p {
    font-size: 15px;
  }

  .workspace-grid {
    gap: 14px;
  }

  .tool-sidebar {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 5px;
    border-radius: 18px;
    background: #eef2f8;
  }

  .tool-tab {
    min-height: 46px;
    padding: 8px 6px;
    border-radius: 14px;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    box-shadow: none;
  }

  .tool-tab.active {
    background: #fff;
    color: var(--blue);
    box-shadow: 0 8px 18px rgba(17, 24, 39, 0.08);
  }

  .tool-panel,
  .result-panel,
  .credit-card,
  .wechat-card,
  .ad-card,
  .account-card,
  .history-card,
  .template-card {
    border-radius: 22px;
    box-shadow: none;
  }

  .primary-button,
  .secondary-button,
  .ghost-button {
    min-height: 48px;
    border-radius: 16px;
  }

  .primary-button {
    background: #007aff;
    box-shadow: none;
  }

  .secondary-button {
    background: #f4f6fb;
  }

  textarea,
  input,
  select {
    min-height: 48px;
    border-radius: 15px;
    font-size: 16px;
  }

  .result-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .toast-region {
    right: 14px;
    bottom: calc(88px + env(safe-area-inset-bottom));
    left: 14px;
  }
}

@media (max-width: 720px) and (prefers-color-scheme: dark) {
  .app-header {
    border-bottom: 1px solid rgba(235, 235, 245, 0.08);
    background: rgba(0, 0, 0, 0.8);
  }

  .tool-sidebar {
    background: #2c2c2e;
  }

  .tool-tab.active {
    background: var(--surface);
    color: var(--blue);
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.25);
  }

  .secondary-button {
    background: var(--surface-elevated);
  }

}

/* iOS owns the top-level tab navigation in the native view hierarchy. */
html.native-ios body,
body.native-ios {
  padding-bottom: calc(88px + env(safe-area-inset-bottom));
}
