:root {
  color-scheme: light;
  --ink-950: #14231f;
  --ink-900: #1c302a;
  --ink-800: #2b4038;
  --ink-700: #465950;
  --paper: #eee4d0;
  --paper-light: #fbf7ec;
  --paper-deep: #dccdb1;
  --gold: #b58b4d;
  --gold-light: #d7bb81;
  --verm: #96372d;
  --verm-deep: #70251f;
  --jade: #4c6f60;
  --muted: #7b806f;
  --line: rgb(107 91 65 / 34%);
  --line-strong: rgb(107 91 65 / 58%);
  --shadow: 0 24px 54px rgb(5 14 12 / 22%), 0 2px 8px rgb(5 14 12 / 16%);
  --serif: "Noto Serif SC", "Songti SC", "STSong", Georgia, serif;
  --kai: "STKaiti", "KaiTi", "FZKai-Z03", "Noto Serif SC", serif;
  --sans: "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  font-family: var(--serif);
  color: var(--ink-900);
  background: var(--ink-950);
  font-synthesis: none;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--ink-950);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink-900);
  background:
    radial-gradient(circle at 50% -18%, rgb(83 120 98 / 38%), transparent 32rem),
    radial-gradient(circle at 0% 100%, rgb(96 64 35 / 16%), transparent 28rem),
    linear-gradient(145deg, #182923 0%, var(--ink-950) 58%, #101b18 100%);
}

body::before {
  position: fixed;
  z-index: 0;
  inset: 0;
  pointer-events: none;
  content: "";
  opacity: 0.24;
  background-image: repeating-linear-gradient(
    0deg,
    rgb(255 255 255 / 4%) 0,
    rgb(255 255 255 / 4%) 1px,
    transparent 1px,
    transparent 5px
  );
  mix-blend-mode: soft-light;
}

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

button,
select,
input,
textarea {
  border-radius: 0;
}

.page-shell {
  position: relative;
  z-index: 1;
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 34px 0 58px;
}

.page-shell::before {
  position: absolute;
  top: 0;
  bottom: 0;
  left: -18px;
  width: 1px;
  content: "";
  background: linear-gradient(180deg, transparent, rgb(213 180 119 / 44%) 14%, rgb(213 180 119 / 16%) 86%, transparent);
}

.experimental-banner {
  margin: 0 auto 18px;
  padding: 11px 18px;
  border: 1px solid rgb(215 187 129 / 72%);
  color: var(--paper-light);
  background: rgb(112 37 31 / 84%);
  box-shadow: 0 10px 24px rgb(4 11 9 / 20%);
  font-family: var(--sans);
  font-size: 0.83rem;
  line-height: 1.6;
  letter-spacing: 0.04em;
  text-align: center;
}

.hero {
  position: relative;
  max-width: 820px;
  margin: 0 auto 30px;
  padding: 32px 24px 36px;
  color: var(--paper-light);
  text-align: center;
}

.hero::before,
.hero::after {
  position: absolute;
  right: 10%;
  left: 10%;
  height: 1px;
  content: "";
  background: linear-gradient(90deg, transparent, var(--gold) 18%, var(--gold-light) 50%, var(--gold) 82%, transparent);
}

.hero::before {
  top: 0;
}

.hero::after {
  bottom: 0;
}

.eyebrow,
.step {
  margin: 0 0 12px;
  color: var(--gold-light);
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  line-height: 1.6;
}

.eyebrow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.eyebrow::before,
.eyebrow::after {
  width: 54px;
  height: 1px;
  content: "";
  background: var(--gold);
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin: 14px 0 10px;
  color: var(--paper-light);
  font-family: var(--kai);
  font-size: clamp(4rem, 10vw, 7rem);
  font-weight: 600;
  letter-spacing: 0.12em;
  line-height: 0.92;
  text-shadow: 0 6px 22px rgb(4 11 9 / 24%);
}

.seal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: clamp(52px, 8vw, 68px);
  height: clamp(52px, 8vw, 68px);
  border: 1px solid var(--gold-light);
  color: var(--paper-light);
  background: var(--verm);
  box-shadow: 5px 7px 0 rgb(5 14 12 / 20%), inset 0 0 0 4px rgb(112 37 31 / 58%);
  font-family: var(--kai);
  font-size: clamp(1.6rem, 3vw, 2rem);
  font-weight: 700;
  line-height: 1;
  transform: rotate(-5deg);
}

.title-word {
  display: inline-block;
  transform: translateY(4px);
}

.lede {
  margin-bottom: 18px;
  color: rgb(251 247 236 / 78%);
  font-size: clamp(1.03rem, 2.5vw, 1.24rem);
  line-height: 1.9;
}

.hero-meta {
  display: flex;
  justify-content: center;
  gap: 20px;
  color: var(--gold-light);
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.16em;
}

.hero-meta span + span::before {
  margin-right: 20px;
  color: var(--gold);
  content: "·";
}

.workspace-grid {
  display: grid;
  grid-template-areas: "engine workbench";
  grid-template-columns: minmax(270px, 0.78fr) minmax(0, 1.55fr);
  align-items: stretch;
  gap: 18px;
  margin-bottom: 18px;
}

.engine-panel,
.workbench,
.result-panel {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  background:
    linear-gradient(135deg, rgb(251 247 236 / 97%), rgb(238 228 208 / 95%)),
    repeating-linear-gradient(0deg, rgb(110 80 43 / 4%) 0, rgb(110 80 43 / 4%) 1px, transparent 1px, transparent 5px);
  box-shadow: var(--shadow);
}

.engine-panel::before,
.workbench::before,
.result-panel::before {
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 4px;
  content: "";
  background: linear-gradient(90deg, var(--verm-deep), var(--gold), var(--verm));
}

.engine-panel {
  grid-area: engine;
  padding: 26px;
}

.engine-panel .section-heading {
  display: block;
}

.engine-panel h2 {
  font-size: clamp(1.55rem, 2.8vw, 1.9rem);
  white-space: nowrap;
}

.engine-panel .counter {
  margin-top: 10px;
  padding: 7px 0 0;
  border-top: 1px solid rgb(107 91 65 / 22%);
  border-left: 0;
}

.workbench {
  grid-area: workbench;
  padding: clamp(25px, 4vw, 44px);
}

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

.step {
  display: inline-block;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--gold);
  letter-spacing: 0.15em;
}

h2 {
  margin-bottom: 0;
  color: var(--ink-900);
  font-family: var(--kai);
  font-size: clamp(1.5rem, 3vw, 2.25rem);
  font-weight: 600;
  letter-spacing: 0.04em;
}

.counter {
  flex: 0 0 auto;
  margin: 4px 0 0;
  padding-left: 10px;
  border-left: 1px solid var(--gold);
  color: var(--muted);
  font-family: ui-monospace, monospace;
  font-size: 0.73rem;
  line-height: 1.6;
}

.counter[data-over="true"] {
  color: var(--verm);
  font-weight: 700;
}

.engine-panel .counter[data-kind="error"] {
  color: var(--verm);
}

.engine-panel .counter[data-kind="success"] {
  color: var(--jade);
}

.engine-note {
  margin-bottom: 22px;
  padding-left: 12px;
  border-left: 2px solid var(--gold);
  color: var(--ink-700);
  font-family: var(--sans);
  font-size: 0.79rem;
  line-height: 1.8;
}

.engine-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 15px;
}

.engine-grid label > span,
.controls label > span {
  display: block;
  margin-bottom: 7px;
  color: var(--ink-800);
  font-family: var(--sans);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.engine-grid input,
.engine-grid select,
.controls select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  color: var(--ink-900);
  background: rgb(255 252 243 / 58%);
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.engine-grid input,
.engine-grid select,
.controls select {
  min-height: 44px;
  padding: 0 11px;
  font-family: var(--sans);
  font-size: 0.84rem;
}

.engine-grid input:focus,
.engine-grid select:focus,
.controls select:focus,
textarea:focus,
button:focus-visible {
  border-color: var(--gold);
  background: var(--paper-light);
  box-shadow: 0 0 0 3px rgb(181 139 77 / 18%);
}

.engine-grid input:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.engine-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.engine-actions button {
  flex: 0 0 auto;
  width: auto;
  min-height: 40px;
  padding: 0 16px;
  font-size: 0.76rem;
}

textarea {
  display: block;
  min-height: 232px;
  resize: vertical;
  padding: 20px;
  background:
    linear-gradient(rgb(255 252 243 / 72%), rgb(255 252 243 / 72%)),
    repeating-linear-gradient(0deg, transparent 0, transparent 33px, rgb(181 139 77 / 13%) 34px, transparent 35px);
  font-size: 1.04rem;
  line-height: 2.05;
}

textarea::placeholder,
input::placeholder {
  color: rgb(123 128 111 / 68%);
}

select,
button {
  width: 100%;
  min-height: 48px;
}

button {
  border: 1px solid var(--verm-deep);
  padding: 0 18px;
  color: var(--paper-light);
  background: var(--verm-deep);
  cursor: pointer;
  font-family: var(--sans);
  font-size: 0.83rem;
  font-weight: 700;
  letter-spacing: 0.13em;
  transition: background 160ms ease, border-color 160ms ease, transform 160ms ease;
}

button:hover:not(:disabled) {
  border-color: var(--verm);
  background: var(--verm);
  transform: translateY(-1px);
}

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

button.ghost,
.copy-button {
  border-color: var(--gold);
  color: var(--verm-deep);
  background: transparent;
}

button.ghost:hover:not(:disabled),
.copy-button:hover:not(:disabled) {
  color: var(--paper-light);
  border-color: var(--verm-deep);
  background: var(--verm-deep);
}

.example-row {
  margin-top: 13px;
}

.example-row button {
  min-height: 40px;
  font-size: 0.76rem;
}

.controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(170px, 0.86fr);
  gap: 15px;
  align-items: end;
  margin-top: 22px;
}

.status {
  min-height: 1.5em;
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px solid rgb(107 91 65 / 22%);
  color: var(--ink-700);
  font-family: var(--sans);
  font-size: 0.8rem;
  line-height: 1.7;
}

.status[data-kind="error"] {
  color: var(--verm);
}

.status[data-kind="success"] {
  color: var(--jade);
}

.error-detail-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-top: 10px;
}

.error-detail {
  flex: 1 1 auto;
  margin: 10px 0 0;
  color: var(--verm);
  font-family: ui-monospace, monospace;
  font-size: 0.74rem;
  line-height: 1.6;
  word-break: break-all;
}

.error-detail-copy {
  flex: 0 0 auto;
  min-height: 32px;
  margin-top: 0;
  padding: 0 11px;
  font-size: 0.72rem;
}

.result-panel {
  margin-top: 18px;
  padding: clamp(27px, 4vw, 46px);
  border-left: 5px solid var(--verm);
}

.result-panel::after {
  position: absolute;
  top: 18px;
  right: 25px;
  color: rgb(150 55 45 / 12%);
  content: "“";
  font-family: Georgia, serif;
  font-size: 7rem;
  line-height: 1;
  pointer-events: none;
}

.result-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 18px;
}

.result-actions {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 9px;
}

.result-actions button {
  position: relative;
  flex: 0 0 auto;
  width: auto;
  min-height: 40px;
  padding: 0 16px;
  font-size: 0.75rem;
}

.share-card-button {
  border-color: var(--jade);
  background: var(--jade);
}

.share-card-button:hover:not(:disabled) {
  border-color: var(--ink-900);
  background: var(--ink-900);
}

.result-meta {
  margin: 12px 0 0;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.75rem;
  letter-spacing: 0.05em;
}

.result-text {
  position: relative;
  z-index: 1;
  margin: 24px 0 0;
  white-space: pre-wrap;
  color: var(--ink-900);
  font-family: var(--kai);
  font-size: clamp(1.06rem, 2.4vw, 1.24rem);
  line-height: 2.08;
}

.share-card-block {
  position: relative;
  z-index: 1;
  margin-top: 34px;
  padding-top: 28px;
  border-top: 1px solid rgb(107 91 65 / 28%);
}

.share-card-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  max-width: 580px;
  margin: 0 auto;
}

.share-card-kicker {
  margin: 0 0 6px;
  color: var(--verm);
  font-family: var(--sans);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.16em;
}

.share-card-heading h3 {
  margin: 0;
  color: var(--ink-900);
  font-family: var(--kai);
  font-size: 1.45rem;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.share-card-heading > p {
  margin: 0 0 3px;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.7rem;
}

.share-card-preview {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  width: min(100%, 580px);
  min-height: 124px;
  margin: 18px auto 0;
  padding: 18px 24px;
  border: 1px solid rgb(181 139 77 / 62%);
  color: var(--ink-900);
  background:
    linear-gradient(135deg, rgb(251 247 236 / 92%), rgb(238 228 208 / 88%)),
    repeating-linear-gradient(0deg, rgb(110 80 43 / 4%) 0, rgb(110 80 43 / 4%) 1px, transparent 1px, transparent 5px);
  text-align: left;
}

.share-card-preview:hover:not(:disabled) {
  border-color: var(--verm);
  background: var(--paper-light);
  transform: translateY(-1px);
}

.share-card-preview:disabled {
  color: var(--muted);
  background: rgb(238 228 208 / 48%);
}

.share-card-preview-seal {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border: 2px solid var(--gold);
  color: var(--paper-light);
  background: var(--verm-deep);
  font-family: var(--kai);
  font-size: 2rem;
  transform: rotate(-4deg);
}

.share-card-preview-copy {
  display: grid;
  gap: 6px;
}

.share-card-preview-copy strong {
  color: var(--ink-900);
  font-family: var(--kai);
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: 0.06em;
}

.share-card-preview-copy small {
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.72rem;
  letter-spacing: 0.04em;
}

.share-card-preview-arrow {
  color: var(--verm);
  font-family: var(--sans);
  font-size: 1.5rem;
}

.share-card-frame {
  width: min(100%, 580px);
  max-height: 760px;
  margin: 18px auto 0;
  overflow: auto;
  border: 1px solid rgb(181 139 77 / 42%);
  padding: 12px;
  background: rgb(20 35 31 / 8%);
  box-shadow: inset 0 0 28px rgb(20 35 31 / 12%);
}

#share-card-canvas {
  display: block;
  width: 100%;
  height: auto;
  background: var(--ink-950);
  box-shadow: 0 12px 32px rgb(20 35 31 / 22%);
}

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

.share-card-backdrop {
  position: absolute;
  inset: 0;
  background: rgb(9 18 15 / 78%);
  backdrop-filter: blur(4px);
}

.share-card-dialog-panel {
  position: relative;
  display: flex;
  width: min(100%, 760px);
  max-height: calc(100vh - 48px);
  flex-direction: column;
  border: 1px solid var(--gold);
  padding: 28px;
  background:
    linear-gradient(135deg, rgb(251 247 236 / 99%), rgb(238 228 208 / 98%)),
    repeating-linear-gradient(0deg, rgb(110 80 43 / 4%) 0, rgb(110 80 43 / 4%) 1px, transparent 1px, transparent 5px);
  box-shadow: 0 28px 80px rgb(0 0 0 / 38%);
}

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

.share-card-dialog-heading h3 {
  margin: 0;
  color: var(--ink-900);
  font-family: var(--kai);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.share-card-close {
  width: 42px;
  min-height: 42px;
  padding: 0;
  border-color: var(--line-strong);
  color: var(--ink-800);
  background: transparent;
  font-family: var(--sans);
  font-size: 1.5rem;
  line-height: 1;
}

.share-card-close:hover:not(:disabled) {
  border-color: var(--verm);
  color: var(--paper-light);
  background: var(--verm-deep);
}

.share-card-dialog-panel .share-card-frame {
  width: min(100%, 620px);
  max-height: min(68vh, 760px);
  margin: 0 auto;
}

.share-card-dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 18px;
}

.share-card-dialog-actions button {
  width: auto;
  min-width: 132px;
  min-height: 44px;
}

.share-card-dialog-actions #download-card-button {
  border-color: var(--verm-deep);
}

.share-card-dialog-status {
  min-height: 1.5em;
  margin: 12px 0 0;
  color: var(--muted);
  font-family: var(--sans);
  font-size: 0.74rem;
  line-height: 1.6;
  text-align: center;
}

.share-card-dialog-status[data-kind="error"] {
  color: var(--verm);
}

.share-card-dialog-status[data-kind="success"] {
  color: var(--jade);
}

body.modal-open {
  overflow: hidden;
}

footer {
  max-width: 760px;
  margin: 28px auto 0;
  padding-top: 18px;
  border-top: 1px solid rgb(213 180 119 / 26%);
  color: rgb(238 228 208 / 62%);
  font-family: var(--sans);
  font-size: 0.72rem;
  line-height: 1.8;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

@media (max-width: 860px) {
  .workspace-grid {
    grid-template-areas:
      "workbench"
      "engine";
    grid-template-columns: 1fr;
  }

  .engine-grid {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }
}

@media (max-width: 640px) {
  .page-shell {
    width: min(100% - 24px, 560px);
    padding-top: 24px;
  }

  .page-shell::before {
    display: none;
  }

  .hero {
    padding: 26px 8px 30px;
  }

  .hero::before,
  .hero::after {
    right: 0;
    left: 0;
  }

  .eyebrow {
    gap: 8px;
    font-size: 0.65rem;
    letter-spacing: 0.13em;
  }

  .eyebrow::before,
  .eyebrow::after {
    width: 22px;
  }

  h1 {
    gap: 12px;
    font-size: clamp(3.7rem, 22vw, 5.3rem);
  }

  .hero-meta {
    gap: 10px;
    font-size: 0.64rem;
    letter-spacing: 0.1em;
  }

  .hero-meta span + span::before {
    margin-right: 10px;
  }

  .engine-panel,
  .workbench,
  .result-panel {
    padding: 22px 18px;
  }

  .engine-grid,
  .controls {
    grid-template-columns: 1fr;
  }

  .section-heading {
    flex-direction: column;
    gap: 10px;
  }

  .result-heading,
  .share-card-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .result-actions {
    justify-content: flex-start;
  }

  .share-card-preview {
    grid-template-columns: 58px minmax(0, 1fr) auto;
    gap: 12px;
    padding: 16px;
  }

  .share-card-dialog {
    padding: 12px;
  }

  .share-card-dialog-panel {
    max-height: calc(100vh - 24px);
    padding: 20px 16px;
  }

  .counter {
    margin-top: 0;
  }

  textarea {
    min-height: 210px;
    padding: 15px;
  }

  .result-heading {
    align-items: flex-start;
    flex-direction: column;
  }
}

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