:root {
  --ink: #0b1d33;
  --muted: #6d7d91;
  --blue: #096ef0;
  --blue-dark: #0753bc;
  --blue-soft: #edf5ff;
  --gold: #e5b44c;
  --paper: #ffffff;
  --line: #dce5ef;
  --background: #f3f7fb;
  --font: "HarmonyOS Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --number-font: "DIN Alternate", "Avenir Next Condensed", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
  background: var(--background);
}

body {
  min-width: 320px;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 0, rgba(9, 110, 240, 0.08), transparent 30rem),
    var(--background);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button:disabled,
input:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.primary-button:disabled:hover {
  transform: none;
}

button:focus-visible,
input:focus-visible,
canvas:focus-visible,
summary:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(9, 110, 240, 0.25);
  outline-offset: 3px;
}

.topbar {
  display: flex;
  width: min(1180px, calc(100% - 40px));
  min-height: 76px;
  margin: 0 auto;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(182, 197, 214, 0.55);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  border-radius: 13px;
  box-shadow: 0 9px 20px rgba(9, 110, 240, 0.24);
  object-fit: cover;
}

.brand strong,
.brand small {
  display: block;
}

.brand strong {
  font-size: 16px;
}

.brand small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.privacy,
.local-note {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.privacy i,
.local-note i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #24a56a;
  box-shadow: 0 0 0 4px rgba(36, 165, 106, 0.11);
}

.tool-layout {
  display: grid;
  width: min(1180px, calc(100% - 40px));
  margin: 28px auto 40px;
  grid-template-columns: minmax(0, 1fr) 350px;
  gap: 20px;
  align-items: start;
}

.preview-panel,
.action-panel {
  min-width: 0;
  border: 1px solid rgba(213, 224, 236, 0.92);
  border-radius: 22px;
  background: var(--paper);
  box-shadow: 0 20px 55px rgba(29, 57, 91, 0.1);
}

.preview-panel {
  grid-column: 1;
  grid-row: 1;
  padding: 22px;
}

.panel-heading {
  display: flex;
  margin-bottom: 15px;
  align-items: center;
  justify-content: space-between;
}

.panel-heading h1,
.panel-heading p {
  margin: 0;
}

.panel-heading h1 {
  font-size: 22px;
  line-height: 1.2;
}

.panel-heading p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.panel-heading > span {
  color: var(--muted);
  font: 700 12px/1 var(--number-font);
}

.canvas-stage {
  position: relative;
  width: min(100%, 760px);
  margin: 0 auto;
  overflow: hidden;
  border: 1px dashed #b9cce0;
  border-radius: 16px;
  background: #ffffff;
  box-shadow: 0 10px 30px rgba(25, 53, 84, 0.13);
}

.canvas-stage::before {
  display: block;
  padding-top: 100%;
  content: "";
}

#editorCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  cursor: grab;
  touch-action: none;
}

#editorCanvas:active {
  cursor: grabbing;
}

.canvas-upload,
.drop-mask {
  position: absolute;
  inset: 0;
  z-index: 2;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.canvas-upload:not([hidden]),
.drop-mask:not([hidden]) {
  display: flex;
}

.canvas-upload {
  width: 100%;
  border: 0;
  background: #ffffff;
  cursor: pointer;
}

.canvas-upload b {
  display: grid;
  width: 50px;
  height: 50px;
  margin-bottom: 12px;
  place-items: center;
  color: white;
  border-radius: 50%;
  background: var(--blue);
  font-size: 28px;
  font-weight: 400;
}

.canvas-upload small {
  margin-top: 5px;
  color: var(--muted);
}

.drop-mask {
  color: white;
  background: rgba(5, 76, 163, 0.78);
  backdrop-filter: blur(7px);
  font-weight: 700;
}

.drag-tip {
  margin: 13px 0 0;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
}

.drag-tip span {
  margin-right: 6px;
  color: var(--blue);
}

.action-panel {
  position: sticky;
  top: 18px;
  grid-column: 2;
  grid-row: 1 / span 2;
  overflow: hidden;
}

.quick-actions {
  padding: 22px;
}

.upload-button {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 12px;
  padding: 13px;
  color: var(--ink);
  border: 1px solid #bdd5f1;
  border-radius: 14px;
  background: var(--blue-soft);
  cursor: pointer;
  text-align: left;
}

.upload-button:hover {
  border-color: #7eb3f2;
  background: #e4f0ff;
}

.upload-button > span:last-child {
  min-width: 0;
}

.upload-button strong,
.upload-button small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upload-button strong {
  font-size: 15px;
}

.upload-button small {
  max-width: 225px;
  margin-top: 3px;
  color: #5d7188;
  font-size: 11px;
}

.upload-icon {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  color: white;
  border-radius: 11px;
  background: var(--blue);
  font-size: 22px;
}

.file-meta {
  display: block;
  margin: 7px 3px 0;
  color: var(--muted);
  font-size: 10px;
}

.save-dialog {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
}

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

.save-backdrop {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: rgba(7, 20, 38, 0.62);
  backdrop-filter: blur(6px);
  cursor: pointer;
}

.save-sheet {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 24px;
  border-radius: 20px;
  background: white;
  box-shadow: 0 24px 70px rgba(4, 18, 35, 0.3);
  text-align: center;
}

.save-sheet h2 {
  margin: 0;
  font-size: 20px;
}

.save-sheet p {
  margin: 7px 24px 16px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.save-preparing {
  margin: 0 auto 14px;
  padding: 12px 14px;
  border: 1px solid #cfe1f7;
  border-radius: 12px;
  background: #f3f8ff;
  text-align: left;
}

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

.save-progress-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #214364;
  font-size: 12px;
}

.save-progress-heading span {
  color: var(--blue-dark);
  font: 700 12px/1 var(--number-font);
}

.save-progress-track {
  height: 7px;
  margin-top: 9px;
  overflow: hidden;
  border-radius: 99px;
  background: #dceafb;
}

.save-progress-track i {
  display: block;
  width: var(--save-progress, 0%);
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #0a78ff, #37a5ff);
  transition: width 180ms ease;
}

.save-preparing > small {
  display: block;
  margin-top: 8px;
  color: #6d7d91;
  font-size: 10px;
}

.save-preview-image {
  display: block;
  width: min(100%, 320px);
  aspect-ratio: 1;
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f4f7fb;
  cursor: default;
  object-fit: contain;
  -webkit-touch-callout: default;
  -webkit-user-select: auto;
  user-select: auto;
  touch-action: auto;
}

/* author 样式中的 display:block 会覆盖浏览器默认 [hidden]，必须显式隐藏以免出现破图占位。 */
.save-preview-image[hidden] {
  display: none;
}

.save-dialog.is-preparing .save-preview-image {
  opacity: 0.72;
  pointer-events: none;
}

.save-close {
  position: absolute;
  top: 11px;
  right: 13px;
  width: 34px;
  height: 34px;
  color: #617287;
  border: 0;
  border-radius: 50%;
  background: #eef3f7;
  cursor: pointer;
  font-size: 24px;
  line-height: 1;
}

.simple-control,
.option-block {
  margin-top: 22px;
}

.control-label {
  display: flex;
  margin-bottom: 10px;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 650;
}

.control-label output {
  color: var(--blue-dark);
  font: 800 13px/1 var(--number-font);
}

input[type="range"] {
  width: 100%;
  height: 5px;
  margin: 0;
  border-radius: 999px;
  outline: none;
  background: linear-gradient(90deg, var(--blue) 0 var(--range-progress, 44%), #dfe7ef var(--range-progress, 44%) 100%);
  appearance: none;
}

input[type="range"]::-webkit-slider-thumb {
  width: 19px;
  height: 19px;
  border: 4px solid white;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 2px 8px rgba(5, 77, 164, 0.32);
  appearance: none;
}

input[type="range"]::-moz-range-thumb {
  width: 11px;
  height: 11px;
  border: 4px solid white;
  border-radius: 50%;
  background: var(--blue);
  box-shadow: 0 2px 8px rgba(5, 77, 164, 0.32);
}

.primary-button {
  width: 100%;
  margin-top: 24px;
  padding: 14px 18px;
  color: white;
  border: 0;
  border-radius: 14px;
  background: linear-gradient(135deg, #0a78ff, #0753bc);
  box-shadow: 0 12px 24px rgba(7, 83, 188, 0.22);
  cursor: pointer;
  font-size: 16px;
  font-weight: 750;
}

.primary-button:hover {
  transform: translateY(-1px);
}

.preview-download {
  display: block;
  width: 100%;
  margin: 0;
  grid-column: 1;
  grid-row: 2;
  border-radius: 16px;
}

.primary-button small {
  display: block;
  margin-top: 3px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 10px;
  font-weight: 400;
}

.more-controls {
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.more-controls summary {
  position: relative;
  padding: 16px 22px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 650;
  list-style: none;
}

.more-controls summary::-webkit-details-marker {
  display: none;
}

.more-controls summary::after {
  position: absolute;
  top: 50%;
  right: 22px;
  color: var(--muted);
  content: "＋";
  transform: translateY(-50%);
}

.more-controls[open] summary::after {
  content: "－";
}

.more-content {
  padding: 0 22px 20px;
  border-top: 1px solid #edf1f5;
}

.option-title {
  display: block;
  margin-bottom: 9px;
  font-size: 12px;
  font-weight: 650;
}

.segmented-control,
.position-row,
.secondary-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.segmented-control {
  padding: 4px;
  border-radius: 11px;
  background: #eef3f7;
}

.segment,
.position-button,
.secondary-actions button {
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
  font-size: 12px;
}

.segment.is-active {
  color: var(--blue-dark);
  background: white;
  box-shadow: 0 3px 10px rgba(27, 52, 81, 0.09);
  font-weight: 700;
}

.position-row {
  margin-top: 20px;
}

.position-button,
.secondary-actions button {
  border-color: var(--line);
  background: white;
}

.position-button.is-active {
  color: var(--blue-dark);
  border-color: #8abaf3;
  background: var(--blue-soft);
  font-weight: 700;
}

.round-preview-row {
  display: flex;
  margin-top: 20px;
  align-items: center;
  justify-content: space-between;
}

.round-preview-row strong,
.round-preview-row small {
  display: block;
}

.round-preview-row strong {
  font-size: 13px;
}

.round-preview-row small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 10px;
}

.round-preview-frame {
  width: 82px;
  height: 82px;
  flex: 0 0 auto;
  padding: 4px;
  border-radius: 16px;
  background: linear-gradient(145deg, #f7df9d, #c99128);
}

#roundPreview {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 12px;
}

.secondary-actions {
  margin-top: 20px;
}

.local-note {
  justify-content: center;
  width: 100%;
  margin: 0;
  padding: 15px 12px;
  font-size: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 25px;
  z-index: 10;
  padding: 11px 16px;
  color: white;
  border-radius: 10px;
  background: rgba(11, 29, 51, 0.92);
  box-shadow: 0 12px 30px rgba(8, 25, 45, 0.22);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 160ms ease, transform 160ms ease;
  font-size: 12px;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 850px) {
  .tool-layout {
    grid-template-columns: 1fr;
  }

  .preview-panel,
  .preview-download,
  .action-panel {
    grid-column: 1;
    grid-row: auto;
  }

  .action-panel {
    position: static;
  }

  .quick-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
  }

  .upload-button,
  .file-meta {
    grid-column: 1 / -1;
  }

  .simple-control {
    margin-top: 0;
  }

  .preview-download {
    margin: 0;
  }
}

@media (max-width: 560px) {
  .topbar,
  .tool-layout {
    width: calc(100% - 20px);
  }

  .topbar {
    min-height: 68px;
  }

  .privacy {
    font-size: 0;
  }

  .tool-layout {
    margin-top: 12px;
    gap: 12px;
  }

  .preview-panel,
  .action-panel {
    border-radius: 16px;
  }

  .preview-panel {
    padding: 12px;
  }

  .panel-heading {
    margin: 3px 2px 11px;
  }

  .panel-heading h1 {
    font-size: 18px;
  }

  .panel-heading p {
    display: none;
  }

  .canvas-stage {
    border-radius: 12px;
  }

  .drag-tip {
    margin-top: 10px;
  }

  .quick-actions {
    grid-template-columns: 1fr;
    gap: 20px;
    padding: 16px;
  }

  .upload-button,
  .file-meta {
    grid-column: auto;
  }

  .file-meta {
    margin-top: -14px;
  }

  .more-controls summary,
  .more-content {
    padding-right: 16px;
    padding-left: 16px;
  }

  .upload-button small {
    max-width: 240px;
  }
}

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