:root {
  --bg: #eef1f4;
  --panel: #ffffff;
  --line: #dde2e8;
  --line-strong: #c9d0d8;
  --text: #232830;
  --text-2: #5b6470;
  --text-3: #8a93a0;
  --accent: #0e7c86;
  --accent-strong: #0a626a;
  --accent-soft: #e2f3f4;
  --warm: #d98324;
  --danger: #b3423f;
  --radius: 8px;
  --shadow: 0 10px 26px rgba(28, 36, 46, 0.12);
  font-size: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
}

body {
  font-family: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB", "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  background: none;
  cursor: pointer;
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-width: 0;
}

.topbar {
  height: 56px;
  flex: 0 0 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: #fff;
  background: var(--accent);
  border-radius: var(--radius);
  flex: 0 0 auto;
}

.brand-text {
  font-size: 17px;
  font-weight: 700;
  white-space: nowrap;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-3);
  white-space: nowrap;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 36px;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: #fff;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
}

.leftbar {
  flex: 0 0 76px;
  width: 76px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  padding: 12px 9px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
}

.left-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.left-group-grow {
  margin-top: auto;
}

.tool-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 58px;
  border-radius: var(--radius);
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  border: 1px solid transparent;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.tool-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.tool-btn.active {
  background: var(--accent);
  color: #fff;
}

.stage {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background:
    linear-gradient(rgba(120, 134, 150, 0.10) 1px, transparent 1px),
    linear-gradient(90deg, rgba(120, 134, 150, 0.10) 1px, transparent 1px);
  background-size: 22px 22px;
}

.stage-head {
  height: 48px;
  flex: 0 0 48px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  background: rgba(255, 255, 255, 0.82);
  border-bottom: 1px solid var(--line);
}

.view-switch {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: #e7ebef;
  border-radius: var(--radius);
}

.view-btn {
  height: 30px;
  padding: 0 13px;
  border-radius: 6px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 600;
}

.view-btn.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(28, 36, 46, 0.16);
}

.stage-head .preview-option {
  margin-left: 4px;
  white-space: nowrap;
}

.stage-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  color: var(--text-2);
  font-size: 12px;
  white-space: nowrap;
}

.stage-meta span + span::before {
  content: "·";
  margin-right: 10px;
  color: var(--text-3);
}

.zoom-controls {
  display: flex;
  align-items: center;
  gap: 2px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.zoom-controls button {
  width: 30px;
  height: 30px;
  font-size: 18px;
  color: var(--text-2);
  border-radius: 6px;
}

.zoom-controls button:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.zoom-controls span {
  min-width: 46px;
  text-align: center;
  font-size: 12px;
  color: var(--text-2);
}

.canvas-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#mainCanvas {
  background: #fff;
  box-shadow: var(--shadow);
  touch-action: none;
  image-rendering: pixelated;
}

.stage-hint {
  flex: 0 0 auto;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-3);
  font-size: 12px;
  background: rgba(255, 255, 255, 0.72);
  border-top: 1px solid var(--line);
}

.rightbar {
  flex: 0 0 336px;
  width: 336px;
  background: var(--panel);
  border-left: 1px solid var(--line);
  overflow-y: auto;
}

.panel-section {
  padding: 15px 16px 17px;
  border-bottom: 1px solid var(--line);
}

.panel-section h2 {
  margin: 0 0 11px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.field-row:last-child {
  margin-bottom: 0;
}

.field-label {
  flex: 0 0 auto;
  min-width: 58px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}

select,
input[type="number"],
input[type="text"] {
  height: 32px;
  min-width: 0;
  padding: 0 9px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 13px;
}

select {
  flex: 1;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

input[type="color"] {
  width: 36px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
}

.palette-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 2px 0 10px;
}

.check-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
}

.check-label input {
  accent-color: var(--accent);
}

.adjust-check {
  display: flex;
  margin: 2px 0 10px;
}

.mini-btn {
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.mini-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.mini-btn.wide {
  width: 100%;
  margin-top: 8px;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(30px, 1fr));
  gap: 7px;
  min-height: 40px;
}

.color-swatch {
  aspect-ratio: 1;
  border-radius: 6px;
  border: 1px solid rgba(20, 26, 34, 0.22);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
  transition: transform 0.12s, box-shadow 0.12s;
}

.color-swatch:hover {
  transform: translateY(-2px);
  box-shadow: 0 3px 7px rgba(20, 26, 34, 0.22);
}

.color-swatch.active {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.palette-empty {
  grid-column: 1 / -1;
  padding: 10px 4px;
  color: var(--text-3);
  font-size: 12px;
}

.current-color {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 12px;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #f8fafb;
  min-width: 0;
}

.swatch {
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  border-radius: 6px;
  border: 2px solid var(--line-strong);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.3);
}

.swatch.sm {
  width: 20px;
  height: 20px;
  border-width: 1px;
}

.current-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}

.custom-form {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 10px;
}

.custom-form input[type="text"] {
  flex: 1;
}

.hidden {
  display: none !important;
}

.replace-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.replace-row select {
  flex: 1;
}

.replace-arrow {
  color: var(--text-3);
  font-size: 15px;
  flex: 0 0 auto;
}

.wide-btn {
  width: 100%;
  height: 34px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 13px;
  font-weight: 700;
  transition: background 0.15s, color 0.15s;
}

.wide-btn:hover {
  background: var(--accent);
  color: #fff;
}

.btn-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stats-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 208px;
  overflow-y: auto;
}

.stat-row {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto auto 24px;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  padding: 3px 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.stat-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 600;
}

.stat-code {
  color: var(--text-3);
  font-size: 11px;
}

.stat-count {
  min-width: 34px;
  text-align: right;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 700;
}

.eye-btn {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: var(--text-3);
}

.eye-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.stats-unhide {
  display: flex;
  justify-content: flex-end;
}

.stats-empty {
  padding: 12px 4px;
  color: var(--text-3);
  font-size: 12px;
}

.range-row {
  margin-bottom: 11px;
}

.muted-note {
  margin: 10px 0 0;
  color: var(--text-3);
  font-size: 12px;
  line-height: 1.6;
}

.export-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.export-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  min-height: 88px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  text-align: left;
  font-size: 13px;
  font-weight: 700;
  transition: border-color 0.15s, transform 0.15s;
}

.export-btn:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.export-btn small {
  color: var(--text-3);
  font-size: 11px;
  font-weight: 500;
}

.export-ico {
  width: 34px;
  height: 26px;
  border-radius: 4px;
  border: 1px solid var(--line-strong);
  background-color: #f2f5f8;
  background-repeat: repeat;
}

.ico-beads {
  background-image:
    radial-gradient(circle at 50% 42%, #ffffff 0 26%, #0e7c86 30% 62%, #0a626a 66% 100%);
  background-size: 11px 11px;
  border-color: #9fc9cd;
}

.ico-flat {
  background-image:
    linear-gradient(45deg, #7fc2d8 25%, transparent 25%),
    linear-gradient(-45deg, #7fc2d8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #7fc2d8 75%),
    linear-gradient(-45deg, transparent 75%, #7fc2d8 75%);
  background-color: #d9ecf3;
  background-size: 8px 8px;
  background-position: 0 0, 4px 0, 4px -4px, 0 4px;
}

.ico-list {
  background-image: linear-gradient(#d98324 0 0), linear-gradient(#e3e6ea 0 0), linear-gradient(#e3e6ea 0 0), linear-gradient(#e3e6ea 0 0);
  background-size: 14px 3px, 22px 2px, 22px 2px, 22px 2px;
  background-position: 4px 5px, 6px 12px, 6px 16px, 6px 20px;
  background-repeat: no-repeat;
}

.ico-text {
  background-image: linear-gradient(#e3e6ea 0 0), linear-gradient(#e3e6ea 0 0), linear-gradient(#e3e6ea 0 0);
  background-size: 22px 2px;
  background-position: 6px 7px, 6px 12px, 6px 17px;
  background-repeat: no-repeat;
  background-color: #fff;
}

.export-options {
  margin-top: 11px;
  display: flex;
}

.export-options + .export-options {
  margin-top: 8px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(25, 30, 38, 0.46);
}

.modal {
  width: min(480px, 100%);
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: 0 18px 44px rgba(20, 26, 34, 0.28);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 10px;
}

.modal-head h2 {
  margin: 0;
  font-size: 16px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  font-size: 20px;
  color: var(--text-3);
}

.icon-btn:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.modal-body {
  padding: 6px 16px 8px;
}

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

.preset-btn {
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.preset-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.modal-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.modal-fields label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--text-2);
  font-size: 12px;
  font-weight: 600;
}

.modal-fields input,
.modal-fields select {
  width: 100%;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 9px;
  padding: 12px 16px 16px;
}

.toast-wrap {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  max-width: 86vw;
  padding: 9px 15px;
  border-radius: var(--radius);
  background: #26313c;
  color: #fff;
  font-size: 13px;
  box-shadow: 0 8px 20px rgba(20, 26, 34, 0.3);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.22s, transform 0.22s;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1100px) {
  .workspace {
    flex-direction: column;
    overflow-y: auto;
  }

  .leftbar {
    flex: 0 0 auto;
    width: 100%;
    flex-direction: row;
    justify-content: center;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 8px 10px;
  }

  .left-group {
    flex-direction: row;
  }

  .left-group-grow {
    margin-top: 0;
  }

  .tool-btn {
    width: 62px;
    height: 48px;
  }

  .stage {
    min-height: 460px;
    flex: 0 0 64vh;
  }

  .rightbar {
    flex: 0 0 auto;
    width: 100%;
    border-left: 0;
    border-top: 1px solid var(--line);
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    column-gap: 4px;
  }

  .panel-section {
    border-right: 1px solid var(--line);
  }

  .panel-section:nth-child(even) {
    border-right: 0;
  }
}

@media (max-width: 720px) {
  .brand-sub {
    display: none;
  }

  .topbar {
    padding: 0 10px;
    gap: 6px;
  }

  .brand-text {
    font-size: 14px;
  }

  #clearBtn {
    display: none;
  }

  .stage-head {
    gap: 7px;
    padding: 0 9px;
  }

  .stage-meta {
    font-size: 11px;
  }

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

  .panel-section {
    border-right: 0;
  }
}

@media (max-width: 480px) {
  .topbar-actions .btn {
    padding: 0 9px;
    font-size: 12px;
  }

  #topCanvasBtn {
    display: none;
  }

  .left-group:nth-child(2) {
    display: none;
  }

  .tool-btn {
    width: 54px;
  }

  .stage {
    flex-basis: 58vh;
    min-height: 380px;
  }

  .stage-hint {
    font-size: 11px;
    padding: 0 10px;
    text-align: center;
    height: 38px;
  }

  .modal-fields {
    grid-template-columns: 1fr;
  }
}
