body {
  font-family: "Microsoft YaHei", Arial, sans-serif;
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 20px;
  background-color: #f0f0f0;
  color: #333;
}

h1 {
  color: #333;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}

h1 img {
  width: 36px;
  height: 36px;
  flex: none;
}

.privacy {
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.5;
  color: #555;
  text-align: center;
}

.container {
  background-color: white;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 900px;
  box-sizing: border-box;
}

input[type="file"],
input[type="text"] {
  margin: 10px 0;
  padding: 10px;
  border: 1px solid #ccc;
  border-radius: 5px;
  width: 300px;
  max-width: 100%;
  box-sizing: border-box;
}

select,
input[type="number"],
input[type="range"],
input[type="color"] {
  margin: 10px 0;
  padding: 5px;
  border: 1px solid #ccc;
  border-radius: 5px;
  width: 150px;
}

button {
  margin: 10px;
  padding: 10px 20px;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
}

@media (hover: hover) and (pointer: fine) {
  button:hover {
    background-color: #0056b3;
  }
}

#canvas {
  display: none;
  max-width: none;
}

#canvas.is-visible {
  display: block;
}

.canvas-container {
  display: none;
  max-width: 100%;
  min-width: 0;
  overflow: auto;
  margin-top: 10px;
  border: 1px solid #ccc;
  box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
}

.canvas-container.is-visible {
  display: block;
}

#download {
  display: none;
}

#download.is-visible {
  display: inline-block;
}

.options {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
  max-width: 800px;
}

.option-group {
  margin: 5px 10px;
  padding: 5px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  width: 180px;
}

.option-group label {
  margin-bottom: 3px;
  font-size: 14px;
}

.zoom-controls {
  margin: 10px 0;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.color-templates {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 10px 0;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.color-template-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid #ddd;
  cursor: pointer;
  padding: 0;
  margin: 0;
  transition: transform 0.15s, border-color 0.15s;
}

@media (hover: hover) and (pointer: fine) {
  .color-template-btn:hover {
    transform: scale(1.15);
    border-color: #007bff;
  }
}

.color-template-btn.active {
  border-color: #007bff;
  box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.4);
}

.color-template-btn.light {
  border-color: #999;
}

.color-btn-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.color-template-label {
  font-size: 12px;
  color: #666;
  text-align: center;
  margin-top: 2px;
}

.current-color-info {
  font-size: 13px;
  color: #555;
  margin: 5px 0;
  text-align: center;
}

.current-color-name {
  font-weight: bold;
  color: #007bff;
}

.current-color-hex {
  font-weight: normal;
  color: #888;
}

.section-title {
  font-size: 14px;
  color: #333;
  font-weight: bold;
  margin: 12px 0 5px;
  width: 100%;
  text-align: center;
}

.scene-templates {
  display: flex;
  gap: 12px;
  margin: 10px 0;
  flex-wrap: wrap;
  justify-content: center;
}

.scene-btn {
  margin: 0;
  padding: 12px 22px;
  border: 2px solid #ccc;
  border-radius: 8px;
  background-color: #fafafa;
  color: #333;
  cursor: pointer;
  font-size: 14px;
  transition: border-color 0.2s, background-color 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 140px;
}

@media (hover: hover) and (pointer: fine) {
  .scene-btn:hover {
    border-color: #007bff;
    background-color: #f0f7ff;
  }
}

.scene-btn.active {
  border-color: #007bff;
  background-color: #e6f0ff;
  box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.2);
}

.scene-title {
  font-weight: bold;
  font-size: 15px;
  margin-bottom: 3px;
}

.scene-desc {
  font-size: 12px;
  color: #888;
}

.scene-btn.active .scene-desc {
  color: #007bff;
}

.auto-detect-tip {
  font-size: 13px;
  color: #28a745;
  margin: 5px 0;
  min-height: 18px;
  text-align: center;
}

.missing {
  max-width: 640px;
  margin: 40px auto;
  padding: 24px;
  background: white;
  border-radius: 10px;
  text-align: center;
}

.missing a {
  color: #007bff;
}

.controls,
.preview-panel {
  width: 100%;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#fit-screen {
  margin: 0;
}

input[type="range"] {
  accent-color: #007bff;
}

@media (max-width: 720px) {
  body {
    margin: 0;
    min-height: 100dvh;
  }

  .container {
    min-height: 100dvh;
    border-radius: 0;
    box-shadow: none;
    padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }

  h1 {
    justify-content: center;
    font-size: 1.35rem;
    line-height: 1.3;
    text-align: center;
    margin: 0 0 6px;
  }

  .privacy {
    margin-bottom: 8px;
    font-size: 13px;
  }

  input[type="file"],
  input[type="text"],
  input[type="number"],
  select {
    width: 100%;
    max-width: none;
    font-size: 16px;
  }

  input[type="file"],
  input[type="text"] {
    margin: 6px 0;
  }

  .section-title {
    margin: 8px 0 4px;
  }

  .scene-templates {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
    gap: 8px;
    margin: 6px 0;
  }

  .scene-btn {
    width: 100%;
    min-width: 0;
    min-height: 48px;
    padding: 10px 14px;
    box-sizing: border-box;
  }

  .scene-title,
  .scene-desc {
    text-align: center;
    line-height: 1.35;
  }

  .auto-detect-tip {
    margin: 2px 0 4px;
  }

  .preview-panel {
    order: 1;
  }

  .controls {
    order: 2;
  }

  .preview-panel:not(:has(.is-visible)) {
    display: none;
  }

  .color-templates {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    justify-items: center;
    gap: 10px 4px;
  }

  .color-btn-wrapper {
    width: 100%;
    min-width: 0;
  }

  .color-template-btn {
    width: 40px;
    height: 40px;
  }

  .color-template-label {
    width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 14px;
    max-width: none;
  }

  .option-group {
    width: auto;
    min-width: 0;
    margin: 0;
    padding: 0;
  }

  .option-group:last-child {
    grid-column: 1 / -1;
  }

  .option-group label {
    line-height: 1.35;
  }

  .option-group select,
  .option-group input[type="number"],
  .option-group input[type="range"],
  .option-group input[type="color"] {
    width: 100%;
    margin: 6px 0 0;
    box-sizing: border-box;
  }

  .option-group input[type="color"] {
    height: 42px;
    padding: 4px;
  }

  #add-watermark,
  #download.is-visible {
    width: 100%;
    min-height: 48px;
    margin: 8px 0 0;
    font-size: 16px;
    box-sizing: border-box;
  }

  .zoom-controls {
    width: 100%;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    margin: 0 0 8px;
  }

  .zoom-controls label {
    font-size: 14px;
    white-space: nowrap;
  }

  .zoom-controls input[type="range"] {
    width: 100%;
    margin: 0;
    padding: 0;
  }

  #fit-screen {
    width: auto;
    min-height: 44px;
    margin: 0;
    padding: 8px 12px;
    font-size: 14px;
    white-space: nowrap;
  }

  .canvas-container.is-visible {
    width: 100%;
    max-height: 52vh;
    margin-top: 8px;
    box-sizing: border-box;
  }
}

@media (max-width: 720px) and (min-height: 781px) {
  .canvas-container.is-visible {
    /* 表单仍在预览上方。减去标题到画布、下载按钮和底部安全区。 */
    max-height: calc(100dvh - 580px);
  }
}

@media (max-width: 720px) and (max-height: 780px) {
  .container:has(#canvas.is-visible) > * {
    order: 3;
  }

  .container:has(#canvas.is-visible) > h1 {
    order: 0;
    margin-bottom: 8px;
  }

  .container:has(#canvas.is-visible) > .preview-panel {
    order: 1;
  }
}

@media (max-width: 380px) {
  .options {
    grid-template-columns: 1fr;
  }
}
