:root {
  --paper: #ece4d2;
  --paper-deep: #d8c8a7;
  --ink: #2b2b2b;
  --ink-soft: rgba(43, 43, 43, 0.72);
  --seal: #a8331f;
  --green: #5a7d6e;
  --peach: #d98a8a;
  --gold: #d7a85e;
  --shadow: rgba(28, 22, 14, 0.32);
  --font-title: "Ma Shan Zheng", "Noto Serif TC", serif;
  --font-body: "Noto Serif TC", "Songti TC", serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body {
  background: linear-gradient(135deg, #f5efdf 0%, var(--paper) 42%, #dce5d8 100%);
  color: var(--ink);
  font-family: var(--font-body);
}

/* 手機直向旋轉提示：橫向或桌機一律不顯示 */
.rotate-hint {
  display: none;
}
@media (orientation: portrait) and (max-width: 900px) {
  .rotate-hint {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(20, 16, 10, 0.94);
    color: #f5efdf;
    text-align: center;
    cursor: pointer;
  }
  .rotate-hint.dismissed {
    display: none;
  }
}
.rotate-hint-inner {
  max-width: 320px;
}
.rotate-icon {
  font-size: 3.6rem;
  line-height: 1;
  display: inline-block;
  animation: rotateHintSpin 2.6s ease-in-out infinite;
}
.rotate-title {
  margin: 16px 0 8px;
  font-family: var(--font-title);
  font-size: 1.42rem;
  font-weight: 900;
}
.rotate-sub {
  margin: 0;
  font-size: 1rem;
  line-height: 1.7;
  opacity: 0.8;
}
@keyframes rotateHintSpin {
  0%, 55% { transform: rotate(0deg); }
  78%, 100% { transform: rotate(90deg); }
}

button {
  font: inherit;
}

[hidden] {
  display: none !important;
}

.music-toggle {
  position: absolute;
  top: clamp(10px, 1.8vw, 18px);
  right: clamp(10px, 1.8vw, 18px);
  z-index: 50;
  padding: 7px 14px 8px;
  border: 1px solid rgba(43, 43, 43, 0.46);
  border-radius: 999px;
  background: rgba(236, 228, 210, 0.78);
  backdrop-filter: blur(3px);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: clamp(0.78rem, 1.2vw, 0.95rem);
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(43, 43, 43, 0.18);
  transition: background 0.22s ease, color 0.22s ease, transform 0.22s ease, opacity 0.22s ease;
}

.music-toggle:hover,
.music-toggle:focus-visible {
  background: var(--seal);
  color: var(--paper);
  transform: translateY(-1px);
  outline: none;
}

.music-toggle.muted {
  background: rgba(236, 228, 210, 0.52);
  color: var(--ink-soft);
  opacity: 0.82;
}

.music-toggle.muted:hover,
.music-toggle.muted:focus-visible {
  background: var(--ink);
  color: var(--paper);
  opacity: 1;
}

.page-shell {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: linear-gradient(135deg, #f5efdf 0%, var(--paper) 42%, #dce5d8 100%);
}

.game-shell {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1100px;
  height: 618.75px;
  transform-origin: center center;
  transform: translate(-50%, -50%) scale(var(--game-scale, 1));
  overflow: hidden;
  border: 1px solid rgba(43, 43, 43, 0.32);
  background: var(--paper);
  box-shadow: 0 18px 46px var(--shadow);
  isolation: isolate;
}

.backdrop,
.scene-image,
.screen,
.play-layer,
.village-layer,
.dialogue-layer,
.petal-layer,
.paper-noise {
  position: absolute;
  inset: 0;
}

.backdrop {
  background: var(--paper);
  z-index: 0;
}

.scene-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transform: scale(1);
  transition: opacity 1s ease, filter 1s ease;
}

.scene-image.visible {
  opacity: 1;
}

.scene-image.kenburns {
  animation: kenBurns 20s ease-in-out infinite alternate;
}

.paper-noise {
  z-index: 3;
  pointer-events: none;
  opacity: 0.05;
  mix-blend-mode: multiply;
  background-image:
    radial-gradient(circle at 18% 24%, rgba(43, 43, 43, 0.5) 0 1px, transparent 1px),
    radial-gradient(circle at 72% 58%, rgba(168, 51, 31, 0.32) 0 1px, transparent 1px),
    radial-gradient(circle at 41% 82%, rgba(90, 125, 110, 0.42) 0 1px, transparent 1px);
  background-size: 34px 34px, 47px 47px, 59px 59px;
}

.screen {
  z-index: 5;
}

.title-screen {
  z-index: 20;
  display: block;
  padding: 0;
  cursor: pointer;
  background: var(--paper);
}

.cover-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

h1,
h2 {
  margin: 0;
  font-family: var(--font-title);
  font-weight: 400;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(4rem, 10vw, 8.5rem);
  line-height: 0.95;
}

.ink-button {
  border: 1px solid rgba(43, 43, 43, 0.74);
  color: var(--paper);
  background: var(--ink);
  box-shadow: 0 10px 22px rgba(43, 43, 43, 0.28);
  cursor: pointer;
  transition: transform 0.22s ease, background 0.22s ease, box-shadow 0.22s ease;
}

.ink-button:hover,
.ink-button:focus-visible {
  background: var(--seal);
  transform: translateY(-2px);
  box-shadow: 0 14px 24px rgba(43, 43, 43, 0.28);
}

.primary-button {
  margin-top: clamp(20px, 4vw, 38px);
  padding: 10px 28px 12px;
  min-width: 152px;
  border-radius: 2px;
  font-weight: 900;
}

.hud {
  position: absolute;
  top: clamp(10px, 2.2vw, 22px);
  left: clamp(12px, 2.6vw, 28px);
  right: clamp(12px, 2.6vw, 28px);
  z-index: 9;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  pointer-events: none;
}

.chapter-name {
  padding: 8px 18px 10px;
  border: 1px solid rgba(43, 43, 43, 0.36);
  background: rgba(236, 228, 210, 0.76);
  color: var(--ink);
  font-family: var(--font-title);
  font-size: clamp(1.35rem, 2.2vw, 2.15rem);
  line-height: 1;
  box-shadow: 0 8px 18px rgba(43, 43, 43, 0.12);
}

.progress-dots {
  display: flex;
  gap: 9px;
  padding: 9px 12px;
  border: 1px solid rgba(43, 43, 43, 0.26);
  background: rgba(236, 228, 210, 0.68);
}

.progress-dot {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  border: 1px solid rgba(43, 43, 43, 0.58);
  background: rgba(236, 228, 210, 0.8);
}

.progress-dot.done {
  background: var(--peach);
  border-color: rgba(168, 51, 31, 0.72);
  box-shadow: 0 0 0 4px rgba(217, 138, 138, 0.2);
}

.progress-dot.current {
  outline: 2px solid rgba(168, 51, 31, 0.7);
  outline-offset: 3px;
}

.play-layer {
  z-index: 7;
  pointer-events: none;
}

.village-layer {
  z-index: 8;
  pointer-events: none;
}

.hotspot {
  position: absolute;
  width: clamp(24px, 3.4vw, 38px);
  height: clamp(24px, 3.4vw, 38px);
  border: 1px solid rgba(168, 51, 31, 0.62);
  border-radius: 999px;
  background:
    radial-gradient(circle, rgba(255, 248, 220, 0.96) 0 23%, rgba(217, 138, 138, 0.68) 24% 46%, rgba(168, 51, 31, 0.18) 47% 72%, transparent 73%);
  box-shadow: 0 0 22px rgba(255, 244, 208, 0.8), 0 0 0 8px rgba(217, 138, 138, 0.15);
  transform: translate(-50%, -50%);
  cursor: pointer;
  pointer-events: auto;
  animation: hotspotPulse 1.7s ease-in-out infinite;
}

.hotspot:hover,
.hotspot:focus-visible {
  outline: none;
  box-shadow: 0 0 28px rgba(255, 244, 208, 0.96), 0 0 0 12px rgba(168, 51, 31, 0.2);
  transform: translate(-50%, -50%) scale(1.08);
}

.hotspot.completed {
  animation: none;
  background:
    radial-gradient(circle, rgba(236, 228, 210, 0.75) 0 28%, rgba(90, 125, 110, 0.46) 29% 58%, rgba(43, 43, 43, 0.08) 59% 74%, transparent 75%);
  border-color: rgba(90, 125, 110, 0.6);
  box-shadow: 0 0 0 5px rgba(90, 125, 110, 0.12);
  opacity: 0.72;
}

.farmhouse-hotspot {
  border-color: rgba(215, 168, 94, 0.9);
  background:
    radial-gradient(circle, rgba(255, 251, 217, 1) 0 26%, rgba(215, 168, 94, 0.76) 27% 48%, rgba(168, 51, 31, 0.22) 49% 72%, transparent 73%);
}

.dialogue-layer {
  z-index: 18;
  display: block;
  padding: 0;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.28s ease;
}

.dialogue-layer.visible {
  opacity: 1;
  pointer-events: auto;
}

.dialogue-card {
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  width: 100%;
  min-height: 0;
  margin: 0;
  display: grid;
  grid-template-columns: minmax(300px, 46%) minmax(0, 1fr);
  gap: 0;
  align-items: end;
  padding: clamp(12px, 2vw, 24px);
  border: 0;
  background: linear-gradient(180deg, transparent 0 46%, rgba(25, 20, 15, 0.08) 100%);
  box-shadow: none;
  pointer-events: none;
}

.dialogue-portrait {
  align-self: end;
  justify-self: center;
  width: 100%;
  height: 100%;
  min-height: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  overflow: hidden;
  pointer-events: none;
}

.dialogue-portrait img {
  display: block;
  width: auto;
  max-width: min(52vw, 620px);
  height: min(124%, 780px);
  max-height: none;
  object-fit: contain;
  object-position: center bottom;
  filter: drop-shadow(0 22px 26px rgba(43, 43, 43, 0.30));
  animation: portraitBreath 3.6s ease-in-out infinite alternate;
}

.dialogue-content {
  box-sizing: border-box;
  width: min(100%, 720px);
  min-width: 0;
  align-self: end;
  justify-self: end;
  margin: 0 0 clamp(8px, 1.5vw, 18px);
  padding: clamp(13px, 1.7vw, 20px) clamp(16px, 2.4vw, 28px);
  border: 1px solid rgba(43, 43, 43, 0.42);
  background: rgba(236, 228, 210, 0.82);
  backdrop-filter: blur(5px);
  box-shadow: 0 18px 42px rgba(43, 43, 43, 0.30);
  pointer-events: auto;
}

.dialogue-name {
  display: inline-block;
  margin-bottom: 8px;
  padding: 5px 12px 6px;
  background: var(--seal);
  color: var(--paper);
  font-family: var(--font-title);
  font-size: clamp(1.1rem, 2vw, 1.55rem);
  line-height: 1;
}

.dialogue-text {
  min-height: 3.6em;
  margin: 0 0 12px;
  color: var(--ink);
  font-size: clamp(1rem, 1.8vw, 1.28rem);
  font-weight: 700;
  line-height: 1.7;
}

.dialogue-options {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.dialogue-option {
  border: 1px solid rgba(43, 43, 43, 0.46);
  border-radius: 2px;
  padding: 8px 13px 9px;
  background: rgba(255, 250, 234, 0.76);
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.dialogue-option:hover,
.dialogue-option:focus-visible {
  background: var(--seal);
  color: var(--paper);
  transform: translateY(-1px);
}

.continue-option {
  min-width: 92px;
  justify-content: center;
}

.word-card {
  position: absolute;
  width: clamp(126px, 15.4%, 180px);
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  pointer-events: auto;
  user-select: none;
  transition: opacity 0.3s ease, filter 0.3s ease, transform 0.22s ease;
  animation: floatCard 2s ease-in-out infinite alternate;
}

.word-card:hover,
.word-card:focus-visible {
  transform: translateY(-4px);
  filter: brightness(1.04);
}

.word-card.used {
  opacity: 0.28;
  pointer-events: none;
  filter: saturate(0.6);
}

.card-image {
  display: block;
  width: 100%;
  height: auto;
  filter: drop-shadow(0 8px 14px rgba(43, 43, 43, 0.22));
}

.word-card.leaving,
.puzzle-panel.leaving {
  opacity: 0;
}

.puzzle-panel {
  position: absolute;
  left: clamp(14px, 2.4vw, 28px);
  right: clamp(14px, 2.4vw, 28px);
  bottom: clamp(12px, 2.2vw, 24px);
  z-index: 8;
  height: clamp(132px, 23%, 180px);
  display: block;
  padding: 16px 18px;
  border: 1px solid rgba(43, 43, 43, 0.5);
  background: rgba(236, 228, 210, 0.46);
  backdrop-filter: blur(3px);
  box-shadow: 0 16px 30px rgba(43, 43, 43, 0.22);
  transform-origin: bottom;
}

.puzzle-panel.open {
  animation: scrollReveal 0.6s ease both;
}

.puzzle-panel.wrong {
  animation: shake 0.36s ease;
  border-color: var(--seal);
  box-shadow: 0 0 0 4px rgba(168, 51, 31, 0.14), 0 16px 30px rgba(43, 43, 43, 0.22);
}

.answer-track {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 0;
  height: 100%;
  padding: 8px 84px 8px 8px;
  border: 1px dashed rgba(43, 43, 43, 0.28);
  background: rgba(255, 250, 234, 0.22);
  overflow: visible;
}

.answer-token {
  display: block;
  flex: 0 1 min(160px, calc((100% - 48px) / 6));
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
}

.answer-token.arrived {
  animation: inkDrop 0.3s ease both;
}

.reset-button {
  position: absolute;
  right: 18px;
  bottom: 18px;
  min-width: 68px;
  min-height: 38px;
  border: 1px solid rgba(43, 43, 43, 0.52);
  border-radius: 2px;
  background: rgba(236, 228, 210, 0.7);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 900;
  transition: background 0.2s ease, color 0.2s ease;
}

.reset-button:hover,
.reset-button:focus-visible {
  background: var(--seal);
  color: var(--paper);
}

.message-toast {
  position: absolute;
  left: 50%;
  bottom: clamp(18px, 4vw, 42px);
  z-index: 14;
  transform: translate(-50%, 14px);
  max-width: min(70%, 640px);
  padding: 10px 18px 12px;
  border: 1px solid rgba(168, 51, 31, 0.48);
  background: rgba(244, 235, 214, 0.9);
  color: var(--seal);
  font-weight: 900;
  opacity: 0;
  pointer-events: none;
  text-align: center;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.message-toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.flying-card {
  position: fixed;
  z-index: 30;
  padding: 0;
  border: 0;
  background: transparent;
  pointer-events: none;
  transition: transform 0.42s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.42s ease;
}

.petal-layer {
  z-index: 12;
  pointer-events: none;
  overflow: hidden;
}

.petal {
  position: absolute;
  top: -8%;
  width: 14px;
  height: 9px;
  border-radius: 80% 20% 70% 30%;
  background: rgba(217, 138, 138, 0.82);
  box-shadow: 0 0 8px rgba(255, 235, 235, 0.52);
  animation: petalFall var(--fall-time, 2.6s) linear forwards;
}

.explain-screen {
  display: grid;
  align-items: end;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.8s ease;
}

.explain-screen.visible {
  opacity: 1;
  pointer-events: auto;
}

.explain-screen.prose-only {
  background: linear-gradient(0deg, rgba(43, 43, 43, 0.14), rgba(43, 43, 43, 0.02));
}

.explain-screen.prose-only .explain-image {
  display: none;
}

.explain-image {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.explain-copy {
  position: relative;
  z-index: 2;
  margin: 0 auto clamp(18px, 3vw, 34px);
  width: min(86%, 880px);
  min-height: clamp(68px, 12vw, 106px);
  display: flex;
  align-items: center;
  padding: clamp(14px, 2.4vw, 22px) clamp(18px, 4vw, 38px);
  border: 1px solid rgba(43, 43, 43, 0.32);
  background: rgba(236, 228, 210, 0.82);
  box-shadow: 0 14px 34px rgba(43, 43, 43, 0.22);
}

.explain-copy p {
  margin: 0;
  color: var(--ink);
  font-size: clamp(1rem, 2vw, 1.45rem);
  font-weight: 700;
  line-height: 1.8;
}

.ending-screen {
  display: block;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  background: transparent;
  cursor: pointer;
  transition: opacity 0.9s ease;
}

.ending-screen.visible {
  opacity: 1;
  pointer-events: auto;
}

.scene-image.transition-1 {
  animation: travelCreek 4s ease-in-out forwards;
}

.scene-image.transition-2 {
  animation: fallingBlossomLook 4.2s ease-in-out forwards;
}

.scene-image.transition-3 {
  animation: pushToSource 4s ease-in-out forwards;
  filter: saturate(0.88) hue-rotate(8deg) brightness(0.96);
}

.scene-image.transition-4 {
  animation: enterCave 4.4s ease-in-out forwards;
}

.scene-image.transition-5 {
  animation: leaveCave 4.5s ease-in-out forwards;
}

.game-shell.vignette::after,
.game-shell.flash::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 13;
  pointer-events: none;
}

.game-shell.vignette::after {
  background: radial-gradient(circle at 50% 50%, transparent 22%, rgba(12, 10, 8, 0.54) 78%);
  animation: vignetteIn 4.4s ease-in-out forwards;
}

.game-shell.flash::after {
  background: rgba(255, 248, 229, 0);
  animation: whiteFlash 4.5s ease-in-out forwards;
}

@keyframes kenBurns {
  from { transform: scale(1); }
  to { transform: scale(1.08); }
}

@keyframes floatCard {
  from { translate: 0 -6px; }
  to { translate: 0 6px; }
}

@keyframes hotspotPulse {
  from {
    opacity: 0.76;
    transform: translate(-50%, -50%) scale(0.94);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.08);
  }
}

@keyframes portraitBreath {
  from { transform: translateY(18%) scale(1); }
  to { transform: translateY(17%) scale(1.025); }
}

@keyframes scrollReveal {
  from {
    transform: scaleY(0);
    opacity: 0.2;
  }
  to {
    transform: scaleY(1);
    opacity: 1;
  }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-8px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(4px); }
}

@keyframes inkDrop {
  from {
    opacity: 0;
    transform: translateY(-6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes petalFall {
  from {
    transform: translate3d(0, -10%, 0) rotate(0deg);
    opacity: 0;
  }
  12% {
    opacity: 1;
  }
  to {
    transform: translate3d(var(--drift, 70px), 120vh, 0) rotate(var(--spin, 280deg));
    opacity: 0;
  }
}

@keyframes travelCreek {
  from { transform: scale(1.04) translate(0, 0); filter: brightness(1); }
  70% { transform: scale(1.18) translate(-4%, 3%); filter: brightness(1.04); }
  to { transform: scale(1.24) translate(-8%, 6%); filter: brightness(1.14); opacity: 0.85; }
}

@keyframes fallingBlossomLook {
  from { transform: scale(1.05) translateY(0); filter: blur(0) brightness(1); }
  45% { transform: scale(1.14) translateY(5%); filter: blur(0) brightness(1.05); }
  to { transform: scale(1.2) translateY(-5%); filter: blur(3px) brightness(1.08); opacity: 0.82; }
}

@keyframes pushToSource {
  from { transform: scale(1.04); }
  to { transform: scale(1.24) translateY(1%); opacity: 0.84; }
}

@keyframes enterCave {
  from { transform: scale(1.03); filter: brightness(1); }
  72% { transform: scale(1.32); filter: brightness(1.1); }
  to { transform: scale(1.48); filter: brightness(1.75); opacity: 0.92; }
}

@keyframes leaveCave {
  from { transform: scale(1.02); filter: brightness(1); }
  62% { transform: scale(1.35); filter: brightness(1.8); }
  to { transform: scale(1.58); filter: brightness(2.35); opacity: 0.5; }
}

@keyframes vignetteIn {
  from { opacity: 0; }
  52% { opacity: 0.55; }
  to { opacity: 0.18; }
}

@keyframes whiteFlash {
  from { opacity: 0; }
  58% { opacity: 0.05; }
  82% { opacity: 0.84; }
  to { opacity: 0; }
}

/* 全螢幕等比縮放後，手機與桌機共用同一份排版；不再需要 @media 微調 */
@media (max-width: 0px) {
  .page-shell {
    padding: 8px;
  }

  .game-shell {
    width: min(1100px, 98vw, calc(98vh * 16 / 9));
  }

  .primary-button {
    min-width: 128px;
    padding-inline: 18px;
  }

  .hud {
    gap: 8px;
  }

  .progress-dots {
    gap: 6px;
  }

  .progress-dot {
    width: 10px;
    height: 10px;
  }

  .puzzle-panel {
    left: 8px;
    right: 8px;
    height: clamp(112px, 26%, 146px);
    gap: 8px;
    padding: 10px;
  }

  .answer-track {
    padding-right: 72px;
  }

  .word-card {
    width: clamp(104px, 17%, 132px);
  }

  .answer-token {
    flex-basis: min(126px, calc((100% - 48px) / 6));
  }

  .reset-button {
    right: 12px;
    bottom: 12px;
  }

  .message-toast {
    max-width: 86%;
    font-size: 0.9rem;
  }

  .dialogue-card {
    grid-template-columns: 42% minmax(0, 1fr);
    padding: 8px;
  }

  .dialogue-portrait img {
    max-width: 48vw;
    height: 118%;
  }

  .dialogue-content {
    width: 100%;
    max-height: calc(100% - 16px);
    margin-bottom: 4px;
    padding: 9px 11px;
    overflow-y: auto;
  }

  .dialogue-name {
    margin-bottom: 5px;
    padding: 4px 9px 5px;
    font-size: clamp(0.95rem, 3.6vw, 1.18rem);
  }

  .dialogue-text {
    min-height: 0;
    margin-bottom: 6px;
    line-height: 1.45;
    font-size: clamp(0.76rem, 2.8vw, 0.95rem);
  }

  .dialogue-options {
    gap: 5px;
  }

  .dialogue-option {
    padding: 4px 7px 5px;
    font-size: 0.76rem;
    line-height: 1.25;
  }
}
