:root { --ink: #171423; --paper: #e9e2d2; --gold: #d9c9a3; }
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: #07060a; overflow: hidden;
  color: #e9eef2;
  font-family: "Microsoft YaHei", "PingFang SC", SimSun, sans-serif;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
}
body { display: grid; place-items: center; }

/* 16:9 舞台，随屏幕自适应（横竖屏都能用） */
#app {
  position: relative;
  width: min(100vw, 177.78vh);
  height: min(56.25vw, 100vh);
  background: #0b0a10;
  overflow: hidden;
}
#cv {
  width: 100%; height: 100%; display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

/* ---------------- HUD ---------------- */
#hud {
  position: absolute; left: 1.6%; top: 2.4%; right: 1.6%;
  display: flex; align-items: center; gap: 1.2%;
  pointer-events: none;
}
.bar { position: relative; height: 4.6%; min-height: 10px; width: 34%; max-width: 260px; border: 1px solid var(--ink); background: #241f2e; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; width: 100%; background: #b3312a; transition: width .12s linear; }
.bar.xp { height: 2.6%; min-height: 6px; width: 27%; max-width: 200px; }
.bar.xp i { width: 0%; background: #5f8fae; }
.bar span { position: absolute; inset: 0; display: grid; place-items: center; font-size: clamp(9px, 1.3vw, 13px); color: #f2e6cf; text-shadow: 1px 1px 0 var(--ink); }
.meta { margin-left: auto; display: flex; gap: 3vw; font-size: clamp(11px, 1.6vw, 16px); color: var(--gold); text-shadow: 1px 1px 0 var(--ink); }

/* ---------------- 加载 ---------------- */
#loading {
  position: absolute; inset: 0; display: grid; place-content: center; gap: 1.4vh;
  background: radial-gradient(60% 60% at 50% 42%, #1a1626 0%, #0b0a10 100%);
  text-align: center;
}
#loading .logo { font-size: clamp(28px, 5vw, 54px); letter-spacing: .4em; color: var(--gold); text-shadow: 3px 3px 0 var(--ink); }
#loading .tip { font-size: clamp(11px, 1.4vw, 15px); color: #8e83a0; letter-spacing: .2em; }
#loading .progress { width: min(52vw, 360px); height: 8px; border: 1px solid var(--ink); background: #241f2e; margin: 1vh auto 0; }
#loading .progress i { display: block; height: 100%; width: 0%; background: var(--gold); transition: width .1s linear; }
#loading .loadtext { font-size: 12px; color: #6f6684; }

/* ---------------- 对话框 ---------------- */
#dialog {
  position: absolute; left: 50%; bottom: 4%; transform: translateX(-50%);
  width: min(92%, 900px); display: flex; align-items: flex-end; cursor: pointer;
}
#dialog .portrait img { width: clamp(56px, 11vw, 150px); display: block; image-rendering: pixelated; }
#dialog .box {
  position: relative; flex: 1; background: var(--paper); color: #241d2b;
  border: 2px solid var(--ink); box-shadow: inset 0 0 0 3px #c9bda3, 0 8px 0 rgba(0,0,0,.35);
  padding: 2.2vh 2.4vw 2vh;
}
#dialog .name {
  position: absolute; left: 14px; top: -1.9em; background: #241d2b; color: #f2e6cf;
  padding: .18em .8em; border: 1px solid var(--ink); font-size: clamp(12px, 1.5vw, 17px); letter-spacing: .1em;
}
#dialog p { margin: .2em 0 0; font-size: clamp(13px, 1.9vw, 22px); line-height: 1.6; }
#dialog .hint { position: absolute; right: 12px; bottom: 6px; font-size: clamp(10px, 1.1vw, 13px); color: #7d6f5a; }

/* ---------------- 顿悟卡 ---------------- */
#cards {
  position: absolute; inset: 0; background: rgba(8, 6, 14, .78);
  display: grid; grid-template-rows: auto 1fr auto; place-items: center; padding: 4vh 0;
}
#cards .cardsTitle { font-size: clamp(20px, 3vw, 34px); letter-spacing: .5em; color: var(--gold); text-shadow: 2px 2px 0 var(--ink); }
#cards .cardsRow { display: flex; gap: 2.2vw; align-items: center; }
#cards .card {
  width: clamp(110px, 17vw, 220px); min-height: clamp(150px, 30vh, 280px);
  background: var(--paper); border: 3px solid var(--ink);
  box-shadow: inset 0 0 0 4px #c9bda3, 0 10px 0 rgba(0,0,0,.4);
  color: #241d2b; display: grid; grid-template-rows: auto 1fr auto; padding: 14px 12px; cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease;
}
#cards .card:hover { transform: translateY(-6px); box-shadow: inset 0 0 0 4px #c9bda3, 0 16px 0 rgba(0,0,0,.4); }
#cards .card .t { font-size: clamp(15px, 2vw, 24px); font-weight: 700; letter-spacing: .08em; }
#cards .card .d { font-size: clamp(11px, 1.3vw, 15px); line-height: 1.55; color: #5b5040; align-self: center; }
#cards .card .k { font-size: clamp(10px, 1.1vw, 12px); color: #8b7d64; text-align: right; }
#cards .cardsHint { font-size: clamp(11px, 1.2vw, 14px); color: #9c90ad; }

/* ---------------- 结算 ---------------- */
#banner {
  position: absolute; inset: 0; display: grid; place-content: center; gap: 1vh;
  background: rgba(8, 6, 14, .6); text-align: center; cursor: pointer;
}
#banner b { font-size: clamp(44px, 9vw, 96px); color: #e6c257; text-shadow: 4px 4px 0 var(--ink); letter-spacing: .2em; }
#banner span { font-size: clamp(11px, 1.4vw, 15px); color: var(--gold); }
.hidden { display: none !important; }

/* ---------------- 武器栏 / 秘籍栏 ---------------- */
.weapons { position: absolute; left: 1.6%; bottom: 2.2%; display: flex; gap: 5px; pointer-events: none; }
.wslot {
  font-size: clamp(9px, 1.02vw, 12px); color: #7f7591;
  border: 1px solid rgba(23, 20, 35, .9); background: rgba(10, 8, 16, .55);
  padding: 2px 6px; letter-spacing: .02em;
}
.wslot.on { color: #e9e2d2; border-color: #7d6f5a; background: rgba(24, 18, 34, .8); }
.wslot i { font-style: normal; margin-left: 4px; color: #d9c9a3; font-size: .86em; }
.chars { position: absolute; right: 1.6%; bottom: 2.2%; display: flex; gap: 5px; pointer-events: none; flex-wrap: wrap; justify-content: flex-end; max-width: 44%; }
.cslot {
  font-size: clamp(9px, 1vw, 11px); color: #c9bda3;
  border: 1px solid rgba(23, 20, 35, .9); background: rgba(10, 8, 16, .55);
  padding: 2px 5px;
}

/* ---------------- 卡牌稀有度 ---------------- */
.card.rar-fan { border-color: #4a4458; }
.card.rar-liang { border-color: #5f8fae; }
.card.rar-shang { border-color: #8b6bb5; }
.card.rar-jue { border-color: #c0392b; }
.card.rar-tian { border-color: #d4a017; box-shadow: inset 0 0 0 4px #c9bda3, 0 0 18px rgba(212, 160, 23, .55), 0 10px 0 rgba(0, 0, 0, .4); }
.card.rar-tian .t { color: #8a6110; }


/* ---------------- 卡牌图标 / 稀有度角标 ---------------- */
#cards .card { position: relative; grid-template-rows: auto auto 1fr auto; }
#cards .card .headrow { display: flex; align-items: flex-start; justify-content: space-between; gap: 6px; margin-bottom: 2px; }
#cards .card .ico {
  width: clamp(52px, 6vw, 76px); height: auto;
  image-rendering: pixelated; image-rendering: crisp-edges;
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, .25));
}
#cards .card .gem { width: 12px; height: 12px; image-rendering: pixelated; margin-top: 2px; }
#cards .card .num { position: absolute; right: 12px; bottom: 10px; }
#cards .card .k { text-align: left; }
#cards .card .d { line-height: 1.5; }
.wslot .wico { width: 14px; height: 14px; image-rendering: pixelated; vertical-align: -2px; margin-right: 4px; }

#dialog .lastRun { margin: 6px 0 0; font-size: 12px; color: #b9a97f; letter-spacing: .3px; }
#dialog .lastRun:empty { display: none; }

#cards .card .d.stats { color: #6f6350; font-size: 12px; letter-spacing: .2px; margin-bottom: 2px; }
#cards .card .d.mech { color: #3a3226; }

/* ---------------- 开始界面（像素武侠） ---------------- */
.start { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; }
.start.hidden { display: none; }
.start-bg {
  position: absolute; inset: 0;
  background:
    radial-gradient(circle at 50% 38%, rgba(72,58,82,.55), transparent 62%),
    repeating-linear-gradient(90deg, rgba(255,255,255,.020) 0 1px, transparent 1px 4px),
    linear-gradient(180deg, rgba(11,10,16,.80) 0%, rgba(21,17,28,.90) 55%, rgba(11,10,16,.94) 100%);
}
.start-bg::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, transparent 30%, rgba(0,0,0,.78) 100%);
}
.start-inner { position: relative; width: 92vw; max-width: 720px; text-align: center; padding: 16px; }
.title { position: relative; margin: 0 0 16px; }
.title-banner img {
  display: block; margin: 0 auto; width: min(620px, 88vw); height: auto;
  image-rendering: pixelated; filter: drop-shadow(0 6px 0 rgba(0,0,0,.4));
}
.title h1 {
  position: absolute; inset: 0; margin: 0; display: flex; align-items: center; justify-content: center;
  font-family: "STKaiti", "KaiTi", "Kaiti SC", "FZKai-Z03", serif;
  font-size: clamp(38px, 7vw, 64px); letter-spacing: .2em; color: #2b2733;
  text-shadow: 0 1px 0 #f6efdf; padding-bottom: 8px; pointer-events: none;
}
.title .sub {
  margin: 10px 0 0; color: #c9bda3; font-size: 13px; letter-spacing: .38em;
  font-family: "Microsoft YaHei", sans-serif;
}
.title .seal {
  position: absolute; right: 12%; bottom: -8px; width: 42px; height: 42px;
  display: flex; align-items: center; justify-content: center;
  background: #b3312a; border: 2px solid #7a1f1a; color: #f6efdf;
  font-family: "STKaiti", "KaiTi", serif; font-size: 22px;
  transform: rotate(-6deg); box-shadow: 0 0 0 2px rgba(0,0,0,.35);
}
.menu { display: flex; flex-direction: column; gap: 9px; width: min(320px, 80vw); margin: 6px auto 14px; }
.mbtn {
  border-style: solid; border-width: 7px 12px;
  border-image: url("assets/ui/btn_normal.png") 7 12 fill stretch;
  background: transparent; padding: 7px 14px; text-align: left; cursor: pointer;
  font-family: "STKaiti", "KaiTi", "Kaiti SC", serif;
}
.mbtn span { display: block; font-size: 20px; letter-spacing: .3em; color: #2b2733; }
.mbtn i { display: block; margin-top: 2px; font-size: 10px; font-style: normal; color: #8a7a5e; letter-spacing: .06em; font-family: "Microsoft YaHei", sans-serif; }
.mbtn:hover, .mbtn:focus-visible { border-image-source: url("assets/ui/btn_hover.png"); outline: none; }
.mbtn:hover span { color: #f6efdf; }
.mbtn:hover i { color: #f0c85a; }
.mbtn:active { transform: translateY(1px); }
.start .meta { display: block; min-height: 18px; color: #b9a97f; font-size: 12px; line-height: 1.7; font-family: "Microsoft YaHei", sans-serif; }
.start .meta b { color: #e6c257; font-weight: normal; }
.start .meta span { color: #8f8168; }
.start .ver { margin-top: 8px; color: #6b6575; font-size: 11px; letter-spacing: .18em; font-family: "Microsoft YaHei", sans-serif; }
.start .panel {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(420px, 86vw); text-align: left; color: #2b2733;
  border-style: solid; border-width: 32px 20px 22px 18px;
  border-image: url("assets/ui/panel.png") 32 20 22 18 fill stretch;
  padding: 4px 16px 14px; font-family: "Microsoft YaHei", sans-serif;
}
.start .panel.hidden { display: none; }
.start .panel.small { width: min(330px, 82vw); }
.panel-title { font-family: "STKaiti", "KaiTi", serif; font-size: 20px; letter-spacing: .3em; margin: 0 0 8px; }
.panel .row { display: flex; align-items: center; justify-content: space-between; padding: 7px 2px; border-bottom: 1px dashed rgba(43,39,51,.25); font-size: 14px; }
.panel .row input { width: 16px; height: 16px; accent-color: #b3312a; }
.panel .note { font-size: 13px; line-height: 1.8; color: #3d3749; margin: 4px 0 10px; }
.panel .row2 { display: flex; gap: 8px; }
.panel .btn {
  border-style: solid; border-width: 7px 12px; border-image: url("assets/ui/btn_normal.png") 7 12 fill stretch;
  background: transparent; padding: 5px 12px; margin-top: 10px; cursor: pointer;
  font-family: "STKaiti", "KaiTi", serif; font-size: 15px; letter-spacing: .18em; color: #2b2733;
}
.panel .btn:hover { border-image-source: url("assets/ui/btn_hover.png"); color: #f6efdf; }
.panel .btn.danger { color: #8e2a20; }
.toast {
  position: absolute; left: 50%; bottom: 14%; transform: translateX(-50%);
  background: rgba(23,20,35,.94); color: #f0e6d2; border: 1px solid #8a6710;
  padding: 8px 16px; font-size: 13px; letter-spacing: .08em; font-family: "Microsoft YaHei", sans-serif;
}
.toast.hidden { display: none; }

.start .couplet {
  position: absolute; top: 14%; writing-mode: vertical-rl;
  font-family: "STKaiti", "KaiTi", "Kaiti SC", serif;
  font-size: clamp(16px, 2vw, 24px); letter-spacing: .34em;
  color: rgba(201, 189, 163, .30); pointer-events: none;
  text-shadow: 0 1px 0 rgba(0,0,0,.5);
}
.start .couplet.left { left: 7%; }
.start .couplet.right { right: 7%; }

.start .meta .sub { color: #8f8168; font-size: 11px; margin-top: 2px; }

/* ---------------- 升级时的角色属性面板 ---------------- */
.statPanel {
  position: absolute; left: max(16px, 3.2vw); top: 50%; transform: translateY(-50%);
  width: clamp(178px, 15vw, 232px); padding: 10px 12px 9px;
  background: var(--paper); border: 3px solid var(--ink);
  box-shadow: inset 0 0 0 3px #c9bda3, 0 8px 0 rgba(0,0,0,.35);
  color: #241d2b; font-family: "Microsoft YaHei", sans-serif;
}
.statPanel .sp-title {
  display: flex; align-items: center; justify-content: space-between;
  font-family: "STKaiti", "KaiTi", serif; font-size: 17px; letter-spacing: .28em;
  padding-bottom: 6px; margin-bottom: 5px; border-bottom: 1px solid rgba(43,39,51,.28);
}
.statPanel .sp-title i { font-style: normal; font-size: 10px; color: #8b7d64; letter-spacing: .1em; }
.statPanel .sp-row {
  display: flex; align-items: baseline; justify-content: space-between;
  font-size: 12px; line-height: 1.75; color: #4a4136;
}
.statPanel .sp-row span { color: #7b6c55; }
.statPanel .sp-row b { font-weight: 600; color: #241d2b; }
.statPanel .sp-row b em { font-style: normal; font-size: 10px; color: #2f7a45; margin-left: 3px; }
.statPanel .sp-row b em.down { color: #a33a2a; }
.statPanel .sp-sep { height: 1px; margin: 5px 0; background: rgba(43,39,51,.22); }
.statPanel .sp-foot { margin-top: 6px; font-size: 10px; color: #8b7d64; letter-spacing: .05em; }
@media (pointer: coarse), (max-width: 900px) { .statPanel { display: none; } }

/* ---------------- 手机 / 触屏 ---------------- */
#app { touch-action: none; }
.touch-only { display: none !important; }
body.touch .touch-only { display: inline !important; }
body.touch .kb-only { display: none !important; }

#stick {
  position: absolute; z-index: 30; width: 112px; height: 112px;
  margin-left: -56px; margin-top: -56px; display: none; pointer-events: none;
}
#stick.on { display: block; }
#stick .ring {
  position: absolute; inset: 0; border-radius: 50%;
  background: radial-gradient(circle, rgba(20,16,30,.35) 0%, rgba(20,16,30,.18) 62%, rgba(20,16,30,0) 70%);
  border: 2px solid rgba(230,194,87,.45);
  box-shadow: inset 0 0 0 1px rgba(23,20,35,.6);
}
#stick .knob {
  position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px;
  border-radius: 50%; background: rgba(233,226,210,.85);
  border: 2px solid #171423; box-shadow: inset 0 0 0 2px #c9bda3, 0 3px 0 rgba(0,0,0,.35);
  will-change: transform;
}

#rotate {
  position: fixed; inset: 0; z-index: 90; display: none; place-items: center;
  background: #07060a; color: #e6c257;
  font-family: "STKaiti", "KaiTi", serif; font-size: 22px; letter-spacing: .5em;
}
@media (orientation: portrait) and (pointer: coarse) {
  #rotate { display: grid; }
}

/* 小屏横屏：压缩开始界面，保证一屏放得下 */
@media (max-height: 520px) and (orientation: landscape) {
  .start-inner { padding: 4px 8px; }
  .title { margin-bottom: 6px; }
  .title-banner img { width: min(340px, 58vw); }
  .title h1 { font-size: clamp(22px, 4.6vw, 34px); letter-spacing: .14em; padding-bottom: 3px; }
  .title .sub { font-size: 10px; letter-spacing: .18em; margin-top: 4px; }
  .title .seal { width: 28px; height: 28px; font-size: 15px; right: 16%; bottom: -6px; }
  .menu { width: min(260px, 46vw); gap: 5px; margin: 2px auto 6px; }
  .mbtn { border-width: 5px 9px; padding: 3px 10px; }
  .mbtn span { font-size: 15px; letter-spacing: .2em; }
  .mbtn i { font-size: 8px; margin-top: 0; }
  .start .meta { font-size: 10px; line-height: 1.45; }
  .start .ver { font-size: 9px; margin-top: 3px; }
  .start .couplet { display: none; }
  .start .panel { transform: translate(-50%, -50%) scale(.86); }
}

/* 小屏卡牌：三张并排仍然放得下 */
@media (pointer: coarse), (max-width: 900px) {
  #cards .card { width: clamp(108px, 21vw, 180px); min-height: auto; padding: 10px 9px; }
  #cards .card .d { font-size: 11px; }
  #cards .card .ico { width: 44px; }
  #cards .cardsRow { gap: 2vw; }
}

@media (pointer: coarse), (max-width: 900px) {
  #hud { left: 8px; right: 8px; top: 6px; gap: 6px; }
  .bar { width: 32%; max-width: 150px; }
  .bar.xp { width: 24%; max-width: 110px; }
  #hud .meta { gap: 8px; font-size: 10px; letter-spacing: 0; white-space: nowrap; }
  #hud .meta .hintkey { display: none !important; }
  #weapons { left: 8px; bottom: 8px; gap: 4px; }
  .wslot { font-size: 10px; padding: 3px 5px; }
  .wslot .wico { width: 12px; height: 12px; }
  #chars { right: 8px; bottom: 8px; gap: 4px; }
  .cslot { font-size: 10px; padding: 2px 5px; }
}

/* 手机端：属性面板压成顶部横条 */
#statPanel.compact {
  position: absolute; left: 50%; top: 11%; transform: translateX(-50%);
  width: auto; max-width: 94vw; display: flex; flex-wrap: wrap; align-items: center;
  gap: 2px 12px; padding: 5px 10px;
}
#statPanel.compact .sp-title {
  width: 100%; padding-bottom: 3px; margin-bottom: 2px; font-size: 13px;
  border-bottom: 1px solid rgba(43,39,51,.22);
}
#statPanel.compact .sp-title i { font-size: 9px; }
#statPanel.compact .sp-row { font-size: 10px; line-height: 1.5; gap: 3px; }
#statPanel.compact .sp-row b em { font-size: 9px; }
@media (pointer: coarse), (max-width: 900px) { #statPanel:not(.compact) { display: none; } }

/* ---------------- 像素血条 / 经验条（用 UI kit 素材） ---------------- */
#hud { align-items: flex-start; }
#hud .bars { display: flex; flex-direction: column; gap: 4px; width: 38%; max-width: 340px; }
#hud .bar { position: relative; border: none; background: none; box-shadow: none; width: 100%; }
#hud .bar i {
  position: absolute; left: 0; top: 0; bottom: 0; width: 100%;
  image-rendering: pixelated; transition: width .12s linear;
}
#hud .bar.hp {
  height: clamp(15px, 2.6vh, 22px);
  border-style: solid; border-width: 3px 10px;
  border-image: url("assets/ui/bar_hp_frame.png") 3 10 3 10 fill stretch;
}
#hud .bar.hp i { top: 3px; bottom: 3px; background-color: #b3312a; background-image: url("assets/ui/fill_hp.png"); background-repeat: repeat-x; background-position: left center; background-size: 8px 8px; }
#hud .bar.xp {
  height: clamp(8px, 1.6vh, 13px); width: 86%;
  border-style: solid; border-width: 2px 8px;
  border-image: url("assets/ui/bar_xp_frame.png") 2 8 2 8 fill stretch;
}
#hud .bar.xp i { top: 2px; bottom: 2px; background-color: #3b6e8f; background-image: url("assets/ui/fill_xp.png"); background-repeat: repeat-x; background-position: left center; background-size: 8px 4px; }
#hud .bar span {
  font-size: clamp(10px, 1.2vw, 13px); font-weight: 700; letter-spacing: .06em;
  color: #f7f2e6; text-shadow: 1px 1px 0 #171423, 0 0 2px rgba(0,0,0,.6);
}
#hud .meta { margin-top: 2px; }

/* ---------------- 手机端三选一：竖排列表，方便点选 ---------------- */
@media (pointer: coarse), (max-width: 900px) {
  #hud .bars { width: 44%; max-width: none; }
  #hud .bar.hp { height: 18px; }
  #hud .bar.xp { height: 10px; }
  #cards { padding: 6px 0 2px; }
  #cards .cardsTitle { font-size: 20px; letter-spacing: .4em; }
  #cards { padding: 2px 0 2px; }
  #cards .cardsRow {
    flex-direction: column; width: min(93vw, 560px); gap: 6px; align-self: center;
    max-height: 66vh; overflow-y: auto; padding: 56px 4px 2px;
  }
  #cards .card {
    width: 100%; min-height: 0; padding: 6px 10px 6px 8px; align-items: start;
    grid-template-columns: 52px 1fr auto;
    grid-template-rows: auto auto auto auto;
    grid-template-areas:
      "ico kind num"
      "ico title title"
      "ico stats stats"
      "ico mech mech";
    column-gap: 8px; row-gap: 1px; flex: 0 0 auto;
  }
  #cards .card .headrow { grid-area: ico; position: relative; justify-content: center; align-self: center; margin: 0; }
  #cards .card .ico { width: 44px; }
  #cards .card .gem { position: absolute; top: -2px; right: -2px; width: 10px; height: 10px; margin: 0; }
  #cards .card .k:not(.num) { grid-area: kind; text-align: left; font-size: 10px; }
  #cards .card .t { grid-area: title; font-size: 17px; line-height: 1.3; }
  #cards .card .d.stats { grid-area: stats; font-size: 11px; line-height: 1.4; margin: 1px 0 0; }
  #cards .card .d.mech { grid-area: mech; font-size: 10.5px; line-height: 1.35; margin-top: 1px; }
  #cards .card .num { position: static; grid-area: num; font-size: 10px; color: #8b7d64; }
  #cards .cardsHint { font-size: 11px; }
}

/* 手机端属性条：三列网格，不挤成一行 */
#statPanel.compact {
  top: 7.5%; z-index: 5; width: 92%; display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px 10px;
  padding: 5px 12px 6px;
}
#statPanel.compact .sp-title { grid-column: 1 / -1; margin-bottom: 0; }
#statPanel.compact .sp-row { display: flex; justify-content: space-between; gap: 4px; font-size: 10.5px; line-height: 1.55; }

@media (pointer: coarse), (max-width: 900px) {
  #cards .card .k:not(.num) { display: none; }
  #cards .card .t { font-size: 16px; }
  #cards .card .d.stats { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 11px; line-height: 1.3; }
  #cards .card .d.stats .r2 { display: inline; }
  #cards .card .d.stats .r2::before { content: " · "; }
  #cards .card .d.mech {
    display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical;
    overflow: hidden; font-size: 10px; line-height: 1.3;
  }
}

#cards .card .d.stats .r2 { display: block; }

/* ================= 手机端最终版：三卡一行 + 单行属性条 ================= */
@media (pointer: coarse), (max-width: 900px) {
  #cards { padding: 0; grid-template-rows: auto 1fr auto; }
  #cards .cardsTitle { font-size: 19px; letter-spacing: .36em; margin: 2px 0 0; }
  #cards .cardsRow {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: stretch; justify-items: stretch;
    width: 94%; max-width: none; gap: 6px; padding: 0; overflow: visible;
    max-height: none; align-self: center;
  }
  #cards .card {
    width: 100%; min-width: 0;
    height: clamp(168px, 46vh, 220px);
    padding: 8px 8px 8px 7px; align-items: start;
    grid-template-columns: 1fr;
    grid-template-rows: 46px auto auto 1fr;
    grid-template-areas: "ico" "title" "stats" "mech";
    row-gap: 2px;
  }
  #cards .card .headrow { grid-area: ico; align-self: start; justify-content: flex-start; position: relative; margin: 0; }
  #cards .card .ico { width: 44px; }
  #cards .card .gem { position: absolute; top: 0; right: 0; width: 11px; height: 11px; margin: 0; }
  #cards .card .k:not(.num) { display: none; }
  #cards .card .t { grid-area: title; font-size: 15px; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #cards .card .d.stats {
    grid-area: stats; font-size: 10.5px; line-height: 1.4; margin: 0;
    white-space: normal; overflow: hidden;
  }
  #cards .card .d.stats .r2 { display: block; }
  #cards .card .d.stats .r2::before { content: ""; }
  #cards .card .d.mech {
    grid-area: mech; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
    overflow: hidden; font-size: 10px; line-height: 1.4; margin-top: 2px;
  }
  #cards .card .num { position: absolute; right: 8px; bottom: 6px; font-size: 10px; color: #8b7d64; }
  
  /* 单行属性条 */
  #statPanel.compact {
    top: 38px; left: 50%; transform: translateX(-50%);
    width: 94%; max-width: none; display: flex; align-items: center; justify-content: space-between;
    gap: 6px; padding: 4px 10px; flex-wrap: nowrap; overflow: hidden;
  }
  #statPanel.compact .sp-cell {
    display: flex; align-items: baseline; gap: 3px;
    font-size: 10.5px; line-height: 1.4; white-space: nowrap; color: #4a4136;
  }
  #statPanel.compact .sp-cell span { color: #7b6c55; }
  #statPanel.compact .sp-cell b { color: #241d2b; font-weight: 600; }
  #statPanel.compact .sp-cell b em { color: #2f7a45; font-style: normal; font-size: 9px; margin-left: 2px; }
  #statPanel.compact .sp-cell.title { font-family: "STKaiti","KaiTi",serif; letter-spacing: .1em; font-size: 12px; }
  #cards .cardsHint { font-size: 10.5px; margin-bottom: 2px; }
}

/* ================= 品阶内框 + 流光（不外扩） ================= */
#cards .card { position: relative; overflow: hidden; }
#cards .card::before {
  content: ''; position: absolute; inset: 6px; pointer-events: none; z-index: 2;
  border: 2px solid transparent; border-radius: 1px;
}
#cards .card.rar-liang::before {
  border-color: rgba(74, 124, 89, .75);
  box-shadow: inset 0 0 10px rgba(74, 124, 89, .22);
}
#cards .card.rar-shang::before {
  border-color: rgba(139, 107, 181, .85);
  box-shadow: inset 0 0 12px rgba(139, 107, 181, .3);
}
#cards .card.rar-jue::before {
  border-color: rgba(192, 57, 43, .9);
  box-shadow: inset 0 0 14px rgba(192, 57, 43, .38);
}
#cards .card.rar-tian::before {
  border-color: #d4a017;
  box-shadow: inset 0 0 16px rgba(212, 160, 23, .45), inset 0 0 0 1px rgba(255, 240, 190, .7);
  animation: tianPulse 2.8s ease-in-out infinite;
}
#cards .card.rar-tian { box-shadow: inset 0 0 0 4px #c9bda3, 0 10px 0 rgba(0, 0, 0, .4); }
#cards .card.rar-liang .t { color: #3f6b56; }
#cards .card.rar-shang .t { color: #5b4276; }
#cards .card.rar-jue .t { color: #8e2a20; }

/* 流光：只在良品以上；从左到右扫过，贴卡片内边距，不出卡 */
#cards .card::after {
  content: ''; position: absolute; top: 0; bottom: 0; left: 0; width: 55%;
  background: linear-gradient(105deg,
    transparent 0%, rgba(255, 255, 255, 0) 28%,
    rgba(255, 255, 255, .30) 50%, rgba(255, 255, 255, 0) 72%, transparent 100%);
  transform: translateX(-180%) skewX(-16deg);
  pointer-events: none; z-index: 3; opacity: 0;
}
#cards .card.rar-shang::after,
#cards .card.rar-jue::after,
#cards .card.rar-tian::after { opacity: .75; animation: cardShine 3.8s ease-in-out infinite; }
#cards .card.rar-tian::after {
  background: linear-gradient(105deg,
    transparent 0%, rgba(255, 236, 170, 0) 26%,
    rgba(255, 236, 170, .5) 48%, rgba(255, 255, 255, .35) 54%, transparent 76%);
}
#cards .card.rar-shang:hover::after,
#cards .card.rar-jue:hover::after,
#cards .card.rar-tian:hover::after { animation-duration: 1.8s; }

@keyframes cardShine {
  0%, 55% { transform: translateX(-180%) skewX(-16deg); }
  85%, 100% { transform: translateX(320%) skewX(-16deg); }
}
@keyframes tianPulse {
  0%, 100% { box-shadow: inset 0 0 16px rgba(212, 160, 23, .4), inset 0 0 0 1px rgba(255, 240, 190, .65); }
  50% { box-shadow: inset 0 0 22px rgba(255, 214, 92, .6), inset 0 0 0 1px rgba(255, 250, 220, .9); }
}

/* 选中：内嵌高亮，不改变卡尺寸、不向外扩 */
#cards .card.sel {
  outline: none;
  box-shadow: inset 0 0 0 3px #e6c257, inset 0 0 0 6px rgba(230, 194, 87, .22), 0 10px 0 rgba(0, 0, 0, .35);
  transform: none;
}
@media (prefers-reduced-motion: reduce) {
  #cards .card::after { animation: none !important; }
  #cards .card.rar-tian::before { animation: none !important; }
}
