/* ================================================================================
   恋爱彩蛋：手账便签风的小游戏入口 + 全屏弹窗
   ————————————————————————————————————————————————————————————————
   · 这个文件只管「悬浮按钮 + 弹窗」两件事，跟登录、日记、主题逻辑完全隔离。
   · 颜色全部走 tokens.css 的令牌，四套主题自动跟着变（没有任何字面量颜色）。
   · 弹窗里的 iframe 默认不带 src：只有第一次点按钮时，由 scripts/game-modal.js
     把 src 指到 games/love-game/index.html，避免一进首页就下载 38 MB 的 wasm。
   ================================================================================ */

/* ---------------------------- 1. 右下角悬浮按钮 ---------------------------- */

/* 做成一张斜贴的小便签：左侧一条胶带、楷体字、纸影，和站内卡片一个手感 */
.game-fab {
  position: fixed;
  right: var(--sp-5);
  bottom: calc(var(--sp-5) + env(safe-area-inset-bottom, 0px));
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 46px;
  padding: var(--sp-2) var(--sp-4);
  border: 1px solid var(--c-line-dash);
  border-radius: var(--r-sm);
  background-color: var(--c-surface);
  background-image: var(--paper-grain);
  background-size: var(--paper-noise-size);
  box-shadow: var(--shadow-paper);
  color: var(--c-ink);
  font-family: var(--font-title);
  font-size: var(--fs-base);
  letter-spacing: var(--ls-title);
  cursor: pointer;
  rotate: -0.8deg;
  transition: translate var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), scale var(--dur-fast) var(--ease);
}

/* 左上角那条小胶带 */
.game-fab::before {
  content: "";
  position: absolute;
  top: -8px;
  left: 16px;
  width: 44px;
  height: 13px;
  background-color: var(--tape-c-2);
  opacity: .72;
  rotate: -5deg;
  box-shadow: var(--shadow-tape);
  pointer-events: none;
}

.game-fab:hover {
  translate: 0 -2px;
  box-shadow: var(--shadow-note);
}

.game-fab:active {
  scale: var(--press-scale);
}

.game-fab__emoji {
  font-size: var(--fs-md);
  line-height: 1;
}

.game-fab__text {
  white-space: nowrap;
}

/* ---------------------------- 2. 全屏遮罩 + 弹窗 ---------------------------- */

.game-modal {
  position: fixed;
  inset: 0;
  z-index: var(--z-game);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
}

/* 半透明纸色遮罩：点它也能关 */
.game-modal__scrim {
  position: absolute;
  inset: 0;
  background-color: color-mix(in srgb, var(--c-ink) 58%, transparent);
  backdrop-filter: blur(3px);
  animation: game-fade var(--dur-base) var(--ease) both;
}

@keyframes game-fade {
  from { opacity: 0 }
  to { opacity: 1 }
}

/* 弹窗本体：宽 90% 高 88%，手机上略微收一点边距 */
.game-modal__panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(90vw, 1280px);
  height: 88vh;
  height: 88dvh;
  border: 1px solid var(--c-line-dash);
  border-radius: var(--r-md);
  background-color: var(--c-surface);
  box-shadow: var(--shadow-paper);
  overflow: hidden;
  animation: game-pop var(--dur-base) var(--ease) both;
}

@keyframes game-pop {
  from { opacity: 0; translate: 0 10px }
  to { opacity: 1; translate: 0 0 }
}

/* 顶上那条胶带，把弹窗也贴成一张便签 */
.game-modal__panel::before {
  content: "";
  position: absolute;
  top: -9px;
  left: 50%;
  width: 96px;
  height: 18px;
  margin-left: -48px;
  background-color: var(--tape-c-2);
  opacity: .7;
  rotate: -2deg;
  box-shadow: var(--shadow-tape);
  pointer-events: none;
  z-index: 2;
}

.game-modal__head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex: none;
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px dashed var(--c-line-soft);
  background-color: var(--c-paper-tint);
}

.game-modal__title {
  flex: 1 1 auto;
  min-width: 0;
  margin: 0;
  color: var(--c-ink);
  font-family: var(--font-title);
  font-size: var(--fs-lg);
  font-weight: var(--fw-title);
  letter-spacing: var(--ls-title);
}

/* 右上角那个「X」：44px 触摸区，描边小方章，醒目但不刺眼 */
.game-modal__close {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border: 1px solid var(--c-primary);
  border-radius: var(--r-sm);
  background-color: var(--c-surface);
  color: var(--c-primary);
  font-family: var(--font-title);
  font-size: var(--fs-lg);
  line-height: 1;
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), scale var(--dur-fast) var(--ease);
}

.game-modal__close:hover {
  background-color: var(--c-primary);
  color: var(--c-on-primary);
}

.game-modal__close:active {
  scale: var(--press-scale);
}

/* 游戏舞台：iframe 铺满，加载提示浮在中间 */
.game-modal__stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  background-color: var(--c-surface-2);
}

.game-modal__frame {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  opacity: 0;
  transition: opacity var(--dur-slow) var(--ease);
}

.game-modal__stage.is-ready .game-modal__frame {
  opacity: 1;
}

.game-modal__hint {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  margin: 0;
  padding: var(--sp-5);
  color: var(--c-ink-muted);
  font-family: var(--font-title);
  font-size: var(--fs-base);
  letter-spacing: var(--ls-base);
  text-align: center;
  pointer-events: none;
}

/* 转圈的小纸风车 */
.game-modal__hint::before {
  content: "";
  width: 26px;
  height: 26px;
  border: 2px dashed var(--c-primary-soft);
  border-radius: var(--r-pill);
  animation: game-spin 1.4s linear infinite;
}

@keyframes game-spin {
  to { rotate: 360deg }
}

/* 游戏真的加载出来后，提示自然消失 */
.game-modal__stage.is-ready .game-modal__hint {
  display: none;
}

/* ---------------------------- 3. 手机端 ---------------------------- */

@media screen and (max-width: 768px) {
  /* 手机上按钮缩成小圆贴，别挡着正文 */
  .game-fab {
    right: var(--sp-3);
    bottom: calc(var(--sp-4) + env(safe-area-inset-bottom, 0px));
    min-height: 44px;
    padding: var(--sp-2) var(--sp-3);
    font-size: var(--fs-sm);
  }

  .game-fab__emoji {
    font-size: var(--fs-base);
  }

  /* 手机上让游戏尽量占满 */
  .game-modal {
    padding: 0;
  }

  .game-modal__panel {
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }

  .game-modal__panel::before {
    display: none;
  }

  .game-modal__head {
    padding: var(--sp-2) var(--sp-3);
  }

  .game-modal__title {
    font-size: var(--fs-md);
  }
}

@media (prefers-reduced-motion: reduce) {
  .game-modal__scrim,
  .game-modal__panel {
    animation: none;
  }

  .game-modal__hint::before {
    animation: none;
  }
}
