:root {
  color-scheme: dark;
  --bg: #0d1020;
  --card: rgba(20, 25, 45, 0.82);
  --card-strong: rgba(28, 35, 62, 0.95);
  --border: rgba(255, 255, 255, 0.1);
  --text: #eef3ff;
  --muted: #9aa8c7;
  --primary: #7c5cff;
  --primary-2: #00d4ff;
  --danger: #ff5c7c;
  --ok: #31d0aa;
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.35);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html {
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top left, rgba(124, 92, 255, 0.26), transparent 30%),
              radial-gradient(circle at bottom right, rgba(0, 212, 255, 0.16), transparent 28%),
              var(--bg);
  color: var(--text);
  overflow-x: hidden;
}
button, input, textarea, select { font: inherit; }
button, a, input, textarea, select {
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }

.bg-orb { position: fixed; border-radius: 999px; filter: blur(35px); opacity: 0.42; pointer-events: none; }
.orb-a { width: 280px; height: 280px; background: #7c5cff; top: 6%; right: 8%; }
.orb-b { width: 220px; height: 220px; background: #00d4ff; left: 4%; bottom: 10%; }

.shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 38px 0 64px; }
.hero { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
h1, h2, p { margin: 0; }
h1 { font-size: clamp(34px, 7vw, 70px); line-height: 0.95; letter-spacing: -0.06em; }
h2 { font-size: 24px; letter-spacing: -0.03em; }
.subtitle { margin-top: 14px; color: var(--muted); font-size: 17px; }
.eyebrow { color: var(--primary-2); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.18em; margin-bottom: 8px; }
.muted { color: var(--muted); }
.small-text { font-size: 13px; line-height: 1.5; }

.user-box { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--border); border-radius: 999px; background: rgba(255,255,255,0.05); }
.avatar {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.08);
}
.avatar.large {
  width: 72px;
  height: 72px;
}
.avatar-fallback {
  display: grid;
  place-items: center;
  color: var(--text);
  font-weight: 800;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
}
.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.58);
  backdrop-filter: blur(10px);
}
.modal-card {
  width: min(460px, 100%);
}
.profile-preview {
  display: grid;
  justify-items: center;
  gap: 10px;
  text-align: center;
}
.card { background: var(--card); border: 1px solid var(--border); border-radius: 24px; padding: 24px; box-shadow: var(--shadow); backdrop-filter: blur(18px); }
.auth-card { width: min(460px, 100%); margin-top: 32px; }
.grid { display: grid; gap: 18px; }
.two-cols { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.wide-card { grid-column: 1 / -1; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.section-head.wrap { flex-wrap: wrap; }

.tabs { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.tab, .btn {
  border: 0;
  border-radius: 999px;
  padding: 11px 18px;
  color: var(--text);
  background: rgba(255,255,255,0.07);
  cursor: pointer;
  transition: transform .15s ease, background .15s ease, opacity .15s ease;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
}
.tab:hover, .btn:hover { transform: translateY(-1px); }
.tab.active { background: linear-gradient(135deg, var(--primary), var(--primary-2)); }
.btn.primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); font-weight: 800; }
.btn.secondary { background: rgba(255,255,255,0.09); border: 1px solid var(--border); }
.btn.danger { background: rgba(255, 92, 124, 0.14); color: #ffdbe3; border: 1px solid rgba(255, 92, 124, 0.28); }
.btn.small { padding: 8px 12px; font-size: 13px; }
.btn:disabled { cursor: not-allowed; opacity: 0.55; transform: none; }
.link-btn {
  justify-self: center;
  border: 0;
  background: transparent;
  color: var(--primary-2);
  cursor: pointer;
  padding: 2px 4px;
  text-decoration: underline;
  text-underline-offset: 4px;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }
.hidden { display: none !important; }

.form-card, .form-grid { display: grid; gap: 16px; }
.form-grid.narrow { margin-top: 20px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
label { display: grid; gap: 8px; color: var(--muted); font-size: 14px; }
input, textarea, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(7, 10, 24, 0.72);
  color: var(--text);
  padding: 12px 14px;
  outline: none;
  min-height: 46px;
}
textarea { resize: vertical; min-height: 120px; line-height: 1.55; }
input:focus, textarea:focus, select:focus { border-color: rgba(0, 212, 255, 0.72); box-shadow: 0 0 0 4px rgba(0, 212, 255, 0.08); }
.checkbox-label { align-self: end; display: flex; align-items: center; gap: 10px; min-height: 48px; }
.checkbox-label input { width: auto; }

.advanced-panel {
  border: 1px solid var(--border);
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.035);
  overflow: hidden;
}
.advanced-panel summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 50px;
  padding: 14px 16px;
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
  list-style: none;
}
.advanced-panel summary::-webkit-details-marker { display: none; }
.advanced-panel summary::after {
  content: "展开";
  color: var(--primary-2);
  font-size: 12px;
  font-weight: 700;
}
.advanced-panel[open] summary::after { content: "收起"; }
.advanced-content {
  display: grid;
  gap: 14px;
  padding: 0 16px 16px;
}

.pill { border: 1px solid var(--border); background: rgba(255,255,255,0.08); border-radius: 999px; padding: 6px 10px; font-size: 12px; white-space: nowrap; }
.pill.ok { color: #baffee; border-color: rgba(49,208,170,.35); background: rgba(49,208,170,.12); }
.pill.warn { color: #ffe7ac; border-color: rgba(255,196,87,.35); background: rgba(255,196,87,.12); }
.pill.neutral { color: var(--muted); }

.result-card { min-height: 520px; display: flex; flex-direction: column; }
.empty-preview, .empty-list {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 320px;
  border: 1px dashed rgba(255,255,255,0.16);
  border-radius: 22px;
  color: var(--muted);
  background: rgba(255,255,255,0.03);
  text-align: center;
  padding: 24px;
}
.preview { width: 100%; max-height: 640px; object-fit: contain; border-radius: 20px; background: #070a18; border: 1px solid var(--border); }
.meta { font-size: 13px; margin-top: 12px; line-height: 1.5; }
.toolbar { display: flex; gap: 10px; align-items: center; }
.toolbar input { min-width: min(360px, 70vw); }

.history-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(245px, 1fr)); gap: 16px; }
.history-card { background: rgba(255,255,255,0.045); border: 1px solid var(--border); border-radius: 20px; overflow: hidden; display: flex; flex-direction: column; }
.history-card img { width: 100%; aspect-ratio: 1; object-fit: cover; background: #070a18; }
.history-body { padding: 14px; display: grid; gap: 10px; }
.prompt { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; line-height: 1.45; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.user-list { display: grid; gap: 12px; }
.user-item { border: 1px solid var(--border); border-radius: 18px; padding: 14px; background: rgba(255,255,255,0.04); display: grid; gap: 12px; }
.user-item-head { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.inline-controls { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.toast { position: sticky; top: 12px; z-index: 5; margin: 0 0 18px; border-radius: 16px; padding: 13px 16px; background: var(--card-strong); border: 1px solid var(--border); box-shadow: var(--shadow); }
.toast.error { border-color: rgba(255, 92, 124, 0.45); color: #ffdbe3; }
.toast.ok { border-color: rgba(49, 208, 170, 0.45); color: #d6fff5; }

@media (max-width: 840px) {
  .hero, .section-head { align-items: flex-start; flex-direction: column; }
  .two-cols, .form-row, .inline-controls { grid-template-columns: 1fr; }
  .user-box { border-radius: 20px; flex-wrap: wrap; }
  .toolbar { width: 100%; flex-direction: column; align-items: stretch; }
  .toolbar input { min-width: 0; }
}

@media (max-width: 640px) {
  :root { --shadow: 0 16px 48px rgba(0, 0, 0, 0.32); }
  body { min-height: 100svh; }
  .bg-orb { opacity: 0.26; filter: blur(46px); }
  .orb-a { width: 190px; height: 190px; top: 1%; right: -42px; }
  .orb-b { width: 170px; height: 170px; left: -54px; bottom: 18%; }

  .shell {
    width: 100%;
    padding: calc(18px + env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) calc(92px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  }
  .hero { gap: 14px; margin-bottom: 18px; }
  .hero > div:first-child { min-width: 0; }
  h1 { font-size: clamp(30px, 12vw, 44px); line-height: 1; letter-spacing: -0.05em; }
  h2 { font-size: 21px; }
  .subtitle { margin-top: 10px; font-size: 14px; line-height: 1.5; }
  .eyebrow { margin-bottom: 6px; font-size: 11px; }

  .user-box {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 8px;
    align-items: center;
    border-radius: 18px;
    padding: 8px;
  }
  #userName {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .user-box .btn {
    width: auto;
    min-height: 38px;
    padding: 7px 10px;
  }

  .card {
    border-radius: 20px;
    padding: 16px;
  }
  .auth-card {
    width: 100%;
    margin-top: 20px;
  }

  .tabs {
    position: fixed;
    z-index: 40;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
    gap: 8px;
    margin: 0;
    padding: 10px max(12px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
    background: rgba(13, 16, 32, 0.9);
    border-top: 1px solid var(--border);
    box-shadow: 0 -16px 44px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(20px);
  }
  .tab {
    min-height: 46px;
    padding: 9px 6px;
    border-radius: 16px;
    font-size: 12px;
  }
  .tab:hover, .btn:hover { transform: none; }

  .section-head { gap: 12px; margin-bottom: 14px; }
  .section-head.wrap { align-items: stretch; }
  .form-card, .form-grid { gap: 14px; }
  label { font-size: 13px; }
  input, textarea, select {
    min-height: 48px;
    border-radius: 14px;
    padding: 12px;
    font-size: 16px;
  }
  textarea {
    min-height: 180px;
    max-height: 45svh;
  }
  .advanced-panel { border-radius: 16px; }
  .advanced-panel summary {
    min-height: 48px;
    padding: 13px 14px;
  }
  .advanced-content {
    gap: 12px;
    padding: 0 14px 14px;
  }
  .checkbox-label {
    min-height: auto;
    align-items: flex-start;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.04);
    padding: 12px;
  }
  .checkbox-label input {
    min-height: auto;
    margin-top: 2px;
  }
  .btn { min-height: 48px; }
  .form-card > .btn.primary,
  .form-grid .btn.primary,
  .toolbar .btn {
    width: 100%;
  }
  .link-btn { min-height: 42px; }

  .result-card { min-height: auto; }
  .empty-preview, .empty-list {
    min-height: 220px;
    border-radius: 18px;
    padding: 20px;
  }
  .preview {
    max-height: 62svh;
    border-radius: 16px;
  }
  .meta {
    overflow-wrap: anywhere;
    font-size: 12px;
  }

  .toolbar { gap: 8px; }
  .history-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .history-card { border-radius: 18px; }
  .history-card img { aspect-ratio: 4 / 3; }
  .history-body {
    gap: 9px;
    padding: 12px;
  }
  .prompt { -webkit-line-clamp: 4; }
  .actions {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(88px, 1fr));
    gap: 8px;
  }
  .actions .btn {
    width: 100%;
    min-height: 42px;
    padding: 9px 10px;
  }

  .user-list { gap: 10px; }
  .user-item {
    border-radius: 16px;
    padding: 12px;
  }
  .user-item-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }
  .pill {
    padding: 5px 8px;
    font-size: 11px;
  }
  .toast {
    position: fixed;
    z-index: 60;
    top: calc(12px + env(safe-area-inset-top));
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    margin: 0;
    border-radius: 14px;
  }
}

@media (max-width: 380px) {
  .tabs { grid-template-columns: repeat(auto-fit, minmax(64px, 1fr)); }
  .tab { font-size: 11px; }
}
