/* ============================================
   小草生日游戏 — game.css
   目标平台：iPhone Safari (横屏)
   ============================================ */

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --text-primary: #f4f4f6;
  --text-muted: rgba(244, 244, 246, 0.6);
  --accent: #ffb3c7;
  --dialogue-bg: rgba(15, 15, 20, 0.55);
  --dialogue-border: rgba(255, 255, 255, 0.08);
  --font-stack: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Segoe UI', sans-serif;
  --camera-ease: cubic-bezier(0.4, 0, 0.2, 1);
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: var(--text-primary);
  font-family: var(--font-stack);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: none;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html { -webkit-text-size-adjust: none; text-size-adjust: none; }

/* HTML [hidden] should always force display: none, otherwise CSS-positioned
   elements ignore the attribute. */
[hidden] { display: none !important; }

body {
  position: fixed;
  inset: 0;
  overscroll-behavior-y: contain;
}

/* ============================================
   Portrait prompt (visible only when portrait)
   ============================================ */
.layer-portrait {
  position: fixed;
  inset: 0;
  background: #000;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1100;
}

.rotate-icon {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 28px;
}

.phone-body {
  width: 38px;
  height: 64px;
  border: 2px solid var(--text-primary);
  border-radius: 6px;
  padding: 3px;
  transform: rotate(90deg);
  transition: transform 0.4s ease;
}

.phone-screen {
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
}

.arrow {
  font-size: 28px;
  color: var(--accent);
  animation: nudge 1.4s ease-in-out infinite;
}

@keyframes nudge {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(8px); }
}

.portrait-text {
  font-size: 16px;
  color: var(--text-primary);
  letter-spacing: 0.3em;
}

@media (orientation: portrait) {
  .layer-portrait { display: flex; }
  .layer-start, .layer-loading, .layer-stage, .layer-end { display: none !important; }
}

/* ============================================
   Loading screen
   ============================================ */
.layer-loading {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  transition: opacity 0.5s ease-out;
}

.layer-loading.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.loading-title {
  font-size: 20px;
  letter-spacing: 0.4em;
  color: var(--text-primary);
  margin-bottom: 32px;
  font-weight: 300;
}

.loading-bar-track {
  width: 220px;
  height: 2px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 1px;
  overflow: hidden;
}

.loading-bar-fill {
  width: 0%;
  height: 100%;
  background: var(--accent);
  transition: width 0.3s ease-out;
}

.loading-percent {
  margin-top: 16px;
  font-size: 12px;
  color: var(--text-muted);
  letter-spacing: 0.1em;
}

/* ============================================
   Start screen
   ============================================ */
.layer-start {
  position: fixed;
  inset: 0;
  background-color: #050506;
  background-image: linear-gradient(90deg, rgba(5, 6, 8, .08) 0%, rgba(5, 6, 8, .06) 43%, rgba(5, 6, 8, .56) 100%), url('../assets/images/opening-cover.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 900;
  opacity: 0;
  transition: opacity 1s ease-out;
}

.layer-start.is-ready { opacity: 1; }

.start-copy { position: absolute; z-index: 1; left: 58%; width: min(34vw, 390px); text-align: center; transform: translateY(8px); opacity: 0; transition: opacity .7s ease .2s, transform .7s ease .2s; }
.layer-start.is-ready .start-copy { opacity: 1; transform: translateY(0); }
.start-save,
.start-title,
.start-date,
.start-btn { opacity: 0; transform: translateY(8px); }
.layer-start.is-ready .start-save,
.layer-start.is-ready .start-title,
.layer-start.is-ready .start-date,
.layer-start.is-ready .start-btn { opacity: 1; transform: translateY(0); }
.start-save { display: flex; align-items: center; justify-content: center; gap: .55em; color: rgba(255,248,239,.72); font: 400 clamp(10px, 1vw, 12px)/1.2 'SF Mono', Menlo, monospace; letter-spacing: .28em; text-indent: .28em; transition: opacity .65s ease .28s, transform .65s ease .28s; text-shadow: 0 2px 12px rgba(0,0,0,.68); }
.start-save-mark { color: rgba(246,211,179,.72); font-size: .72em; letter-spacing: 0; text-indent: 0; }
.start-title { color: #fff8ef; font-family: var(--font-stack); font-size: clamp(29px, 4vw, 48px); line-height: 1.3; letter-spacing: .18em; text-indent: .18em; font-weight: 450; text-shadow: 0 2px 13px rgba(0,0,0,.56); margin-top: clamp(12px, 2vh, 20px); transition: opacity .7s ease .34s, transform .7s ease .34s; }
.start-date { display: flex; align-items: center; justify-content: center; gap: clamp(8px, 1.4vw, 16px); color: rgba(255,248,239,.68); font: 400 clamp(11px, 1.2vw, 14px)/1.4 'SF Mono', Menlo, monospace; letter-spacing: .24em; text-indent: .24em; margin-top: clamp(10px, 1.5vh, 16px); text-shadow: 0 2px 12px rgba(0,0,0,.68); transition: opacity .65s ease .43s, transform .65s ease .43s; }
.start-date::before, .start-date::after { content: ''; width: clamp(22px, 4vw, 46px); height: 1px; background: rgba(255,239,221,.38); }

.layer-start.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.start-btn {
  margin-top: clamp(24px, 4vh, 36px);
  min-width: 150px;
  min-height: 48px;
  padding: 12px 28px;
  background: rgba(8, 9, 12, .38);
  color: #fff8ef;
  border: 1px solid rgba(255, 239, 221, .58);
  border-radius: 8px;
  font-size: clamp(14px, 1.5vw, 16px);
  font-family: inherit;
  letter-spacing: .22em;
  cursor: pointer;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  transition: background .3s ease, border-color .3s ease, opacity .55s ease .72s, transform .55s ease .72s;
  box-shadow: 0 0 0 0 rgba(246,211,179,0);
  text-indent: .22em;
  animation: none;
}

.layer-start.is-ready .start-btn { animation: opening-breathe 3.2s ease-in-out 1.35s infinite; }

.start-btn:active {
  background: rgba(246, 211, 179, 0.16);
  border-color: rgba(246, 211, 179, 0.8);
  transform: scale(0.98);
}

@keyframes opening-breathe {
  0%, 100% { opacity: .92; border-color: rgba(255, 239, 221, .48); }
  50% { opacity: 1; border-color: rgba(255, 239, 221, .7); }
}

@media (orientation: landscape) and (max-height: 500px) {
  .start-copy { left: auto; right: max(8vw, calc(8vw + var(--safe-right))); width: min(38vw, 360px); }
  .start-title { font-size: clamp(24px, 6vh, 38px); margin-top: clamp(9px, 1.8vh, 15px); }
  .start-date { font-size: clamp(10px, 2.4vh, 13px); margin-top: clamp(7px, 1.5vh, 12px); }
  .start-btn { margin-top: clamp(17px, 3.5vh, 28px); min-height: 46px; }
}

@media (prefers-reduced-motion: reduce) {
  .layer-start, .start-copy, .start-save, .start-title, .start-date, .start-btn { transition: none; }
  .start-btn { animation: none; }
}

.start-hint {
  margin-top: 20px;
  font-size: 11px;
  color: rgba(243,233,223,.45);
  letter-spacing: 0.2em;
}

/* ============================================
   Game stage
   ============================================ */
.layer-stage {
  position: fixed;
  inset: 0;
  background: #000;
  overflow: hidden;
}

/* Background canvas: uses background-image so we can pan/zoom via
   background-position and transform. */
.bg-frame {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #000;
}

.bg-canvas {
  position: absolute;
  inset: 0;
  background-size: cover;
  background-position: 50% 50%;
  background-repeat: no-repeat;
  background-color: #000;
  /* Camera & crossfade transitions */
  transition:
    background-position 2s var(--camera-ease),
    transform 2s var(--camera-ease),
    opacity 0.6s ease-out;
  opacity: 0;
  transform: scale(1);
  transform-origin: 50% 50%;
  will-change: transform, background-position, opacity;
}

.bg-canvas.is-loaded {
  opacity: 1;
}

.bg-canvas.is-out {
  opacity: 0;
}

.bg-canvas.is-animating {
  /* Inline-set transition duration overrides the default. */
}

/* Brightness overlay (multiplies: black = darker, white = lighter.
   We use rgba with mix-blend-mode for proper control. */
.overlay-brightness {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0);
  pointer-events: none;
  transition: background 0.25s ease-out;
  z-index: 2;
}

/* Flash overlay (white brief pulse) */
.overlay-flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease-out;
  z-index: 3;
  mix-blend-mode: screen;
}

.overlay-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 50%, rgba(0, 0, 0, 0.45) 100%);
  opacity: 0;
  transition: opacity 0.6s ease-out;
  z-index: 2;
}

.overlay-vignette.is-on { opacity: 1; }

/* Time UI */
.time-ui {
  position: absolute;
  top: calc(11% + var(--safe-top));
  left: 50%;
  min-width: 4.8em;
  padding: .24em .62em .3em;
  border: 1px solid rgba(255, 239, 220, .34);
  border-radius: 3px;
  background: rgba(18, 14, 13, .45);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  font-size: clamp(28px, 6vw, 64px);
  line-height: 1;
  font-weight: 300;
  color: rgba(255, 247, 237, .96);
  letter-spacing: .12em;
  text-indent: .12em;
  text-align: center;
  text-shadow: 0 2px 16px rgba(0, 0, 0, .75);
  font-variant-numeric: tabular-nums;
  transform: translateX(-50%) scale(.96);
  transition: opacity .42s ease, transform .42s ease;
  z-index: 8;
  font-family: 'SF Mono', 'Menlo', monospace;
}

.time-ui.is-visible { transform: translateX(-50%) scale(1); }

/* System message layer (centered narration) */
.system-layer {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  padding: 0 10%;
  z-index: 9;
  opacity: 0;
  transition: opacity 0.4s ease-out;
}

.system-layer.is-visible { opacity: 1; }

.system-layer.is-narration { align-items: flex-end; padding-bottom: calc(20% + var(--safe-bottom)); }
.system-layer.is-system { align-items: center; }
.system-layer.is-action { align-items: flex-start; padding-top: 13%; }

.system-text {
  max-width: min(680px, 82vw);
  padding: 14px 24px 16px;
  border: 1px solid rgba(246, 211, 179, 0.18);
  border-radius: 3px;
  background: rgba(14, 13, 14, 0.72);
  -webkit-backdrop-filter: blur(16px) saturate(115%);
  backdrop-filter: blur(16px) saturate(115%);
  font-size: 19px;
  line-height: 1.75;
  letter-spacing: 0.12em;
  color: rgba(255, 248, 241, 0.94);
  text-align: center;
  text-shadow: 0 0 12px rgba(0, 0, 0, 0.7);
  font-weight: 300;
  white-space: pre-wrap;
}

.system-layer.is-system .system-text { font-size: 14px; padding: 10px 18px; color: rgba(246,211,179,.9); letter-spacing: .16em; }
.system-layer.is-action .system-text { font-size: 13px; padding: 8px 15px; color: rgba(246,211,179,.78); letter-spacing: .1em; }
.ending-text { padding: 14px 24px; color: rgba(246,211,179,.9); font: 18px/1.7 Georgia, 'Songti SC', serif; letter-spacing: .18em; text-indent: .18em; border-top: 1px solid rgba(246,211,179,.25); border-bottom: 1px solid rgba(246,211,179,.25); }

/* Baked BG-18-final ending: image and replay hit area share one SVG viewBox. */
.ending-final-stage { position: absolute; inset: 0; z-index: 30; overflow: hidden; background: #000; opacity: 0; pointer-events: none; transition: opacity 1.1s ease; }
.ending-final-stage.is-visible { opacity: 1; }
.ending-final-stage.is-actionable { pointer-events: auto; }
.ending-final-svg { position: absolute; inset: 0; display: block; width: 100%; height: 100%; overflow: hidden; }
.ending-replay-hit { pointer-events: all; cursor: pointer; outline: none; }
.ending-replay-hit:focus-visible { stroke: rgba(255,239,221,.7); stroke-width: 3; }

/* ============================================
   Dialogue box
   ============================================ */
.dialogue-box {
  position: absolute;
  left: 5%;
  right: 5%;
  bottom: calc(5% + var(--safe-bottom));
  background: var(--dialogue-bg);
  -webkit-backdrop-filter: blur(14px) saturate(120%);
  backdrop-filter: blur(14px) saturate(120%);
  border: 1px solid var(--dialogue-border);
  border-radius: 14px;
  padding: 16px 22px 20px;
  color: var(--text-primary);
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
  z-index: 10;
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
  transition: opacity 0.4s ease-out, transform 0.4s ease-out;
  max-width: 720px;
  margin: 0 auto;
}

.dialogue-box.is-visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.dialogue-box.micro-shake { animation: micro-shake .26s ease-out 1; }
@keyframes micro-shake { 0%,100% { transform: translateY(0); } 25% { transform: translate(-1px,0); } 50% { transform: translate(1px,0); } 75% { transform: translate(-1px,0); } }

.speaker-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 0.15em;
  margin-bottom: 6px;
  min-height: 1.2em;
  text-indent: 0.15em;
}

.speaker-name:empty { display: none; }

.dialogue-text {
  font-size: 17px;
  line-height: 1.7;
  letter-spacing: 0.02em;
  min-height: 1.7em;
  white-space: pre-wrap;
  word-break: break-word;
  font-weight: 300;
}

.dialogue-next {
  position: absolute;
  right: 16px;
  bottom: 10px;
  font-size: 11px;
  color: var(--text-primary);
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  animation: blink 1.2s ease-in-out infinite;
}

.dialogue-next.is-visible { opacity: 0.85; }

@keyframes blink {
  0%, 100% { opacity: 0.3; }
  50% { opacity: 0.9; }
}

/* ============================================
   Choice layer
   ============================================ */
.choice-layer {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 0 10%;
  z-index: 20;
  background: rgba(0, 0, 0, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.4s ease-out;
}

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

.choice-btn {
  background: rgba(20, 20, 28, 0.7);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 28px;
  padding: 14px 36px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 16px;
  font-weight: 300;
  letter-spacing: 0.1em;
  cursor: pointer;
  min-width: 220px;
  transition: all 0.2s ease;
}

.choice-btn:active {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--accent);
  transform: scale(0.98);
}

/* ============================================
   Click catcher
   ============================================ */
.click-catcher {
  position: absolute;
  inset: 0;
  background: transparent;
  z-index: 5;
  touch-action: none;
}

#click-catcher.is-disabled { pointer-events: none; }

/* ============================================
   End screen (DEV END)
   ============================================ */
.layer-end {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 950;
  opacity: 0;
  pointer-events: none;
  transition: opacity 1s ease-out;
}

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

.end-line {
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 300;
  letter-spacing: 0.3em;
  margin: 8px 0;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.8s ease-out, transform 0.8s ease-out;
}

.end-line.is-visible {
  opacity: 1;
  transform: translateY(0);
}

#end-line-3 {
  margin-top: 36px;
  color: var(--accent);
  letter-spacing: 0.5em;
  font-size: 14px;
}

/* ============================================
   Small screen adaptation
   ============================================ */
@media (max-height: 380px) {
  .time-ui { top: calc(7% + var(--safe-top)); font-size: clamp(25px, 7vw, 42px); }
  .dialogue-box {
    bottom: calc(3% + var(--safe-bottom));
    padding: 10px 16px 14px;
  }
  .dialogue-text { font-size: 15px; line-height: 1.5; }
  .system-text { font-size: 16px; }
  .speaker-name { font-size: 12px; margin-bottom: 4px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  .time-ui { top: calc(7vh + var(--safe-top)); font-size: clamp(26px, 7vh, 42px); }
}

@media (max-width: 700px) {
  .dialogue-box { left: 4%; right: 4%; }
}
