* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #ffffff;
  color: #111827;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  overflow: hidden;
}

body {
  min-height: 100vh;
}

.page {
  height: 100vh;
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
}

.demo-section {
  flex: 1;
  min-height: 0;
  border-top: 1px solid #f1f5f9;
  padding-top: 14px;
  display: flex;
  flex-direction: column;
}

.demo-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 14px;
  flex-shrink: 0;
}

.demo-title {
  margin: 0;
  font-size: 28px;
  line-height: 1.15;
  font-weight: 700;
  color: #111827;
}

.demo-desc {
  margin: 6px 0 0;
  font-size: 14px;
  color: #6b7280;
}

.demo-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 20px;
  align-items: stretch;
}

.result-panel {
  border: 1px solid #e5e7eb;
  background: #f9fafb;
  border-radius: 18px;
  padding: 12px;
  min-height: 0;
  display: flex;
}

.result-frame-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
  border: 1px solid #e5e7eb;
  border-radius: 14px;
  overflow: hidden;
  background: #ffffff;
}

#brainFrame {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  background: #ffffff;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #ffffff;
  text-align: center;
  pointer-events: none;
  z-index: 1;
}

.empty-title {
  font-size: 18px;
  font-weight: 600;
  color: #111827;
}

.empty-desc {
  margin-top: 8px;
  font-size: 13px;
  color: #9ca3af;
}

.viewer-loading {
  position: absolute;
  inset: 0;
  z-index: 3;
  background: rgba(255, 255, 255, 0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.viewer-loading.hidden {
  display: none;
}

.viewer-loading-spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid #e5e7eb;
  border-top-color: #0f172a;
  animation: spin 0.9s linear infinite;
}

.viewer-loading-text {
  font-size: 14px;
  color: #4b5563;
}

.viewer-loading-progress {
  width: 200px;
  height: 8px;
  border-radius: 999px;
  background: #f3f4f6;
  overflow: hidden;
  position: relative;
}

.viewer-loading-progress-bar {
  width: 40%;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #0f172a, #334155);
}

.viewer-loading-progress-bar.is-animating {
  animation: indeterminateMove 1.2s ease-in-out infinite;
}

@keyframes indeterminateMove {
  0% {
    transform: translateX(-40%);
    width: 28%;
  }
  50% {
    transform: translateX(90%);
    width: 42%;
  }
  100% {
    transform: translateX(230%);
    width: 28%;
  }
}

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

.control-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  border: 1px solid #e5e7eb;
  background: #ffffff;
  border-radius: 14px;
  padding: 14px;
}

.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: #111827;
}

#textInput {
  width: 100%;
  min-height: 96px;
  margin-top: 10px;
  border: 1px solid #d1d5db;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.6;
  color: #374151;
  resize: vertical;
  outline: none;
  background: #ffffff;
}

#textInput:focus {
  border-color: #9ca3af;
}

.primary-btn {
  width: 100%;
  margin-top: 10px;
  height: 42px;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s ease;
  background: #0f172a;
  color: #ffffff;
}

.primary-btn:hover {
  background: #111827;
}

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

#imageInput {
  display: none;
}

.upload-box {
  margin-top: 10px;
  height: 160px;
  border: 1px dashed #d1d5db;
  border-radius: 10px;
  background: #f9fafb;
  color: #6b7280;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 10px;
  cursor: pointer;
  transition: 0.2s ease;
  overflow: hidden;
  position: relative;
}

.upload-box:hover {
  background: #f3f4f6;
}

.upload-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.upload-placeholder-title {
  font-size: 14px;
  color: #4b5563;
  font-weight: 500;
}

.upload-placeholder-desc {
  margin-top: 6px;
  font-size: 12px;
  color: #9ca3af;
}

.image-preview {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
  border-radius: 8px;
  background: #ffffff;
}

@media (max-width: 960px) {
  html,
  body {
    overflow: auto;
  }

  .page {
    height: auto;
    min-height: 100vh;
    padding: 14px;
  }

  .demo-section {
    display: block;
  }

  .demo-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .demo-title {
    font-size: 24px;
  }

  .result-panel {
    display: block;
  }

  .result-frame-wrap {
    height: 42vh;
    min-height: 300px;
  }

  #brainFrame {
    height: 100%;
  }

  .upload-box {
    height: 180px;
  }
}