:root {
  --bg: #f5f6f7;
  --panel: #ffffff;
  --ink: #1f2329;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #111827;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
  --motion-smooth: cubic-bezier(0.22, 1, 0.36, 1);
  --motion-gentle: cubic-bezier(0.16, 1, 0.3, 1);
  --font-body:
    "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-display:
    "Noto Serif SC", "Songti SC", "STSong", "Source Han Serif SC", serif;
  --radius-field: 12px;
  --radius-card: 24px;
  --radius-pill: 999px;
  --page-width: min(980px, calc(100% - 24px));
  --topbar-width: min(760px, 100%);
  --page-padding-top: 20px;
  --page-padding-bottom: 48px;
  --article-min-height: 720px;
  --article-padding: 56px 64px 88px;
  --article-section-gap: 42px;
  --article-break-gap: 34px;
  --article-line-gap: 12px;
  --article-copy-size: 1.08rem;
  --article-copy-line-height: 1.9;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  color-scheme: light;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a {
  color: inherit;
  text-decoration: none;
}

.page-shell {
  width: var(--page-width);
  margin: 0 auto;
  min-height: 100vh;
  padding: var(--page-padding-top) 0 var(--page-padding-bottom);
}

.topbar {
  width: var(--topbar-width);
  margin: 0 auto;
  transform-origin: center top;
  transition:
    transform 720ms var(--motion-smooth),
    width 720ms var(--motion-smooth),
    margin 720ms var(--motion-smooth);
  will-change: transform, width;
}

.generator-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  transform-origin: center center;
  transition:
    transform 720ms var(--motion-gentle),
    opacity 220ms ease;
  will-change: transform, opacity;
}

.warning-note {
  position: fixed;
  left: 50%;
  bottom: 22px;
  z-index: 20;
  display: block;
  width: min(720px, calc(100% - 24px));
  padding: 12px 14px;
  border: 1px solid #f3d19c;
  border-radius: 14px;
  background: rgba(255, 248, 235, 0.96);
  box-shadow: 0 12px 32px rgba(101, 67, 24, 0.08);
  color: #7a4b12;
  font-size: 0.82rem;
  line-height: 1.6;
  text-wrap: balance;
  transform: translate3d(-50%, 0, 0);
  transition:
    opacity 240ms ease,
    transform 360ms var(--motion-gentle);
}

.warning-note span {
  display: block;
  min-width: 0;
}

.warning-note span + span {
  margin-top: 2px;
}

.warning-note a {
  text-decoration: none;
}

.generator-form input,
.generator-form button {
  min-height: 44px;
  border-radius: var(--radius-field);
  font: inherit;
}

.generator-form input {
  width: 100%;
  padding: 0 14px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
}

.generator-form input:focus {
  outline: 2px solid rgba(17, 24, 39, 0.1);
  border-color: #cfd4dc;
}

.generator-form button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 96px;
  padding: 0 16px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
}

.generator-form button:hover {
  background: #fafafa;
}

.generator-form #submit-btn {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
}

.generator-form #submit-btn .button-icon {
  width: 16px;
  height: 16px;
}

.generator-form #submit-btn .button-icon svg {
  display: block;
  width: 100%;
  height: 100%;
}

.generator-form #submit-btn:disabled {
  opacity: 0.65;
  cursor: progress;
}

.workspace {
  display: grid;
  gap: 10px;
  opacity: 0;
  transform: translate3d(0, 22px, 0);
  filter: blur(10px);
  visibility: hidden;
  pointer-events: none;
  transition:
    opacity 360ms ease,
    transform 720ms var(--motion-gentle),
    filter 420ms ease;
  will-change: opacity, transform, filter;
}

.status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 24px;
  padding: 0 2px;
}

.status-loader {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 4px;
  min-width: 24px;
  align-items: center;
  opacity: 0;
  transition: opacity 200ms ease;
}

.status-loader span {
  width: 5px;
  height: 5px;
  border-radius: 999px;
  background: #9ca3af;
  transform: translateY(0) scale(0.72);
  animation: loader-pulse 1s ease-in-out infinite;
  animation-play-state: paused;
}

.status-loader span:nth-child(2) {
  animation-delay: 120ms;
}

.status-loader span:nth-child(3) {
  animation-delay: 240ms;
}

.status-bar.is-loading .status-loader {
  opacity: 0.9;
}

.status-bar.is-loading .status-loader span {
  background: #111827;
  animation-play-state: running;
}

.status-bar p {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.article-frame {
  position: relative;
  min-height: var(--article-min-height);
  padding: var(--article-padding);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
}

.article-frame.is-empty {
  display: none;
}

.article-toolbar {
  position: absolute;
  right: 32px;
  bottom: 28px;
  display: flex;
  align-items: flex-end;
  margin: 0;
}

.article-frame.is-error .article-toolbar {
  display: none;
}

body.is-generating .article-toolbar {
  display: none;
}

.floating-btn,
.copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: #fff;
  color: var(--muted);
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  transition:
    border-color 180ms ease,
    color 180ms ease,
    background 180ms ease;
}

.floating-btn:hover,
.copy-btn:hover {
  border-color: #d1d5db;
  color: var(--ink);
  background: #fafafa;
}

.floating-btn.is-copied,
.copy-btn.is-copied {
  border-color: #d1d5db;
  color: var(--ink);
  background: #f3f4f6;
}

.top-btn {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 24;
  width: 36px;
  min-width: 36px;
  min-height: 36px;
  padding: 0;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
}

body:not(.app-active) .top-btn {
  display: none !important;
}

.top-btn svg {
  display: block;
  width: 16px;
  height: 16px;
}

body:not(.app-active) .topbar {
  transform: translate3d(0, calc(50vh - 20px - 50%), 0);
}

body:not(.app-active) .generator-form {
  transform: scale(1.015);
}

body:not(.app-active) .workspace {
  display: none;
}

body.app-active .topbar {
  width: 100%;
  margin: 0 0 18px;
  transform: translate3d(0, 0, 0);
}

body.app-active .generator-form {
  transform: scale(1);
}

body.app-active .warning-note {
  opacity: 0;
  pointer-events: none;
  transform: translate3d(-50%, 8px, 0);
}

body.app-active .workspace {
  display: grid;
}

body.app-ready .workspace {
  opacity: 1;
  transform: translate3d(0, 0, 0);
  filter: blur(0);
  visibility: visible;
  pointer-events: auto;
}

.article-stream {
  display: block;
}

.error-card h2 {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 700;
}

:is(.doc-section + .doc-section, .article-stream > section + section) {
  margin-top: var(--article-section-gap);
}

.article-stream p + .doc-section,
.article-stream ul + .doc-section {
  margin-top: var(--article-break-gap);
}

:is(.doc-title, .article-stream > section:first-child > h2:first-child) {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(2rem, 4vw, 3rem);
  line-height: 1.18;
  font-weight: 900;
  letter-spacing: -0.03em;
}

:is(
  .doc-section-title,
  .article-stream h3:not([class]),
  .article-stream section > h3:first-child
) {
  margin: 0 0 16px;
  font-family: var(--font-display);
  font-size: clamp(1.45rem, 2.8vw, 2rem);
  line-height: 1.35;
  font-weight: 700;
}

.article-stream p + .doc-title,
.article-stream p + .doc-section-title,
.article-stream ul + .doc-title,
.article-stream ul + .doc-section-title,
.article-stream p + h2:not([class]),
.article-stream p + h3:not([class]),
.article-stream ul + h2:not([class]),
.article-stream ul + h3:not([class]) {
  margin-top: var(--article-break-gap);
}

.lead-paragraph,
.dialogue-line,
.continuation-line,
.article-stream p:not([class]),
.bullet-list {
  margin: 0;
  font-size: var(--article-copy-size);
  line-height: var(--article-copy-line-height);
  color: #2b3138;
}

.lead-paragraph + .lead-paragraph,
.lead-paragraph + .dialogue-line,
.dialogue-line + .dialogue-line,
.dialogue-line + .continuation-line,
.continuation-line + .continuation-line,
.continuation-line + .dialogue-line,
.bullet-list + .dialogue-line,
.dialogue-line + .bullet-list,
.article-stream p + p {
  margin-top: var(--article-line-gap);
}

.speaker-name {
  display: inline;
  margin-right: 4px;
  color: #1f2329;
  font-weight: 800;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.bullet-list {
  padding-left: 1.3rem;
}

.error-card {
  color: #b42318;
}

@keyframes loader-pulse {
  0%,
  80%,
  100% {
    transform: translateY(0) scale(0.72);
    opacity: 0.32;
  }

  40% {
    transform: translateY(-1px) scale(1);
    opacity: 1;
  }
}

@media (max-width: 720px) {
  :root {
    --page-width: min(100% - 12px, 980px);
    --page-padding-top: max(14px, env(safe-area-inset-top));
    --page-padding-bottom: max(126px, calc(env(safe-area-inset-bottom) + 22px));
    --article-min-height: 560px;
    --article-padding: 26px 18px 72px;
    --article-section-gap: 30px;
    --article-break-gap: 24px;
    --article-line-gap: 10px;
    --article-copy-size: 0.98rem;
    --article-copy-line-height: 1.82;
    --radius-card: 20px;
    --radius-field: 14px;
  }

  .page-shell {
    display: flex;
    flex-direction: column;
  }

  body:not(.app-active) .page-shell {
    justify-content: center;
    gap: 22px;
  }

  .generator-form {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .warning-note {
    position: fixed;
    left: 50%;
    bottom: max(14px, calc(env(safe-area-inset-bottom) + 10px));
    width: min(100% - 12px, 720px);
    padding: 11px 12px;
    font-size: 0.78rem;
    line-height: 1.55;
    transform: translate3d(-50%, 0, 0);
  }

  body:not(.app-active) .topbar {
    margin: 0;
    transform: none;
  }

  body:not(.app-active) .generator-form {
    transform: none;
  }

  body.app-active .warning-note {
    display: block;
    opacity: 1;
    pointer-events: auto;
    transform: translate3d(-50%, 0, 0);
  }

  .generator-form input,
  .generator-form button {
    min-height: 50px;
  }

  .generator-form input {
    padding-inline: 16px;
  }

  .generator-form button {
    width: auto;
    min-width: 132px;
    justify-self: center;
  }

  .status-bar {
    min-height: 28px;
    padding: 2px 4px 0;
  }

  .status-bar p {
    font-size: 0.88rem;
    line-height: 1.5;
  }

  .article-toolbar {
    left: 18px;
    right: 18px;
    bottom: 16px;
    justify-content: flex-end;
  }

  .copy-btn {
    min-height: 36px;
    padding: 0 14px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.08);
    backdrop-filter: blur(10px);
  }

  .top-btn {
    right: 16px;
    bottom: max(16px, calc(env(safe-area-inset-bottom) + 12px));
    width: 40px;
    min-width: 40px;
    min-height: 40px;
  }

  .doc-title,
  .article-stream > section:first-child > h2:first-child {
    font-size: clamp(1.7rem, 9vw, 2.2rem);
    line-height: 1.16;
  }

  :is(
    .doc-section-title,
    .article-stream h3:not([class]),
    .article-stream section > h3:first-child
  ) {
    margin-bottom: 12px;
    font-size: clamp(1.26rem, 6.8vw, 1.55rem);
    line-height: 1.3;
  }

  .speaker-name {
    text-decoration-thickness: 1.5px;
    text-underline-offset: 2px;
  }
}
