@font-face {
  font-family: 'Ma Shan Zheng';
  src: url('/assets/fonts/ma-shan-zheng.woff2') format('woff2');
  font-display: swap;
  font-style: normal;
  font-weight: 400;
}

:root {
  color-scheme: light;
  --paper: #f7f7f2;
  --paper-raised: #ffffff;
  --ink: #17272a;
  --muted: #657276;
  --line: #cfd7d5;
  --line-strong: #9aaba8;
  --coral: #ee796e;
  --coral-dark: #cc564f;
  --aqua: #51b4ad;
  --aqua-soft: #d7efeb;
  --yellow: #f0c963;
  --danger: #bf4f4b;
  --shadow: 0 18px 48px rgba(23, 39, 42, 0.12);
  font-family: 'Microsoft YaHei UI', 'PingFang SC', sans-serif;
  font-synthesis: none;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

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

body {
  background-color: var(--paper);
  background-image:
    linear-gradient(rgba(23, 39, 42, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(23, 39, 42, 0.035) 1px, transparent 1px);
  background-size: 32px 32px;
  color: var(--ink);
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(81, 180, 173, 0.35);
  outline-offset: 2px;
}

.topbar {
  align-items: center;
  background: rgba(247, 247, 242, 0.94);
  border-bottom: 1px solid var(--line);
  display: flex;
  height: 76px;
  justify-content: space-between;
  padding: 0 clamp(18px, 3vw, 46px);
  position: sticky;
  top: 0;
  z-index: 20;
}

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

.brand > span:last-child {
  display: grid;
  line-height: 1;
}

.brand strong {
  font-family: 'Ma Shan Zheng', 'Microsoft YaHei UI', sans-serif;
  font-size: 27px;
  font-weight: 400;
}

.brand small {
  color: var(--muted);
  font-size: 9px;
  font-weight: 700;
  margin-top: 7px;
}

.brand-mark {
  display: block;
  height: 34px;
  position: relative;
  transform: rotate(8deg);
  width: 34px;
}

.brand-mark i {
  background: var(--coral);
  border: 2px solid var(--ink);
  border-radius: 50% 50% 45% 55%;
  height: 17px;
  left: 9px;
  position: absolute;
  top: 1px;
  transform-origin: 8px 16px;
  width: 17px;
}

.brand-mark i:nth-child(2) { transform: rotate(90deg); }
.brand-mark i:nth-child(3) { transform: rotate(180deg); }
.brand-mark i:nth-child(4) { transform: rotate(270deg); }
.brand-mark::after {
  background: var(--yellow);
  border: 2px solid var(--ink);
  border-radius: 50%;
  content: '';
  height: 9px;
  left: 13px;
  position: absolute;
  top: 13px;
  width: 9px;
}

.key-button,
.download-button {
  align-items: center;
  background: var(--paper-raised);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  display: inline-flex;
  font-size: 13px;
  font-weight: 700;
  gap: 9px;
  min-height: 40px;
  padding: 0 13px;
}

.key-button:hover,
.download-button:hover:not(:disabled) {
  border-color: var(--ink);
  transform: translateY(-1px);
}

.key-button img,
.download-button img,
.generate-button img,
.privacy-note img {
  height: 17px;
  width: 17px;
}

.status-dot {
  background: var(--line-strong);
  border-radius: 50%;
  height: 7px;
  width: 7px;
}

.key-button.is-ready .status-dot {
  background: var(--aqua);
  box-shadow: 0 0 0 4px var(--aqua-soft);
}

.studio-shell {
  display: grid;
  grid-template-columns: minmax(330px, 410px) minmax(0, 1fr);
  min-height: calc(100vh - 76px);
}

.control-panel {
  background: rgba(255, 255, 255, 0.86);
  border-right: 1px solid var(--line);
  padding: clamp(28px, 4vw, 52px) clamp(22px, 3vw, 40px) 28px;
}

.panel-heading {
  margin-bottom: 32px;
}

.issue-number,
.canvas-kicker {
  color: var(--coral-dark);
  display: block;
  font-size: 10px;
  font-weight: 800;
  margin-bottom: 9px;
}

.panel-heading h1 {
  font-family: 'Ma Shan Zheng', 'Microsoft YaHei UI', sans-serif;
  font-size: clamp(36px, 4vw, 50px);
  font-weight: 400;
  line-height: 1.1;
  margin: 0;
}

.field-block {
  border: 0;
  margin: 0 0 25px;
  min-width: 0;
  padding: 0;
}

.field-block legend,
.field-label-row label,
.key-field {
  font-size: 13px;
  font-weight: 800;
  margin-bottom: 10px;
}

.field-label-row {
  align-items: center;
  display: flex;
  justify-content: space-between;
}

.field-label-row span {
  color: var(--muted);
  font-size: 11px;
}

textarea {
  background: var(--paper-raised);
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  line-height: 1.75;
  min-height: 180px;
  padding: 16px;
  resize: vertical;
  width: 100%;
}

textarea:hover,
textarea:focus {
  border-color: var(--aqua);
}

.preset-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.preset-grid button {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 12px;
  min-height: 40px;
  padding: 8px 10px;
}

.preset-grid button:hover {
  background: var(--aqua-soft);
  border-color: var(--aqua);
}

.size-switch {
  background: #edf0ed;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: grid;
  gap: 3px;
  grid-template-columns: repeat(3, 1fr);
  padding: 3px;
}

.size-switch input {
  height: 1px;
  opacity: 0;
  position: absolute;
  width: 1px;
}

.size-switch span {
  align-items: center;
  border: 1px solid transparent;
  border-radius: 4px;
  display: flex;
  font-size: 12px;
  font-weight: 700;
  gap: 7px;
  justify-content: center;
  min-height: 40px;
}

.size-switch input:checked + span {
  background: var(--paper-raised);
  border-color: var(--line-strong);
  box-shadow: 0 2px 8px rgba(23, 39, 42, 0.08);
}

.ratio {
  border: 1.5px solid currentColor;
  display: inline-block;
}

.ratio.portrait { height: 16px; width: 11px; }
.ratio.square { height: 14px; width: 14px; }
.ratio.landscape { height: 11px; width: 16px; }

.generate-button {
  align-items: center;
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 6px;
  color: white;
  display: flex;
  font-size: 15px;
  font-weight: 800;
  gap: 10px;
  justify-content: center;
  min-height: 52px;
  transition: background 160ms ease, transform 160ms ease;
  width: 100%;
}

.generate-button img {
  filter: brightness(0) invert(1);
}

.generate-button:hover:not(:disabled) {
  background: var(--coral-dark);
  border-color: var(--coral-dark);
  transform: translateY(-2px);
}

.privacy-note {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 11px;
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
}

.canvas-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: clamp(22px, 3vw, 40px);
}

.canvas-toolbar {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 16px;
  min-height: 42px;
}

.canvas-toolbar > div:first-child {
  min-width: 0;
}

.canvas-toolbar .canvas-kicker {
  margin-bottom: 4px;
}

.canvas-toolbar strong {
  display: block;
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.icon-button {
  align-items: center;
  background: var(--paper-raised);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  display: inline-flex;
  height: 40px;
  justify-content: center;
  padding: 0;
  width: 40px;
}

.icon-button img {
  height: 18px;
  width: 18px;
}

.canvas-stage {
  align-items: center;
  background: #e3e8e5;
  border: 1px solid var(--line-strong);
  display: flex;
  flex: 1;
  justify-content: center;
  min-height: 520px;
  overflow: hidden;
  position: relative;
}

.canvas-stage::before {
  background-image:
    linear-gradient(45deg, rgba(23, 39, 42, 0.055) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(23, 39, 42, 0.055) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(23, 39, 42, 0.055) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(23, 39, 42, 0.055) 75%);
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
  content: '';
  inset: 0;
  opacity: 0.8;
  position: absolute;
}

.art-frame {
  align-items: center;
  display: flex;
  height: 100%;
  justify-content: center;
  padding: clamp(30px, 5vw, 72px);
  position: absolute;
  width: 100%;
}

.art-frame img {
  box-shadow: var(--shadow);
  display: block;
  max-height: 100%;
  max-width: 100%;
  object-fit: contain;
}

.canvas-stage[data-state='idle'] .art-frame img {
  filter: saturate(0.82) contrast(0.95);
  opacity: 0.88;
}

.sample-tag,
.corner-note {
  background: var(--paper-raised);
  border: 1px solid var(--ink);
  bottom: 16px;
  font-size: 9px;
  font-weight: 800;
  left: 16px;
  padding: 7px 9px;
  position: absolute;
}

.corner-note {
  left: auto;
  right: 16px;
}

.progress-layer,
.canvas-error {
  align-items: center;
  background: rgba(247, 247, 242, 0.94);
  display: none;
  flex-direction: column;
  inset: 0;
  justify-content: center;
  position: absolute;
  text-align: center;
  z-index: 4;
}

.canvas-stage[data-state='loading'] .progress-layer,
.canvas-stage[data-state='error'] .canvas-error {
  display: flex;
}

.canvas-stage[data-state='loading'] .sample-tag,
.canvas-stage[data-state='error'] .sample-tag {
  display: none;
}

.progress-layer strong,
.canvas-error strong {
  font-family: 'Ma Shan Zheng', 'Microsoft YaHei UI', sans-serif;
  font-size: 30px;
  font-weight: 400;
  margin: 18px 0 7px;
}

.progress-layer span,
.canvas-error span {
  color: var(--muted);
  font-size: 13px;
  max-width: 420px;
  padding: 0 24px;
}

.progress-layer time {
  color: var(--coral-dark);
  font-size: 12px;
  font-weight: 800;
  margin-top: 18px;
}

.orbit-loader {
  height: 64px;
  position: relative;
  width: 64px;
}

.orbit-loader::before {
  border: 2px solid var(--ink);
  border-radius: 50%;
  content: '';
  inset: 13px;
  position: absolute;
}

.orbit-loader i {
  animation: orbit 1.8s linear infinite;
  background: var(--coral);
  border: 2px solid var(--ink);
  border-radius: 50%;
  height: 13px;
  left: 26px;
  position: absolute;
  top: 0;
  transform-origin: 6px 32px;
  width: 13px;
}

.orbit-loader i:nth-child(2) {
  animation-delay: -0.6s;
  background: var(--aqua);
}

.orbit-loader i:nth-child(3) {
  animation-delay: -1.2s;
  background: var(--yellow);
}

@keyframes orbit {
  to { transform: rotate(360deg); }
}

.canvas-error img {
  height: 40px;
  width: 40px;
}

.key-dialog {
  background: var(--paper-raised);
  border: 1px solid var(--ink);
  border-radius: 7px;
  box-shadow: 0 24px 80px rgba(23, 39, 42, 0.28);
  color: var(--ink);
  max-width: calc(100vw - 32px);
  padding: 0;
  width: 460px;
}

.key-dialog::backdrop {
  background: rgba(23, 39, 42, 0.58);
}

.key-dialog form {
  padding: 26px;
}

.dialog-heading {
  align-items: flex-start;
  display: flex;
  justify-content: space-between;
  margin-bottom: 24px;
}

.dialog-heading h2 {
  font-family: 'Ma Shan Zheng', 'Microsoft YaHei UI', sans-serif;
  font-size: 31px;
  font-weight: 400;
  margin: 0;
}

.secret-input {
  display: flex;
  margin-top: 10px;
}

.secret-input input {
  border: 1px solid var(--line-strong);
  border-radius: 5px 0 0 5px;
  flex: 1;
  min-width: 0;
  padding: 12px 13px;
}

.secret-input button {
  background: var(--paper);
  border: 1px solid var(--line-strong);
  border-left: 0;
  border-radius: 0 5px 5px 0;
  width: 44px;
}

.secret-input img {
  height: 17px;
  width: 17px;
}

.key-dialog p {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  margin: 10px 0 0;
}

.dialog-actions {
  display: flex;
  gap: 9px;
  justify-content: flex-end;
  margin-top: 26px;
}

.text-button,
.primary-small {
  border-radius: 5px;
  min-height: 40px;
  padding: 0 16px;
}

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

.primary-small {
  background: var(--ink);
  border: 1px solid var(--ink);
  color: white;
  font-weight: 700;
}

.toast {
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 5px;
  bottom: 24px;
  color: white;
  font-size: 13px;
  left: 50%;
  opacity: 0;
  padding: 11px 15px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 12px);
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 40;
}

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

@media (max-width: 860px) {
  .topbar {
    height: 68px;
  }

  .studio-shell {
    display: block;
  }

  .control-panel {
    border-bottom: 1px solid var(--line);
    border-right: 0;
    padding: 28px 20px;
  }

  .panel-heading {
    margin-bottom: 24px;
  }

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

  textarea {
    min-height: 150px;
  }

  .canvas-panel {
    min-height: calc(100svh - 68px);
    padding: 20px;
  }

  .canvas-stage {
    flex: none;
    min-height: 0;
    height: min(72svh, 680px);
  }

  .art-frame {
    padding: 28px;
  }
}

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

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

  .key-button span {
    display: none;
  }

  .key-button {
    padding: 0 11px;
  }

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

  .canvas-toolbar {
    align-items: flex-end;
    gap: 10px;
  }

  .download-button span {
    display: none;
  }

  .download-button {
    justify-content: center;
    padding: 0;
    width: 40px;
  }

  .canvas-stage {
    height: min(66svh, 560px);
  }

  .corner-note {
    display: none;
  }
}

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