:root {
  color-scheme: light;
  --paper: #f7fbff;
  --ink: #11181f;
  --muted: rgba(17, 24, 31, .58);
  --glass: rgba(255, 255, 255, .46);
  --glass-strong: rgba(255, 255, 255, .68);
  --glass-faint: rgba(255, 255, 255, .26);
  --line: rgba(255, 255, 255, .68);
  --line-dark: rgba(17, 24, 31, .08);
  --accent: #2d7ff9;
  --accent-2: #17b7aa;
  --accent-3: #ff7aa7;
  --danger: #aa342f;
  --shadow: 0 24px 90px rgba(36, 48, 62, .16);
  --shadow-soft: 0 12px 40px rgba(36, 48, 62, .11);
  --blur: blur(26px) saturate(170%);
}

[data-theme="dark"] {
  color-scheme: dark;
  --paper: #0c1015;
  --ink: #f7f8fb;
  --muted: rgba(247, 248, 251, .6);
  --glass: rgba(24, 29, 38, .54);
  --glass-strong: rgba(36, 42, 54, .72);
  --glass-faint: rgba(255, 255, 255, .08);
  --line: rgba(255, 255, 255, .14);
  --line-dark: rgba(255, 255, 255, .08);
  --shadow: 0 28px 92px rgba(0, 0, 0, .36);
  --shadow-soft: 0 12px 40px rgba(0, 0, 0, .24);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  font-family: ui-serif, "Songti SC", "Noto Serif CJK SC", "Source Han Serif SC", Georgia, serif;
  letter-spacing: 0;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, .9), rgba(216, 238, 255, .58) 34%, rgba(255, 224, 238, .5) 66%, rgba(226, 250, 238, .82)),
    linear-gradient(180deg, #f7fbff 0%, #f3f8ff 48%, #fff9fb 100%);
  overflow-x: hidden;
}

[data-theme="dark"] body {
  background:
    linear-gradient(125deg, rgba(20, 28, 39, .96), rgba(22, 45, 72, .76) 42%, rgba(57, 34, 56, .62) 72%, rgba(21, 47, 44, .76)),
    #0c1015;
}

body::before,
body::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -2;
  pointer-events: none;
}

body::before {
  background:
    conic-gradient(from 200deg at 18% 12%, rgba(255, 255, 255, .86), rgba(81, 175, 255, .24), rgba(255, 150, 194, .22), rgba(255, 255, 255, .76)),
    linear-gradient(135deg, rgba(255, 255, 255, .18), rgba(45, 127, 249, .08) 48%, rgba(23, 183, 170, .08));
  filter: blur(18px);
  transform: scale(1.06);
}

[data-theme="dark"] body::before {
  background:
    conic-gradient(from 210deg at 18% 12%, rgba(43, 52, 68, .72), rgba(45, 127, 249, .16), rgba(255, 122, 167, .12), rgba(26, 34, 45, .86)),
    linear-gradient(135deg, rgba(255, 255, 255, .04), rgba(45, 127, 249, .08), rgba(23, 183, 170, .06));
}

body::after {
  z-index: -1;
  opacity: .48;
  background-image:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, .22) 0, rgba(255, 255, 255, .22) 1px, transparent 1px, transparent 16px),
    repeating-linear-gradient(0deg, rgba(17, 24, 31, .035) 0, rgba(17, 24, 31, .035) 1px, transparent 1px, transparent 18px);
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, .56), transparent 75%);
}

button,
a,
textarea {
  font: inherit;
  letter-spacing: 0;
}

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

.write-page {
  width: min(1080px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: clamp(24px, 5vw, 66px) clamp(16px, 4vw, 28px) 72px;
}

.write-header {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: clamp(16px, 4vw, 42px);
  align-items: start;
  margin-bottom: clamp(24px, 5vw, 48px);
}

.back-link,
.choice-chip,
.primary-btn,
.secondary-btn,
.close-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: linear-gradient(135deg, var(--glass-strong), var(--glass-faint));
  color: var(--ink);
  cursor: pointer;
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .7), 0 8px 22px rgba(36, 48, 62, .08);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  transition: transform .28s ease, box-shadow .28s ease, border-color .28s ease, opacity .28s ease;
}

[data-theme="dark"] .back-link,
[data-theme="dark"] .choice-chip,
[data-theme="dark"] .primary-btn,
[data-theme="dark"] .secondary-btn,
[data-theme="dark"] .close-btn {
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .12), 0 8px 24px rgba(0, 0, 0, .18);
}

.back-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 9px 15px;
}

.back-link::before {
  content: "";
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-left: 1.7px solid currentColor;
  border-bottom: 1.7px solid currentColor;
  transform: rotate(45deg);
}

.back-link:hover,
.choice-chip:hover,
.primary-btn:hover,
.secondary-btn:hover,
.close-btn:hover {
  border-color: rgba(255, 255, 255, .86);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .9), 0 12px 30px rgba(36, 48, 62, .12);
  opacity: 1;
  transform: translateY(-1px);
}

.eyebrow,
.field-label,
.result-meta,
.write-header p,
.share-tip {
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, sans-serif;
}

h1,
h2,
p {
  margin: 0;
}

h1,
h2 {
  font-weight: 400;
}

.write-header h1 {
  max-width: 660px;
  font-size: clamp(38px, 7vw, 76px);
  line-height: 1.16;
}

.write-header .eyebrow {
  max-width: 580px;
  margin-top: 16px;
  font-size: 14px;
  line-height: 1.8;
}

.write-layout {
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
  gap: clamp(18px, 4vw, 34px);
  align-items: stretch;
}

.compose-panel,
.result-card,
.share-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(145deg, rgba(255, 255, 255, .78), rgba(255, 255, 255, .36) 52%, rgba(255, 255, 255, .62)),
    linear-gradient(120deg, rgba(45, 127, 249, .11), transparent 42%, rgba(23, 183, 170, .1));
  box-shadow: var(--shadow);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  overflow: hidden;
}

[data-theme="dark"] .compose-panel,
[data-theme="dark"] .result-card,
[data-theme="dark"] .share-card {
  background:
    linear-gradient(145deg, rgba(48, 56, 70, .68), rgba(24, 29, 38, .48) 52%, rgba(35, 42, 54, .64)),
    linear-gradient(120deg, rgba(45, 127, 249, .12), transparent 42%, rgba(23, 183, 170, .1));
}

.compose-panel::before,
.result-card::before,
.share-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, .86), transparent 30%),
    linear-gradient(300deg, transparent 72%, rgba(255, 255, 255, .48));
  opacity: .68;
}

[data-theme="dark"] .compose-panel::before,
[data-theme="dark"] .result-card::before,
[data-theme="dark"] .share-card::before {
  opacity: .16;
}

.compose-panel {
  min-width: 0;
  padding: clamp(18px, 4vw, 30px);
}

.compose-panel > *,
.result-card > *,
.share-card > * {
  position: relative;
  z-index: 1;
}

.field-group {
  margin-bottom: 22px;
}

.one-line-field {
  margin-bottom: 24px;
}

.field-label {
  display: block;
  margin-bottom: 10px;
  font-size: 13px;
}

.choice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.choice-chip {
  min-height: 36px;
  padding: 8px 14px;
  background: linear-gradient(145deg, rgba(255, 255, 255, .62), rgba(255, 255, 255, .28));
}

.choice-chip.is-active {
  border-color: rgba(255, 255, 255, .9);
  background:
    linear-gradient(135deg, rgba(45, 127, 249, .9), rgba(23, 183, 170, .76)),
    linear-gradient(180deg, rgba(255, 255, 255, .46), transparent);
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .52), 0 12px 26px rgba(45, 127, 249, .22);
}

.prompt-input {
  display: block;
  width: 100%;
  min-height: 116px;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
  resize: vertical;
  color: var(--ink);
  background: linear-gradient(145deg, rgba(255, 255, 255, .55), rgba(255, 255, 255, .22));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .62), 0 8px 24px rgba(36, 48, 62, .07);
  font-size: 16px;
  line-height: 1.75;
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
}

.prompt-input::placeholder {
  color: color-mix(in srgb, var(--muted) 72%, transparent);
}

.prompt-input:focus {
  border-color: rgba(45, 127, 249, .42);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .72), 0 0 0 4px rgba(45, 127, 249, .08), 0 12px 30px rgba(36, 48, 62, .1);
}

.primary-btn {
  width: min(100%, 220px);
  min-height: 46px;
  padding: 11px 22px;
  border-color: rgba(255, 255, 255, .84);
  background:
    linear-gradient(135deg, rgba(17, 24, 31, .94), rgba(45, 127, 249, .82) 52%, rgba(23, 183, 170, .78)),
    linear-gradient(180deg, rgba(255, 255, 255, .42), transparent);
  color: #fff;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .5), 0 16px 40px rgba(45, 127, 249, .2);
}

.primary-btn:disabled {
  cursor: wait;
  opacity: .62;
  transform: none;
}

.result-card {
  min-width: 0;
  min-height: 360px;
  display: grid;
  place-items: center;
  padding: clamp(22px, 5vw, 46px);
}

.result-card.empty::after {
  content: "生成后的诗会落在这里";
  position: relative;
  z-index: 1;
  color: var(--muted);
  font-family: ui-sans-serif, system-ui, sans-serif;
  font-size: 14px;
}

.result-poem {
  width: 100%;
  margin: 0 0 22px;
  text-align: center;
  white-space: pre-wrap;
  font-size: clamp(24px, 4vw, 38px);
  line-height: 2.05;
  font-weight: 400;
}

.result-poem p {
  margin: 0;
  opacity: 0;
  transform: translateY(12px) scale(.98);
  filter: blur(2px);
  animation: poemFadeIn 1.2s cubic-bezier(.16, 1, .3, 1) forwards;
  animation-delay: calc(var(--line-index) * .16s);
}

@keyframes poemFadeIn {
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}

.result-meta {
  width: 100%;
  margin: -4px 0 22px;
  text-align: center;
  font-size: 13px;
  line-height: 1.6;
  opacity: 0;
  animation: metaFadeIn 1s ease forwards;
  animation-delay: .6s;
}

@keyframes metaFadeIn {
  to {
    opacity: .72;
  }
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.secondary-btn {
  min-height: 36px;
  padding: 8px 14px;
}

.ink-loader {
  display: flex;
  justify-content: center;
  gap: 8px;
}

.ink-loader span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  opacity: .38;
  animation: inkDot 1s ease-in-out infinite;
}

.ink-loader span:nth-child(2) {
  animation-delay: .15s;
}

.ink-loader span:nth-child(3) {
  animation-delay: .3s;
}

@keyframes inkDot {
  50% {
    opacity: .96;
    transform: translateY(-4px);
  }
}

.error {
  color: var(--danger);
  font-family: ui-sans-serif, system-ui, sans-serif;
}

.share-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  pointer-events: none;
}

.share-modal[aria-hidden="false"] {
  display: block;
  pointer-events: auto;
}

.overlay-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background:
    linear-gradient(145deg, rgba(248, 251, 255, .66), rgba(241, 246, 255, .42)),
    rgba(255, 255, 255, .28);
  backdrop-filter: blur(22px) saturate(150%);
  -webkit-backdrop-filter: blur(22px) saturate(150%);
}

[data-theme="dark"] .overlay-backdrop {
  background:
    linear-gradient(145deg, rgba(11, 15, 21, .78), rgba(18, 24, 32, .58)),
    rgba(0, 0, 0, .32);
}

.share-card {
  left: 50%;
  top: 50%;
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100vh - 42px);
  padding: 22px;
  overflow: auto;
  transform: translate(-50%, -50%);
}

.sheet-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 13px;
  line-height: 1.5;
}

.share-tip {
  margin: 10px 0 16px;
  font-size: 13px;
  line-height: 1.7;
}

.close-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.share-image-box img {
  display: block;
  width: 100%;
  border: 1px solid rgba(255, 255, 255, .72);
  border-radius: 8px;
  box-shadow: 0 18px 60px rgba(36, 48, 62, .16);
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0s !important;
    transition-duration: 0s !important;
  }

  .result-poem p,
  .result-meta {
    opacity: 1 !important;
    transform: none !important;
    filter: none !important;
  }
}

@media (max-width: 800px) {
  .write-page {
    padding: 18px 14px 56px;
  }

  .write-header {
    display: block;
    margin-bottom: 22px;
  }

  .back-link {
    margin-bottom: 26px;
  }

  .write-header h1 {
    font-size: clamp(36px, 11vw, 48px);
    line-height: 1.18;
  }

  .write-header .eyebrow {
    margin-top: 12px;
    font-size: 13px;
  }

  .write-layout {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .compose-panel {
    padding: 16px;
  }

  .field-group {
    margin-bottom: 20px;
  }

  .choice-row {
    gap: 8px;
  }

  .choice-chip {
    min-height: 34px;
    padding: 7px 12px;
    font-size: 13px;
  }

  .prompt-input {
    min-height: 104px;
    font-size: 15px;
  }

  .primary-btn {
    width: 100%;
  }

  .result-card {
    min-height: 260px;
    padding: 22px 16px;
  }

  .result-poem {
    font-size: clamp(24px, 8vw, 32px);
  }
}
