:root {
  font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #293a30;
  background: #f0f2ed;
  font-size: 13px;
  --border: #e1e6de;
  --green: #ddebba;
}

* {
  box-sizing: border-box;
}

/* 页面内的滚动区域统一使用轻量滚动条。 */
* {
  scrollbar-width: thin;
  scrollbar-color: #b9c3b0 transparent;
}

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track,
::-webkit-scrollbar-corner {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: #b9c3b0;
  border: 2px solid transparent;
  border-radius: 8px;
  background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
  background-color: #8c9c7f;
}

::-webkit-scrollbar-button {
  display: none;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.icons {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 9px 13px;
  font: inherit;
  color: #42533f;
  cursor: pointer;
  white-space: nowrap;
}

button:hover {
  background: #f2f5ec;
}

button:disabled {
  opacity: .35;
  cursor: default;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 2px solid #849f60;
  outline-offset: 3px;
}

.primary {
  background: var(--green);
  border-color: #cedda9;
  color: #334525;
  font-weight: 600;
}

.primary:hover {
  background: #cfdfa6;
}

.icon-button {
  position: relative;
  border-color: transparent;
  background: transparent;
  padding: 9px;
  width: 38px;
  height: 38px;
}

[data-tip]:hover::after {
  content: attr(data-tip);
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 15;
  background: #2d3e30;
  color: white;
  font-size: 11px;
  border-radius: 5px;
  padding: 7px 10px;
  pointer-events: none;
}

.topbar {
  height: 52px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  gap: 24px;
  background: white;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 16px;
  white-space: nowrap;
}

.brand img {
  display: block;
  width: 58px;
  height: 36px;
  object-fit: contain;
}

.brand span {
  font-size: 12px;
  border-left: 1px solid var(--border);
  padding-left: 16px;
  color: #879081;
}

.project-heading {
  margin-right: auto;
  min-width: 90px;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.project-heading input {
  display: block;
  border: 0;
  background: transparent;
  padding: 0;
  width: 180px;
  max-width: 100%;
  color: #3c4e38;
  font: inherit;
  font-weight: 600;
  line-height: 18px;
  text-overflow: ellipsis;
}

.project-heading input:focus {
  outline: none;
  box-shadow: none;
}

.project-heading input[readonly] {
  cursor: default;
}

#save-state {
  font-size: 10px;
  line-height: 12px;
  color: #8a9583;
}

#save-state.failed {
  color: #a84c35;
}

.topbar nav {
  display: flex;
  gap: 6px;
  align-items: center;
}

.divider {
  height: 22px;
  border-left: 1px solid var(--border);
  margin: 0 5px;
}

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

/* 工具栏浮在画布上，不再占用左侧空间；提示向上弹出。 */
.toolrail {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px;
  background: #2d2f2edd;
  border: 1px solid #424542;
  border-radius: 18px;
  box-shadow: 0 8px 24px #1e291e24;
  z-index: 4;
}

.toolrail .icon-button {
  width: 32px;
  height: 32px;
  color: #e4e7e2;
  border-radius: 10px;
}

.toolrail .icon-button:hover {
  background: #414440;
}

.toolrail .icon-button.selected {
  color: white;
  background: #168c53;
  border-color: #168c53;
}

.toolrail [data-tip]:hover::after {
  top: auto;
  bottom: calc(100% + 16px);
  left: 50%;
  right: auto;
  transform: translateX(-50%);
}

.rail-divider {
  height: 28px;
  border-left: 1px solid #4d504b;
  margin: 0 5px;
}

.swatch {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  margin: 0 6px;
  border: 3px solid #2d2f2e;
  border-radius: 7px;
  overflow: hidden;
  box-shadow: 0 0 0 1px #81867b;
  cursor: pointer;
}

input[type=color] {
  width: 44px;
  height: 44px;
  margin: -10px;
  padding: 0;
  border: 0;
  cursor: pointer;
}

#stage {
  position: relative;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  background: #edf0e9;
}

#editor {
  display: block;
  width: 100%;
  height: 100%;
  outline: none;
  touch-action: none;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  text-align: center;
  padding: 24px;
}

.empty-state button {
  pointer-events: auto;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  background: #e2e9da;
  border-radius: 18px;
  color: #879a73;
  margin-bottom: 16px;
}

.empty-icon svg {
  width: 30px;
  height: 30px;
}

h1 {
  font-size: 24px;
  font-weight: 550;
  letter-spacing: -.7px;
  margin: 6px 0;
}

.empty-state p {
  color: #88917f;
  line-height: 1.9;
  margin: 8px 0 22px;
}

.empty-state div:has(>button) {
  display: flex;
  gap: 10px;
}

.empty-state small {
  font-size: 11px;
  color: #9ba38f;
  margin-top: 20px;
}

.zoom-controls {
  position: absolute;
  bottom: 8px;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #6f7c66;
  font-size: 11px;
  z-index: 2;
}

.notice {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 32px);
  padding: 11px 18px;
  background: #293a30;
  color: white;
  border-radius: 8px;
  box-shadow: 0 5px 20px #26351c20;
  line-height: 1.7;
  z-index: 6;
}

.zoom-controls .icon-button {
  width: 29px;
  height: 29px;
  padding: 6px;
  background: transparent;
}

.zoom-controls .icon-button:hover {
  color: #263e20;
}

#zoom-value {
  width: 30px;
  text-align: center;
  color: #4b5d40;
  font-variant-numeric: tabular-nums;
}

.drawer,
.reference-panel {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 270px;
  max-height: calc(100% - 32px);
  overflow-y: auto;
  border: 1px solid #dce3d3;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 10px 35px #26351c12;
  z-index: 3;
}

.drawer {
  padding: 16px 20px;
}

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

h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}

.drawer-heading .icon-button {
  width: 28px;
  height: 28px;
  padding: 5px;
}

.section-label {
  font-size: 10px;
  letter-spacing: 1px;
  color: #95a18c;
  margin: 24px 0 12px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 14px 0;
  font-size: 12px;
}

input[type=checkbox],
input[type=range] {
  accent-color: #779352;
}

label {
  display: block;
  font-size: 12px;
  color: #68785c;
}

input[type=number],
input[type=text],
select,
#new-name {
  width: 100%;
  margin-top: 7px;
  padding: 10px;
  background: #fbfcf8;
  border: 1px solid #dce3d4;
  border-radius: 6px;
  font: inherit;
  color: #394d2e;
}

select {
  margin-bottom: 16px;
}

.wide {
  width: 100%;
}

.hint {
  font-size: 11px;
  line-height: 1.9;
  color: #8b9681;
}

.reference-panel {
  left: 50px;
  right: auto;
  width: 310px;
}

.reference-panel .drawer-heading {
  padding: 13px 16px;
  margin: 0;
  border-bottom: 1px solid var(--border);
}

.reference-panel>div:last-child {
  padding: 14px;
  max-height: 420px;
  overflow: auto;
  background: #f5f6f1;
}

.reference-panel img {
  display: block;
  width: 100%;
}

.selection-actions {
  position: absolute;
  top: 0;
  left: 0;
  width: max-content;
  max-width: calc(100% - 46px);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: #2d2f2e;
  border: 1px solid #4d504b;
  border-radius: 10px;
  box-shadow: 0 8px 24px #1e291e30;
  white-space: nowrap;
  z-index: 3;
}

.selection-actions>span {
  font-size: 11px;
  color: #bdc7b7;
  padding: 0 6px;
}

.selection-actions button {
  font-size: 11px;
  padding: 7px 10px;
  color: #e4e7e2;
  background: transparent;
  border-color: transparent;
}

.selection-actions button:hover {
  background: #414440;
}

.selection-actions .icon-button {
  width: 32px;
  height: 32px;
  padding: 6px;
}

.patterns-panel {
  position: absolute;
  bottom: 82px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  width: 700px;
  max-width: calc(100% - 24px);
  max-height: calc(100% - 110px);
  overflow: hidden;
  padding: 16px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 36px #26351c20;
  z-index: 5;
}

.patterns-panel .drawer-heading,
.patterns-panel>.hint {
  flex-shrink: 0;
}

.patterns-panel .hint {
  margin: 6px 0 14px;
}

.pattern-list {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.pattern-card {
  flex-direction: column;
  gap: 5px;
  padding: 10px 6px;
  font-size: 11px;
}

.pattern-card span {
  white-space: normal;
  text-align: center;
  line-height: 1.35;
}

.pattern-card:hover {
  border-color: #a2b68c;
}

.pattern-card .pattern-preview {
  width: 62px;
  height: 62px;
  padding: 5px;
  color: var(--pattern-color, #344b87);
  background: #f5f7f1;
  fill: currentColor;
  stroke: none;
}

.pattern-card small {
  font-size: 10px;
  color: #929e87;
}

dialog {
  border: 1px solid #dce3d3;
  border-radius: 15px;
  padding: 0;
  color: #33432d;
  box-shadow: 0 25px 100px #22351826;
  max-height: 92dvh;
}

dialog::backdrop {
  background: #23321e50;
  backdrop-filter: blur(3px);
}

.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 26px;
  border-bottom: 1px solid var(--border);
}

.eyebrow {
  font-size: 9px;
  letter-spacing: 2px;
  color: #92a17f;
  margin: 0 0 7px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  padding: 18px 24px;
  border-top: 1px solid var(--border);
}

.dialog-actions>span {
  margin-right: auto;
  font-size: 11px;
  color: #93a087;
}

.small-dialog {
  width: 380px;
  max-width: calc(100vw - 30px);
}

.small-dialog form>label,
.small-dialog .fields,
.small-dialog .hint,
.small-dialog .error {
  margin: 22px 26px;
}

.format-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  border: 0;
  padding: 0;
  margin: 22px 26px;
}

.format-options legend {
  padding: 0;
  margin-bottom: 10px;
  font-size: 12px;
  color: #68785c;
}

.format-option {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 14px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}

.format-option:has(:checked) {
  background: #f1f6e8;
  border-color: #91aa6f;
}

.format-option input {
  margin: 0;
  accent-color: #779352;
}

.format-option strong,
.format-option small {
  display: block;
}

.format-option strong {
  font-size: 14px;
  color: #394d2e;
}

.format-option small {
  margin-top: 4px;
  font-size: 10px;
}

.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 22px 0;
}

.error {
  color: #ae6047;
  font-size: 11px;
}

.import-dialog {
  width: 980px;
  max-width: calc(100vw - 32px);
}

.import-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
}

.import-view {
  min-width: 0;
  background: #eef1e8;
}

.preview-tabs {
  display: flex;
  gap: 3px;
  align-items: center;
  padding: 9px 15px;
  background: #f9faf6;
  border-bottom: 1px solid var(--border);
}

.preview-tabs button {
  border: 0;
  background: transparent;
  font-size: 11px;
  padding: 8px 10px;
}

.preview-tabs button.active {
  background: #e7eedc;
  color: #48622e;
}

#image-info {
  margin-left: auto;
  font-size: 10px;
  color: #94a087;
}

.import-canvas-wrap {
  padding: 20px;
  height: min(54dvh, 540px);
  overflow: auto;
}

#import-preview {
  display: block;
  max-width: 100%;
  height: auto;
  background: white;
  touch-action: none;
  cursor: crosshair;
}

.crop-actions {
  display: flex;
  gap: 8px;
}

.crop-actions button {
  flex: 1;
}

.import-controls {
  padding: 20px;
  overflow-y: auto;
  max-height: 65dvh;
}

h3 {
  font-size: 13px;
  margin: 0;
}

details {
  border-top: 1px solid var(--border);
  margin-top: 24px;
  padding-top: 18px;
}

summary {
  color: #6a7e57;
  font-size: 12px;
  cursor: pointer;
}

input[type=range] {
  width: 100%;
  display: block;
  margin-top: 12px;
}

#threshold-value {
  float: right;
}

@media(max-width:900px) {
  .topbar {
    padding: 0 12px;
    gap: 15px;
  }

  .brand span {
    display: none;
  }

  .project-heading input {
    width: 140px;
  }

  .topbar nav {
    gap: 2px;
  }

  .topbar nav button:not(.icon-button) {
    padding: 9px;
  }
}

@media(max-width:600px) {
  .topbar {
    height: 48px;
    gap: 8px;
  }

  .brand img {
    width: 46px;
    height: 30px;
  }

  .project-heading input {
    width: 100px;
    font-size: 11px;
  }

  .topbar nav button span,
  .divider {
    display: none;
  }

  .topbar nav button {
    width: 30px;
    height: 34px;
    padding: 6px;
  }

  #save-state {
    font-size: 9px;
  }

  .toolrail {
    gap: 2px;
    padding: 7px;
    border-radius: 15px;
  }

  .toolrail .icon-button {
    width: 34px;
    height: 36px;
  }

  .rail-divider {
    margin: 0 3px;
  }

  .swatch {
    margin: 0 3px;
  }

  .drawer {
    right: 8px;
    width: min(270px, calc(100% - 16px));
  }

  .zoom-controls {
    right: 8px;
    gap: 4px;
    font-size: 10px;
  }

  .import-body {
    grid-template-columns: 1fr;
  }

  .import-canvas-wrap {
    height: 25dvh;
  }

  .import-controls {
    max-height: 30dvh;
  }

  .dialog-heading {
    padding: 16px 20px;
  }

  .dialog-actions {
    padding: 12px;
  }

  .dialog-actions>span {
    display: none;
  }

  .reference-panel {
    left: 10px;
    width: calc(100% - 20px);
  }

  .selection-actions {
    gap: 3px;
  }

  .selection-actions>span {
    display: none;
  }

  h1 {
    font-size: 20px;
  }
}