@font-face {
  font-family: "ZCOOLXiaoWei";
  src: url("./fonts/ZCOOLXiaoWei-Regular.ttf") format("truetype");
  font-display: swap;
}

@font-face {
  font-family: "LongCang";
  src: url("./fonts/LongCang-Regular.ttf") format("truetype");
  font-display: swap;
}

:root {
  --charcoal: #1b1a17;
  --charcoal-soft: #25231f;
  --charcoal-light: #322f29;
  --paper: #e9e1d2;
  --paper-deep: #d5c8b3;
  --paper-white: #f7f1e6;
  --muted: #8f887c;
  --line: rgba(233, 225, 210, 0.12);
  --red: #a73226;
  --red-bright: #c74534;
  --gold: #b58b46;
  --green: #6e8d77;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
  background: #151411;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--paper);
  font-family: "PingFang SC", "Hiragino Sans GB", sans-serif;
  background:
    radial-gradient(circle at 46% 2%, rgba(105, 83, 52, 0.16), transparent 31rem),
    #171613;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

.grain {
  position: fixed;
  inset: 0;
  z-index: 99;
  opacity: 0.13;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.15'/%3E%3C/svg%3E");
  mix-blend-mode: overlay;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 76px;
  padding: 0 26px;
  border-bottom: 1px solid var(--line);
  background: rgba(24, 23, 20, 0.93);
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  width: max-content;
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(232, 218, 194, 0.28);
  color: var(--paper-white);
  font: 27px/1 "LongCang", serif;
  background:
    linear-gradient(130deg, transparent 0 58%, rgba(167, 50, 38, 0.7) 58% 63%, transparent 63%),
    var(--charcoal-light);
  transform: rotate(-2deg);
}

.brand p {
  margin: 0 0 2px;
  color: var(--gold);
  font: 8px/1.1 Georgia, serif;
  letter-spacing: 0.2em;
}

.brand h1 {
  margin: 0;
  font: 29px/0.9 "ZCOOLXiaoWei", serif;
  letter-spacing: 0.16em;
}

.autosave {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #9d968a;
  font-size: 11px;
}

.autosave span,
.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(110, 141, 119, 0.1);
}

.workspace-nav {
  display: grid;
  grid-template-columns: 1fr 1fr;
  justify-self: center;
  min-width: 230px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.025);
}

.workspace-nav a {
  display: grid;
  min-height: 34px;
  place-items: center;
  border-radius: 2px;
  color: #777167;
  font-size: 10px;
  font-weight: 650;
  text-decoration: none;
  transition: color 150ms ease, background 150ms ease;
}

.workspace-nav a:hover {
  color: var(--paper);
}

.workspace-nav a.active {
  color: var(--paper-white);
  background: var(--charcoal-light);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}

.top-actions {
  display: flex;
  justify-self: end;
  gap: 8px;
}

.quiet-button,
.export-button,
.transparent-export {
  min-height: 39px;
  padding: 0 17px;
  border-radius: 3px;
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
  transition: transform 150ms ease, border 150ms ease, background 150ms ease;
}

.quiet-button:hover,
.export-button:hover,
.transparent-export:hover {
  transform: translateY(-1px);
}

.quiet-button {
  border: 1px solid var(--line);
  background: transparent;
}

.export-button {
  border: 1px solid #be4939;
  color: #fff5e7;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent 50%),
    var(--red);
  box-shadow: 0 7px 24px rgba(117, 31, 23, 0.24);
}

.workspace {
  display: grid;
  grid-template-columns: 142px minmax(440px, 1fr) 318px;
  min-height: calc(100vh - 76px);
}

.tool-rail {
  position: relative;
  z-index: 2;
  padding: 24px 16px;
  border-right: 1px solid var(--line);
  background: rgba(31, 29, 25, 0.74);
}

.rail-label {
  margin: 0 0 10px 4px;
  color: var(--gold);
  font: italic 10px Georgia, serif;
}

.tool-group {
  display: grid;
  gap: 8px;
}

.tool {
  position: relative;
  display: grid;
  min-height: 78px;
  padding: 9px 7px 8px;
  overflow: hidden;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 3px;
  color: #afa89b;
  background: transparent;
  cursor: pointer;
  transition: color 150ms ease, border 150ms ease, background 150ms ease;
}

.tool:hover {
  color: var(--paper);
  background: rgba(255, 255, 255, 0.03);
}

.tool.active {
  border-color: rgba(181, 139, 70, 0.42);
  color: var(--paper-white);
  background:
    linear-gradient(135deg, rgba(181, 139, 70, 0.11), transparent 65%),
    rgba(255, 255, 255, 0.025);
}

.tool.active::after {
  position: absolute;
  top: 9px;
  right: 8px;
  width: 4px;
  height: 4px;
  border-radius: 50%;
  content: "";
  background: var(--red-bright);
}

.tool-icon {
  position: relative;
  display: block;
  width: 42px;
  height: 20px;
  margin-bottom: 4px;
}

.tool-icon::before {
  position: absolute;
  top: 9px;
  left: 4px;
  width: 34px;
  height: 4px;
  border-radius: 100% 10% 10% 100%;
  content: "";
  background: currentColor;
  transform: rotate(-12deg);
}

.ink-icon::before {
  height: 7px;
  border-radius: 100% 0 100% 0;
}

.dry-icon::before {
  height: 6px;
  background: repeating-linear-gradient(0deg, currentColor 0 1px, transparent 1px 2px);
}

.marker-icon::before {
  height: 5px;
  border-radius: 0;
}

.eraser-icon::before {
  top: 5px;
  left: 12px;
  width: 20px;
  height: 13px;
  border: 1px solid currentColor;
  border-radius: 2px;
  background: transparent;
  transform: rotate(-18deg);
}

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

.tool strong {
  font-size: 11px;
}

.tool small {
  margin-top: 2px;
  color: #706a61;
  font-size: 8px;
}

.rail-divider {
  height: 1px;
  margin: 22px 0;
  background: var(--line);
}

.history-tools {
  gap: 6px;
}

.mini-tool {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 2px;
  color: #9f988b;
  background: rgba(255, 255, 255, 0.018);
  font-size: 9px;
  cursor: pointer;
}

.mini-tool:hover {
  color: var(--paper-white);
  border-color: rgba(233, 225, 210, 0.25);
}

.mini-tool span {
  font: 17px Georgia, serif;
}

.pressure-meter {
  position: absolute;
  right: 16px;
  bottom: 22px;
  left: 16px;
  display: flex;
  align-items: end;
  justify-content: center;
  height: 62px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(0, 0, 0, 0.14);
}

.pressure-meter span {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 14%;
  opacity: 0.72;
  background:
    linear-gradient(0deg, var(--red), var(--gold));
  transition: height 80ms linear;
}

.pressure-meter small {
  position: relative;
  z-index: 1;
  margin-bottom: 7px;
  color: rgba(255, 255, 255, 0.66);
  font: 8px Georgia, serif;
  letter-spacing: 0.16em;
}

.stage-column {
  position: sticky;
  top: 76px;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 76px);
  min-height: 640px;
  padding: 18px clamp(20px, 3vw, 46px) 14px;
  background:
    linear-gradient(30deg, rgba(255, 255, 255, 0.018) 12%, transparent 12.5%, transparent 87%, rgba(255, 255, 255, 0.018) 87.5%),
    linear-gradient(150deg, rgba(255, 255, 255, 0.018) 12%, transparent 12.5%, transparent 87%, rgba(255, 255, 255, 0.018) 87.5%),
    #14130f;
  background-size: 48px 84px;
}

.stage-head,
.stage-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #777167;
  font-size: 9px;
}

.stage-head {
  margin-bottom: 11px;
}

.stage-head > div:first-child {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stage-head strong {
  color: #b7afa1;
  font-size: 10px;
}

.stage-head small {
  margin-left: 4px;
}

.ratio-switch {
  display: flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 3px;
}

.ratio-switch button {
  min-width: 42px;
  height: 25px;
  border: 0;
  border-radius: 2px;
  color: #777167;
  background: transparent;
  font: 9px Georgia, serif;
  cursor: pointer;
}

.ratio-switch button.active {
  color: var(--paper-white);
  background: var(--charcoal-light);
}

.grid-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  border: 0;
  color: #706a60;
  background: transparent;
  font-size: 9px;
  cursor: pointer;
}

.grid-toggle span {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid var(--line);
  font: 12px "ZCOOLXiaoWei", serif;
}

.grid-toggle.active {
  color: var(--gold);
}

.grid-toggle.active span {
  border-color: rgba(181, 139, 70, 0.46);
}

.stage {
  position: relative;
  display: grid;
  flex: 1;
  min-height: 0;
  place-items: center;
}

.paper-shadow {
  position: relative;
  display: grid;
  max-width: 100%;
  max-height: 100%;
  place-items: center;
  filter: drop-shadow(0 28px 44px rgba(0, 0, 0, 0.46));
  animation: paper-in 650ms cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes paper-in {
  from {
    opacity: 0;
    transform: translateY(14px) scale(0.97) rotate(0.4deg);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1) rotate(0);
  }
}

canvas {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 180px);
  border: 6px solid rgba(216, 203, 181, 0.12);
  outline: 1px solid rgba(231, 220, 199, 0.22);
  background: #e8decc;
  touch-action: none;
  cursor: crosshair;
}

body.eraser-mode canvas {
  cursor: cell;
}

.empty-prompt {
  position: absolute;
  top: 50%;
  left: 50%;
  display: grid;
  width: max-content;
  place-items: center;
  color: rgba(76, 67, 55, 0.38);
  pointer-events: none;
  transform: translate(-50%, -50%);
  transition: opacity 160ms ease;
}

.empty-prompt.hidden {
  opacity: 0;
}

.prompt-brush {
  font: 76px/0.8 "LongCang", serif;
  transform: rotate(-18deg);
}

.empty-prompt strong {
  margin-top: 10px;
  font: 22px "ZCOOLXiaoWei", serif;
  letter-spacing: 0.12em;
}

.empty-prompt small {
  margin-top: 6px;
  font-size: 9px;
}

.drop-overlay {
  position: absolute;
  inset: 10px;
  display: grid;
  place-items: center;
  border: 2px dashed rgba(181, 139, 70, 0.48);
  color: var(--gold);
  background: rgba(20, 19, 15, 0.88);
  font: 18px "ZCOOLXiaoWei", serif;
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease;
}

.stage.dragging .drop-overlay {
  opacity: 1;
}

.stage-footer {
  margin-top: 9px;
}

.motto {
  color: #9b7151;
  font: 13px "LongCang", serif;
}

.settings {
  min-height: calc(100vh - 76px);
  border-left: 1px solid var(--line);
  background: rgba(31, 29, 25, 0.7);
}

.settings-section {
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title > div {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.section-title span {
  color: var(--gold);
  font: italic 9px Georgia, serif;
}

.section-title h2 {
  margin: 0;
  font: 16px "ZCOOLXiaoWei", serif;
  letter-spacing: 0.08em;
}

.section-title small {
  color: #777066;
  font-size: 9px;
}

.upload-button {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 54px;
  padding: 9px 11px;
  border: 1px dashed rgba(233, 225, 210, 0.18);
  border-radius: 3px;
  color: #aaa295;
  background: rgba(255, 255, 255, 0.02);
  cursor: pointer;
}

.upload-button:hover {
  border-color: rgba(181, 139, 70, 0.5);
}

.upload-button > span {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--gold);
  font: 19px Georgia, serif;
}

.upload-button strong,
.upload-button small {
  display: block;
}

.upload-button strong {
  margin-bottom: 2px;
  font-size: 10px;
}

.upload-button small {
  color: #686259;
  font-size: 8px;
}

.upload-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.background-presets {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 9px;
}

.background-presets button {
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 31px;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 2px;
  color: #817a70;
  background: rgba(255, 255, 255, 0.018);
  font-size: 8px;
  cursor: pointer;
}

.background-presets button.active {
  border-color: rgba(181, 139, 70, 0.45);
  color: var(--paper);
}

.background-presets span {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.bg-paper {
  background: #d9cdb8;
}

.bg-ink {
  background: #171a1d;
}

.bg-red {
  background: #74241e;
}

.color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.color-row > label {
  display: flex;
  align-items: center;
  gap: 9px;
  color: #8f887e;
  font-size: 9px;
}

input[type="color"] {
  width: 28px;
  height: 28px;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type="color"]::-webkit-color-swatch {
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-radius: 50%;
}

.quick-colors {
  display: flex;
  gap: 7px;
}

.quick-colors button {
  width: 20px;
  height: 20px;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.16);
  border-radius: 50%;
  background: var(--swatch);
  cursor: pointer;
}

.slider-control {
  display: block;
  margin-top: 14px;
}

.slider-control > span {
  display: flex;
  justify-content: space-between;
  margin-bottom: 8px;
  color: #918a80;
  font-size: 9px;
}

.slider-control output {
  color: var(--gold);
  font: 9px Georgia, serif;
}

input[type="range"] {
  width: 100%;
  height: 3px;
  margin: 0;
  appearance: none;
  border-radius: 999px;
  outline: none;
  background: linear-gradient(90deg, var(--gold) 0 50%, #4d4942 50%);
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  width: 13px;
  height: 13px;
  appearance: none;
  border: 2px solid #292722;
  border-radius: 50%;
  background: var(--paper);
  box-shadow: 0 0 0 1px rgba(181, 139, 70, 0.65);
}

.section-description {
  margin: -2px 0 12px;
  color: #777066;
  font-size: 9px;
  line-height: 1.6;
}

.correction-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.correction-actions button {
  min-height: 68px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 3px;
  text-align: left;
  background:
    linear-gradient(135deg, rgba(181, 139, 70, 0.06), transparent),
    rgba(255, 255, 255, 0.018);
  cursor: pointer;
}

.correction-actions button:hover {
  border-color: rgba(181, 139, 70, 0.42);
}

.correction-actions span,
.correction-actions strong,
.correction-actions small {
  display: block;
}

.correction-actions span {
  margin-bottom: 6px;
  color: var(--gold);
  font: 20px/0.8 Georgia, serif;
}

.correction-actions strong {
  margin-bottom: 2px;
  font-size: 10px;
}

.correction-actions small {
  color: #686159;
  font-size: 8px;
}

.tiny-switch {
  position: relative;
}

.tiny-switch input {
  position: absolute;
  opacity: 0;
}

.tiny-switch span {
  display: block;
  width: 28px;
  height: 15px;
  padding: 2px;
  border-radius: 99px;
  background: #4f4a42;
  cursor: pointer;
}

.tiny-switch span::after {
  display: block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  content: "";
  background: #b7afa1;
  transition: transform 140ms ease, background 140ms ease;
}

.tiny-switch input:checked + span {
  background: var(--red);
}

.tiny-switch input:checked + span::after {
  background: #f2e7d4;
  transform: translateX(13px);
}

.seal-editor {
  display: grid;
  grid-template-columns: 1fr 48px;
  align-items: center;
  gap: 10px;
}

.seal-editor input {
  width: 100%;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 2px;
  outline: none;
  color: var(--paper);
  background: rgba(0, 0, 0, 0.13);
  font: 16px "ZCOOLXiaoWei", serif;
}

.seal-editor input:focus {
  border-color: rgba(181, 139, 70, 0.5);
}

.seal-preview {
  grid-row: 1 / span 2;
  grid-column: 2;
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border: 2px solid #bd4b3b;
  color: #d15c49;
  font: 17px/0.92 "ZCOOLXiaoWei", serif;
  text-align: center;
  white-space: pre-line;
  transform: rotate(-3deg);
}

.seal-editor small {
  color: #625d55;
  font-size: 8px;
}

.export-panel {
  padding: 18px 20px 24px;
}

.export-button.full,
.transparent-export {
  width: 100%;
}

.transparent-export {
  margin-top: 7px;
  border: 1px solid rgba(181, 139, 70, 0.35);
  color: #bda980;
  background: transparent;
}

.export-panel p {
  margin: 10px 4px 0;
  color: #635d54;
  font-size: 8px;
  line-height: 1.5;
}

dialog {
  width: min(370px, calc(100% - 28px));
  padding: 28px;
  border: 1px solid rgba(232, 223, 205, 0.18);
  color: var(--paper);
  background:
    radial-gradient(circle at 100% 0, rgba(167, 50, 38, 0.18), transparent 14rem),
    #24221e;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.5);
}

dialog::backdrop {
  background: rgba(10, 9, 7, 0.74);
  backdrop-filter: blur(4px);
}

.dialog-mark {
  color: var(--red-bright);
  font: 34px "LongCang", serif;
}

dialog h2 {
  margin: 3px 0 6px;
  font: 22px "ZCOOLXiaoWei", serif;
}

dialog p {
  margin: 0 0 20px;
  color: #8d867c;
  font-size: 10px;
}

dialog > div {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

dialog button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: transparent;
  font-size: 10px;
  cursor: pointer;
}

dialog .danger-button {
  border-color: var(--red);
  background: var(--red);
}

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  z-index: 100;
  padding: 10px 15px;
  border: 1px solid rgba(232, 223, 205, 0.13);
  border-radius: 2px;
  color: var(--paper-white);
  background: rgba(35, 32, 27, 0.96);
  box-shadow: 0 14px 44px rgba(0, 0, 0, 0.45);
  font-size: 10px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 160ms ease, transform 160ms ease;
}

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

@media (max-width: 1080px) {
  .workspace {
    grid-template-columns: 116px 1fr;
  }

  .settings {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    min-height: auto;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

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

  .export-panel {
    align-self: center;
  }
}

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: 1fr auto;
    height: 118px;
    padding: 0 14px;
  }

  .autosave,
  .quiet-button {
    display: none;
  }

  .workspace-nav {
    grid-row: 2;
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    margin-bottom: 8px;
  }

  .workspace {
    display: flex;
    flex-direction: column;
  }

  .stage-column {
    position: relative;
    top: auto;
    order: -1;
    height: 70vh;
    min-height: 500px;
  }

  .tool-rail {
    display: grid;
    grid-template-columns: 3fr 1fr;
    padding: 12px;
    border-top: 1px solid var(--line);
    border-right: 0;
  }

  .tool-group {
    grid-template-columns: repeat(4, 1fr);
  }

  .history-tools {
    grid-template-columns: 1fr;
    margin-left: 8px;
  }

  .rail-label,
  .rail-divider,
  .pressure-meter {
    display: none;
  }

  .tool {
    min-height: 70px;
  }

  .settings {
    display: block;
  }
}

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