:root {
  --bg: #f3f6fb;
  --panel: #ffffff;
  --panel-soft: #f8fbff;
  --text: #111827;
  --muted: #687385;
  --line: #dce5f1;
  --line-strong: #c8d5e6;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --accent-soft: #eaf2ff;
  --danger: #b42318;
  --shadow: 0 2px 12px rgba(15, 23, 42, 0.06);
  --shadow-strong: 0 18px 42px rgba(15, 23, 42, 0.09);
}

body[data-theme="light"] { color-scheme: light; }
body[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101722;
  --panel: #172033;
  --panel-soft: #111827;
  --text: #e6edf7;
  --muted: #9aa8ba;
  --line: #29364a;
  --line-strong: #40516a;
  --accent: #60a5fa;
  --accent-dark: #bfdbfe;
  --accent-soft: #183456;
  --danger: #fca5a5;
  --shadow: 0 2px 14px rgba(0, 0, 0, 0.28);
  --shadow-strong: 0 18px 42px rgba(0, 0, 0, 0.34);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: "Microsoft YaHei", Arial, sans-serif;
  transition: background 0.2s ease, color 0.2s ease;
}
button, select { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.announcement-bar { padding: 18px 22px 0; background: var(--bg); }
.announcement-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 1480px;
  min-height: 44px;
  margin: 0 auto;
  padding: 12px 14px;
  border: 1px solid #bfdbfe;
  border-left: 4px solid var(--accent);
  border-radius: 16px;
  background: #eff6ff;
  color: #1e3a8a;
  box-shadow: var(--shadow);
  font-size: 14px;
  line-height: 1.55;
}
body[data-theme="dark"] .announcement-inner { border-color: #2f5f95; border-left-color: var(--accent); background: #10243a; color: #dbeafe; }
.announcement-inner strong { flex: 0 0 auto; font-weight: 900; }
.announcement-inner span { min-width: 0; }
.announcement-inner a { flex: 0 0 auto; color: var(--accent-dark); font-weight: 800; text-decoration: none; }
.announcement-inner a:hover { text-decoration: underline; }

.app {
  min-height: calc(100vh - 80px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 22px;
  padding: 22px;
}
.preview-panel,
.control-panel {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
  transition: background 0.2s ease, border-color 0.2s ease;
}
.preview-panel { min-width: 0; display: flex; flex-direction: column; padding: 18px; }
.preview-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 2px 4px 14px; }
.eyebrow { margin: 0 0 4px; color: var(--accent); font-size: 12px; font-weight: 900; letter-spacing: 0; text-transform: uppercase; }
.preview-header h1,
.panel-header h2 { margin: 0; font-size: 24px; line-height: 1.22; }
.preview-tools { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; }
.preview-tools span,
.pin-preview-button { min-height: 34px; display: inline-flex; align-items: center; border-radius: 999px; padding: 0 12px; font-size: 12px; font-weight: 900; }
.preview-tools span { background: var(--accent-soft); color: var(--accent-dark); }
.pin-preview-button { border: 1px solid var(--accent); background: var(--accent); color: #ffffff; cursor: pointer; }
.canvas-shell { flex: 1; min-height: 0; display: grid; place-items: center; padding: 18px; border: 0; border-radius: 0; background: var(--bg); }
body[data-theme="dark"] .canvas-shell { background: var(--bg); }
#previewCanvas { width: min(100%, calc(100vh - 210px)); max-width: 920px; aspect-ratio: 1 / 1; height: auto; display: block; border: 0; border-radius: 0; background: transparent; }
.preview-note { margin: 12px 4px 0; color: var(--muted); font-size: 12px; line-height: 1.6; text-align: center; }

.control-panel { display: flex; flex-direction: column; min-height: 0; padding: 18px; }
.panel-header { padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.panel-header p:last-child,
.panel-header #statusText { margin: 8px 0 0; min-height: 20px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.panel-header p.is-error { color: var(--danger); font-weight: 700; }
.theme-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; }
.theme-row > span { color: var(--muted); font-size: 13px; font-weight: 900; }
.theme-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel-soft); }
.theme-toggle button { min-width: 58px; min-height: 32px; border: 0; border-radius: 999px; background: transparent; color: var(--muted); cursor: pointer; font-weight: 900; }
.theme-toggle button.is-active { background: var(--accent); color: #ffffff; box-shadow: var(--shadow); }

.selection-summary { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; margin: 14px 0 0; padding: 12px; border: 1px solid #bfdbfe; border-radius: 12px; background: var(--accent-soft); }
body[data-theme="dark"] .selection-summary { border-color: #2f5f95; }
.selection-summary span { display: block; margin-bottom: 4px; color: #1e40af; font-size: 12px; font-weight: 900; }
.selection-summary p { margin: 0; color: #1f3f77; font-size: 13px; line-height: 1.5; }
body[data-theme="dark"] .selection-summary span,
body[data-theme="dark"] .selection-summary p { color: #dbeafe; }
.selection-summary button { min-width: 58px; min-height: 34px; border: 1px solid #93c5fd; border-radius: 10px; background: #ffffff; color: var(--accent-dark); cursor: pointer; font-weight: 900; }
body[data-theme="dark"] .selection-summary button { border-color: #3b82f6; background: #0f172a; color: #bfdbfe; }

.controls { overflow: auto; display: grid; gap: 12px; padding: 16px 0; }
.control-section { overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
.control-section summary { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; min-height: 54px; padding: 13px 14px; cursor: pointer; list-style: none; }
.control-section summary::-webkit-details-marker { display: none; }
.section-title { font-weight: 900; font-size: 15px; }
.section-badge { padding: 3px 8px; border-radius: 999px; background: #eef2ff; color: #3730a3; font-size: 11px; font-weight: 900; }
body[data-theme="dark"] .section-badge { background: #1e3a5f; color: #bfdbfe; }
.section-arrow { color: var(--accent); font-size: 15px; font-weight: 900; }
.control-section[open] .section-arrow { transform: rotate(180deg); }
.section-hint { grid-column: 1 / -1; color: var(--muted); font-size: 12px; }
.section-body { display: grid; gap: 0; padding: 0 14px 12px; }
.control-group { display: grid; grid-template-columns: minmax(96px, 0.42fr) minmax(0, 1fr); gap: 12px; align-items: center; padding: 12px 0; border-top: 1px solid #eef2f7; }
body[data-theme="dark"] .control-group { border-top-color: #263449; }
.control-label { display: flex; align-items: center; gap: 8px; min-width: 0; font-weight: 900; font-size: 13px; }
.color-dot { width: 9px; height: 9px; flex: 0 0 auto; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.1); }
.control-group select { width: 100%; height: 40px; padding: 0 34px 0 12px; border: 1px solid var(--line-strong); border-radius: 8px; background-color: #ffffff; color: var(--text); cursor: pointer; }
body[data-theme="dark"] .control-group select { background-color: #0f172a; }
.control-group select:focus { outline: 2px solid rgba(37, 99, 235, 0.18); border-color: var(--accent); }
.mobile-choice-button { display: none; width: 100%; min-height: 42px; align-items: center; justify-content: space-between; border: 1px solid var(--line-strong); border-radius: 8px; background: var(--panel-soft); color: var(--text); cursor: pointer; padding: 0 12px; text-align: left; font-weight: 800; }
.mobile-choice-button span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.actions button { min-height: 44px; border: 1px solid var(--accent); border-radius: 10px; background: #ffffff; color: var(--accent); cursor: pointer; font-weight: 900; transition: transform 0.16s ease, box-shadow 0.16s ease, background 0.16s ease; }
body[data-theme="dark"] .actions button { background: #0f172a; }
.actions button:hover,
.selection-summary button:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.actions button:last-child { background: var(--accent); color: #ffffff; }
.actions button:last-child:hover { background: var(--accent-dark); }
.color-sheet { display: none; }

@media (max-width: 980px) {
  .announcement-bar { padding: 12px 12px 0; }
  .announcement-inner { align-items: flex-start; flex-direction: column; gap: 6px; padding: 12px; font-size: 13px; }
  .app { grid-template-columns: 1fr; gap: 14px; padding: 12px; }
  .preview-panel, .control-panel { border-radius: 14px; padding: 14px; }
  .preview-header h1, .panel-header h2 { font-size: 22px; }
  .theme-row { align-items: flex-start; flex-direction: column; }
  .theme-toggle { width: 100%; }
  .canvas-shell { padding: 10px; }
  #previewCanvas { width: min(100%, calc(100vh - 300px)); min-width: 260px; }
  .control-group { grid-template-columns: 1fr; gap: 8px; }
  .control-group select { display: none; }
  .mobile-choice-button { display: flex; }
  body.preview-pinned .announcement-bar { display: none; }
  body.preview-pinned .app { gap: 10px; }
  body.preview-pinned .preview-panel { position: sticky; top: 0; z-index: 30; margin: -12px -12px 0; border-width: 0 0 1px; border-radius: 0; box-shadow: 0 12px 26px rgba(15, 23, 42, 0.12); }
  body.preview-pinned .preview-header { align-items: center; padding-bottom: 8px; }
  body.preview-pinned .preview-header h1 { font-size: 18px; }
  body.preview-pinned .preview-header .eyebrow,
  body.preview-pinned .preview-note { display: none; }
  body.preview-pinned .canvas-shell { padding: 4px; }
  body.preview-pinned #previewCanvas { width: min(100%, 42vh); min-width: 0; max-width: 520px; }
  .color-sheet { position: fixed; inset: 0; z-index: 80; display: grid; align-items: end; pointer-events: none; }
  body.color-sheet-open .color-sheet { pointer-events: auto; }
  .color-sheet-backdrop { position: absolute; inset: 0; border: 0; background: transparent; }
  .color-sheet-panel { position: relative; z-index: 1; max-height: min(52vh, 480px); display: flex; flex-direction: column; border-radius: 22px 22px 0 0; border: 1px solid var(--line); background: var(--panel); box-shadow: 0 -18px 42px rgba(15, 23, 42, 0.24); transform: translateY(105%); transition: transform 0.2s ease; }
  body.color-sheet-open .color-sheet-panel { transform: translateY(0); }
  .color-sheet-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
  .color-sheet-kicker { display: block; margin-bottom: 2px; color: var(--accent); font-size: 11px; font-weight: 900; text-transform: uppercase; }
  .color-sheet-layer-button { min-width: 0; flex: 1; min-height: 48px; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; border: 1px solid var(--line-strong); border-radius: 14px; background: var(--panel-soft); color: var(--text); cursor: pointer; padding: 7px 12px; text-align: left; }
  .color-sheet-layer-button .color-sheet-kicker { grid-column: 1 / -1; }
  .color-sheet-layer-button strong { min-width: 0; overflow: hidden; font-size: 17px; line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; }
  .color-sheet-layer-button b { font-size: 20px; line-height: 1; }
  .color-sheet-close { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 50%; background: var(--panel-soft); color: var(--text); cursor: pointer; font-size: 26px; line-height: 1; }
  .color-sheet-options { overflow: auto; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px 16px 16px; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  .color-sheet-options.is-layer-list { grid-template-columns: 1fr; }
  .color-option-button { min-height: 44px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--panel-soft); color: var(--text); cursor: pointer; font-weight: 800; line-height: 1.35; text-align: center; }
  .color-option-button.is-active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); box-shadow: inset 0 0 0 1px var(--accent); }
  body[data-theme="dark"] .color-option-button.is-active { color: #dbeafe; }
  .layer-option-button { text-align: left; padding-left: 14px; }
  body.preview-pinned.color-sheet-open .color-sheet-panel { max-height: min(44vh, 410px); }
}
