:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
  --bg: #090a0d;
  --surface: #111318;
  --surface-raised: #171920;
  --surface-hover: #1d2028;
  --border: #272a33;
  --border-strong: #383c48;
  --text: #f5f6f8;
  --muted: #989da9;
  --accent: #7c5cff;
  --accent-hover: #8d73ff;
  --accent-soft: rgba(124, 92, 255, 0.14);
  --success: #55d69e;
  --danger: #ff7c88;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 16% -10%, rgba(124, 92, 255, 0.12), transparent 30rem),
    var(--bg);
  color: var(--text);
}

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

button,
select,
input[type="file"] + span,
.upload-field {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  height: 68px;
  padding: 0 clamp(20px, 4vw, 52px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(9, 10, 13, 0.78);
  backdrop-filter: blur(20px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--text);
  font-size: 15px;
  font-weight: 680;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 9px;
  background: linear-gradient(145deg, #242731, #14161b);
  display: grid;
  place-items: center;
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.08);
}

.brand-mark svg {
  width: 19px;
  stroke: #c5baff;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.connection-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #6e7380;
  box-shadow: 0 0 0 4px rgba(110, 115, 128, 0.1);
}

.connection.is-connected .connection-dot {
  background: var(--success);
  box-shadow: 0 0 0 4px rgba(85, 214, 158, 0.1);
}

.connection.is-missing .connection-dot {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(255, 124, 136, 0.1);
}

.change-key {
  padding: 4px 0 4px 4px;
  border: 0;
  background: transparent;
  color: #bdb4ff;
  font-size: 11px;
  cursor: pointer;
}

.change-key:hover {
  color: white;
}

main {
  width: min(1380px, 100%);
  margin: 0 auto;
  padding: 34px clamp(20px, 4vw, 52px) 48px;
}

.tabs {
  width: fit-content;
  margin-bottom: 26px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(17, 19, 24, 0.9);
  display: flex;
  gap: 4px;
}

.tab {
  min-width: 116px;
  height: 42px;
  padding: 0 18px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font-weight: 630;
  cursor: pointer;
  transition: 160ms ease;
}

.tab:hover {
  color: var(--text);
}

.tab.is-active {
  color: var(--text);
  background: var(--surface-hover);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.045), 0 2px 8px rgba(0, 0, 0, 0.22);
}

.tab svg {
  width: 18px;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.token-notice {
  margin: -10px 0 20px;
  padding: 12px 15px;
  border: 1px solid rgba(255, 124, 136, 0.23);
  border-radius: 10px;
  background: rgba(255, 124, 136, 0.08);
  color: #ffc1c7;
  font-size: 13px;
}

.key-panel {
  margin: -10px 0 20px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(17, 19, 24, 0.88);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.16);
}

.key-copy {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.key-copy strong {
  color: #e6e7eb;
  font-size: 13px;
}

.key-copy span {
  color: var(--muted);
  font-size: 12px;
}

.key-input-row {
  display: flex;
  gap: 9px;
  margin-top: 13px;
}

.key-input-row input {
  min-width: 0;
  height: 42px;
  flex: 1;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  outline: 0;
  background: #0d0f13;
  color: var(--text);
  font-size: 13px;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.key-input-row input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.key-submit {
  flex: none;
  height: 42px;
  padding: 0 16px;
  border: 0;
  border-radius: 9px;
  background: var(--accent);
  color: white;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
}

.key-submit:hover {
  background: var(--accent-hover);
}

.key-actions {
  min-height: 18px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.key-error {
  margin: 9px 0 0;
  color: var(--danger);
  font-size: 12px;
  line-height: 1.4;
}

.clear-key {
  margin-top: 7px;
  padding: 2px 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
  cursor: pointer;
}

.clear-key:hover {
  color: var(--text);
}

.workspace {
  min-height: calc(100vh - 196px);
  border: 1px solid var(--border);
  border-radius: 18px;
  background: rgba(17, 19, 24, 0.93);
  overflow: hidden;
  display: grid;
  grid-template-columns: minmax(310px, 390px) minmax(0, 1fr);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.22);
}

.controls {
  min-width: 0;
  padding: clamp(24px, 3vw, 34px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.section-heading h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
  letter-spacing: -0.025em;
}

.section-heading p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.field {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.field > span {
  color: #d7dae0;
  font-size: 13px;
  font-weight: 590;
}

.field small {
  margin-top: -3px;
  color: #737986;
  font-size: 11px;
  text-align: right;
}

.field-grow {
  flex: 1;
}

textarea,
select {
  width: 100%;
  border: 1px solid var(--border);
  outline: 0;
  color: var(--text);
  background: #0d0f13;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

textarea {
  min-height: 156px;
  padding: 14px 15px;
  border-radius: 11px;
  line-height: 1.7;
  resize: vertical;
}

textarea::placeholder {
  color: #626774;
}

select {
  height: 43px;
  padding: 0 34px 0 12px;
  border-radius: 10px;
  cursor: pointer;
}

textarea:hover,
select:hover {
  border-color: var(--border-strong);
}

textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

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

.upload-field {
  min-height: 76px;
  padding: 12px;
  border: 1px dashed var(--border-strong);
  border-radius: 11px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease;
}

.upload-field:hover,
.upload-field.has-file {
  border-color: rgba(124, 92, 255, 0.72);
  background: var(--accent-soft);
}

.upload-field input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-icon {
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: 9px;
  background: var(--surface-hover);
  display: grid;
  place-items: center;
}

.upload-icon svg {
  width: 19px;
  stroke: #b4a7ff;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.upload-copy {
  min-width: 0;
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 5px;
}

.upload-copy strong {
  overflow: hidden;
  font-size: 12px;
  font-weight: 610;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-copy small {
  color: var(--muted);
  font-size: 11px;
}

.clear-upload {
  padding: 6px 8px;
  border: 0;
  background: transparent;
  color: #c8cbd3;
  font-size: 11px;
  cursor: pointer;
}

.primary-button,
.secondary-button {
  width: 100%;
  height: 46px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font-size: 14px;
  font-weight: 680;
  cursor: pointer;
  transition: 160ms ease;
}

.primary-button {
  border: 0;
  background: var(--accent);
  color: white;
  box-shadow: 0 8px 24px rgba(124, 92, 255, 0.2);
}

.primary-button:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.primary-button:disabled {
  opacity: 0.46;
  cursor: not-allowed;
  box-shadow: none;
}

.secondary-button {
  margin-top: -10px;
  border: 1px solid var(--border);
  background: transparent;
  color: #c8cbd3;
}

.secondary-button:hover {
  border-color: var(--border-strong);
  background: var(--surface-hover);
}

.button-spinner {
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.38);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
  display: none;
}

.is-loading .button-spinner {
  display: block;
}

.form-error {
  min-height: 17px;
  margin: -10px 0 0;
  color: var(--danger);
  font-size: 12px;
  line-height: 1.45;
}

.result {
  min-width: 0;
  min-height: 520px;
  padding: clamp(22px, 3.5vw, 46px);
  background:
    linear-gradient(rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px),
    #0b0d11;
  background-size: 32px 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.empty-state {
  max-width: 320px;
  text-align: center;
}

.empty-visual {
  width: 92px;
  height: 92px;
  margin: 0 auto 24px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 28px;
  background: linear-gradient(145deg, #181b22, #101217);
  display: grid;
  place-items: center;
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.3), inset 0 1px rgba(255, 255, 255, 0.05);
}

.empty-visual svg {
  width: 50px;
  stroke: #6f7480;
  stroke-width: 1.35;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.empty-state h2 {
  margin: 0;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.empty-state p {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.result-loading {
  width: min(420px, 100%);
  text-align: center;
}

.loading-ring {
  width: 58px;
  height: 58px;
  margin: 0 auto 22px;
  border: 3px solid rgba(124, 92, 255, 0.13);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 900ms linear infinite;
}

.result-loading h2 {
  margin: 0;
  font-size: 16px;
}

.result-loading p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.progress-track {
  height: 5px;
  margin-top: 22px;
  border-radius: 999px;
  background: #20232b;
  overflow: hidden;
}

.progress-bar {
  width: 4%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #a492ff);
  transition: width 350ms ease;
}

.media-result {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.image-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
  gap: 18px;
}

.image-item {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 13px;
}

.image-item img,
.video-player {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 300px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 14px;
  background: #050608;
  object-fit: contain;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.34);
}

.image-item img {
  width: 100%;
}

.video-player {
  width: min(920px, 100%);
}

.download-link {
  height: 39px;
  padding: 0 16px;
  border: 1px solid var(--border-strong);
  border-radius: 9px;
  background: rgba(17, 19, 24, 0.82);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 620;
  text-decoration: none;
  transition: 160ms ease;
}

.download-link:hover {
  border-color: #575c6a;
  background: var(--surface-hover);
}

.download-link svg {
  width: 15px;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 900px) {
  main {
    padding-top: 24px;
  }

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

  .controls {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .result {
    min-height: 480px;
  }

  .image-item img,
  .video-player {
    max-height: 70vh;
  }
}

@media (max-width: 560px) {
  .topbar {
    height: 62px;
  }

  .brand-mark {
    width: 28px;
    height: 28px;
  }

  main {
    padding: 18px 12px 24px;
  }

  .tabs {
    width: 100%;
    margin-bottom: 16px;
  }

  .tab {
    min-width: 0;
    flex: 1;
  }

  .workspace {
    min-height: auto;
    border-radius: 14px;
  }

  .controls,
  .result {
    padding: 22px 18px;
  }

  .key-input-row {
    flex-direction: column;
  }

  .key-submit {
    width: 100%;
  }

  .field-row,
  .three-columns {
    grid-template-columns: 1fr;
  }

  .result {
    min-height: 390px;
  }
}

@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;
  }
}
