:root {
  color-scheme: light;
  --page: #eef1f6;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #ffffff;
  --surface-soft: rgba(255, 255, 255, 0.5);
  --ink: #1d232b;
  --muted: #8a9099;
  --line: rgba(60, 70, 85, 0.1);
  --line-strong: rgba(60, 70, 85, 0.2);
  --blue: #0d6efd;
  --blue-dark: #075acb;
  --glass-blur: saturate(180%) blur(22px);
  --shadow: 0 12px 40px rgba(38, 52, 74, 0.12);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--page);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(1100px 620px at 12% -8%, rgba(120, 159, 204, 0.22), transparent 60%),
    radial-gradient(900px 560px at 108% 4%, rgba(148, 130, 220, 0.18), transparent 55%),
    var(--page);
  background-attachment: fixed;
}

button,
input,
textarea {
  font: inherit;
}

button,
input[type="range"],
input[type="color"] {
  cursor: pointer;
}

button {
  color: inherit;
}

:focus-visible {
  outline: 3px solid rgba(13, 110, 253, 0.24);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(348px, 1fr);
  align-items: start;
  width: min(100% - 40px, 1200px);
  margin: 0 auto;
  padding: 28px 0 44px;
  gap: 28px;
}

.preview-pane {
  min-width: 0;
}

.preview-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  margin: 0 0 10px;
}

.eyebrow,
.canvas-size,
.preview-meta {
  color: var(--muted);
  font-size: 12px;
}

.eyebrow {
  color: #6c7480;
}

.preview-heading h1 {
  margin: 2px 0 0;
  font-size: 23px;
  line-height: 1.25;
}

.canvas-size {
  padding-bottom: 2px;
  font-variant-numeric: tabular-nums;
}

.canvas-frame {
  overflow: hidden;
  width: 100%;
  aspect-ratio: 16 / 9;
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 2px;
  background: #000;
  box-shadow: var(--shadow);
}

.canvas-frame canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
}

.preview-meta {
  display: flex;
  justify-content: space-between;
  padding: 8px 2px 0;
}

.editor-panel {
  position: sticky;
  top: 20px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 2px;
  background: var(--surface);
  -webkit-backdrop-filter: var(--glass-blur);
  backdrop-filter: var(--glass-blur);
  box-shadow: var(--shadow), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.control-section {
  padding: 16px 20px 18px;
}

.control-section + .control-section {
  border-top: 1px solid var(--line);
}

.section-heading {
  display: flex;
  align-items: center;
  min-height: 20px;
  margin-bottom: 13px;
}

.section-heading h2 {
  margin: 0;
  color: #125dbf;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1.4;
}

.field,
.range-field {
  display: block;
}

.field + .field,
.field-row + .field,
.field-row,
.range-grid + .settings-label,
.settings-label + .range-grid,
.settings-label-spaced {
  margin-top: 14px;
}

.field > span,
.control-group legend,
.range-field > span {
  display: block;
  color: #495057;
  font-size: 12px;
  font-weight: 600;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.62);
  outline: none;
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.field input {
  height: 38px;
  padding: 0 11px;
}

.field select {
  height: 38px;
  padding: 0 34px 0 11px;
  appearance: auto;
}

.field textarea {
  min-height: 62px;
  padding: 8px 11px;
  resize: vertical;
  line-height: 1.5;
}

.field input:focus,
.field textarea:focus,
.field select:focus {
  border-color: var(--blue);
  background: #ffffff;
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.12);
}

.field small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
  text-align: right;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

/* 并排的两个字段不应再叠加 .field + .field 的 14px 上边距，否则会错位 */
.field-row > .field + .field {
  margin-top: 0;
}

.control-group {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.control-group legend {
  margin-bottom: 9px;
  padding: 0;
}

.template-selector {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.template-button {
  display: grid;
  width: 100%;
  height: 92px;
  padding: 4px;
  border: 2px solid var(--line);
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.5);
  font-size: 11px;
  text-align: center;
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

.template-button:hover {
  border-color: #aeb4bc;
  background: rgba(255, 255, 255, 0.72);
}

.template-button[aria-pressed="true"] {
  border-color: var(--blue);
  background: #ffffff;
  box-shadow: 0 0 0 1px rgba(13, 110, 253, 0.08);
}

.template-button svg {
  display: block;
  width: 100%;
  min-height: 0;
  height: 66px;
  border-radius: 2px;
}

.tmpl-cap {
  display: block;
  align-self: end;
  color: #aeb4bc;
  font-size: 11px;
  line-height: 13px;
}

.template-button[aria-pressed="true"] .tmpl-cap {
  color: var(--blue);
}

.settings-label {
  color: #495057;
  font-size: 12px;
  font-weight: 600;
}

.range-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 22px;
}

.range-field > span {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  min-height: 19px;
}

.range-field output {
  color: var(--blue);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

/* ===== 苹果风玻璃滑块 ===== */
.range-field input[type="range"] {
  --fill: 50%;
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 6px;
  margin: 9px 0 0;
  border-radius: 999px;
  background: linear-gradient(
    to right,
    var(--blue) 0%,
    var(--blue) var(--fill),
    rgba(118, 132, 152, 0.32) var(--fill),
    rgba(118, 132, 152, 0.32) 100%
  );
  box-shadow: inset 0 1px 2px rgba(20, 28, 40, 0.22),
    inset 0 0 0 1px rgba(255, 255, 255, 0.3);
  cursor: pointer;
}

.range-field input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
}

.range-field input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  margin-top: -8px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #ffffff 0%, #eef2f8 70%, #dde4ee 100%);
  border: 0.5px solid rgba(20, 28, 40, 0.12);
  box-shadow: 0 1px 4px rgba(20, 28, 40, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.95);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 140ms ease;
}

.range-field input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.08);
  box-shadow: 0 2px 7px rgba(13, 110, 253, 0.32),
    0 0 0 6px rgba(13, 110, 253, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.95);
}

.range-field input[type="range"]:focus-visible::-webkit-slider-thumb {
  box-shadow: 0 0 0 5px rgba(13, 110, 253, 0.18),
    0 1px 4px rgba(20, 28, 40, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.95);
}

.range-field input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 999px;
  background: rgba(118, 132, 152, 0.32);
  box-shadow: inset 0 1px 2px rgba(20, 28, 40, 0.22),
    inset 0 0 0 1px rgba(255, 255, 255, 0.3);
}

.range-field input[type="range"]::-moz-range-progress {
  height: 6px;
  border-radius: 999px;
  background: var(--blue);
}

.range-field input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 28%, #ffffff 0%, #eef2f8 70%, #dde4ee 100%);
  border: 0.5px solid rgba(20, 28, 40, 0.12);
  box-shadow: 0 1px 4px rgba(20, 28, 40, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.95);
  cursor: pointer;
  transition: transform 120ms ease, box-shadow 140ms ease;
}

.range-field input[type="range"]::-moz-range-thumb:hover {
  transform: scale(1.08);
  box-shadow: 0 2px 7px rgba(13, 110, 253, 0.32),
    0 0 0 6px rgba(13, 110, 253, 0.12),
    inset 0 1px 0 rgba(255, 255, 255, 0.95);
}

.layout-grid {
  align-items: center;
}

.color-field > span {
  margin-bottom: 7px;
}

.color-picker {
  position: relative;
  display: flex;
  width: 132px;
  height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.62);
}

.color-picker button {
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  margin: 4px 8px 4px 4px;
  padding: 0;
  border: 0;
  border-radius: 2px;
  background: #262626;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.12);
}

.color-picker input[type="text"] {
  width: 85px;
  min-width: 0;
  padding: 0 6px 0 0;
  border: 0;
  color: #495057;
  background: transparent;
  font-size: 12px;
  outline: none;
  text-transform: uppercase;
}

.color-picker input[type="color"] {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0 15px;
  border: 1px solid var(--blue);
  border-radius: 2px;
  color: #ffffff;
  background: var(--blue);
  font-size: 13px;
  font-weight: 600;
}

.primary-button:hover {
  border-color: var(--blue-dark);
  background: var(--blue-dark);
}

.toast {
  position: fixed;
  z-index: 50;
  right: 18px;
  bottom: 18px;
  visibility: hidden;
  padding: 10px 13px;
  border-radius: 2px;
  color: #ffffff;
  background: #252b32;
  box-shadow: 0 9px 26px rgba(24, 35, 46, 0.22);
  font-size: 12px;
  opacity: 0;
  transform: translateY(5px);
  transition: opacity 140ms ease, transform 140ms ease, visibility 140ms ease;
}

.toast.is-visible {
  visibility: visible;
  opacity: 1;
  transform: translateY(0);
}

/* ===== 下载确认弹窗（苹果风毛玻璃） ===== */
.confirm-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 23, 42, 0.22);
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  backdrop-filter: blur(10px) saturate(140%);
  opacity: 0;
  visibility: hidden;
  transition: opacity 240ms ease, visibility 240ms ease;
}

.confirm-overlay.is-open {
  opacity: 1;
  visibility: visible;
}

.confirm-dialog {
  width: min(100%, 360px);
  padding: 24px 22px 20px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.7);
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  backdrop-filter: saturate(180%) blur(30px);
  box-shadow: 0 22px 55px rgba(15, 23, 42, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.8);
  text-align: center;
  transform: scale(0.92) translateY(6px);
  opacity: 0;
  transition: transform 320ms cubic-bezier(0.2, 0.85, 0.3, 1.15), opacity 200ms ease;
}

.confirm-overlay.is-open .confirm-dialog {
  transform: scale(1) translateY(0);
  opacity: 1;
}

.confirm-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: rgba(13, 110, 253, 0.12);
  color: var(--blue);
}

.confirm-icon svg {
  width: 22px;
  height: 22px;
}

.confirm-title {
  margin: 0 0 6px;
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.confirm-desc {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.confirm-cancel,
.confirm-ok {
  flex: 1;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 120ms ease, background 140ms ease, border-color 140ms ease, box-shadow 140ms ease;
}

.confirm-cancel {
  border: 1px solid rgba(60, 70, 85, 0.14);
  background: rgba(255, 255, 255, 0.55);
  color: #495057;
}

.confirm-cancel:hover {
  background: rgba(255, 255, 255, 0.9);
}

.confirm-ok {
  border: 1px solid var(--blue);
  background: var(--blue);
  color: #fff;
  box-shadow: 0 4px 14px rgba(13, 110, 253, 0.28);
}

.confirm-ok:hover {
  background: var(--blue-dark);
  border-color: var(--blue-dark);
}

.confirm-cancel:active,
.confirm-ok:active {
  transform: scale(0.97);
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
    width: min(100% - 40px, 640px);
    gap: 22px;
  }

  .editor-panel {
    position: static;
    top: auto;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100% - 28px, 620px);
    padding-top: 18px;
  }

  .control-section {
    padding: 18px 16px 20px;
  }

  .template-selector {
    gap: 8px;
  }

  .template-button {
    width: calc(25% - 6px);
    min-width: 0;
    height: 88px;
  }

  .template-button svg {
    height: 62px;
  }

  .tmpl-cap {
    font-size: 10px;
    line-height: 11px;
  }
}

@media (max-width: 470px) {
  .preview-heading h1 {
    font-size: 20px;
  }

  .canvas-size {
    max-width: 86px;
    text-align: right;
  }

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

  .template-button {
    width: calc(50% - 4px);
    height: 96px;
  }

  .template-button svg {
    height: 70px;
  }
}
