:root {
  color-scheme: light;
  --canvas: #f9f8f2;
  --surface: rgb(249 248 242 / 88%);
  --surface-soft: #eceae1;
  --ink: #151515;
  --muted: #5f5c55;
  --faint: #77736a;
  --line: #151515;
  --line-strong: #151515;
  --accent-bg: #f2dfda;
  --accent: #b51a1f;
  --success-bg: transparent;
  --success: #8d1216;
  --error-bg: #f2dfda;
  --error: #8d1216;
  --serif: "Songti SC", "STSong", "Source Han Serif SC", Georgia, serif;
  --sans: "SF Pro Display", "Helvetica Neue", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", Arial, sans-serif;
  --mono: "SFMono-Regular", "Cascadia Mono", "Courier New", monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  color: var(--ink);
  background-color: var(--canvas);
  background-image: radial-gradient(rgb(21 21 21 / 7%) 0.55px, transparent 0.55px);
  background-size: 4px 4px;
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
summary:focus-visible,
article:focus-visible,
a:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.skip-link {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 10;
  padding: 9px 12px;
  color: #fff;
  background: var(--ink);
  border-radius: 4px;
  transform: translateY(-180%);
}

.skip-link:focus {
  transform: translateY(0);
}

.page-shell {
  width: min(1280px, calc(100% - 32px));
  margin: 18px auto 0;
}

.page-header {
  background: var(--surface);
  border-top: 4px solid var(--ink);
  border-bottom: 4px solid var(--ink);
}

.hero-copy {
  max-width: 980px;
  margin: 0 auto;
  padding: 42px 24px 36px;
  text-align: center;
}

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

h1 {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  column-gap: 0.22em;
  margin-bottom: 14px;
  font: 800 clamp(36px, 4.5vw, 52px) / 1.06 var(--serif);
  letter-spacing: -0.055em;
  text-wrap: balance;
}

.hero-signature {
  margin: 0 0 8px;
  color: var(--accent);
  font: 800 clamp(17px, 2vw, 22px) / 1.2 var(--serif);
  letter-spacing: -0.04em;
}

.hero-tagline {
  max-width: 650px;
  margin: 0 auto;
  color: var(--muted);
  font: 400 14px/1.75 var(--serif);
}

.api-settings {
  border-top: 1px solid var(--ink);
}

.api-settings summary {
  display: flex;
  min-height: 50px;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  list-style: none;
  cursor: pointer;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 700;
}

.api-settings summary::-webkit-details-marker {
  display: none;
}

.api-settings summary::before {
  width: 18px;
  flex: 0 0 auto;
  content: "+";
  color: var(--muted);
  font: 400 18px/1 var(--mono);
}

.api-settings[open] summary::before {
  content: "−";
}

.api-settings summary > span {
  flex: 1;
}

.api-settings summary small {
  color: var(--muted);
  font-size: 11px;
  font-weight: 500;
}

.api-settings-body {
  padding: 20px 46px 22px;
  border-top: 1px solid var(--ink);
}

.api-settings-body > label {
  display: block;
  margin-bottom: 7px;
  font-size: 11px;
  font-weight: 650;
}

.key-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.key-input-row input {
  height: 44px;
}

.text-button,
.save-key-button,
.output-actions button,
.share-actions button,
.example-button,
.generate-button {
  min-height: 40px;
  border-radius: 0;
  transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease,
    transform 120ms ease;
}

.text-button {
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--ink);
  font-size: 12px;
}

.text-button:hover {
  color: var(--ink);
  border-color: var(--line-strong);
}

.save-key-button {
  padding: 0 16px;
  color: var(--canvas);
  background: var(--ink);
  border: 1px solid var(--ink);
  font-size: 12px;
  font-weight: 650;
}

.key-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-top: 10px;
}

.key-actions > p {
  max-width: 610px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

.key-actions > div {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

.key-notice {
  min-height: 18px;
  margin: 8px 0 0;
  color: var(--error);
  font-size: 11px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 5fr) minmax(500px, 7fr);
  align-items: stretch;
  min-height: calc(100dvh - 286px);
  background: var(--surface);
  border-right: 1px solid var(--ink);
  border-bottom: 4px solid var(--ink);
  border-left: 1px solid var(--ink);
}

.input-pane,
.output-pane {
  min-width: 0;
  padding: 32px 38px 40px;
  background: transparent;
}

.input-pane {
  border-right: 1px solid var(--ink);
}

.output-pane {
  display: flex;
  flex-direction: column;
  background: rgb(236 234 225 / 50%);
}

.section-heading {
  display: flex;
  min-height: 52px;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 4px solid var(--ink);
}

.section-heading span {
  display: block;
  margin-bottom: 5px;
  color: var(--accent);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

h2 {
  margin-bottom: 0;
  font: 800 25px/1.12 var(--serif);
  letter-spacing: -0.035em;
}

.section-heading > p {
  max-width: 190px;
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
  text-align: right;
}

#storyForm {
  display: grid;
  gap: 17px;
}

#storyForm label {
  display: grid;
  gap: 7px;
}

#storyForm label > span {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.story-primary {
  gap: 8px !important;
}

.story-primary textarea {
  min-height: 264px;
  font-size: 14px;
  line-height: 1.75;
}

.story-primary > small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.5;
}

#storyForm em {
  margin-left: 3px;
  color: var(--faint);
  font-size: 10px;
  font-style: normal;
  font-weight: 500;
}

.name-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.story-details {
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--ink);
}

.story-details summary {
  display: flex;
  min-height: 47px;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  list-style: none;
}

.story-details summary::-webkit-details-marker {
  display: none;
}

.story-details summary::before {
  flex: 0 0 auto;
  content: "+";
  color: var(--muted);
  font: 400 18px/1 var(--mono);
}

.story-details[open] summary::before {
  content: "−";
}

.story-details summary > span {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.story-details summary > small {
  margin-left: auto;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.45;
  text-align: right;
}

.story-details-body {
  display: grid;
  gap: 17px;
  padding: 16px 0 20px;
  border-top: 1px solid rgb(21 21 21 / 26%);
}

input,
textarea {
  width: 100%;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 2px solid var(--ink);
  border-radius: 0;
  font-family: var(--mono);
  transition: background-color 160ms ease, border-color 160ms ease;
}

input {
  height: 44px;
  padding: 0 12px;
  font-size: 13px;
}

textarea {
  padding: 11px 12px;
  resize: vertical;
  font-size: 13px;
  line-height: 1.65;
}

input:hover,
textarea:hover {
  background: rgb(21 21 21 / 3%);
}

input:focus,
textarea:focus {
  background: var(--surface-soft);
  border-color: var(--accent);
}

::placeholder {
  color: var(--faint);
  opacity: 1;
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 0;
}

.example-button {
  padding: 0;
  color: var(--ink);
  background: transparent;
  border: 0;
  font-size: 12px;
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 5px;
}

.example-button:hover {
  color: var(--ink);
}

.generate-button {
  min-width: 150px;
  min-height: 46px;
  padding: 0 20px;
  color: var(--canvas);
  background: var(--ink);
  border: 1px solid var(--ink);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.generate-button:hover,
.save-key-button:hover {
  color: var(--ink);
  background: var(--canvas);
  box-shadow: 4px 4px 0 var(--ink);
  transform: translate(-2px, -2px);
}

.generate-button:active,
.save-key-button:active,
.text-button:active,
.output-actions button:active,
.share-actions button:active {
  transform: scale(0.98);
}

.generate-button:disabled {
  cursor: wait;
  opacity: 0.48;
}

.fine-print {
  margin: -6px 0 0;
  color: var(--faint);
  font: 400 9px/1.55 var(--mono);
  text-align: right;
}

.output-heading {
  align-items: center;
}

.output-actions {
  display: flex;
  align-items: center;
  gap: 9px;
}

.output-actions small {
  color: var(--muted);
  font: 400 10px/1 var(--mono);
}

.output-actions button {
  padding: 0 12px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--ink);
  font-size: 11px;
}

.output-actions button:not(:disabled):hover {
  color: var(--canvas);
  background: var(--ink);
}

.output-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.36;
}

.share-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-top: 12px;
  padding: 11px 12px;
  background: rgb(242 223 218 / 45%);
}

.share-actions > span {
  flex: 0 0 auto;
  color: var(--accent);
  font: 700 11px/1.4 var(--serif);
}

.share-actions > div {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 7px;
}

.share-actions button {
  min-height: 34px;
  padding: 0 10px;
  color: var(--ink);
  background: transparent;
  border: 1px solid var(--ink);
  font-size: 11px;
}

.share-actions button:first-child {
  color: var(--canvas);
  background: var(--ink);
}

.share-actions button:hover {
  color: var(--canvas);
  background: var(--ink);
}

.article-area {
  position: relative;
  flex: 1;
  min-height: 640px;
  padding: 46px clamp(30px, 4.8vw, 68px);
  overflow: auto;
  background-color: var(--canvas);
  background-image: linear-gradient(rgb(21 21 21 / 2%) 1px, transparent 1px);
  background-size: 100% 29px;
  border: 1px solid var(--ink);
  border-radius: 0;
}

.empty-state,
.loading-state {
  position: absolute;
  top: 50%;
  left: 50%;
  width: min(310px, calc(100% - 48px));
  text-align: center;
  transform: translate(-50%, -50%);
}

.empty-state p,
.loading-state p {
  margin-bottom: 7px;
  color: var(--ink);
  font: 700 17px/1.45 var(--serif);
}

.empty-state small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.65;
}

.skeleton-lines {
  display: grid;
  gap: 10px;
  margin-bottom: 18px;
}

.skeleton-lines span {
  width: 100%;
  height: 7px;
  background: var(--ink);
  border-radius: 0;
  animation: skeleton-breathe 1.2s ease-in-out infinite alternate;
}

.skeleton-lines span:nth-child(2) {
  width: 84%;
}

.skeleton-lines span:nth-child(3) {
  width: 94%;
}

.skeleton-lines span:nth-child(4) {
  width: 69%;
}

#storyOutput {
  max-width: 680px;
  margin: 0 auto;
  white-space: pre-wrap;
  font: 400 17px/2.05 var(--serif);
  text-align: justify;
  animation: story-in 220ms ease-out both;
}

#storyOutput::first-line {
  font-size: 1.24em;
  font-weight: 800;
}

.error-banner {
  margin-top: 12px;
  padding: 11px 12px;
  color: var(--error);
  background: var(--error-bg);
  border: 2px solid var(--error);
  border-radius: 0;
  font-size: 11px;
  line-height: 1.55;
}

.output-note {
  margin: 10px 0 0;
  color: var(--muted);
  font: 400 9px/1.5 var(--mono);
  text-align: right;
}

@keyframes skeleton-breathe {
  from {
    opacity: 0.4;
  }
  to {
    opacity: 0.8;
  }
}

@keyframes story-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

@media (max-width: 900px) {
  .page-shell {
    width: min(720px, calc(100% - 28px));
  }

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

  .input-pane {
    border-right: 0;
    border-bottom: 4px solid var(--ink);
  }

  .article-area {
    min-height: 540px;
  }
}

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

  .page-header,
  .input-pane,
  .output-pane {
    border-right: 0;
    border-left: 0;
    border-radius: 0;
  }

  .page-header {
    margin-bottom: 0;
    padding: 0;
  }

  .hero-copy {
    padding: 32px 20px 28px;
  }

  h1 {
    font-size: 36px;
    line-height: 1.12;
  }

  .hero-signature {
    margin-bottom: 9px;
    font-size: 18px;
  }

  .hero-tagline {
    font-size: 14px;
  }

  .api-settings-body {
    padding: 18px 20px 20px;
  }

  .api-settings summary {
    padding: 0 20px;
  }

  .key-actions {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .key-actions > div {
    width: 100%;
    justify-content: flex-end;
  }

  .workspace {
    gap: 0;
  }

  .input-pane,
  .output-pane {
    padding: 24px 20px 28px;
  }

  .section-heading {
    margin-bottom: 20px;
  }

  .section-heading > p {
    display: none;
  }

  .name-row {
    grid-template-columns: 1fr;
    gap: 17px;
  }

  .story-primary textarea {
    min-height: 240px;
  }

  .story-details summary > small {
    max-width: 160px;
  }

  .form-actions {
    align-items: stretch;
    flex-direction: column-reverse;
  }

  .example-button {
    align-self: flex-start;
  }

  .generate-button {
    width: 100%;
  }

  .fine-print {
    text-align: left;
  }

  .article-area {
    min-height: 500px;
    padding: 36px 24px;
  }

  #storyOutput {
    font-size: 16px;
    line-height: 2;
  }

  .output-note {
    text-align: left;
  }

  .share-actions {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .share-actions > div {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .share-actions button:nth-child(3) {
    grid-column: 1 / -1;
  }
}

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