:root {
  color-scheme: light;
  --ink: #24453f;
  --ink-soft: #58736c;
  --paper: #fffdf6;
  --jade: #5d8a77;
  --jade-deep: #356855;
  --orange: #d96f45;
  --line: rgba(53, 104, 85, 0.2);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  background: #edf6ec;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100svh;
  color: var(--ink);
  background:
    radial-gradient(circle at 18% 0%, rgba(255, 252, 229, 0.92), transparent 35%),
    linear-gradient(180deg, #eaf4ec 0%, #f8f3e8 100%);
  -webkit-tap-highlight-color: transparent;
}

button,
summary {
  font: inherit;
}

.app-shell {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) 14px max(10px, env(safe-area-inset-bottom));
}

.page-header {
  display: flex;
  justify-content: center;
  align-items: baseline;
  gap: 14px;
  padding: 1px 8px 5px;
  text-align: center;
}

.page-header h1 {
  margin: 0;
}

.poem-experience {
  width: 100%;
}

.poem-scene {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(100%, 480px);
  margin: 8px auto 0;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 30px;
  color: var(--ink);
  background: #bad8c8;
  box-shadow:
    0 20px 45px rgba(49, 89, 72, 0.18),
    inset 0 0 0 1px rgba(255, 255, 255, 0.58);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}

.poem-scene:focus-visible {
  outline: 4px solid rgba(217, 111, 69, 0.72);
  outline-offset: 4px;
}

.scene-visual {
  position: relative;
  display: block;
  width: 100%;
  height: clamp(200px, 42svh, 380px);
  overflow: hidden;
}

.scene-art {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 55%;
  pointer-events: none;
}

.goose-swim {
  position: absolute;
  z-index: 1;
  top: 53%;
  left: 50%;
  width: min(78%, 45svh);
  aspect-ratio: 3 / 2;
  transform: translate(-50%, -50%);
  animation: goose-glide 9s ease-in-out infinite;
  pointer-events: none;
}

.goose-sprite {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 5px 7px rgba(24, 104, 105, 0.2));
  animation: goose-bob 3.8s ease-in-out infinite;
}

.goose-wake {
  position: absolute;
  z-index: 1;
  right: 5%;
  bottom: 1%;
  left: 6%;
  height: 13%;
  border: 2px solid rgba(248, 255, 252, 0.78);
  border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(67, 121, 102, 0.12);
  animation: wake-breathe 4.6s ease-in-out infinite;
}

.goose-wake-front {
  z-index: 3;
  right: 9%;
  bottom: -1%;
  left: 11%;
  height: 10%;
  border-color: rgba(251, 255, 245, 0.7);
  border-top-color: transparent;
  box-shadow: none;
  animation-delay: -2.3s;
}

.boat-swim {
  position: absolute;
  z-index: 1;
  top: 53%;
  left: 50%;
  width: min(84%, 45svh);
  aspect-ratio: 3 / 2;
  transform: translate(-50%, -50%);
  animation: boat-glide 10s ease-in-out infinite;
  pointer-events: none;
}

.boat-sprite {
  position: relative;
  z-index: 2;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 5px 6px rgba(32, 96, 90, 0.2));
  animation: boat-bob 3.8s ease-in-out infinite;
}

.boat-wake {
  position: absolute;
  z-index: 1;
  right: 5%;
  bottom: 2%;
  left: 5%;
  height: 12%;
  border: 2px solid rgba(248, 255, 252, 0.75);
  border-radius: 50%;
  animation: wake-breathe 4.8s ease-in-out infinite;
}

.scene-petals {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: none;
  overflow: hidden;
  pointer-events: none;
}

.scene-petals i {
  position: absolute;
  top: -12px;
  width: 10px;
  height: 7px;
  border-radius: 90% 10% 90% 10%;
  background: #ffcfde;
  box-shadow: 0 1px 2px rgba(176, 91, 98, 0.15);
  animation: petal-fall 9s linear infinite;
}

.scene-petals i:nth-child(1) { left: 22%; animation-delay: -1s; }
.scene-petals i:nth-child(2) { left: 56%; animation-delay: -4s; }
.scene-petals i:nth-child(3) { left: 79%; animation-delay: -7s; }

body[data-poem="chun-xiao"] .scene-petals {
  display: block;
}

body[data-poem="feng"] .scene-petals {
  display: block;
}

body[data-poem="feng"] .scene-petals i {
  background: #eac66c;
}

body[data-poem="feng"] .scene-petals i:nth-child(2) {
  background: #f8cbd5;
}

.scene-visual::after {
  content: "";
  position: absolute;
  z-index: 2;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

body[data-poem="jing-ye-si"] .scene-visual::after {
  background: radial-gradient(circle at 66% 18%, rgba(254, 255, 232, 0.4), transparent 24%);
  animation: ambient-glow 7s ease-in-out infinite alternate;
}

body[data-poem="deng-guan-que-lou"] .scene-visual::after {
  background: radial-gradient(circle at 73% 38%, rgba(255, 232, 131, 0.35), transparent 27%);
  animation: ambient-glow 8s ease-in-out infinite alternate;
}

body[data-poem="shan-cun-yong-huai"] .scene-art,
body[data-poem="deng-guan-que-lou"] .scene-art {
  animation: landscape-drift 18s ease-in-out infinite alternate;
}

.poem-title {
  font-family: "STKaiti", "KaiTi", serif;
  font-size: clamp(1.7rem, 7vw, 2.3rem);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: 0.08em;
  white-space: nowrap;
}

.poem-title.is-long {
  font-size: clamp(1.45rem, 6vw, 2rem);
  letter-spacing: 0.05em;
}

.poem-title.is-extra-long {
  font-size: clamp(1.3rem, 5.4vw, 1.85rem);
  letter-spacing: 0.02em;
}

.poem-author {
  color: var(--ink-soft);
  font-size: clamp(0.74rem, 2.8vw, 0.92rem);
  font-weight: 700;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.poem-sheet {
  width: min(100%, 560px);
  margin: 8px auto 0;
  padding: 10px 8px;
  border: 1px solid rgba(75, 120, 101, 0.16);
  border-radius: 20px;
  background: rgba(255, 253, 246, 0.84);
  box-shadow: 0 6px 20px rgba(54, 81, 70, 0.06);
}

.poem-lines {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: center;
  gap: 4px;
  font-family: "STKaiti", "KaiTi", serif;
  font-size: clamp(1.15rem, 5vw, 1.65rem);
  font-weight: 700;
  line-height: 1.35;
  letter-spacing: 0.02em;
}

.poem-line {
  display: block;
  min-width: 0;
  padding: 1px 3px;
  border-radius: 12px;
  text-align: center;
  white-space: nowrap;
  transition: color 260ms ease, background-color 260ms ease, transform 260ms ease;
}

.poem-line.is-active {
  color: #af4e2d;
  background: rgba(255, 239, 197, 0.82);
  transform: scale(1.045);
}

.scene-status {
  display: flex;
  width: 100%;
  justify-content: center;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 14px;
  color: #315f52;
  background: rgba(255, 253, 246, 0.94);
  font-size: clamp(0.95rem, 3.5vw, 1.06rem);
  font-weight: 750;
  letter-spacing: 0.02em;
  pointer-events: none;
}

.sound-mark {
  display: inline-flex;
  align-items: flex-end;
  gap: 3px;
  height: 19px;
}

.sound-mark i {
  display: block;
  width: 3px;
  height: 7px;
  border-radius: 99px;
  background: currentColor;
}

.sound-mark i:nth-child(2) {
  height: 14px;
}

.sound-mark i:nth-child(3) {
  height: 10px;
}

.poem-scene.is-playing .sound-mark i {
  animation: voice-wave 900ms ease-in-out infinite alternate;
}

.poem-scene.is-playing .sound-mark i:nth-child(2) {
  animation-delay: 150ms;
}

.poem-scene.is-playing .sound-mark i:nth-child(3) {
  animation-delay: 300ms;
}

.poem-scene.is-playing:not(.has-goose-animation) .scene-art {
  animation: water-breathe 5.4s ease-in-out infinite alternate;
}

.tap-bloom {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: 61%;
  width: 86px;
  height: 34px;
  border: 3px solid rgba(255, 255, 255, 0.72);
  border-radius: 50%;
  opacity: 0;
  transform: translate(-50%, -50%) scale(0.65);
  pointer-events: none;
}

.tap-bloom.is-visible {
  animation: tap-ripple 650ms ease-out;
}

.quick-controls {
  display: grid;
  gap: 6px;
  margin: 4px 4px 0;
}

.quick-controls.is-line-mode + .poem-scene .scene-visual {
  height: clamp(180px, 35svh, 320px);
}

.poem-navigation {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 8px;
  align-items: stretch;
}

.soft-button {
  min-height: 46px;
  padding: 9px 12px;
  border: 1px solid rgba(75, 120, 101, 0.2);
  border-radius: 15px;
  color: #41695d;
  background: rgba(255, 253, 247, 0.9);
  box-shadow: 0 4px 14px rgba(52, 88, 73, 0.055);
  font-size: 0.9rem;
  font-weight: 750;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 180ms ease, border-color 180ms ease, transform 180ms ease;
}

.soft-button:active:not(:disabled) {
  background: #f0f7ef;
  transform: scale(0.985);
}

.soft-button:focus-visible {
  outline: 3px solid rgba(217, 111, 69, 0.42);
  outline-offset: 2px;
}

.soft-button:disabled {
  opacity: 0.46;
  cursor: default;
}

.poem-nav-button {
  white-space: nowrap;
}

.current-poem {
  display: flex;
  min-width: 62px;
  margin: 0;
  padding: 4px 8px;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  border: 1px solid rgba(75, 120, 101, 0.13);
  border-radius: 15px;
  color: var(--ink);
  background: rgba(247, 250, 241, 0.72);
  font-size: 0.8rem;
  font-weight: 750;
}

.poem-position {
  color: #7e968e;
  font-size: 0.78rem;
  font-weight: 700;
}

.mode-toggle {
  display: flex;
  width: 100%;
  min-height: 44px;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  padding-right: 16px;
  padding-left: 16px;
  text-align: left;
  background: rgba(241, 248, 239, 0.92);
}

.mode-toggle.is-line-mode {
  border-color: rgba(197, 132, 83, 0.24);
  color: #805f49;
  background: rgba(255, 247, 233, 0.94);
}

.mode-toggle-copy {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.mode-toggle-kicker {
  color: #789087;
  font-size: 0.67rem;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.mode-toggle-label {
  color: currentColor;
  font-size: 0.9rem;
  font-weight: 800;
}

.mode-toggle-hint {
  color: #82968f;
  font-size: 0.76rem;
  font-weight: 650;
  text-align: right;
}

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

.line-actions .soft-button {
  min-height: 40px;
  padding: 6px 8px;
}

body.poem-cartoon {
  background: linear-gradient(180deg, #e9f8fb 0%, #f5f7df 72%, #fff8e7 100%);
}

body[data-poem="jing-ye-si"] {
  background: linear-gradient(180deg, #e9efff 0%, #f5f2ec 70%, #fff8e7 100%);
}

body[data-poem="deng-guan-que-lou"] {
  background: linear-gradient(180deg, #fff2e5 0%, #f7f4dc 75%, #fff9e9 100%);
}

.poem-cartoon .poem-title,
.poem-cartoon .poem-lines {
  font-family: "SF Pro Rounded", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  letter-spacing: 0;
}

.poem-cartoon .poem-title {
  color: #315c46;
}

.poem-cartoon .poem-scene {
  background: #66cdd1;
  box-shadow: 0 12px 28px rgba(59, 135, 117, 0.17);
}

.poem-cartoon .scene-art {
  object-position: center center;
}

.poem-cartoon .poem-sheet {
  border-color: rgba(111, 172, 128, 0.23);
  background: rgba(255, 254, 246, 0.96);
}

.poem-cartoon .poem-line.is-active {
  color: #995021;
  background: #fff0bd;
}

.poem-cartoon .scene-status {
  color: #3c6952;
  background: rgba(255, 253, 237, 0.96);
}

[hidden] {
  display: none !important;
}

@keyframes voice-wave {
  from { transform: scaleY(0.62); }
  to { transform: scaleY(1.18); }
}

@keyframes water-breathe {
  from { transform: scale(1); }
  to { transform: scale(1.018); }
}

@keyframes goose-glide {
  0%, 100% { transform: translate(-50%, -50%); }
  50% { transform: translate(calc(-50% + 24px), calc(-50% - 2px)); }
}

@keyframes boat-glide {
  0%, 100% { transform: translate(-50%, -50%); }
  50% { transform: translate(calc(-50% + 18px), calc(-50% - 2px)); }
}

@keyframes boat-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(2px); }
}

@keyframes petal-fall {
  0% { opacity: 0; transform: translate(0, 0) rotate(0deg); }
  12% { opacity: 0.8; }
  88% { opacity: 0.8; }
  100% { opacity: 0; transform: translate(24px, 55svh) rotate(150deg); }
}

@keyframes ambient-glow {
  from { opacity: 0.18; }
  to { opacity: 0.6; }
}

@keyframes landscape-drift {
  from { transform: scale(1); }
  to { transform: scale(1.018); }
}

@keyframes goose-bob {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(2px); }
}

@keyframes wake-breathe {
  0%, 100% { opacity: 0.54; transform: scale(0.96); }
  50% { opacity: 0.82; transform: scale(1.06); }
}

@keyframes tap-ripple {
  0% { opacity: 0; transform: translate(-50%, -50%) scale(0.62); }
  18% { opacity: 0.88; }
  100% { opacity: 0; transform: translate(-50%, -50%) scale(1.55); }
}

@media (max-width: 420px) {
  .app-shell {
    padding-right: 8px;
    padding-left: 8px;
  }

  .page-header {
    padding-bottom: 3px;
  }

  .poem-scene {
    border-radius: 22px;
  }

  .poem-title.is-extra-long {
    font-size: clamp(1.22rem, 5.5vw, 1.55rem);
  }
}

@media (max-width: 360px) {
  .page-header {
    gap: 8px;
  }

  .poem-title,
  .poem-title.is-long,
  .poem-title.is-extra-long {
    font-size: clamp(1.2rem, 6vw, 1.5rem);
    letter-spacing: 0.02em;
  }

  .poem-lines {
    font-size: 1.15rem;
  }

  .poem-lines.is-seven-character {
    font-size: clamp(0.95rem, 4.7vw, 1.05rem);
  }
}

@media (max-width: 699px) and (min-height: 601px) and (orientation: portrait) {
  .poem-cartoon .scene-visual {
    height: clamp(200px, max(42svh, calc(100svh - 390px)), 510px);
  }

  .poem-cartoon .quick-controls.is-line-mode + .poem-scene .scene-visual {
    height: clamp(180px, max(35svh, calc(100svh - 440px)), 470px);
  }

  body[data-poem="deng-guan-que-lou"].poem-cartoon .scene-visual {
    height: clamp(200px, 44svh, 400px);
  }

  body[data-poem="deng-guan-que-lou"].poem-cartoon .quick-controls.is-line-mode + .poem-scene .scene-visual {
    height: clamp(180px, 37svh, 340px);
  }
}

@media (max-height: 600px) and (orientation: portrait) {
  .poem-cartoon .scene-visual {
    height: clamp(145px, 32svh, 192px);
  }

  .poem-cartoon .quick-controls.is-line-mode + .poem-scene .scene-visual {
    height: clamp(128px, 28svh, 168px);
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  .app-shell {
    width: min(100%, 980px);
    padding-top: 8px;
  }

  .page-header {
    padding-bottom: 3px;
  }

  .poem-scene {
    width: min(100%, 360px);
  }
}

@media (min-width: 700px) {
  .scene-visual {
    height: min(54svh, 500px);
  }

  .quick-controls.is-line-mode + .poem-scene .scene-visual {
    height: min(46svh, 420px);
  }
}

@media (max-width: 699px) and (max-height: 520px) {
  .quick-controls.is-line-mode + .poem-scene .scene-visual {
    height: clamp(155px, 32svh, 170px);
  }

  .quick-controls.is-line-mode + .poem-scene .scene-art {
    object-position: center 48%;
  }
}

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

  html.motion-preview .goose-swim {
    animation-duration: 9s !important;
    animation-iteration-count: infinite !important;
  }

  html.motion-preview .goose-sprite {
    animation-duration: 3.8s !important;
    animation-iteration-count: infinite !important;
  }

  html.motion-preview .goose-wake {
    animation-duration: 4.6s !important;
    animation-iteration-count: infinite !important;
  }

  html.motion-preview .boat-swim { animation-duration: 10s !important; animation-iteration-count: infinite !important; }
  html.motion-preview .boat-sprite { animation-duration: 3.8s !important; animation-iteration-count: infinite !important; }
  html.motion-preview .boat-wake { animation-duration: 4.8s !important; animation-iteration-count: infinite !important; }
  html.motion-preview .scene-petals i { animation-duration: 9s !important; animation-iteration-count: infinite !important; }
  html.motion-preview .scene-visual::after { animation-duration: 8s !important; animation-iteration-count: infinite !important; }
  html.motion-preview body[data-poem="shan-cun-yong-huai"] .scene-art,
  html.motion-preview body[data-poem="deng-guan-que-lou"] .scene-art {
    animation-duration: 18s !important;
    animation-iteration-count: infinite !important;
  }
}
