:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-soft: #f7f8fb;
  --text: #121826;
  --muted: #7a8494;
  --line: #dde2ea;
  --line-soft: #edf0f5;
  --blue: #1f9cf0;
  --purple: #7d7cf4;
  --green: #20c7b3;
  --red: #ef6461;
  --shadow: 0 18px 50px rgba(20, 27, 42, 0.06);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

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

button {
  cursor: pointer;
}

button:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 22px;
  min-height: 68px;
  padding: 0 44px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 180px;
  font-size: 20px;
  white-space: nowrap;
}

.brand-mark {
  width: 26px;
  height: 26px;
  color: var(--green);
  stroke-width: 1.7;
  transition: transform 0.3s ease;
}

.brand-mark:hover {
  animation: key-wiggle 0.55s ease;
}

@keyframes key-wiggle {
  0%   { transform: rotate(0deg); }
  20%  { transform: rotate(-18deg); }
  40%  { transform: rotate(10deg); }
  60%  { transform: rotate(-5deg); }
  80%  { transform: rotate(2deg); }
  100% { transform: rotate(0deg); }
}

.nav-tabs {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

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

.nav-tabs button,
.settings summary {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #2e3442;
  white-space: nowrap;
  font-size: 14px;
  font-weight: 750;
}

.nav-tabs button {
  padding: 0 12px;
}

.nav-tabs button.is-active {
  background: #eef7ff;
  color: var(--blue);
}

.settings {
  position: relative;
}

.settings summary {
  padding: 0 13px;
  list-style: none;
  border: 1px solid var(--line);
  background: var(--panel);
}

.settings summary::-webkit-details-marker {
  display: none;
}

.settings-panel {
  position: absolute;
  right: 0;
  z-index: 30;
  display: grid;
  gap: 10px;
  width: min(460px, calc(100vw - 32px));
  max-height: min(76vh, 720px);
  margin-top: 10px;
  padding: 14px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.settings-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 4px 8px;
}

.settings-head strong {
  color: var(--text);
  font-size: 16px;
}

.settings-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.settings-count {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border: 1px solid #d7ecff;
  border-radius: 999px;
  background: #f2f9ff;
  color: #1678bd !important;
  white-space: nowrap;
}

.provider-config {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfcfe;
  transition: border-color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}

.provider-config summary {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 11px;
  min-height: 62px;
  padding: 10px 12px;
  list-style: none;
  border: 0;
  background: transparent;
}

.provider-config summary::-webkit-details-marker {
  display: none;
}

.provider-config summary::after {
  content: "";
  align-self: center;
  width: 8px;
  height: 8px;
  border-right: 2px solid #8a94a6;
  border-bottom: 2px solid #8a94a6;
  transform: rotate(45deg);
  transition: transform 0.16s ease;
}

.provider-config[open] summary::after {
  transform: rotate(225deg);
}

.provider-config[open] {
  border-color: #c8e9ff;
  background: #f5fbff;
  box-shadow: 0 10px 28px rgba(22, 120, 189, 0.07);
}

.provider-avatar {
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: #eef7ff;
  color: #1479ba;
  font-size: 15px;
  font-weight: 950;
}

.provider-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.provider-copy strong {
  color: #1d2736;
  font-size: 14px;
  font-weight: 900;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.provider-copy small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.provider-state {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid #ffd6d5;
  border-radius: 999px;
  background: #fff7f6;
  color: var(--red);
  font-size: 11px;
  font-weight: 900;
  white-space: nowrap;
}

.provider-state.is-ready {
  border-color: #bff0e6;
  background: #f0fffb;
  color: #0f927d;
}

.provider-config-body {
  display: grid;
  gap: 12px;
  padding: 12px;
  border-top: 1px solid var(--line-soft);
  background: #fff;
}

.provider-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.provider-links a {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid #dbeafe;
  border-radius: 999px;
  background: #f8fbff;
  color: #176aa5;
  font-size: 12px;
  font-weight: 850;
  text-decoration: none;
}

.provider-links a::after {
  content: "↗";
  margin-left: 5px;
  font-size: 11px;
}

.provider-links a:hover {
  border-color: #a9dcff;
  background: #eef7ff;
}

.key-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: min(1360px, calc(100% - 88px));
  margin: 22px auto 0;
  padding: 14px 18px;
  border: 1px solid #b9e9ff;
  border-radius: 14px;
  background: linear-gradient(90deg, rgba(34, 167, 255, 0.1), rgba(125, 124, 244, 0.07));
}

.key-card p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.key-card button,
.primary-button,
.ghost-button {
  min-height: 38px;
  padding: 0 16px;
  border-radius: 10px;
  font-weight: 800;
}

.key-card button,
.primary-button {
  border: 0;
  background: linear-gradient(135deg, var(--blue), var(--purple));
  color: #fff;
}

.ghost-button {
  border: 1px solid var(--line);
  background: var(--panel-soft);
  color: var(--text);
}

.refresh-models {
  justify-self: start;
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.is-hidden {
  display: none !important;
}

.view {
  display: none;
  width: min(1360px, calc(100% - 88px));
  margin: 26px auto 56px;
}

.view.is-active {
  display: block;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.eyebrow {
  display: inline-flex;
  margin-bottom: 7px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.02em;
}

h1 {
  margin: 0;
  color: var(--text);
  font-size: 29px;
  line-height: 1.1;
  letter-spacing: 0;
}

p {
  margin: 8px 0 0;
}

.page-head p {
  color: var(--muted);
  font-size: 14px;
}

.provider-status {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 11px;
  border: 1px solid #ffd6d5;
  border-radius: 999px;
  background: #fff7f6;
  color: var(--red);
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.provider-status.is-ready {
  border-color: #bff0e6;
  background: #f0fffb;
  color: #0f927d;
}

.work-grid {
  display: grid;
  grid-template-columns: minmax(520px, 0.62fr) minmax(390px, 0.38fr);
  gap: 24px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.form-panel,
.result-panel {
  padding: 22px;
}

.form-section {
  display: grid;
  gap: 14px;
  margin: 0 0 20px;
  padding: 0 0 20px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
}

.form-section:last-of-type {
  margin-bottom: 0;
}

.form-section legend {
  margin-bottom: 2px;
  color: #1c2535;
  font-size: 14px;
  font-weight: 900;
}

.provider-catalog {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -2px 0 4px;
}

.provider-catalog span {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafc;
  color: #667085;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.provider-catalog span::before {
  content: "可用";
  margin-right: 6px;
  color: #98a2b3;
  font-size: 11px;
  font-weight: 850;
}

.provider-catalog span.is-ready {
  border-color: #bfe9ff;
  background: #f0f9ff;
  color: #1479ba;
}

.provider-catalog span.is-ready::before {
  content: "可用";
  color: #1683c7;
}

.field {
  display: grid;
  gap: 8px;
  margin: 0;
}

.field span,
.capability-note,
.field-help {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  outline: none;
}

input,
select {
  height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 112px;
  padding: 13px;
  resize: vertical;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(34, 167, 255, 0.12);
}

.inline-fields {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}

.two-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.action-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 18px;
}

.action-row.split {
  justify-content: space-between;
}

.upload-button,
.upload-drop {
  border: 1px dashed var(--line);
  background: var(--panel-soft);
}

.upload-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: fit-content;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  font-weight: 800;
}

.upload-button input,
.upload-drop input {
  display: none;
}

.upload-drop {
  display: grid;
  place-items: center;
  gap: 8px;
  min-height: 160px;
  border-radius: 12px;
  text-align: center;
}

.upload-drop span {
  color: var(--muted);
  font-size: 13px;
}

.thumb-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.thumb {
  position: relative;
  width: 78px;
  height: 78px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb button {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.62);
  color: #fff;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-title span {
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #536174;
  font-size: 13px;
}

.result-box {
  display: grid;
  place-items: center;
  min-height: 390px;
  padding: 24px;
  overflow: auto;
  border: 1px dashed var(--line);
  border-radius: 18px;
  background: #fbfcfe;
  color: #5f6b7c;
  text-align: center;
  white-space: pre-wrap;
}

.result-box.is-loading {
  border-color: #a9dcff;
  background: #f1f9ff;
  color: #2075a8;
}

.result-box.has-result {
  border-style: solid;
  background: #fff;
  color: var(--text);
}

.image-results.has-result {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  align-items: start;
  place-items: stretch;
}

.image-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}

.image-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  background: #f4f6f8;
}

.image-card a,
.download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  margin: 10px;
  padding: 0 12px;
  border-radius: 999px;
  background: #eef7ff;
  color: #1678bd;
  text-decoration: none;
  font-weight: 800;
}

.text-result {
  display: block;
  text-align: left;
  line-height: 1.7;
}

audio {
  width: min(420px, 100%);
}

.remember {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.remember input {
  width: 16px;
  height: 16px;
}

.history-list {
  display: grid;
  gap: 12px;
  padding: 18px;
}

.history-item {
  display: grid;
  gap: 5px;
  padding: 14px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  background: var(--panel-soft);
}

.history-item span,
.history-item small,
.empty-copy {
  color: var(--muted);
  font-size: 13px;
}

.history-item p {
  margin: 0;
  color: #4d5868;
}

@media (max-width: 1180px) {
  .topbar {
    grid-template-columns: 1fr auto;
    padding: 12px 24px;
  }

  .brand {
    grid-column: 1;
    grid-row: 1;
  }

  .settings {
    grid-column: 2;
    grid-row: 1;
  }

  .nav-tabs {
    grid-column: 1 / -1;
    grid-row: 2;
    justify-content: flex-start;
  }

  .work-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .topbar {
    padding: 12px 16px;
  }

  .settings > summary span {
    display: none;
  }

  .view,
  .key-card {
    width: min(100% - 24px, 1360px);
  }

  .key-card,
  .page-head,
  .action-row,
  .action-row.split {
    align-items: stretch;
    flex-direction: column;
  }

  .inline-fields,
  .two-fields {
    grid-template-columns: 1fr;
  }

  .form-panel,
  .result-panel {
    padding: 16px;
  }

}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161b;
    --panel: #1e2128;
    --panel-soft: #252830;
    --text: #e1e5ee;
    --muted: #8b92a2;
    --line: #343840;
    --line-soft: #2c3038;
  }

  .topbar {
    background: rgba(20, 22, 27, 0.94);
    border-bottom-color: #2c3038;
  }

  .nav-tabs button.is-active {
    background: #1d3040;
  }

  .provider-config {
    background: #21242b;
  }

  .provider-config[open] {
    background: #1a2833;
    border-color: #1e4568;
  }

  .provider-config-body {
    background: #1e2128;
    border-top-color: #2c3038;
  }

  .form-section {
    border-bottom-color: #2c3038;
  }

  .key-card {
    background: linear-gradient(90deg, rgba(34, 167, 255, 0.08), rgba(125, 124, 244, 0.05));
    border-color: #1e4568;
  }

  .settings-panel {
    background: #1e2128;
    border-color: #343840;
  }

  .settings-count {
    background: #1c2e40;
    border-color: #254868;
  }

  .ghost-button {
    background: #252830;
    border-color: #343840;
    color: #e1e5ee;
  }

  .provider-catalog span {
    background: #1e2128;
    color: #8b92a2;
  }

  .provider-catalog span.is-ready {
    background: #1d3040;
    border-color: #1e4568;
  }

  .result-box,
  .upload-button,
  .upload-drop {
    background: #21242b;
    border-color: #2c3038;
  }

  .history-item,
  .refresh-models {
    background: #252830;
    border-color: #2c3038;
  }

  input, select, textarea {
    background: #1c1f25;
    border-color: #343840;
    color: #e1e5ee;
  }
}
