/* 单词会咬人 — 像素风打宝（产品版） */
:root {
  --bg: #1a1c2c;
  --bg2: #33357a;
  --ink: #f4f4f4;
  --dim: #9ba0b8;
  --gold: #ffd23f;
  --common: #c8cbcd;
  --rare: #58c470;
  --epic: #4d9be6;
  --legend: #ffaa5f;
  --blood: #b13e53;
  --stone: #566c86;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background:
    radial-gradient(ellipse at 50% -20%, var(--bg2), transparent 60%),
    var(--bg);
  color: var(--ink);
  font-family: "Hiragino Sans", "Yu Gothic", "PingFang SC", ui-sans-serif, monospace;
  min-height: 100vh;
  min-height: 100dvh; /* iOS 工具栏遮挡问题，dvh 优先 */
  overscroll-behavior-y: contain; /* 独立 PWA 里防下拉刷新打断战斗 */
  display: flex;
  justify-content: center;
}

#app { width: min(560px, 100vw); padding: 16px 14px 48px; padding-top: max(16px, env(safe-area-inset-top)); display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.screen { display: flex; flex-direction: column; align-items: center; gap: 14px; }
/* 战斗屏锁在视口内：解释区占满剩余空间而不把页面撑出滚动 */
#screen-battle { height: calc(100dvh - 48px - max(16px, env(safe-area-inset-top))); overflow: hidden; }
.hidden { display: none !important; }

/* ---------- 顶栏 ---------- */
.top { display: flex; align-items: baseline; gap: 10px; margin-top: 10px; }
.game-title { font-size: 30px; letter-spacing: 5px; text-shadow: 3px 3px 0 #000; }
.tagline { color: var(--dim); letter-spacing: 3px; font-size: 13px; }

/* ---------- 城镇 ---------- */
.town-wrap { position: relative; width: 100%; border: 3px solid var(--stone); background: #12131f; }
.town-wrap canvas { display: block; }
.npc-bubble {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  max-width: 92%; padding: 8px 12px; font-size: 13px; line-height: 1.5;
  background: #000; border: 2px solid var(--gold); color: var(--gold);
}
.village-stats { font-size: 12px; color: var(--dim); letter-spacing: 1px; }
.deck-status { font-size: 12px; color: var(--dim); min-height: 16px; text-align: center; }

/* ---------- 区域卡 ---------- */
.region-grid { width: 100%; display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.region-card {
  font: inherit; color: var(--ink); text-align: left; cursor: pointer;
  border: 3px solid var(--skin-accent, var(--stone)); background: #12131f;
  padding: 10px 12px; display: flex; flex-direction: column; gap: 4px;
}
.region-card:disabled { cursor: default; opacity: .45; }
.region-card:not(:disabled):active { transform: translateY(2px); }
.region-name { font-size: 15px; font-weight: 700; letter-spacing: 1px; }
.region-sub { font-size: 11px; color: var(--dim); }
.region-meta { font-size: 11px; color: var(--skin-accent, var(--dim)); }
.skin-cave { --skin-accent: #58c470; }
.skin-mega { --skin-accent: #4dd0e1; }
.skin-map { --skin-accent: #d9a660; }
.skin-forest { --skin-accent: #7ac74f; }
.skin-hall { --skin-accent: #9b8cff; }
.region-card.locked { border-style: dashed; }

/* ---------- 设置 ---------- */
.settings { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; justify-content: center; font-size: 13px; color: var(--dim); }
.settings label { display: flex; align-items: center; gap: 4px; cursor: pointer; }

/* ---------- 按钮 ---------- */
.btn {
  font: inherit; font-size: 16px; letter-spacing: 2px;
  color: var(--ink); background: var(--stone);
  border: 0; outline: 3px solid #000;
  padding: 12px 26px; cursor: pointer;
  box-shadow: inset -3px -3px 0 rgba(0,0,0,.35), inset 3px 3px 0 rgba(255,255,255,.18);
}
.btn:active { transform: translateY(2px); }
.btn:disabled { opacity: .4; cursor: default; }
.btn-primary { background: var(--blood); }
.btn-kill { background: #2e7d46; }
.btn-spare { background: #6b6f8a; }
.btn-mini { font-size: 11px; padding: 6px 10px; letter-spacing: 1px; }
.hint { font-size: 11px; color: var(--dim); text-align: center; line-height: 1.6; }

/* ---------- HUD ---------- */
.hud { width: 100%; display: flex; justify-content: space-between; gap: 8px; font-size: 12px; letter-spacing: 1px; color: var(--dim); }
#hud-combo.hot { color: var(--gold); }

/* ---------- 洞窟（区域皮肤染色） ---------- */
.cave {
  position: relative; width: 100%; min-height: 300px;
  border: 3px solid var(--stone);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  overflow: hidden; padding: 18px 14px;
}
.cave.skin-cave { background: linear-gradient(#101122, #1d2a1f 70%, #2b3a26); }
.cave.skin-mega { background: linear-gradient(#060a12, #0d1b26 70%, #123040); }
.cave.skin-map { background: linear-gradient(#1c150c, #2e2413 70%, #453417); }
.cave.skin-forest { background: linear-gradient(#0b140c, #142614 70%, #1d3a1d); }
.cave.skin-hall { background: linear-gradient(#120f1e, #1e1838 70%, #2c2350); }

/* 怪物 sprite：Kenney Tiny Dungeon 图集裁切（CC0） */
.msprite {
  position: relative;
  width: 48px; height: 48px;
  background-image: url(/assets/dungeon.png);
  background-size: 576px 528px;
  background-repeat: no-repeat;
  image-rendering: pixelated;
  animation: bob 1.6s ease-in-out infinite;
  filter: drop-shadow(0 5px 0 rgba(0,0,0,.4));
}
.msprite.boss { width: 64px; height: 64px; background-size: 768px 704px; animation-duration: 1s; }

.msprite.hurt { animation: hurt .28s steps(2) 1; filter: brightness(2) saturate(0); }
@keyframes hurt { 25% { transform: translateX(-8px); } 75% { transform: translateX(8px); } }
.msprite.dead { animation: die .4s steps(3) forwards; }
@keyframes die { to { transform: translateY(24px) scaleY(.2); opacity: 0; } }
.msprite.flee { animation: flee .45s steps(4) forwards; }
@keyframes flee { to { transform: translateX(220px); opacity: 0; } }

.boss-crown {
  position: absolute; top: -4px; left: 50%; transform: translateX(-50%);
  width: 0; height: 0; z-index: 2;
  border-left: 14px solid transparent; border-right: 14px solid transparent;
  border-bottom: 18px solid var(--gold);
  filter: drop-shadow(0 0 6px var(--gold));
}

.monster { display: flex; flex-direction: column; align-items: center; position: relative; }
.monster-word {
  margin-top: 14px; font-size: 28px; font-weight: 700; letter-spacing: 2px;
  text-shadow: 2px 2px 0 #000; text-align: center; max-width: 100%; word-break: break-all;
}
.monster-word.long { font-size: 15px; line-height: 1.5; letter-spacing: 0; }
.hp { width: 160px; height: 10px; margin-top: 10px; background: #000; outline: 2px solid var(--stone); }
.hp i { display: block; height: 100%; width: 100%; background: var(--blood); transition: width .25s steps(4); }
.dmg-num {
  position: absolute; top: -6px; right: -30px;
  font-size: 22px; font-weight: 700; color: var(--gold);
  text-shadow: 2px 2px 0 #000; animation: floatup .7s ease-out forwards; pointer-events: none;
}
@keyframes floatup { from { transform: translateY(0); opacity: 1; } to { transform: translateY(-30px); opacity: 0; } }

/* 揭示面板 */
.reveal {
  position: absolute; inset: 0; background: rgba(10,11,22,.94);
  padding: 20px 18px; display: flex; flex-direction: column; gap: 10px;
  justify-content: safe center; overflow-y: auto;
}
.reveal-front { font-size: 14px; color: var(--dim); }
.reveal-back { font-size: 16px; line-height: 1.6; white-space: pre-wrap; }
.reveal-meta { font-size: 12px; color: var(--dim); display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.btn-replay { align-self: flex-start; }
.accent-bar { display: inline-flex; align-items: flex-end; gap: 2px; height: 18px; }
.accent-bar i { width: 6px; background: var(--gold); }

/* 解释区：占下半剩余空间，完整释义自适应字号，通常无需滚动 */
.recall {
  flex: 1; min-height: 0; width: 100%;
  overflow: hidden;
  border-top: 1px dashed var(--stone);
  display: flex;
}
.recall-body {
  margin: auto; padding: 10px 16px 14px;
  white-space: pre-wrap; line-height: 1.6; font-size: 16px;
  max-height: 100%;
}


/* 掉落弹窗 */
.loot-pop {
  position: absolute; right: 12px; top: 12px; left: 12px;
  padding: 8px 12px; font-size: 13px; letter-spacing: 1px;
  background: #000; border: 2px solid var(--rare);
  animation: pop .35s steps(4); text-align: center;
}
@keyframes pop { 0% { transform: scale(.4); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
.loot-pop.common { border-color: var(--common); color: var(--common); }
.loot-pop.rare { border-color: var(--rare); color: var(--rare); }
.loot-pop.epic { border-color: var(--epic); color: var(--epic); }
.loot-pop.legend { border-color: var(--legend); color: var(--legend); }

.actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.judge-group { display: flex; gap: 12px; }

/* ---------- 结算 ---------- */
.result-title { font-size: 26px; letter-spacing: 4px; text-shadow: 2px 2px 0 #000; margin-top: 14px; }
.result-region { font-size: 12px; color: var(--dim); letter-spacing: 2px; }
.result-stats { font-size: 14px; color: var(--dim); display: flex; gap: 18px; }
.result-town-note { font-size: 12px; color: var(--gold); padding: 6px 10px; }
.result-loot {
  width: 100%; display: flex; flex-direction: column; gap: 6px;
  max-height: 200px; overflow-y: auto;
}
.loot-line {
  display: flex; justify-content: space-between; gap: 10px; font-size: 13px;
  padding: 6px 10px; background: #12131f; border-left: 4px solid var(--common);
}
.loot-line.rare { border-color: var(--rare); color: var(--rare); }
.loot-line.epic { border-color: var(--epic); color: var(--epic); }
.loot-line.legend { border-color: var(--legend); color: var(--legend); }
.loot-line.dead { color: var(--dim); border-color: var(--dim); opacity: .7; }

/* 掉落稀有度图标（Kenney Tiny Dungeon 图集裁切） */
.li {
  display: inline-block; width: 24px; height: 24px;
  background-image: url(/assets/dungeon.png);
  background-size: 288px 264px;
  background-repeat: no-repeat;
  image-rendering: pixelated;
  vertical-align: -7px;
  margin-right: 6px;
}
.li-common { background-position: -120px -216px; } /* 113 灰药水 */
.li-rare { background-position: -192px -192px; }   /* 104 剑 */
.li-epic { background-position: -192px -216px; }   /* 116 蓝药水 */
.li-legend { background-position: -192px -168px; } /* 92 打开的宝箱 */

@media (max-width: 480px) {
  .game-title { font-size: 24px; }
  .region-grid { grid-template-columns: 1fr; }
  .btn { width: 100%; }
  .judge-group { width: 100%; }
  .judge-group .btn { width: 50%; }
}

/* 触屏：键盘提示隐藏，小按钮和复选框放大到可点尺寸 */
@media (pointer: coarse) {
  .kbd-only { display: none; }
  .btn-mini { padding: 10px 14px; }
  .settings input[type="checkbox"] { width: 18px; height: 18px; }
}

/* 精确指针（鼠标）隐藏触屏提示 */
@media (pointer: fine) {
  .touch-only { display: none; }
}

/* ---------- API 密钥 ---------- */
.api-keys { margin: 12px auto 0; max-width: 420px; font-size: 13px; color: var(--dim); }
.api-keys summary { cursor: pointer; text-align: center; }
.api-keys-body { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.api-keys-new { display: flex; gap: 6px; }
.api-keys-new input {
  flex: 1; min-width: 0;
  background: var(--bg); border: 2px solid var(--stone); color: var(--ink);
  /* 16px 下限：iOS Safari 聚焦小字号输入框会自动缩放整页 */
  padding: 8px 10px; font-size: 16px; outline: none;
}
.api-keys-new input:focus { border-color: var(--gold); }
.api-keys-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.api-keys-list li { display: flex; align-items: center; gap: 8px; }
.api-keys-list li span:first-child { flex: 1; color: var(--ink); }
.key-date { font-size: 11px; }
.key-reveal { display: flex; flex-direction: column; gap: 6px; padding: 8px; border: 2px solid var(--stone); }
.key-once { font-size: 12px; margin: 0; }
.key-reveal code { word-break: break-all; font-size: 11px; color: var(--ink); }
.key-reveal-actions { display: flex; gap: 6px; }

/* ---------- 登录 ---------- */
.auth-box {
  display: flex; flex-direction: column; gap: 12px;
  width: min(340px, 88vw); margin-top: 8vh;
  border: 3px solid var(--stone); background: #12131f;
  padding: 22px 20px;
}
.auth-title { font-size: 16px; letter-spacing: 2px; color: var(--gold); }
.auth-box input {
  background: var(--bg); border: 2px solid var(--stone); color: var(--ink);
  /* 16px 是下限：iOS Safari 聚焦小于 16px 的输入框会自动缩放整页（见 ios-input-zoom-fix） */
  padding: 10px 12px; font-size: 16px; outline: none;
}
.auth-box input:focus { border-color: var(--gold); }
.auth-invite { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--dim); }
.auth-error { color: var(--blood); font-size: 13px; min-height: 1em; }
