* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-user-select: none;
  user-select: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #05060a;
  font-family: "Trebuchet MS", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #f2f2f2;
}

#game-container { position: relative; width: 100vw; height: 100vh; }

#game {
  display: block;
  width: 100%;
  height: 100%;
  background: #0b0f1a;
  cursor: crosshair;
}

/* ---------- 稀有度配色 ---------- */
:root {
  --r-common: #b8c0cc;
  --r-uncommon: #4ade80;
  --r-rare: #38bdf8;
  --r-epic: #c084fc;
  --r-legendary: #fbbf24;
}
.rar-common    { color: var(--r-common); }
.rar-uncommon  { color: var(--r-uncommon); }
.rar-rare      { color: var(--r-rare); }
.rar-epic      { color: var(--r-epic); }
.rar-legendary { color: var(--r-legendary); }
.bd-common    { border-color: var(--r-common) !important; }
.bd-uncommon  { border-color: var(--r-uncommon) !important; }
.bd-rare      { border-color: var(--r-rare) !important; }
.bd-epic      { border-color: var(--r-epic) !important; }
.bd-legendary { border-color: var(--r-legendary) !important; }

/* ---------- 顶部 HUD ---------- */
#hud {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  width: min(540px, 92vw);
  display: flex;
  flex-direction: column;
  gap: 7px;
  pointer-events: none;
  z-index: 5;
}
.hud-row { width: 100%; }

.bar {
  position: relative;
  width: 100%;
  height: 20px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 10px;
  overflow: hidden;
}
.bar .fill {
  position: absolute;
  inset: 0;
  width: 100%;
  transform-origin: left center;
  transition: transform 0.15s ease-out;
}
#hp-fill { background: linear-gradient(90deg, #ff4d5e, #ff8a3d); }
.bar span {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: bold;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  letter-spacing: 0.5px;
}
.hud-stats {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 14px;
  font-size: 15px;
  font-weight: bold;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
  padding: 0 4px;
}
#diff-text { color: #7dd3fc; }
#zone-text { color: #c084fc; }
#time-text { color: #fde68a; }
#kills-text { color: #fca5a5; }
#choice-eta { color: #86efac; }
#boss-eta { color: #fb7185; }

/* ---------- Boss 血条 ---------- */
#boss-bar {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  width: min(620px, 94vw);
  z-index: 5;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: center;
}
#boss-bar.hidden { display: none; }
#boss-name {
  font-size: 13px;
  font-weight: bold;
  letter-spacing: 3px;
  color: #fca5a5;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
}
.bar.boss { height: 14px; border-color: rgba(239,68,68,0.5); }
.bar.boss .fill { background: linear-gradient(90deg, #ef4444, #f97316); }

/* ---------- 难度选择 ---------- */
.diff-select { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.diff-btn { margin-top: 4px; }
.diff-btn[data-diff="easy"] { background: linear-gradient(90deg, #4ade80, #22d3ee); }
.diff-btn[data-diff="hard"] { background: linear-gradient(90deg, #f97316, #ef4444); box-shadow: 0 6px 24px rgba(239,68,68,0.4); }
.diff-btn[data-diff="hell"] {
  background: linear-gradient(90deg, #7f1d1d, #b91c1c, #450a0a);
  color: #fecaca;
  box-shadow: 0 6px 26px rgba(185,28,28,0.6);
}

/* ---------- 拾取提示 toast ---------- */
#toast {
  position: absolute;
  top: 96px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  padding: 8px 18px;
  border-radius: 10px;
  background: rgba(10, 14, 24, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.2);
  font-size: 14px;
  font-weight: bold;
  pointer-events: none;
  white-space: nowrap;
  transition: opacity 0.3s ease;
}
#toast.hidden { opacity: 0; }

/* ---------- 装备栏 HUD ---------- */
#hand-hud {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: min(680px, 96vw);
}
#combo-tag {
  font-size: 13px;
  font-weight: bold;
  letter-spacing: 1px;
  color: #fde68a;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8);
  min-height: 16px;
}
#gear-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  width: 100%;
}
.gear-slot {
  width: 78px;
  padding: 6px 4px;
  background: rgba(10, 14, 24, 0.72);
  border: 2px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  text-align: center;
  backdrop-filter: blur(3px);
}
.gear-ico { font-size: 18px; }
.gear-label { font-size: 10px; color: #94a3b8; letter-spacing: 1px; margin-top: 1px; }
.gear-info { font-size: 11px; font-weight: bold; margin-top: 2px; line-height: 1.2; }
.gear-info.empty { color: #64748b; font-weight: normal; }

/* ---------- 覆盖层 ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(5, 6, 10, 0.86);
  backdrop-filter: blur(4px);
  text-align: center;
  padding: 24px;
  overflow-y: auto;
}
.overlay.hidden { display: none; }
.overlay h1 {
  font-size: clamp(40px, 9vw, 72px);
  letter-spacing: 6px;
  background: linear-gradient(90deg, #38bdf8, #818cf8, #f472b6);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.overlay h2 { font-size: clamp(26px, 6vw, 40px); color: #fde68a; letter-spacing: 4px; }
.subtitle { letter-spacing: 8px; font-size: 14px; color: #94a3b8; text-transform: uppercase; }
.howto { margin: 8px 0; line-height: 2; color: #cbd5e1; font-size: 15px; }
.howto b { color: #fde68a; }

.btn {
  margin-top: 8px;
  padding: 13px 38px;
  font-size: 18px;
  font-weight: bold;
  letter-spacing: 2px;
  color: #05060a;
  background: linear-gradient(90deg, #38bdf8, #818cf8);
  border: none;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.1s ease, box-shadow 0.2s ease;
  box-shadow: 0 6px 24px rgba(56, 189, 248, 0.4);
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(129, 140, 248, 0.55); }
.btn:active { transform: translateY(0); }
.btn.ghost {
  background: transparent;
  color: #cbd5e1;
  border: 2px solid rgba(255, 255, 255, 0.25);
  box-shadow: none;
}

.result { line-height: 2.1; font-size: 18px; color: #e2e8f0; }
.result span { color: #fde68a; font-weight: bold; }

/* ---------- 背包 / 装备面板 ---------- */
.inv-section-label {
  font-size: 14px;
  letter-spacing: 2px;
  color: #cbd5e1;
  width: min(720px, 94vw);
  text-align: left;
  overflow: hidden;
}
.inv-hint { font-size: 11px; color: #64748b; letter-spacing: 0; }
#inv-count { font-size: 12px; color: #94a3b8; }

#hand-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  justify-content: center;
  width: min(720px, 94vw);
}
#deck-count { font-size: 12px; color: #94a3b8; }

/* 左右两列：左背包 / 右卡组，方便拖拽 */
#inv-columns {
  display: flex;
  gap: 18px;
  align-items: flex-start;
  width: min(1040px, 96vw);
}
.inv-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.inv-col .inv-section-label,
.inv-col .inv-search-row { width: 100%; }

#equipped-row {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: 100%;
  max-height: 48vh;
  overflow-y: auto;
  padding-right: 4px;
}
#inv-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  width: 100%;
  min-height: 70px;
  max-height: 48vh;
  overflow-y: auto;
  padding-right: 4px;
}

.inv-tools { display: flex; gap: 8px; }

.inv-search-row { width: min(720px, 94vw); }
#inv-search {
  width: 100%;
  padding: 9px 14px;
  font-size: 14px;
  color: #f2f2f2;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
}
#inv-search::placeholder { color: #64748b; }
#inv-search:focus { border-color: #38bdf8; background: rgba(56, 189, 248, 0.08); }
.btn.small {
  margin-top: 0;
  padding: 5px 14px;
  font-size: 13px;
  letter-spacing: 1px;
  border-radius: 8px;
  box-shadow: none;
}
.btn.small:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(56,189,248,0.35); }

/* 统一的物品格子 */
.cell {
  position: relative;
  min-height: 64px;
  padding: 6px 5px;
  background: rgba(255, 255, 255, 0.04);
  border: 2px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.15s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.cell:hover { transform: translateY(-2px); background: rgba(129, 140, 248, 0.12); }
.cell[draggable="true"] { cursor: grab; }
.cell.dragging { opacity: 0.45; cursor: grabbing; }
.cell.drag-over {
  border-color: #fbbf24 !important;
  background: rgba(251, 191, 36, 0.18);
  box-shadow: 0 0 0 2px rgba(251, 191, 36, 0.5);
}
.cell.slot-empty { cursor: default; color: #64748b; }
.cell.slot-empty:hover { transform: none; background: rgba(255, 255, 255, 0.04); }
.cell .c-ico { font-size: 18px; }
.cell .c-slot { font-size: 9px; color: #94a3b8; letter-spacing: 1px; }
.cell .c-lv { font-size: 11px; font-weight: bold; }
.cell .c-skill { font-size: 10px; color: #fbbf24; }
.cell .c-badge {
  position: absolute;
  top: -7px;
  left: -7px;
  padding: 1px 6px;
  border-radius: 8px;
  background: #fbbf24;
  color: #1a1205;
  font-size: 9px;
  font-weight: bold;
  letter-spacing: 1px;
}
.cell .c-discard {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #ef4444;
  color: #fff;
  font-size: 12px;
  line-height: 18px;
  font-weight: bold;
  border: 1px solid rgba(0,0,0,0.3);
}
.cell .c-discard:hover { background: #f87171; }

#inv-detail {
  width: min(720px, 94vw);
  min-height: 30px;
  font-size: 13px;
  color: #cbd5e1;
  line-height: 1.7;
  padding: 6px 10px;
}
#inv-detail .d-name { font-weight: bold; font-size: 15px; }
#inv-detail .d-affix { color: #86efac; margin-right: 12px; }
#inv-detail .d-skill { color: #fbbf24; display: block; margin-top: 4px; }

.is-hidden { display: none !important; }

.icon-btn {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  z-index: 6;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: bold;
  letter-spacing: 1px;
  color: #e2e8f0;
  background: rgba(10, 14, 24, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 10px;
  cursor: pointer;
}
.icon-btn:hover { border-color: #38bdf8; color: #fff; }

.hand-timer {
  position: relative;
  width: min(440px, 86vw);
  height: 16px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  overflow: hidden;
}
#hand-fill {
  position: absolute;
  inset: 0;
  width: 100%;
  transform-origin: left center;
  background: linear-gradient(90deg, #818cf8, #fbbf24);
}
.hand-timer span {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: bold;
  letter-spacing: 1px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.diff-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 96px;
}
.diff-best {
  min-height: 14px;
  font-size: 11px;
  letter-spacing: 0;
  font-weight: 700;
  opacity: 0.9;
}
.save-note {
  font-size: 12px;
  color: #64748b;
  letter-spacing: 0;
}
.record-line {
  min-height: 24px;
  font-size: 18px;
  font-weight: bold;
  letter-spacing: 2px;
  color: #fde68a;
}

#choice-row {
  display: flex;
  gap: 14px;
  width: min(980px, 96vw);
  align-items: stretch;
}
.choice-card {
  position: relative;
  flex: 1;
  min-width: 0;
  padding: 18px 14px 16px;
  font-family: inherit;
  color: #e2e8f0;
  text-align: center;
  background: rgba(12, 16, 28, 0.94);
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-radius: 16px;
  cursor: pointer;
  appearance: none;
}
.choice-card:hover { transform: translateY(-3px); background: rgba(30, 41, 59, 0.96); }
.choice-key {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 12px;
  line-height: 22px;
  color: #cbd5e1;
}
.choice-ico { font-size: 36px; }
.choice-name { font-size: 20px; font-weight: bold; margin-top: 4px; }
.choice-meta { font-size: 12px; color: #94a3b8; margin: 4px 0 8px; }
.choice-desc { font-size: 13px; color: #cbd5e1; line-height: 1.45; min-height: 38px; }
.choice-aff { margin-top: 8px; font-size: 13px; color: #86efac; line-height: 1.5; }

#stick {
  display: none;
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(22px, env(safe-area-inset-bottom));
  width: 126px;
  height: 126px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
  border: 2px solid rgba(255, 255, 255, 0.2);
  z-index: 6;
  touch-action: none;
}
#stick-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: rgba(56, 189, 248, 0.9);
  transform: translate(-50%, -50%);
  pointer-events: none;
}
html.touch, html.touch body { touch-action: none; }
html.touch.playing #stick { display: block; }
html.touch.playing #hand-hud { bottom: 168px; }

@media (max-width: 760px) {
  #hud {
    left: 10px;
    transform: none;
    width: calc(100vw - 104px);
  }
  #hand-row { grid-template-columns: repeat(3, 1fr); }
  #inv-columns { flex-direction: column; width: min(720px, 94vw); }
  #equipped-row { grid-template-columns: repeat(4, 1fr); max-height: 28vh; }
  #inv-grid { grid-template-columns: repeat(4, 1fr); max-height: 28vh; }
  #choice-row { flex-direction: column; max-height: 62vh; overflow-y: auto; }
  .choice-card { padding: 12px 10px; }
  .howto { font-size: 14px; line-height: 1.55; }
  .overlay { gap: 8px; padding: 14px 12px 18px; }
  .overlay h1 { font-size: 44px; letter-spacing: 3px; }
  .btn { padding: 11px 22px; font-size: 16px; }
}

@media (max-height: 760px) {
  .overlay { gap: 8px; padding: 12px; }
  .overlay h1 { font-size: 40px; }
  .howto { font-size: 13px; line-height: 1.45; margin: 0; }
  .btn { padding: 10px 18px; font-size: 16px; }
}
