:root {
  /* 全局主题变量：用于主视窗与右侧控制面板。 */
  --bg: #050505;
  --panel: #090e1b;
  --sky: #7eb9ed;
  --line: rgba(236, 245, 255, 0.88);
  --text: #f5f5f7;
  --muted: #9ca6b3;
  --wire: #d5e9ff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: radial-gradient(circle at 62% 18%, #1a2640 0%, #050505 52%);
  color: var(--text);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "SF Pro Text", sans-serif;
  letter-spacing: 0.035em;
  overflow: hidden;
}

.halo {
  position: fixed;
  inset: -30vmax;
  background: radial-gradient(circle at 38% 46%, rgba(126, 185, 237, 0.08), transparent 48%);
  pointer-events: none;
}

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 74px;
  padding: 10px 14px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 20;
}

.toast {
  position: fixed;
  top: 84px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(9, 14, 27, 0.92);
  color: #eaf3ff;
  font-size: 12px;
  z-index: 40;
  opacity: 1;
  transition: opacity 0.35s ease;
}

.toast.success {
  border-color: rgba(126, 185, 237, 0.65);
}

.toast.error {
  border-color: rgba(255, 112, 112, 0.8);
}

.toast.hidden {
  opacity: 0;
  pointer-events: none;
}

.logo {
  font-size: clamp(24px, 1.2vw, 30px);
  line-height: 1.05;
  text-transform: none;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-shadow: 0 0 18px rgba(126, 185, 237, 0.16);
  white-space: nowrap;
  max-width: 52vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar nav {
  display: flex;
  gap: 12px;
  margin-right: 2px;
}

.topbar a {
  text-decoration: none;
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--muted);
  min-width: 132px;
  text-align: center;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 999px;
  letter-spacing: 0.06em;
  transition: box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.hero {
  /* 桌面三栏布局：左侧文案操作区 | 中间视窗 | 右侧控制区 */
  display: grid;
  grid-template-columns: 258px minmax(0, 1fr) 356px;
  gap: 12px;
  height: calc(100vh - 10px);
  padding: 72px 14px 10px;
}

.copy {
  display: flex;
  flex-direction: column;
  /* 左栏文案与底部操作卡片共用一列，操作卡片固定贴底。 */
  gap: 10px;
  justify-content: flex-start;
  min-width: 0;
  min-height: 0;
}

.copy h1 {
  margin: 8px 0px 0px 0px;
  /* 左栏主标题：采用更有笔触感的艺术字体，并控制在左栏宽度内。 */
  font-family: "Kaushan Script", "Sora", Inter, -apple-system, BlinkMacSystemFont, "SF Pro Text", sans-serif;
  font-size: clamp(28px, 2.6vw, 36px);
  font-weight: 400;
  line-height: 1.3;
  letter-spacing: 0.005em;
  /* 冰蓝主题：更突出，但仍保持和页面主色一致。 */
  background: linear-gradient(180deg, #d5ecff 0%, #a9d6ff 48%, #82beff 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  max-width: 100%;
  overflow-wrap: break-word;
  /* 防止手写字体下沿在不同缩放比下被裁切。 */
  padding-bottom: 0.14em;
  text-shadow: 0 0 16px rgba(133, 194, 255, 0.26);
  transition: text-shadow 0.22s ease, filter 0.22s ease;
}

.copy h1 span {
  display: block;
  white-space: nowrap;
}

.copy h1:hover {
  /* 鼠标划过仅轻微增强光晕，不做跳变动画。 */
  text-shadow: 0 0 15px rgba(133, 194, 255, 0.42);
  filter: brightness(1.06);
}

.copy p {
  margin: 8px 0 13px 10px; 
  color: rgba(186, 199, 216, 0.96);
  /* 正文收窄，和标题形成层级，避免文本块过宽。 */
  width: min(100%, 30ch);
  font-size: clamp(12.2px, 0.98vw, 15.6px);
  line-height: 1.9;
  letter-spacing: 0.01em;
  text-align: left;
  text-wrap: pretty;
  hyphens: manual;
  max-width: 100%;
  overflow-wrap: break-word;
}

.feature-row {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
}

.feature-row span {
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.01));
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.02em;
  padding: 10px 16px;
}

.viewport-shell {
  /* 主渲染容器（canvas、扫描线、对比边框、状态动画）。 */
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 24px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0));
  min-height: 520px;
}

#viewport {
  width: 100%;
  height: 100%;
  display: block;
}

#scan-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -4px;
  width: 4px;
  background: linear-gradient(180deg, rgba(126, 185, 237, 0), rgba(126, 185, 237, 1), rgba(126, 185, 237, 0));
  box-shadow: 0 0 24px rgba(126, 185, 237, 0.95);
  opacity: 0;
  z-index: 7;
  transition: opacity 0.2s;
}

#scan-line.scan-indicator {
  opacity: 0.7;
  animation: preScan 0.95s ease-in-out infinite;
}

#split-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 1px;
  background: rgba(242, 247, 255, 0.58);
  left: 50%;
  z-index: 6;
  cursor: ew-resize;
  transition: opacity 0.26s ease;
}

#split-handle.hidden {
  opacity: 0;
  pointer-events: none;
}

#split-handle span {
  position: absolute;
  top: 50%;
  left: -7px;
  width: 14px;
  height: 40px;
  transform: translateY(-50%);
  border: 1px solid rgba(255, 255, 255, 0.45);
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.08);
}

.action-card {
  /* 操作卡片固定在左栏底部，与右侧控制栏底部保持对齐。 */
  margin-top: auto;
  margin-bottom: 2px;
  width: 100%;
  max-width: 100%;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid rgba(126, 185, 237, 0.36);
  background: linear-gradient(180deg, rgba(18, 31, 54, 0.66), rgba(8, 12, 22, 0.72));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06), 0 10px 26px rgba(0, 0, 0, 0.26);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.model-label {
  color: rgba(214, 233, 255, 0.84);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.model-select {
  width: 100%;
  height: 44px;
  border-radius: 12px;
  border: 1px solid rgba(126, 185, 237, 0.48);
  background: linear-gradient(180deg, rgba(20, 38, 66, 0.84), rgba(10, 16, 30, 0.84));
  color: #d8e8fb;
  font-size: 12px;
  letter-spacing: 0.06em;
  padding: 0 12px;
  outline: none;
  appearance: menulist;
  -webkit-appearance: menulist;
  -moz-appearance: menulist;
  background-image: none;
  text-align: left;
}

.model-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#generate-btn {
  position: static;
  transform: none;
  width: 100%;
  height: 48px;
  min-width: 0;
  padding: 0 24px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(5, 5, 5, 0.64);
  color: var(--text);
  font-size: clamp(12px, 0.95vw, 14px);
  letter-spacing: 0.08em;
  cursor: pointer;
  white-space: nowrap;
  line-height: 1;
  transition: box-shadow 0.2s ease, border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}

#generate-btn.compare-mode {
  color: #d5e8ff;
  border-color: rgba(126, 185, 237, 0.85);
  background: rgba(20, 44, 76, 0.72);
}

#generate-btn:hover {
  border-color: rgba(126, 185, 237, 0.9);
  box-shadow: 0 0 18px rgba(126, 185, 237, 0.38);
}

#loading-ring {
  position: absolute;
  right: 18px;
  top: 16px;
  width: 22px;
  height: 22px;
  border: 2px solid rgba(126, 185, 237, 0.15);
  border-top-color: rgba(126, 185, 237, 0.95);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  opacity: 0;
  z-index: 9;
}

.controls {
  /* 右侧面板保持满高，使 preset 列表始终贴底。 */
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 20px;
  background: rgba(7, 10, 18, 0.8);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  height: 100%;
  min-height: 520px;
  overflow: hidden;
}

.slider-wrap label,
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 10px;
}

input[type='range'] {
  width: 100%;
}

input[type='range']:disabled {
  opacity: 0.34;
  cursor: not-allowed;
}

input[type='checkbox']:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.actions {
  display: flex;
  gap: 8px;
}

.upload-btn,
#download-btn {
  flex: 1;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 12px;
  text-decoration: none;
  color: var(--text);
  text-align: center;
  font-size: 10px;
  padding: 8px 8px;
  cursor: pointer;
  transition: box-shadow 0.2s ease, border-color 0.2s ease, background 0.2s ease;
}

.upload-btn:hover,
#download-btn:hover,
.topbar a:hover,
.preset-card:hover {
  border-color: rgba(126, 185, 237, 0.78);
  box-shadow: 0 0 16px rgba(126, 185, 237, 0.34);
  background: rgba(126, 185, 237, 0.08);
}

.preset-card:hover {
  transform: translateY(-1px);
}

.upload-btn input {
  display: none;
}

#download-btn.disabled {
  pointer-events: none;
  opacity: 0.4;
}

#generate-btn:disabled,
.upload-btn:has(input:disabled) {
  opacity: 0.45;
  cursor: not-allowed;
}

.status {
  min-height: 16px;
  color: var(--line);
  font-size: 10px;
  line-height: 1.35;
}

.preset-panel {
  /* 占据剩余高度并锚定到底部区域。 */
  border-top: 1px solid rgba(255, 255, 255, 0.09);
  padding-top: 10px;
  margin-top: auto;
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.preset-panel h3 {
  margin: 0 0 8px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}

.preset-grid {
  /* preset 卡片滚动区：采用弹性高度，避免固定高度导致布局漂移。 */
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  overflow-y: auto;
  padding-right: 0;
  flex: 1 1 auto;
  min-height: 0;
  max-height: none;
  align-content: start;
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
  scrollbar-gutter: stable;
}

.preset-grid::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.preset-grid::-webkit-scrollbar-track {
  background: transparent;
}

.preset-grid::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 999px;
  border: 1px solid transparent;
}

.preset-grid.scrolling {
  scrollbar-color: rgba(126, 185, 237, 0.55) rgba(255, 255, 255, 0.06);
}

.preset-grid.scrolling::-webkit-scrollbar {
  width: 10px;
}

.preset-grid.scrolling::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  backdrop-filter: blur(8px);
}

.preset-grid.scrolling::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, rgba(126, 185, 237, 0.88), rgba(126, 185, 237, 0.45));
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.preset-grid.disabled {
  opacity: 0.45;
  pointer-events: none;
}

.preset-card {
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  padding: 5px;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.preset-card.active {
  border-color: rgba(126, 185, 237, 0.85);
  box-shadow: 0 0 0 1px rgba(126, 185, 237, 0.25);
}

.preset-card img {
  width: 100%;
  aspect-ratio: 1.45;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}

.preset-card span {
  margin-top: 6px;
  font-size: 9.5px;
  color: var(--text);
  display: block;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

@keyframes preScan {
  0% {
    left: 0%;
    opacity: 0.22;
  }
  20% {
    opacity: 0.78;
  }
  50% {
    left: 52%;
    opacity: 0.92;
  }
  100% {
    left: 100%;
    opacity: 0.22;
  }
}

.compare-frames {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 6;
}

.compare-frames.hidden {
  display: none;
}

.compare-frame {
  position: absolute;
  border-radius: 22px;
  border: 1px solid rgba(126, 185, 237, 0.42);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
  color: rgba(224, 238, 255, 0.72);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  padding: 12px;
  background: transparent;
  backdrop-filter: none;
  opacity: 0;
  transition: opacity 0.16s ease;
}

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

  .hero {
    grid-template-columns: 208px minmax(0, 1fr) 292px;
    height: auto;
    min-height: calc(100vh - 10px);
    padding-top: 66px;
  }

  .logo {
    font-size: clamp(20px, 2.2vw, 24px);
  }

  .topbar a {
    min-width: 106px;
    font-size: 12px;
    padding: 8px 12px;
  }

  .copy h1 {
    font-size: clamp(26px, 2.5vw, 32px);
    line-height: 1.14;
  }

  .copy p {
    width: min(100%, 29ch);
    font-size: clamp(11.8px, 1.12vw, 13px);
    line-height: 1.52;
  }

  .viewport-shell {
    min-height: 60vh;
  }

  .controls {
    min-height: 0;
    height: auto;
  }

  .preset-grid {
    max-height: none;
  }
}

@media (max-width: 900px) {
  .hero {
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 72px 10px 12px;
  }

  .copy h1 {
    font-size: clamp(24px, 6.8vw, 34px);
    line-height: 1.14;
  }

  .action-card {
    max-width: 420px;
  }

  .copy p {
    width: min(100%, 30ch);
    font-size: clamp(12px, 3.3vw, 14px);
    line-height: 1.54;
  }

  .viewport-shell {
    min-height: 56vh;
  }

  .controls {
    min-height: 0;
    padding: 14px;
  }
}

@media (max-width: 1024px) and (orientation: landscape) {
  html,
  body {
    overflow: hidden;
  }

  .hero {
    /* 横屏移动端/平板保持三栏一致布局，不切成单列。 */
    grid-template-columns: minmax(250px, 0.95fr) minmax(0, 1.9fr) minmax(250px, 0.95fr);
    gap: 10px;
    height: calc(100vh - 10px);
    min-height: 0;
    padding: 66px 10px 10px;
  }

  .copy h1 {
    font-size: clamp(22px, 2.9vw, 32px);
    line-height: 1.14;
  }

  .copy p {
    width: min(100%, 28ch);
    font-size: clamp(11px, 1.35vw, 12.8px);
    line-height: 1.46;
  }

  .feature-row span {
    font-size: 11px;
    padding: 8px 12px;
  }

  .action-card {
    padding: 10px;
    gap: 8px;
  }

  #generate-btn {
    height: 42px;
    font-size: 13px;
  }

  .viewport-shell,
  .controls {
    min-height: 0;
    height: 100%;
  }

  .controls {
    padding: 12px;
  }
}
