/* === 生辰頁：宣紙直書版 === */

:root {
  --ink-deep: #050508;
  --ink-text: rgba(236, 230, 220, 0.92);
  --ink-muted: rgba(216, 210, 198, 0.65);
  --ink-accent: rgba(180, 150, 100, 0.7);
  --paper-shadow: rgba(0, 0, 0, 0.45);
}

/* ===== 整页背景 ===== */
.page--birth {
  position: relative;
  min-height: 100vh;
  /* background: var(--ink-deep); */
  /* 已移除：使用全局背景 */
  color: var(--ink-text);
  overflow: hidden;
}

/* 確保全域背景雜訊不顯示 */
body.page--birth::before,
.page--birth::before {
  display: none;
}

/* 背景層 */
/* ❌ 已删除：背景层样式已统一定义在 global-background.css */

/* ===== 主容器 ===== */
.birth-container {
  position: relative;
  z-index: 1;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 12vh 6vw 12vh;
  /* Adjusted padding */
}

/* ===== 內容組合群組 (Flex Container) ===== */
.birth-composite-group {
  display: flex;
  flex-direction: row-reverse;
  /* Items: Text(1), Stage(2), CTA(3) -> Right to Left order -> Text Right, Stage Center, CTA Left */
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 1.5vw, 24px);
  /* Further reduced gap */
  width: 100%;
  max-width: 1400px;
  position: relative;
}

/* ===== 顶部标题（横向） ===== */
.page-title {
  /* position: absolute; REMOVED for Flex flow */
  position: relative;
  width: 100%;
  margin: 0 0 5vh 0;
  /* Add bottom margin to separate from content */
  font-family: "Bakudai", "Noto Serif TC", serif;
  font-size: clamp(42px, 7vw, 92px);
  /* INCREASED SIZE per plan */
  font-weight: 400;
  letter-spacing: 0.32em;
  text-indent: 0.32em;
  color: var(--ink-text);
  text-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  text-align: center;
  z-index: 5;
  transform: none;
  flex-shrink: 0;
}

/* ===== 直书说明 ===== */
.vertical-text {
  /* position: absolute; REMOVED */
  position: relative;
  display: flex;
  flex-direction: row-reverse;
  gap: 1.5em;
  z-index: 4;
  height: 100%;
  justify-content: center;
  /* Ensure it doesn't shrink */
  flex-shrink: 0;
}

/* .vertical-text--right removed as it's now empty (handled by parent flex) */

.vertical-text--left {
  /* Only used for select page? Or removed? Keeping basic style safe */
  gap: 0.75em;
}

.vertical-text--left-placeholder {
  display: none;
  /* Deprecated/Unused in this new layout */
}

.v-line {
  margin: 1em 0 0 0;
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-family: "Bakudai", "Noto Serif TC", serif;
  font-size: clamp(22px, 2.75vw, 32px);
  letter-spacing: 0.24em;
  line-height: 1.65;
  color: var(--ink-muted);
  white-space: nowrap;
}

.v-line:first-child {
  font-size: clamp(24px, 3vw, 36px);
}

.v-line--focus {
  color: var(--ink-text);
  opacity: 0.88;
  font-size: clamp(28px, 3.4vw, 40px);
  /* 生辰往上提高一個字高 */
  transform: translateY(-1em);
  /* 生辰維持原位（頂端對齊） */
  margin-top: 0;
  margin-bottom: 0.5em;
}

/* ===== Reveal animations ===== */
.reveal {
  opacity: 0;
  visibility: hidden;
  filter: blur(var(--reveal-blur, 8px));
  transform: translateY(var(--reveal-y, 0px));
  transition:
    opacity var(--reveal-duration, 800ms) ease,
    filter var(--reveal-duration, 800ms) ease,
    transform var(--reveal-duration, 800ms) ease,
    visibility 0s linear 0s;
}

.reveal.is-visible {
  opacity: 1;
  visibility: visible;
  filter: blur(0);
  transform: translateY(0);
}

.page-title.reveal {
  --reveal-duration: 6000ms;
  --reveal-blur: 8px;
}

.v-line.reveal {
  --reveal-duration: 6300ms;
  --reveal-blur: 6px;
}

.page--birth .birth-cta.reveal {
  --reveal-duration: 3000ms;
  --reveal-blur: 15px;
  /* 強制覆蓋 transition，確保動畫參數生效，不被 .cta 的設定干擾 */
  transition:
    opacity var(--reveal-duration, 3000ms) ease,
    filter var(--reveal-duration, 3000ms) ease,
    transform var(--reveal-duration, 3000ms) ease,
    visibility 0s linear 0s;
}

/* ===== Typewriter effect ===== */
.v-line[data-typewriter] {
  filter: none;
  transform: none;
}

.v-line[data-typewriter] .typewriter-char {
  opacity: 0;
  display: inline-block;
  writing-mode: vertical-rl;
  text-orientation: upright;
  animation: typewriterReveal 420ms ease forwards;
}

@keyframes typewriterReveal {
  to {
    opacity: 1;
  }
}

/* ===== 中央輸入舞台（移除宣紙圖檔） ===== */
.birth-stage {
  position: relative;
  width: auto;
  min-width: fit-content;
  /* Adjusted width */
  height: auto;
  min-height: 40vh;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  overflow: visible;
  transition: transform 280ms cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 10;
  flex-shrink: 0;
  /* Prevent shrinking */
}

.birth-stage::before {
  content: none;
}

.birth-stage::after {
  content: none;
}

.birth-stage.pressed {
  transform: translateY(1px) scale(0.997);
}

/* ===== 文具裝飾（依產品規格書補上） ===== */
/* ===== 文具裝飾（已移除） ===== */
.stage-prop {
  display: none;
}

/* ===== 輸入內容區 ===== */
.birth-panel {
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: clamp(20px, 4vh, 40px) clamp(10px, 2vw, 20px);
  /* Significantly reduced padding */
  gap: 36px;
}

/* 提示小字 */
.hint-text {
  margin: 0 0 16px;
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-family: "Bakudai", "Noto Serif TC", serif;
  font-size: clamp(20px, 2.4vw, 26px);
  letter-spacing: 0.28em;
  color: rgba(236, 230, 220, 0.78);
  opacity: 0.82;
  text-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
}

/* ===== 日期输入區 (Centered in Stage) ===== */
.date-grid {
  display: flex;
  gap: clamp(20px, 2.5vw, 30px);
  /* Reduced gap */
  align-items: flex-start;
  justify-content: center;
  position: relative;
  /* Changed from absolute */
  /* Remove old absolute positioning logic */
  left: auto;
  top: auto;
  transform: none;
  flex-direction: row-reverse;
  z-index: 3;
}

.date-col {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  writing-mode: horizontal-tb;
  text-orientation: mixed;
}

/* 栏位标签（直书） */
.date-label {
  writing-mode: vertical-rl;
  text-orientation: upright;
  font-family: "Bakudai", "Noto Serif TC", serif;
  font-size: clamp(20px, 2.5vw, 28px);
  letter-spacing: 0.2em;
  color: var(--ink-text);
  opacity: 0.65;
  margin: 0;
  padding-top: 4px;
}

.date-label.reveal {
  --reveal-duration: 6300ms;
  --reveal-blur: 6px;
}

.date-input.reveal {
  --reveal-duration: 6300ms;
  --reveal-blur: 6px;
  transition:
    opacity var(--reveal-duration, 800ms) ease,
    filter var(--reveal-duration, 800ms) ease,
    transform var(--reveal-duration, 800ms) ease,
    border-color 280ms ease,
    box-shadow 280ms ease;
}

.date-label[data-typewriter] {
  filter: none;
  transform: none;
}

.date-label[data-typewriter] .typewriter-char {
  opacity: 0;
  display: inline-block;
  writing-mode: vertical-rl;
  text-orientation: upright;
  animation: typewriterReveal 420ms ease forwards;
}

/* 输入框（只有底线） */
.date-input {
  height: clamp(140px, 16vh, 180px);
  width: 1.3em;
  padding: 10px 3px 12px;
  border: none;
  border-bottom: none;
  background: transparent;
  color: var(--ink-text);
  font-family: "Bakudai", "Noto Serif TC", serif;
  font-size: clamp(19.2px, 2.56vw, 25.6px);
  text-align: center;
  letter-spacing: 0.08em;
  outline: none;
  -moz-appearance: textfield;
  appearance: textfield;
  transition: border-color 280ms ease, box-shadow 280ms ease, opacity 280ms ease;
  display: block;
  writing-mode: vertical-rl;
  text-orientation: upright;
  /* 拿掉輸入框左側白線 */
  border-left: none;
}

.date-input::-webkit-outer-spin-button,
.date-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* 聚焦時不加額外邊線效果 */
.date-input:focus {
  box-shadow: none;
}

.date-input::placeholder {
  color: var(--ink-muted);
  opacity: 0.2;
  font-family: "Bakudai", "Noto Serif TC", serif;
  font-size: 0.85em;
}

/* ===== 错误提示（直书） ===== */
.error-hint {
  writing-mode: vertical-rl;
  text-orientation: upright;
  margin: 0;
  min-height: 1.5em;
  font-family: "Bakudai", "Noto Serif TC", serif;
  font-size: clamp(16px, 2vw, 20px);
  letter-spacing: 0.24em;
  color: var(--ink-muted);
  opacity: 0;
  transition: opacity 300ms ease;
}

.error-hint.show {
  opacity: 0.65;
}

/* ===== CTA（樣式參照首頁） ===== */
/* Shared base styles in spa.css */

.page--birth .cta:disabled {
  opacity: 0.34;
  cursor: not-allowed;
  pointer-events: none;
}

/* CTA (In Flex Flow) */
/* CTA (In Flex Flow) */
.birth-container .birth-cta.cta--vertical {
  position: relative;
  /* Relative in Flex container */
  left: auto;
  bottom: auto;
  top: auto;
  transform: none;
  /* Margin to ensure separation */
  /* margin-right: 4vw; */
  margin-right: 2vw;
  /* Restore breathing room similar to homepage */
  padding: 42px 19px;
  letter-spacing: 0.12em;
  font-size: clamp(31px, 4.3vw, 41px);
  min-height: auto;
}


/* Ink Ring Animation Removed */

/* ===== 响应式调整 ===== */
@media (max-width: 1024px) {
  .birth-composite-group {
    gap: 40px;
  }

  .page-title {
    font-size: clamp(36px, 6vw, 72px);
  }
}

@media (max-width: 768px) {
  .birth-container {
    padding: 8vh 4vw 8vh;
  }

  .birth-composite-group {
    flex-direction: column;
    /* Stack vertically on mobile */
    gap: 32px;
  }

  .page-title {
    top: auto;
    font-size: clamp(28px, 6vw, 38px);
    margin-bottom: 24px;
  }

  .vertical-text {
    position: static;
    transform: none;
    flex-direction: row;
    gap: 0.6em;
    margin: 0;
    justify-content: center;
    width: 100%;
  }

  .vertical-text--right {
    margin-bottom: 0px;
  }

  /*
  .vertical-text--left {
    margin-top: 12px;
  }
  */

  .v-line {
    font-size: clamp(18px, 3.2vw, 24px);
    writing-mode: vertical-rl;
    /* Maintain vertical text even in horizontal strip? 
       Previous CSS had `writing-mode: vertical-rl` but flex-direction row. 
       This means characters are vertical, but lines are arranged horizontally.
       Correct.
    */
  }

  .v-line--focus {
    transform: translateY(0);
  }

  .birth-stage {
    width: 100%;
    height: auto;
    min-height: 300px;
    margin: 20px 0;
  }

  /* Date Grid Mobile */
  .date-grid {
    position: static;
    transform: none;
    flex-direction: row-reverse;
    gap: 20px;
    margin-top: 0;
  }

  .date-col {
    gap: 6px;
  }

  .date-input {
    height: 140px;
    font-size: 28px;
  }

  .date-label {
    font-size: 20px;
  }

  .page--birth #birthNext {
    position: fixed;
    left: 50%;
    top: auto;
    bottom: calc(env(safe-area-inset-bottom) + 96px);
    transform: translateX(-50%);
    width: min(76vw, 300px);
    max-width: none;
    margin: 0;
    padding: 12px 20px;
    writing-mode: horizontal-tb;
    text-orientation: mixed;
    text-align: center;
    white-space: nowrap;
    font-size: clamp(20px, 5vw, 24px);
    z-index: 95;
    transition: opacity 220ms ease;
  }

  .page--birth #birthNext[aria-disabled="true"] {
    opacity: 0.52;
  }

  .page--birth #birthNext[aria-disabled="false"] {
    opacity: 1;
  }

  .page--birth #birthNext .cta-label {
    writing-mode: horizontal-tb;
    text-orientation: mixed;
    text-align: center !important;
    display: block;
    width: 100%;
  }

  /* Mobile: keep inputs and CTA visible to avoid long reveal-delay blocking interaction */
  .page--birth .date-input.reveal,
  .page--birth .date-label.reveal,
  .page--birth #birthNext.reveal {
    visibility: visible;
    opacity: 1;
    filter: none;
  }
}

@media (max-width: 480px) {
  .birth-container {
    /* Use flex column for the whole page */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* or flex-start if content is tall */
    padding: 8vh 6vw 5vh;
    /* Reduced bottom padding */
    gap: 20px;
    height: auto;
    min-height: 100vh;
  }

  /* 1. Title is already first in DOM, no need for order unless we want to move it */
  .page-title {
    position: relative;
    width: 100%;
    margin-bottom: 0;
    /* 1.2x scale */
    font-size: clamp(36px, 10vw, 60px);
    letter-spacing: 0.18em;
    flex-shrink: 0;
  }

  /* 2. Composite Group (Text + Stage + CTA) */
  .birth-composite-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    gap: 30px;
    /* Gap between text, inputs, cta */
    flex-grow: 1;
    justify-content: center;
  }

  /* 2.1 Vertical Text (Instruction) */
  .vertical-text {
    /* Ensure it acts as a block below title */
    position: static;
    transform: none;
    /* User request: Move down 2cm (~75px) */
    margin: 50px auto 20px;
    height: auto;

    flex-direction: row;
    /* Align top to ensure "Top Left" request */
    align-items: flex-start;
    width: 100%;
    justify-content: center;
    gap: 12px;
  }

  /* User request: Font size +10% for mobile */
  .v-line {
    /* Base was ~22px. 10% is ~24px. */
    font-size: clamp(24px, 5.5vw, 35px) !important;
    line-height: 1.6;
  }

  .v-line:first-child {
    font-size: clamp(26px, 6vw, 40px) !important;
  }

  /* User request: "生辰" (v-line--focus) to Top Left of paragraph */
  .v-line--focus {
    order: -1;
    /* Move to start (Left in LTR) */
    margin-right: 8px;
    /* Slight separation */
    /* Ensure it acts as title */
    opacity: 1;
    transform: none !important;
    /* Reset any desktop transform */
  }

  /* 2.2 Input Stage */
  .birth-stage {
    width: 100%;
    min-height: auto;
    /* User request: Move down 0.5cm from previous (-50px) position */
    /* -50px + 20px = -30px */
    margin-top: -30px;
    margin-bottom: 20px;
    flex-shrink: 0;
  }

  .birth-panel {
    padding: 0;
    gap: 20px;
  }

  /* Keep inputs vertical but center them */
  .date-grid {
    position: static;
    transform: none;
    display: flex;
    /* User request: "年月日" -> Year Month Day order. DOM is Y-M-D. */
    /* flex-direction: row gives Y-M-D LTR. */
    flex-direction: row;
    justify-content: center;
    gap: 20px;
    margin: 0;
  }

  .page--birth #birthNext {
    bottom: calc(env(safe-area-inset-bottom) + 88px);
    width: min(80vw, 286px);
    font-size: clamp(18px, 4.6vw, 21px);
  }
}

/* ===== 小螢幕優化（375px 以下） ===== */
@media (max-width: 375px) {
  .birth-container {
    padding: 5vh 2vw 8vh;
  }

  .birth-composite-group {
    gap: 16px;
  }

  .page-title {
    font-size: 22px;
    letter-spacing: 0.2em;
  }

  .vertical-text {
    margin: 8px auto 12px;
  }

  .v-line {
    font-size: 14px;
    letter-spacing: 0.15em;
  }

  .birth-stage {
    min-height: 180px;
  }

  .birth-panel {
    padding: 8% 4%;
    gap: 16px;
  }

  /* 輸入框改為橫書模式 */
  .date-grid {
    flex-direction: row;
    gap: 8px;
  }

  .date-col {
    flex-direction: column;
    gap: 4px;
  }

  .date-input {
    writing-mode: horizontal-tb;
    text-orientation: mixed;
    height: auto;
    width: clamp(50px, 16vw, 70px);
    padding: 10px 6px;
    font-size: 20px;
    text-align: center;
  }

  .date-label {
    writing-mode: horizontal-tb;
    text-orientation: mixed;
    font-size: 12px;
    letter-spacing: 0.1em;
  }

  html[lang="zh-TW"] .page--birth .date-label {
    font-size: 14px;
    letter-spacing: 0.12em;
  }

  /* CTA sizing remains fluid via clamp() */
}

/* ===== 超小螢幕（320px 以下） ===== */
@media (max-width: 320px) {
  .birth-container {
    padding: 4vh 2vw 6vh;
  }

  .page-title {
    font-size: 18px;
  }

  .v-line {
    font-size: 12px;
  }

  .date-input {
    width: clamp(40px, 14vw, 55px);
    padding: 8px 4px;
    font-size: 16px;
  }

  .date-label {
    font-size: 10px;
  }

  html[lang="zh-TW"] .page--birth .date-label {
    font-size: 12px;
  }
}

/* ===== 无障碍：减少动效 ===== */
@media (prefers-reduced-motion: reduce) {

  .reveal {
    opacity: 1;
    filter: none;
    transform: none;
    transition: none;
  }

  .typewriter-char {
    opacity: 1 !important;
    animation: none !important;
  }

  .birth-stage,
  .stage-prop,
  .page--birth .cta,
  .date-input {
    transition: none;
  }

  .birth-stage::after,
  .stage-prop {
    animation: none;
    display: none;
  }

}
