:root {
  --bg: #121614;
  --bg-deep: #0c0f0d;
  --bg-panel: #1a1f1c;
  --bg-elevated: #232a26;
  --border: #2f3833;
  --border-soft: #26302b;
  --text: #eef2ef;
  --text-muted: #8e9a92;
  --accent: #2f9e8a;
  --accent-hover: #3cb89f;
  --accent-dim: rgba(47, 158, 138, 0.16);
  --danger: #d96868;
  --ok: #5cbc7a;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 10px 28px rgba(0, 0, 0, 0.28);
  --font: "Noto Sans TC", "PingFang HK", "Hiragino Sans CNS", "Microsoft JhengHei", sans-serif;
  --font-display: "IBM Plex Sans", "Noto Sans TC", sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background:
    radial-gradient(ellipse 70% 45% at 8% -5%, rgba(47, 158, 138, 0.14), transparent 55%),
    radial-gradient(ellipse 50% 40% at 95% 5%, rgba(201, 162, 39, 0.07), transparent 50%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.editor-panel,
.controls-panel,
.preview-panel,
#htmlSource {
  scrollbar-width: thin;
  scrollbar-color: #3d4a43 transparent;
}

.app {
  max-width: 1520px;
  margin: 0 auto;
  padding: 22px 18px 48px;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-soft);
}

.brand-kicker {
  font-family: var(--font-display);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 6px;
}

.app-header h1 {
  font-family: var(--font-display);
  font-size: clamp(1.35rem, 2.2vw, 1.7rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.lede {
  font-size: 0.84rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.home-link {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
}

.home-link:hover {
  color: var(--accent-hover);
}

.badge {
  font-size: 0.72rem;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 999px;
  background: var(--accent-dim);
  border: 1px solid rgba(47, 158, 138, 0.35);
  color: var(--accent-hover);
  white-space: nowrap;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 1.1fr) minmax(240px, 0.75fr) minmax(320px, 1.15fr);
  gap: 16px;
  align-items: start;
}

.editor-panel,
.controls-panel,
.preview-panel {
  max-height: calc(100vh - 120px);
  overflow-y: auto;
}

.preview-panel {
  position: sticky;
  top: 14px;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr 1fr;
  }
  .editor-panel {
    grid-column: 1 / -1;
    max-height: none;
  }
  .preview-panel {
    position: static;
  }
}

@media (max-width: 720px) {
  .layout {
    grid-template-columns: 1fr;
  }
  .editor-panel,
  .controls-panel,
  .preview-panel {
    max-height: none;
  }
}

.panel {
  background: linear-gradient(165deg, rgba(255, 255, 255, 0.03), transparent 40%), var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-soft);
}

.panel-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-head h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 0.95rem;
  font-weight: 700;
}

.step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: var(--accent-dim);
  color: var(--accent-hover);
  font-size: 0.72rem;
  font-weight: 700;
  font-family: var(--font-display);
}

.meta {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin: 0 0 8px;
  line-height: 1.5;
}

.btn-reset {
  flex-shrink: 0;
  padding: 4px 10px;
  font-size: 0.72rem;
  font-weight: 650;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: inherit;
  cursor: pointer;
}

.btn-reset:hover {
  color: var(--danger);
  border-color: rgba(217, 104, 104, 0.5);
  background: rgba(217, 104, 104, 0.08);
}

.dropzone {
  border: 1.5px dashed #44524a;
  border-radius: var(--radius-sm);
  padding: 18px 14px 16px;
  text-align: center;
  cursor: pointer;
  background: rgba(35, 42, 38, 0.55);
  margin-bottom: 14px;
  transition: border-color 0.2s, background 0.2s;
}

.dropzone:hover,
.dropzone:focus-visible,
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-dim);
  outline: none;
}

.dropzone-icon {
  width: 32px;
  height: 32px;
  margin: 0 auto 8px;
  border-radius: 10px;
  border: 1.5px dashed #5a6b62;
  position: relative;
}

.dropzone-icon::before,
.dropzone-icon::after {
  content: "";
  position: absolute;
  background: var(--text-muted);
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.dropzone-icon::before {
  width: 12px;
  height: 2px;
}

.dropzone-icon::after {
  width: 2px;
  height: 12px;
}

.dropzone-title {
  font-size: 0.86rem;
  font-weight: 650;
}

.dropzone-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.preset-row,
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}

.chip-row .btn-chip {
  flex: 1;
  min-width: 72px;
  text-align: center;
  border-radius: 8px;
}

.btn-chip {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 6px 12px;
  font-size: 0.76rem;
  font-weight: 600;
  border-radius: 999px;
  font-family: inherit;
  cursor: pointer;
}

.btn-chip:hover,
.btn-chip.active {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent-hover);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 0.86rem;
}

.field textarea {
  font-family: "IBM Plex Sans", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.78rem;
  line-height: 1.5;
  min-height: 280px;
  resize: vertical;
}

.check-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.8rem;
  margin-bottom: 16px;
  cursor: pointer;
}

.check-row input {
  margin-top: 3px;
}

.export-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.btn {
  border: none;
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 650;
  padding: 8px 14px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s, border-color 0.15s, transform 0.1s;
}

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

.btn-primary {
  width: 100%;
  background: linear-gradient(180deg, var(--accent-hover), var(--accent));
  color: #061210;
  padding: 12px 14px;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(47, 158, 138, 0.28);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-block {
  width: 100%;
  padding: 10px 14px;
}

.preview-stage {
  background:
    linear-gradient(45deg, #151a17 25%, transparent 25%),
    linear-gradient(-45deg, #151a17 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #151a17 75%),
    linear-gradient(-45deg, transparent 75%, #151a17 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-color: #0e1210;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  min-height: 360px;
  overflow: auto;
  display: flex;
  justify-content: center;
  padding: 16px 12px 20px;
}

#previewFrame {
  background: #fff;
  border: 0;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
  transform-origin: top center;
}

.capture-host {
  position: fixed;
  left: -12000px;
  top: 0;
  background: #fff;
  color: #111;
  z-index: -1;
}

.status {
  font-size: 0.78rem;
  margin-top: 8px;
  color: var(--text-muted);
}

.status.error {
  color: var(--danger);
}

.status.ok {
  color: var(--ok);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}
