/* ===========================================================
   飞花令 · 水墨诗词闯关  样式表
   移动端优先，适配不同规格手机屏幕
   =========================================================== */
*,
*::before,
*::after { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --paper: #f7f4ed;
  --paper-2: #fffdf8;
  --ink: #1f1d1a;
  --ink-soft: #5a564e;
  --ink-faint: #948d80;
  --cinnabar: #a8342a;
  --cinnabar-soft: rgba(168, 52, 42, .12);
  --line: rgba(31, 29, 26, .18);
  --shadow: 0 2px 10px rgba(40, 32, 20, .07);
  --radius: 10px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: "Songti SC", "STSong", "SimSun", "Noto Serif SC", serif;
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
}

#inkBg {
  position: fixed; inset: 0; z-index: 0;
  width: 100%; height: 100%;
  pointer-events: none; opacity: .95;
}
.ink-scene { animation: inkFade 1.5s ease both; }
@keyframes inkFade { from { opacity: 0; } to { opacity: 1; } }

/* ---------------- 通用按钮 ---------------- */
.primary-btn {
  appearance: none; border: none; cursor: pointer;
  background: var(--ink); color: var(--paper-2);
  font-family: inherit; font-size: 17px; letter-spacing: 3px;
  padding: 13px 34px; border-radius: 8px; transition: transform .12s, opacity .2s;
}
.primary-btn:active { transform: scale(.97); opacity: .85; }
.primary-btn:disabled { background: #cbc3b4; cursor: default; }

.ghost-btn {
  appearance: none; cursor: pointer; background: transparent;
  border: 1px solid var(--cinnabar); color: var(--cinnabar);
  font-family: inherit; font-size: 15px; letter-spacing: 3px;
  padding: 10px 30px; border-radius: 8px; transition: background .15s, color .15s;
}
.ghost-btn:active { background: var(--cinnabar); color: #fff; }

.home-btn {
  position: fixed; top: calc(12px + var(--safe-top)); left: 12px; z-index: 60;
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--line); background: rgba(255, 253, 248, .82);
  color: var(--ink); font-size: 17px; line-height: 1; cursor: pointer;
  display: none; align-items: center; justify-content: center;
  font-family: inherit; box-shadow: var(--shadow); backdrop-filter: blur(4px);
}
.home-btn.show { display: flex; }

/* 右上角声音开关：所有界面都常驻 */
.sound-btn {
  position: fixed; top: calc(12px + var(--safe-top)); right: 12px; z-index: 60;
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--line); background: rgba(255, 253, 248, .82);
  color: var(--ink); font-size: 18px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-family: inherit; box-shadow: var(--shadow); backdrop-filter: blur(4px);
  transition: opacity .2s, color .2s;
}
.sound-btn:active { background: var(--ink); color: #fff; }
/* 简繁切换按钮：常驻右上角，紧邻声音开关 */
.lang-btn {
  position: fixed; top: calc(12px + var(--safe-top)); right: 58px; z-index: 60;
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--line); background: rgba(255, 253, 248, .82);
  color: var(--ink); font-size: 15px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-family: inherit; box-shadow: var(--shadow); backdrop-filter: blur(4px);
}
.lang-btn:active { background: var(--ink); color: #fff; }

.sound-btn.off { color: var(--ink-faint); opacity: .55; text-decoration: line-through; }
/* 自动播放被浏览器拦截时：朱红脉冲，提示「点一下就有音乐」 */
.sound-btn.pending {
  color: var(--cinnabar); border-color: var(--cinnabar);
  animation: soundPulse 1.6s ease-in-out infinite;
}
@keyframes soundPulse {
  0%, 100% { transform: scale(1); box-shadow: var(--shadow); }
  50% { transform: scale(1.12); box-shadow: 0 0 0 7px rgba(168, 52, 42, .13); }
}
.home-btn:active { background: var(--ink); color: #fff; }

/* ---------------- 游戏主界面 ---------------- */
.app[hidden] { display: none !important; }

/* 答题页：中段完全不压色，让水墨全强度透出；只在顶部 HUD 与底部进度条两条窄带局部压纸色 */
.app::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: linear-gradient(180deg,
    rgba(247, 244, 237, .88) 0%,
    rgba(247, 244, 237, .40) 6%,
    rgba(247, 244, 237, 0) 15%,
    rgba(247, 244, 237, 0) 85%,
    rgba(247, 244, 237, .38) 94%,
    rgba(247, 244, 237, .62) 100%);
}   /* 修复：display:flex 覆盖 hidden，导致切回首页透出答题页 */

.app {
  position: relative; z-index: 10;
  height: 100%; max-width: 560px; margin: 0 auto;
  display: flex; flex-direction: column;
  padding: calc(12px + var(--safe-top)) 16px calc(12px + var(--safe-bottom));
}

.hud {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 13px; color: var(--ink-soft);
  padding-bottom: 8px; border-bottom: 1px solid var(--cinnabar-soft);
  padding-left: 46px;   /* 让开左上角“返回首页”按钮 */
}
.hud .hp { letter-spacing: 2px; color: var(--cinnabar); font-size: 15px; min-width: 84px; }
.hud .hp .heart { transition: opacity .3s, transform .3s; display: inline-block; }
.hud .hp .heart.lost { opacity: .18; transform: scale(.8); }
.hud-mid { text-align: center; line-height: 1.4; }
.hud .level { color: var(--ink-faint); font-size: 12px; letter-spacing: 2px; }
.hud .combo { color: var(--cinnabar); font-size: 12px; height: 15px; }
.hud .score { font-weight: 700; color: var(--ink); font-size: 17px; min-width: 84px; text-align: right; font-variant-numeric: tabular-nums; }

.ling-area { text-align: center; padding: 14px 0 6px; position: relative; }
.ling-label { font-size: 12px; color: var(--ink-faint); letter-spacing: 5px; }
.ling-char {
  font-size: 56px; font-weight: 700; color: var(--ink); line-height: 1.1;
  margin-top: 2px; position: relative; display: inline-block;
}
.ling-char::after {
  content: ""; position: absolute; left: 50%; bottom: -5px;
  width: 34px; height: 3px; background: var(--cinnabar);
  transform: translateX(-50%); border-radius: 2px;
}
.timer { font-size: 13px; color: var(--ink-faint); margin-top: 8px; letter-spacing: 1px; font-variant-numeric: tabular-nums; }
.timer.warn { color: var(--cinnabar); font-weight: 700; }

/* 拼句区 */
.board {
  margin-top: 12px; padding: 10px;
  min-height: 76px; max-height: 30vh; overflow-y: auto;
  border: 1px dashed rgba(168, 52, 42, .3); border-radius: var(--radius);
  background: rgba(255, 253, 248, .6);
  display: flex; flex-direction: column; gap: 8px;
}
.board-row {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  min-height: 34px; padding: 4px 8px; border-radius: 6px;
  border-left: 2px dashed #d9d0bf; transition: border-color .2s, background .2s;
}
.board-row.active { border-left-color: var(--cinnabar); background: rgba(168, 52, 42, .05); }
.board-row.done { border-left-style: solid; border-left-color: var(--cinnabar); background: rgba(255, 255, 255, .55); }

.slot {
  min-width: 34px; height: 30px; padding: 0 4px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 5px; font-size: 16px;
}
.slot.empty {
  min-width: 42px; border: 1px dashed #d3cabb;
  background: rgba(255, 255, 255, .35);
  gap: 3px;
}
.slot.empty i {
  display: inline-block; width: 5px; height: 5px; border-radius: 50%;
  background: #c9c0af;
}
.slot.filled {
  border: 1px solid var(--ink); background: rgba(255, 255, 255, .9); cursor: pointer;
}
.slot.filled:active { background: var(--ink); color: #fff; }

.hint-bar {
  margin-top: 0; padding: 0 12px; max-height: 0; overflow: hidden; opacity: 0;
  border-left: 3px solid var(--cinnabar); border-radius: 0 6px 6px 0;
  background: var(--cinnabar-soft); color: var(--cinnabar);
  font-size: 14px; line-height: 1.55;
  transition: opacity .4s, max-height .4s, padding .4s, margin .4s;
}
.hint-bar.show { opacity: 1; max-height: 140px; padding: 9px 12px; margin-top: 8px; }

.actions { display: flex; gap: 10px; margin-top: 10px; }
.confirm-btn {
  flex: 1; padding: 13px;
  border: none; border-radius: 8px; cursor: pointer;
  background: var(--ink); color: #fff;
  font-family: inherit; font-size: 16px; letter-spacing: 4px;
  transition: opacity .2s, transform .12s;
}
.confirm-btn:active { transform: scale(.985); }
.confirm-btn:disabled { background: #cbc3b4; letter-spacing: 6px; }

.clear-btn {
  padding: 13px 18px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: transparent; color: var(--ink-soft);
  font-family: inherit; font-size: 14px; letter-spacing: 2px;
  transition: background .15s, color .15s, transform .12s;
}
.clear-btn:active { transform: scale(.96); background: var(--ink-soft); color: #fff; }

/* 碎片区 */
.pool {
  flex: 1; margin-top: 12px; padding-top: 4px;
  display: flex; flex-wrap: wrap; gap: 8px; align-content: flex-start;
  overflow-y: auto; justify-content: center; align-content: center;
}
.frag {
  padding: 9px 14px; font-size: 16px; cursor: pointer;
  border: 1px solid var(--ink); border-radius: 6px;
  background: rgba(255, 255, 255, .88); color: var(--ink);
  transition: transform .12s, background .15s, opacity .2s;
  box-shadow: 0 1px 3px rgba(40, 32, 20, .05);
}
.frag:active { transform: scale(.94); }
.frag.used { opacity: .25; pointer-events: none; }
.frag.wrong { animation: shake .4s; border-color: var(--cinnabar); }
@keyframes shake {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

/* 玩法说明：小字淡色，两行，不抢选项风头 */
.howto {
  text-align: center; font-size: 11.5px; line-height: 1.7;
  color: var(--ink-faint); opacity: .75; letter-spacing: .5px;
  padding: 8px 6px 2px; margin-top: 2px;
}
.howto span { display: block; }

.progress { text-align: center; font-size: 12px; color: var(--ink-faint); letter-spacing: 2px; padding-top: 8px; }

/* ---------------- 全屏层 ---------------- */
.screen {
  position: fixed; inset: 0; z-index: 40;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom));
  background: transparent;   /* 水墨背景自带上纸色，首页不再叠加一层纸，避免把画压淡 */
  text-align: center;
}
.screen[hidden] { display: none; }

.brand h1 {
  font-size: 58px; letter-spacing: 10px; font-weight: 700;
  color: var(--ink); margin-bottom: 8px;
}
.brand .sub { font-size: 14px; letter-spacing: 6px; color: var(--ink-soft); margin-bottom: 6px; }
.brand .tagline { font-size: 13px; color: var(--ink-faint); letter-spacing: 2px; margin-bottom: 10px; }
/* 「传播中国传统文化」：点睛一句，做成朱红小字 */
.brand .mission {
  font-size: 15px; color: var(--cinnabar); letter-spacing: 6px;
  margin-bottom: 30px; padding-bottom: 10px;
  border-bottom: 1px solid rgba(168, 52, 42, .25);
}
.brand { display: flex; flex-direction: column; align-items: center; }
/* 文字外发光：压住背后的墨色提高对比，又不会形成可见的圆形色块 */
.brand h1, .brand .sub, .brand .tagline, .start-foot, .hud, .progress {
  text-shadow: 0 1px 10px rgba(247, 244, 237, .95), 0 0 22px rgba(247, 244, 237, .8);
}
.brand .primary-btn { margin-bottom: 14px; }
.start-foot { position: absolute; bottom: calc(20px + var(--safe-bottom)); font-size: 12px; color: var(--ink-faint); }
/* 浏览器拦截自动播放时的提示：告诉用户点一下就有音乐 */
.audio-hint {
  position: absolute; bottom: calc(52px + var(--safe-bottom));
  font-size: 13px; color: var(--cinnabar); letter-spacing: 1px;
  padding: 7px 16px; border-radius: 999px;
  border: 1px solid rgba(168, 52, 42, .3); background: rgba(255, 253, 248, .8);
  animation: soundPulse 2s ease-in-out infinite;
}
.audio-hint[hidden] { display: none; }

.levelselect h2 { font-size: 24px; letter-spacing: 6px; font-weight: 400; margin-bottom: 22px; }
.level-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
  width: 100%; max-width: 420px; margin-bottom: 26px;
}
.level-cell {
  aspect-ratio: 1 / 1; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: rgba(255, 253, 248, .8);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-family: inherit; color: var(--ink); transition: transform .12s, border-color .2s;
}
.level-cell:active { transform: scale(.95); border-color: var(--cinnabar); }
.level-cell .num { font-size: 20px; }
.level-cell .ling { font-size: 12px; color: var(--ink-faint); letter-spacing: 1px; }
.level-cell.locked { opacity: .4; pointer-events: none; }

/* 典故小卡 / 结算 */
.overlay {
  position: fixed; inset: 0; z-index: 70;
  display: flex; align-items: center; justify-content: center;
  padding: calc(24px + var(--safe-top)) 22px calc(24px + var(--safe-bottom));
  background: rgba(31, 29, 26, .22); backdrop-filter: blur(2px);
  animation: fadeIn .25s;
}
.overlay[hidden] { display: none; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.card {
  width: 100%; max-width: 400px; max-height: 86vh; overflow-y: auto;
  background: var(--paper-2); border-radius: 14px; box-shadow: 0 12px 40px rgba(30, 24, 16, .22);
  padding: 30px 26px; text-align: center;
  animation: popIn .28s cubic-bezier(.2, .9, .3, 1.3);
}
@keyframes popIn { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.card-source { font-size: 12px; color: var(--ink-faint); letter-spacing: 1px; margin-bottom: 14px; }
.card-poem { font-size: 21px; line-height: 1.9; color: var(--ink); margin-bottom: 16px; }
.card-pinyin {
  font-family: "Times New Roman", Georgia, serif;
  font-size: 13px; line-height: 1.7; letter-spacing: .5px;
  color: var(--ink-faint); padding: 0 6px; margin: -8px 0 12px;
}
.card-notes { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.py-chip {
  font-size: 12.5px; line-height: 1.5; text-align: left;
  padding: 7px 10px; border-radius: 8px;
  border: 1px solid rgba(168, 52, 42, .22); background: rgba(255, 255, 255, .6);
  color: var(--ink-soft);
}
.py-chip b { color: var(--cinnabar); font-size: 14px; margin-right: 2px; }
.py-chip em { display: block; font-style: normal; color: var(--ink-faint); margin-top: 2px; }

.card-poem .ling-mark { font-style: normal; color: var(--cinnabar); font-weight: 700; }

.card-explain {
  font-size: 14px; line-height: 1.75; color: var(--ink-soft);
  padding: 10px 14px; border-radius: 8px; background: rgba(43, 43, 40, .05);
  margin-bottom: 12px; text-align: left;
}
.card-note {
  font-size: 14px; line-height: 1.7; color: var(--cinnabar);
  padding: 10px 14px; border-radius: 8px; background: var(--cinnabar-soft);
  margin-bottom: 14px;
}
.card-story { font-size: 13.5px; line-height: 1.75; color: var(--ink-soft); margin-bottom: 24px; }

.result-card h2 { font-size: 24px; letter-spacing: 4px; font-weight: 400; margin-bottom: 14px; }
.stars { font-size: 34px; letter-spacing: 8px; color: #cfc6b5; margin-bottom: 18px; }
.stars .on { color: var(--cinnabar); }
.result-stat .heal-note { color: var(--cinnabar); font-size: 13px; }
.result-stat { font-size: 14px; line-height: 1.9; color: var(--ink-soft); margin-bottom: 24px; font-variant-numeric: tabular-nums; }
.result-btns { display: flex; flex-direction: column; gap: 10px; align-items: center; }

/* Toast */
.toast {
  /* 位置由居中改为靠上，落在 HUD 与「令」字之间的空隙里：
     既不压典故小卡的「释义」，也不挡正在看的令字 */
  position: fixed; left: 50%; top: calc(8% + var(--safe-top)); z-index: 90;
  transform: translate(-50%, -50%) scale(.94);
  padding: 11px 26px; border-radius: 10px; max-width: 78%;
  background: rgba(31, 29, 26, .58); color: rgba(255, 255, 255, .88);
  font-size: 16px; text-align: center; letter-spacing: 1px;
  backdrop-filter: blur(3px);
  opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
/* 判对：淡朱红 + 半透明，文字也相应减淡，不抢释义的注意力 */
.toast.correct { background: rgba(168, 52, 42, .42); color: rgba(255, 252, 248, .92); }
.toast.wrong { background: rgba(58, 54, 48, .48); color: rgba(255, 255, 255, .86); }

/* 飞花特效 */
.petal-layer { position: fixed; inset: 0; z-index: 65; pointer-events: none; overflow: hidden; }
.petal {
  position: absolute; top: -24px; width: 11px; height: 11px;
  background: var(--cinnabar); opacity: .72;
  border-radius: 50% 0 50% 50%; transform: rotate(45deg);
  animation: petalFall linear forwards;
}
/* 连击奖励：金红双色花瓣 + 放大，形成明显庆祝感 */
.petal.gold { background: #c9971f; opacity: .85; width: 14px; height: 14px; }
@keyframes petalFall {
  0% { transform: translateY(0) rotate(0) scale(1); opacity: .85; }
  100% { transform: translateY(112vh) rotate(420deg) scale(.6); opacity: 0; }
}

/* 五连击奖励：金笺印纹 + 飞花字样 + 补血提示 */
.combo-burst {
  position: fixed; inset: 0; z-index: 88; pointer-events: none;
  display: grid; place-items: center;
  background: radial-gradient(circle at 50% 47%, rgba(201, 151, 31, .14), rgba(201, 151, 31, 0) 43%);
}
.combo-burst[hidden] { display: none; }
.combo-burst-card {
  width: min(78vw, 340px); padding: 24px 22px 21px;
  border: 1px solid rgba(169, 120, 36, .52); border-radius: 18px;
  background:
    linear-gradient(135deg, rgba(255, 253, 247, .96), rgba(247, 238, 217, .93)),
    repeating-linear-gradient(45deg, rgba(176, 132, 48, .08) 0 2px, transparent 2px 8px);
  box-shadow: 0 18px 58px rgba(66, 48, 19, .20), inset 0 0 0 5px rgba(201, 151, 31, .07);
  text-align: center; color: var(--ink);
  opacity: 0; transform: scale(.76) rotate(-2deg);
}
.combo-burst.show .combo-burst-card { animation: comboBurstIn 2.55s cubic-bezier(.19, 1, .22, 1) both; }
.combo-burst-seal {
  display: inline-block; padding: 3px 12px 4px; margin-bottom: 6px;
  border: 1px solid rgba(168, 52, 42, .72); border-radius: 999px;
  color: var(--cinnabar); font-size: 12px; letter-spacing: 4px;
}
.combo-burst-main { line-height: 1; white-space: nowrap; }
.combo-burst-main b { color: #9a6c1f; font-size: clamp(48px, 15vw, 64px); font-weight: 700; letter-spacing: 2px; }
.combo-burst-main span { margin-left: 7px; color: var(--ink); font-size: 21px; letter-spacing: 5px; }
.combo-burst-rule { width: 62px; height: 1px; margin: 12px auto 9px; background: linear-gradient(90deg, transparent, #b8892f, transparent); }
.combo-burst-reward { color: var(--cinnabar); font-size: 15px; letter-spacing: 2px; }
@keyframes comboBurstIn {
  0% { opacity: 0; transform: scale(.76) rotate(-2deg); }
  12% { opacity: 1; transform: scale(1.06) rotate(.7deg); }
  22% { transform: scale(1) rotate(0); }
  76% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: translateY(-18px) scale(.98); }
}

@media (prefers-reduced-motion: reduce) {
  .combo-burst.show .combo-burst-card { animation-duration: 1.2s; }
  .petal { animation-duration: 1.2s !important; }
}

@media (max-height: 680px) {
  .ling-char { font-size: 46px; }
  .ling-area { padding: 8px 0 4px; }
  .brand h1 { font-size: 46px; }
}
@media (min-width: 620px) {
  .app { padding-left: 24px; padding-right: 24px; }
}
