/* 拾光群岛：基础样式与通用组件。小游戏的样式放在 css/games/<id>.css。 */

:root {
  --paper: #fffaf0;
  --paper-2: #f6ecd8;
  --paper-3: #efe0c4;
  --ink: #3d2f27;
  --ink-soft: #6d5a4c;
  --ink-faint: #9c8a7a;
  --line: #e3cfae;
  --accent: #f08c2e;
  --accent-deep: #c9661a;
  --gold: #ffcf4d;
  --gold-soft: #fff1c2;
  --teal: #2c8c7f;
  --teal-soft: #d8f0ea;
  --sky: #5aa9e6;
  --rose: #ef7f8f;
  --leaf: #5fae62;
  --leaf-soft: #e1f3dc;
  --fog: #aeb4bf;
  --night: #1d2442;
  --danger: #e0645a;
  --radius: 18px;
  --radius-sm: 12px;
  --shadow: 0 8px 22px rgba(80, 50, 20, 0.18);
  --shadow-sm: 0 3px 10px rgba(80, 50, 20, 0.14);
  --font-ui: "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans SC", system-ui, sans-serif;
  --font-story: "LXGW WenKai", "Kaiti SC", "STKaiti", "KaiTi", "楷体", "Songti SC", serif;
  --font-en: "Nunito", "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --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);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #2a2420;
  color: var(--ink);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
  touch-action: manipulation;
}

body { user-select: none; -webkit-user-select: none; }

img { -webkit-user-drag: none; user-select: none; }

button { font-family: inherit; color: inherit; }

.app {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

.scene {
  position: absolute;
  inset: 0;
  overflow: hidden;
  animation: scene-in 0.45s ease both;
}
.scene.leaving { animation: scene-out 0.3s ease both; pointer-events: none; }

@keyframes scene-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes scene-out { from { opacity: 1; } to { opacity: 0; } }

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

/* ---------------------------------------------------------------- 按钮 */

.btn {
  appearance: none;
  border: 0;
  border-radius: 999px;
  padding: 0.7em 1.5em;
  min-height: 48px;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 4px 0 var(--paper-3), var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4em;
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--paper-3), var(--shadow-sm); }
.btn:focus-visible { outline: 3px solid var(--sky); outline-offset: 3px; }
.btn[disabled] { filter: grayscale(0.6) opacity(0.6); cursor: default; }
.btn-primary { background: linear-gradient(180deg, #ffb35c, var(--accent)); color: #fff; box-shadow: 0 4px 0 var(--accent-deep), var(--shadow-sm); text-shadow: 0 1px 1px rgba(120, 60, 0, 0.35); }
.btn-primary:active { box-shadow: 0 1px 0 var(--accent-deep), var(--shadow-sm); }
.btn-teal { background: linear-gradient(180deg, #4fb3a5, var(--teal)); color: #fff; box-shadow: 0 4px 0 #1d6b60, var(--shadow-sm); }
.btn-teal:active { box-shadow: 0 1px 0 #1d6b60, var(--shadow-sm); }
.btn-lg { font-size: 1.25rem; padding: 0.8em 2em; min-height: 58px; }
.btn-sm { font-size: 0.92rem; padding: 0.45em 1em; min-height: 40px; }

.icon-btn {
  appearance: none;
  border: 0;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: rgba(255, 250, 240, 0.92);
  box-shadow: var(--shadow-sm);
  font-size: 1.35rem;
  line-height: 1;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.12s ease;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn:focus-visible { outline: 3px solid var(--sky); outline-offset: 2px; }

/* ---------------------------------------------------------------- 纸面卡片 */

.paper {
  background:
    radial-gradient(120% 80% at 20% 0%, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0) 60%),
    linear-gradient(180deg, var(--paper), var(--paper-2));
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.3em 0.8em;
  border-radius: 999px;
  background: rgba(255, 250, 240, 0.92);
  box-shadow: var(--shadow-sm);
  font-weight: 700;
  font-size: 0.95rem;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- 顶部状态栏 */

.hud {
  position: absolute;
  top: calc(10px + var(--safe-top));
  left: calc(10px + var(--safe-left));
  right: calc(10px + var(--safe-right));
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 40;
  pointer-events: none;
}
.hud > * { pointer-events: auto; }
.hud .spacer { flex: 1; pointer-events: none; }
.hud-player { display: flex; align-items: center; gap: 6px; padding: 4px 12px 4px 4px; }
.hud-player img { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; object-position: top; background: var(--gold-soft); }
.hud-light .num, .hud-coins .num { font-variant-numeric: tabular-nums; }
.hud-light.bump, .hud-coins.bump { animation: bump 0.45s ease; }
@keyframes bump { 0% { transform: scale(1); } 40% { transform: scale(1.25); } 100% { transform: scale(1); } }

/* ---------------------------------------------------------------- 对话气泡 */

.bubble {
  position: relative;
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: 20px;
  padding: 14px 18px;
  box-shadow: var(--shadow);
  font-size: 1.12rem;
  line-height: 1.65;
  color: var(--ink);
}
.bubble .who {
  position: absolute;
  top: -14px;
  left: 16px;
  padding: 2px 12px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 800;
  background: var(--accent);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.bubble .who.fox { background: var(--accent); }
.bubble .who.npc { background: var(--teal); }
.bubble .who.fog { background: #8a90a0; }
.bubble .more {
  position: absolute;
  right: 14px;
  bottom: 6px;
  font-size: 0.85rem;
  color: var(--ink-faint);
  animation: blink 1.2s ease-in-out infinite;
}
@keyframes blink { 50% { opacity: 0.2; } }

.bubble > .say-btn {
  position: absolute;
  top: 8px;
  right: 10px;
  margin: 0;
}
.bubble:has(> .say-btn:not([hidden])) { padding-right: 58px; }

.say-btn {
  appearance: none;
  border: 0;
  background: var(--gold-soft);
  border-radius: 999px;
  padding: 2px 10px;
  margin-left: 6px;
  font-size: 0.95rem;
  cursor: pointer;
  vertical-align: middle;
}

/* ---------------------------------------------------------------- 弹层 */

.modal {
  position: absolute;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(16px + var(--safe-top)) 16px calc(16px + var(--safe-bottom));
  background: rgba(30, 22, 15, 0.45);
  backdrop-filter: blur(3px);
  animation: scene-in 0.25s ease both;
}
.modal-card {
  width: min(560px, 100%);
  max-height: 100%;
  overflow: auto;
  padding: 22px 22px 18px;
  animation: pop-in 0.35s cubic-bezier(0.2, 1.4, 0.4, 1) both;
}
.modal-card h2 { margin: 0 0 12px; font-family: var(--font-story); font-size: 1.6rem; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 16px; }
@keyframes pop-in { from { opacity: 0; transform: scale(0.85) translateY(10px); } to { opacity: 1; transform: none; } }

.toast {
  position: absolute;
  left: 50%;
  top: calc(70px + var(--safe-top));
  transform: translateX(-50%);
  z-index: 90;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(40, 30, 22, 0.88);
  color: #fff;
  font-weight: 700;
  box-shadow: var(--shadow);
  animation: toast 2.6s ease both;
  pointer-events: none;
  max-width: 90vw;
  text-align: center;
}
@keyframes toast { 0% { opacity: 0; transform: translate(-50%, -8px); } 10%, 85% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }

/* ---------------------------------------------------------------- 光点粒子 */

.light-dot {
  position: fixed;
  z-index: 95;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border-radius: 50%;
  background: radial-gradient(circle, #fff 0 25%, var(--gold) 45%, rgba(255, 207, 77, 0) 72%);
  box-shadow: 0 0 14px 6px rgba(255, 207, 77, 0.65);
  pointer-events: none;
  transition: transform 0.9s cubic-bezier(0.45, 0, 0.2, 1), opacity 0.9s ease;
}

.confetti {
  position: fixed;
  z-index: 96;
  width: 10px;
  height: 14px;
  border-radius: 3px;
  pointer-events: none;
  animation: confetti 1.6s ease-out forwards;
}
@keyframes confetti {
  0% { transform: translate(0, 0) rotate(0); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) rotate(var(--rot)); opacity: 0; }
}

.shake { animation: shake 0.45s ease; }
@keyframes shake {
  20% { transform: translateX(-8px); }
  40% { transform: translateX(7px); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(3px); }
}

.float-y { animation: float-y 3.2s ease-in-out infinite; }
@keyframes float-y { 50% { transform: translateY(-8px); } }

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: #fff;
  font-size: 1.1rem;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}
.loading .lantern { font-size: 3rem; animation: float-y 1.6s ease-in-out infinite; }

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