:root {
  color-scheme: light;
  --bg: #f3f6fb;
  --panel: #ffffff;
  --panel-soft: #f8fafc;
  --text: #111827;
  --muted: #64748b;
  --line: #dbe3ee;
  --line-strong: #c8d2df;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --shadow: 0 24px 70px rgb(26 37 58 / 0.12);
  --radius: 8px;
  font-family: Arial, "Microsoft YaHei", "PingFang SC", sans-serif;
}

body[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101722;
  --panel: #172233;
  --panel-soft: #111c2b;
  --text: #e6edf7;
  --muted: #9aa8ba;
  --line: #2a3a50;
  --line-strong: #3b4d66;
  --accent: #7dd3fc;
  --accent-ink: #082032;
  --shadow: 0 24px 80px rgb(0 0 0 / 0.32);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
}

body.save-dialog-open {
  overflow: hidden;
}

button,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.announcement-bar {
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.announcement-inner {
  display: flex;
  gap: 10px;
  align-items: center;
  max-width: 1480px;
  margin: 0 auto;
  color: var(--muted);
  font-size: 14px;
}

.announcement-inner strong {
  color: var(--text);
}

.announcement-inner a {
  color: var(--accent);
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 22px;
  width: min(100%, 1500px);
  margin: 0 auto;
  padding: 22px;
  min-height: 100dvh;
}

.preview-panel,
.control-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.preview-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 20px;
}

.preview-header,
.panel-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.preview-header {
  align-items: flex-start;
  padding-right: 190px;
  padding-bottom: 16px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(26px, 3vw, 40px);
  line-height: 1.05;
}

h2 {
  font-size: 26px;
  line-height: 1.15;
}

.preview-tools {
  position: absolute;
  top: 20px;
  right: 20px;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: nowrap;
  justify-content: flex-end;
  color: var(--muted);
  font-size: 14px;
  white-space: nowrap;
}

.preview-tools span {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 10%, var(--panel-soft));
  color: var(--accent);
  padding: 0 14px;
  font-weight: 700;
}

.pin-preview-button,
.actions button,
.selection-summary button {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel-soft);
  color: var(--text);
  padding: 0 14px;
}

.pin-preview-button.is-active,
.theme-toggle button.is-active,
.actions button:last-child {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
}

.canvas-shell {
  position: relative;
  display: grid;
  place-items: center;
  flex: 1;
  min-height: 520px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #eef2f6;
  overflow: hidden;
  cursor: zoom-in;
}

body[data-theme="light"] .canvas-shell {
  background: #eef2f6;
}

body[data-theme="dark"] .canvas-shell {
  background: #111c2b;
}

canvas {
  display: block;
  width: min(100%, 82dvh);
  max-width: 100%;
  aspect-ratio: 1;
  height: auto;
}

.preview-note {
  padding-top: 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  min-width: 0;
}

.panel-header {
  flex-direction: column;
}

.panel-header #statusText {
  color: var(--muted);
  font-size: 14px;
}

.panel-header #statusText.is-error {
  color: #dc2626;
}

.theme-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-top: 4px;
  color: var(--muted);
  font-size: 14px;
}

.theme-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.theme-toggle button {
  min-width: 68px;
  min-height: 34px;
  border: 0;
  background: transparent;
  color: var(--muted);
}

.theme-toggle button.is-active {
  color: var(--accent-ink);
}

.selection-summary {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.selection-summary span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.selection-summary p {
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}

.controls {
  min-height: 0;
}

.control-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}

.control-card summary {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 10px;
  align-items: center;
  min-height: 48px;
  padding: 0 14px;
  list-style: none;
  cursor: pointer;
}

.control-card summary::-webkit-details-marker {
  display: none;
}

.control-card summary span:first-child {
  font-weight: 700;
}

.section-badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 10%, var(--panel-soft));
  color: var(--accent);
  padding: 0 12px;
  font-size: 12px;
  font-weight: 700;
}

.summary-random-button {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  color: var(--text);
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 700;
}

.control-card summary b {
  color: var(--muted);
  transition: transform 0.2s ease;
}

.control-card[open] summary b {
  transform: rotate(180deg);
}

.control-hint {
  padding: 0 14px 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.control-body {
  display: grid;
  gap: 12px;
  padding: 0 14px 14px;
}

.control-group {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 10px;
  align-items: center;
}

.control-group label {
  display: flex;
  gap: 9px;
  align-items: center;
  min-width: 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
}

.color-dot,
.option-swatch {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  border: 1px solid rgb(0 0 0 / 0.14);
  border-radius: 50%;
  background: #d8dde6;
}

select {
  min-width: 0;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel-soft);
  color: var(--text);
  padding: 0 12px;
}

.control-group > select {
  display: none;
}

.desktop-select {
  position: relative;
  min-width: 0;
}

.desktop-select-trigger {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel-soft);
  color: var(--text);
  padding: 0 12px;
  text-align: left;
}

.desktop-select-trigger span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.desktop-select-trigger b {
  color: var(--muted);
  font-size: 14px;
}

.desktop-select-menu {
  position: absolute;
  z-index: 20;
  left: 0;
  right: 0;
  top: calc(100% + 6px);
  display: none;
  max-height: 220px;
  overflow-y: auto;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 18px 42px rgb(15 23 42 / 0.16);
  padding: 6px;
  overscroll-behavior: contain;
}

.desktop-select.is-open .desktop-select-menu {
  display: grid;
  gap: 2px;
}

.desktop-select-option {
  min-height: 34px;
  border: 0;
  border-radius: calc(var(--radius) - 2px);
  background: transparent;
  color: var(--text);
  padding: 0 10px;
  text-align: left;
}

.desktop-select-option:hover,
.desktop-select-option.is-active {
  background: var(--accent);
  color: var(--accent-ink);
}

.mobile-choice-button {
  display: none;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: auto;
}

.actions button {
  width: 100%;
  min-height: 42px;
  font-weight: 700;
}

button:active {
  transform: translateY(1px);
}

.color-sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
}

.color-sheet-open .color-sheet {
  display: block;
}

.save-dialog {
  position: fixed;
  inset: 0;
  z-index: 40;
}

.save-dialog[hidden] {
  display: none;
}

.save-dialog-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgb(15 23 42 / 0.54);
}

.save-dialog-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(92vw, 680px);
  max-height: calc(100dvh - 28px);
  margin: 14px auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: 0 28px 90px rgb(0 0 0 / 0.32);
  overflow: hidden;
}

.save-dialog-header {
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 14px;
  align-items: start;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.save-dialog-header h2 {
  font-size: 22px;
}

.save-dialog-close {
  width: 38px;
  height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel-soft);
  color: var(--text);
  font-size: 24px;
  line-height: 1;
}

.save-dialog-hint {
  padding: 14px 16px 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.save-dialog-image-shell {
  margin: 14px 16px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
  overflow: auto;
}

.save-dialog-image-shell img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: calc(var(--radius) - 2px);
  user-select: auto;
  -webkit-user-select: auto;
  -webkit-touch-callout: default;
}

.save-dialog-download {
  min-height: 48px;
  margin: 0 16px 16px;
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
  font-size: 16px;
}

.color-sheet-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgb(2 6 23 / 0.5);
}

.preview-pinned .color-sheet-backdrop {
  top: var(--color-sheet-top, 0px);
}

.color-sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: min(72dvh, 620px);
  border: 1px solid var(--line);
  border-radius: 28px 28px 0 0;
  background: var(--panel);
  box-shadow: 0 -20px 60px rgb(0 0 0 / 0.22);
  overflow: hidden;
}

.preview-pinned .color-sheet-panel {
  top: calc(var(--color-sheet-top, 0px) + 8px);
  bottom: auto;
  max-height: calc(100dvh - var(--color-sheet-top, 0px) - 8px);
  border-radius: 8px 8px 0 0;
}

.color-sheet-header {
  display: grid;
  grid-template-columns: 1fr 64px;
  gap: 16px;
  align-items: center;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
}

.color-sheet-layer-button,
.color-sheet-close {
  border: 0;
  background: transparent;
  color: var(--text);
}

.color-sheet-layer-button {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  min-height: 76px;
  border: 1px solid var(--line-strong);
  border-radius: 18px;
  background: var(--panel-soft);
  padding: 12px 18px;
  text-align: left;
}

.color-sheet-kicker {
  grid-column: 1 / -1;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.color-sheet-close {
  width: 56px;
  height: 56px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--panel-soft);
  font-size: 34px;
  font-weight: 700;
  color: var(--muted);
}

.color-sheet-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 20px;
  padding: 22px 28px 24px;
  overflow-y: auto;
  max-height: calc(min(72dvh, 620px) - 116px);
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.color-sheet-options.is-layer-list {
  grid-template-columns: 1fr 1fr;
  align-content: start;
  justify-content: stretch;
}

.color-option-button {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  justify-items: center;
  align-items: center;
  width: 100%;
  min-width: 0;
  max-width: none;
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel-soft);
  color: var(--text);
  padding: 12px 14px;
  text-align: center;
}

.color-sheet-options.is-layer-list .color-option-button {
  min-height: 74px;
}

.color-option-button small {
  grid-column: auto;
  color: var(--muted);
}

.color-option-button .option-swatch {
  display: none;
}

.color-option-button.is-active {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}

.preview-pinned .preview-panel {
  position: sticky;
  top: 16px;
  align-self: start;
}

.site-footer {
  width: min(100%, 1500px);
  margin: -8px auto 22px;
  padding: 0 22px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
  text-align: center;
  overflow-wrap: anywhere;
}

@media (max-width: 980px) {
  .app {
    grid-template-columns: 1fr;
    gap: 14px;
    padding: 12px;
  }

  .preview-panel {
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    padding: 20px 18px 18px;
  }

  .preview-header {
    align-items: flex-start;
    min-height: 62px;
    padding-right: 168px;
    padding-bottom: 10px;
  }

  .preview-header .eyebrow {
    display: none;
  }

  .preview-tools {
    top: 18px;
    right: 18px;
    gap: 10px;
    font-size: 13px;
  }

  .preview-tools span {
    min-height: 38px;
    padding: 0 14px;
  }

  .pin-preview-button {
    min-height: 38px;
    border-radius: 999px;
    padding: 0 14px;
    font-weight: 700;
  }

  .canvas-shell {
    min-height: 320px;
    border-radius: 0;
    border: 0;
    background: var(--bg);
  }

  canvas {
    width: min(100%, calc(100dvh - 300px));
    min-width: 260px;
  }

  .control-panel {
    border-radius: 14px;
    padding: 14px;
  }

  .controls {
    padding: 14px 0;
  }

  .control-card {
    border-radius: 14px;
  }

  .control-card summary {
    min-height: 54px;
    grid-template-columns: 1fr auto auto auto;
    gap: 8px;
    padding: 13px 14px;
  }

  .section-title {
    font-size: 18px;
    font-weight: 900;
  }

  .section-badge {
    min-height: 30px;
    padding: 0 12px;
    font-weight: 900;
  }

  .summary-random-button {
    min-height: 30px;
    border-color: var(--accent);
    border-radius: 999px;
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, var(--panel-soft));
    font-weight: 900;
  }

  .control-hint {
    padding: 0 14px 12px;
  }

  .control-body {
    gap: 0;
  }

  .control-group {
    grid-template-columns: 96px 1fr;
    gap: 12px;
    padding: 10px 0;
    border-top: 1px solid var(--line);
  }

  .control-group label {
    font-size: 14px;
    font-weight: 900;
  }

  .control-group select {
    display: none;
  }

  .desktop-select {
    display: none;
  }

  .mobile-choice-button {
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 42px;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background: var(--panel-soft);
    color: var(--text);
    padding: 0 12px;
    text-align: left;
  }

  .mobile-choice-button span {
    min-width: 0;
    color: var(--text);
    font-weight: 900;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-choice-button b {
    color: var(--muted);
    font-size: 18px;
    line-height: 1;
  }

  .actions {
    grid-template-columns: 1fr;
  }

  .site-footer {
    margin: 0 auto 18px;
    padding: 0 16px;
    font-size: 13px;
  }

  .save-dialog-panel {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 16px);
    margin: 8px auto;
  }

  .save-dialog-image-shell {
    margin: 12px 16px;
  }

  .color-option-button strong {
    max-width: 100%;
    font-size: 16px;
    line-height: 1.25;
    overflow-wrap: anywhere;
  }

  .preview-pinned .preview-panel {
    position: sticky;
    top: 0;
    z-index: 25;
    margin: -12px -12px 0;
    background: var(--bg);
    box-shadow: 0 12px 26px rgb(15 23 42 / 0.12);
  }

  .preview-pinned .preview-header {
    align-items: center;
    padding-bottom: 8px;
  }

  .preview-pinned .preview-note {
    display: none;
  }

  .preview-pinned .canvas-shell {
    min-height: 0;
  }

  .preview-pinned canvas {
    width: min(100%, 42dvh);
    min-width: 0;
    max-width: 520px;
  }

  .color-sheet-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px 20px;
    padding: 18px 28px 22px;
    overflow-y: auto;
  }

  .color-sheet-options.is-layer-list {
    grid-template-columns: 1fr 1fr;
  }

  .color-option-button {
    min-height: 62px;
    border-radius: 16px;
    font-size: 16px;
  }
}

@media (max-width: 560px) {
  .preview-header {
    flex-direction: row;
  }

  .preview-tools {
    justify-content: flex-end;
  }

  h1 {
    font-size: 24px;
    line-height: 1.1;
  }

  h2 {
    font-size: 24px;
  }

  .selection-summary {
    grid-template-columns: 1fr;
  }

  .selection-summary button {
    width: 100%;
  }

  .theme-row {
    align-items: flex-start;
    flex-direction: column;
  }

  .theme-toggle,
  .theme-toggle button {
    width: 100%;
  }

}
