/* 《表妹快跑》界面样式 —— 漫画贴纸风 theme tokens
   批次 3 会把 UI 槽位外壳（ui_panel_dialog / ui_btn_primary / ui_hud_plate / ui_level_card）
   以 border-image 九宫格接入；在此之前使用同色系代码外壳兜底。 */
:root {
  --c-ink: #2B1D3A;
  --c-paper: #FFF6E5;
  --c-primary: #FF5A3C;
  --c-primary-dk: #C93A22;
  --c-secondary: #2EC4B6;
  --c-accent: #FFD23F;
  --c-danger: #E63946;
  --lv-a: #E8434F;
  --lv-b: #FFC93C;
  --radius: 22px;
  --shadow-hard: 0 6px 0 var(--c-ink);
  --ease-pop: cubic-bezier(.34, 1.56, .64, 1);
  --dur: 220ms;
  --font-title: var(--yoroll-font-title, sans-serif);
  --font-body: var(--yoroll-font-body, sans-serif);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}
body.lv-2 { --lv-a: #3A86FF; --lv-b: #FFBE0B; }
body.lv-3 { --lv-a: #1D3557; --lv-b: #E63946; }
body.reduced-motion { --dur: 120ms; }

html, body { margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden; background: #2B1D3A; color: var(--c-ink);
  font-family: var(--font-body); -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
#stage { position: fixed; inset: 0; touch-action: none; }
#stage canvas { display: block; width: 100%; height: 100%; }
.hidden { display: none !important; }
.layer { position: fixed; inset: 0; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
button:focus-visible { outline: 3px solid var(--c-accent); outline-offset: 3px; }

/* ---------- 共享组件 ---------- */
.btn-primary {
  position: relative; display: flex; align-items: center; justify-content: center;
  min-width: 220px; min-height: 64px; padding: 0 34px; box-sizing: border-box;
  font-family: var(--font-title); font-size: 28px; letter-spacing: 2px; color: #fff;
  text-shadow: 0 3px 0 rgba(43,29,58,.55);
  background: linear-gradient(#FF7A5C, var(--c-primary) 55%, var(--c-primary-dk));
  border: 4px solid var(--c-ink); border-radius: 999px; box-shadow: var(--shadow-hard), inset 0 4px 0 rgba(255,255,255,.45);
  transition: transform var(--dur) var(--ease-pop), box-shadow 120ms;
}
.btn-primary:active, .btn-primary.pressed { transform: translateY(4px); box-shadow: 0 2px 0 var(--c-ink), inset 0 4px 0 rgba(255,255,255,.45); }
.btn-primary[disabled] { filter: grayscale(.8) brightness(.9); cursor: not-allowed; }
.btn-secondary {
  display: flex; align-items: center; justify-content: center; min-width: 200px; min-height: 52px; padding: 0 24px; box-sizing: border-box;
  font-family: var(--font-body); font-size: 20px; font-weight: 500; color: var(--c-ink);
  background: var(--c-paper); border: 3px solid var(--c-ink); border-radius: var(--radius); box-shadow: 0 4px 0 var(--c-ink);
  transition: transform var(--dur) var(--ease-pop);
}
.btn-secondary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--c-ink); }
.btn-icon {
  display: flex; align-items: center; justify-content: center; width: 52px; height: 52px; border-radius: 50%;
  background: var(--c-paper); border: 3px solid var(--c-ink); box-shadow: 0 4px 0 var(--c-ink); font-size: 20px; font-weight: 700;
}
.btn-icon:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--c-ink); }
.btn-icon.off { background: #cfc6d8; }

.panel {
  position: relative; box-sizing: border-box; width: min(720px, 92vw); max-height: calc(100% - 32px - var(--safe-t) - var(--safe-b));
  overflow: auto; padding: 36px 40px 32px; background: var(--c-paper);
  border: 6px solid var(--c-ink); border-radius: 34px;
  box-shadow: 0 10px 0 var(--c-ink), inset 0 0 0 8px var(--lv-a), inset 0 0 0 12px #fff;
  text-align: center; animation: pop-in var(--dur) var(--ease-pop);
}
.panel h2 { font-family: var(--font-title); font-weight: 400; font-size: 40px; margin: 4px 0 18px; color: var(--c-ink); }
.panel .close { position: absolute; top: 14px; right: 14px; }
.modal { display: flex; align-items: center; justify-content: center; background: rgba(43,29,58,.55); z-index: 20; }
@keyframes pop-in { from { transform: scale(.82); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.hud-plate {
  display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 20px 0 10px; box-sizing: border-box;
  background: var(--c-accent); border: 4px solid var(--c-ink); border-radius: 999px; box-shadow: 0 4px 0 var(--c-ink);
  font-family: var(--font-body); font-size: 26px; font-weight: 700; min-width: 130px;
}
.coin-ico { width: 34px; height: 34px; border-radius: 50%; flex: none;
  background: radial-gradient(circle at 35% 30%, #FFF3A8, #FFC93C 55%, #D9921A); border: 3px solid var(--c-ink); background-size: cover; }
.coin-ico.img { border: 0; background: var(--coin-img) center/contain no-repeat; }

/* ---------- 加载 ---------- */
#screen-loading { display: flex; align-items: center; justify-content: center; background: radial-gradient(circle at 50% 40%, #FF8A5C, #C93A22 70%, #2B1D3A); z-index: 50; }
.loading-box { text-align: center; color: #fff; }
.load-bar { width: min(420px, 70vw); height: 22px; border: 4px solid var(--c-ink); border-radius: 999px; background: var(--c-paper); overflow: hidden; margin: 18px auto; }
#load-fill { height: 100%; width: 0; background: var(--c-accent); transition: width 200ms; }
#load-text { font-size: 18px; margin: 0 0 12px; }

/* ---------- 标题 ---------- */
#screen-title { z-index: 10; pointer-events: none; }   /* 标题背景透出热身跑道：空白处可滑动练习 */
#screen-title button, #screen-title .title-stats { pointer-events: auto; }
.warm-tip { position: absolute; left: 50%; bottom: calc(2.2vh + var(--safe-b)); transform: translateX(-50%); margin: 0; white-space: nowrap;
  background: rgba(43,29,58,.72); color: #fff; border-radius: 999px; padding: 4px 14px; font-size: 14px; }
/* 触屏动作按钮：触屏/窄屏显示；z 介于标题(10)与弹窗(20)之间 */
.touch-pad { position: fixed; right: calc(10px + var(--safe-r)); top: 42%; transform: translateY(-50%); z-index: 12; display: none; flex-direction: column; gap: 12px; }
.pad-btn { width: 62px; height: 62px; border-radius: 50%; border: 4px solid var(--c-ink); background: var(--c-paper); color: var(--c-ink);
  font-family: var(--font-title); font-size: 26px; box-shadow: 0 5px 0 var(--c-ink); display: flex; align-items: center; justify-content: center; padding: 0;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent; cursor: pointer; }
.pad-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--c-ink); }
.pad-btn.pad-power { background: var(--c-accent); }
.pad-btn[hidden] { display: none; }
@media (pointer: coarse), (max-width: 760px) { .touch-pad:not(.hidden) { display: flex; } }
@media (max-height: 480px) { .touch-pad { top: 50%; gap: 8px; } .pad-btn { width: 52px; height: 52px; font-size: 22px; } }
.title-art { position: absolute; inset: 0; background: linear-gradient(160deg, rgba(255,90,60,.35), rgba(43,29,58,.2)); background-size: cover; background-position: center; }
.title-art.has-img { background-image: var(--key-art); }
.logo { position: absolute; left: calc(5vw + var(--safe-l)); top: calc(5vh + var(--safe-t)); margin: 0; font-family: var(--font-title); font-weight: 400;
  font-size: clamp(56px, 10vw, 128px); line-height: .95; color: var(--c-accent); transform: rotate(-6deg);
  -webkit-text-stroke: 6px var(--c-ink); paint-order: stroke fill; text-shadow: 0 8px 0 var(--c-ink); }
.logo.small { position: static; transform: none; font-size: 64px; }
.tagline { position: absolute; left: calc(5vw + var(--safe-l)); top: calc(5vh + var(--safe-t) + clamp(130px, 22vw, 270px)); margin: 0;
  background: var(--c-paper); border: 3px solid var(--c-ink); border-radius: 14px; padding: 6px 14px; font-size: 18px; box-shadow: 0 4px 0 var(--c-ink); }
.title-actions { position: absolute; right: calc(5vw + var(--safe-r)); bottom: calc(10vh + var(--safe-b)); display: flex; flex-direction: column; gap: 16px; align-items: stretch; }
.title-actions .btn-primary { min-width: 280px; min-height: 80px; font-size: 36px; }
.title-stats { position: absolute; left: calc(5vw + var(--safe-l)); bottom: calc(6vh + var(--safe-b)); display: flex; align-items: center; gap: 8px;
  background: var(--c-paper); border: 3px solid var(--c-ink); border-radius: 999px; padding: 6px 16px 6px 8px; box-shadow: 0 4px 0 var(--c-ink); font-size: 18px; }
.title-stats b { font-size: 22px; }

/* ---------- 关卡选择 ---------- */
.panel-levels { width: min(1080px, 94vw); }
.level-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
.level-card { position: relative; display: flex; flex-direction: column; align-items: stretch; text-align: center; box-sizing: border-box;
  background: #fff; border: 5px solid var(--c-ink); border-radius: 26px; box-shadow: 0 6px 0 var(--c-ink), inset 0 0 0 6px var(--c-secondary); padding: 12px; min-height: 44px;
  transition: transform var(--dur) var(--ease-pop); }
.level-card:not([disabled]):hover { transform: translateY(-4px) rotate(-1deg); }
.level-card .thumb { aspect-ratio: 16 / 10; border-radius: 16px; border: 3px solid var(--c-ink); background: #ddd center/cover no-repeat; }
.level-card .lv-no { font-size: 15px; margin-top: 8px; }
.level-card .lv-name { font-family: var(--font-title); font-size: 26px; margin: 2px 0; }
.level-card .lv-meta { font-size: 14px; opacity: .8; }
.level-card .lv-stars { font-size: 22px; letter-spacing: 2px; color: #C9A227; min-height: 26px; }
.level-card[disabled] { filter: grayscale(.9); cursor: not-allowed; }
.level-card .lock { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 22px; font-family: var(--font-title);
  color: #fff; background: rgba(43,29,58,.55); border-radius: 22px; }

/* ---------- 说明 / 暂停 / 结算 ---------- */
.help-body { text-align: left; }
.help-row { display: grid; grid-template-columns: 110px 1fr; gap: 12px; align-items: center; padding: 10px 6px; border-bottom: 2px dashed rgba(43,29,58,.25); font-size: 18px; }
.help-row b { font-family: var(--font-title); font-weight: 400; font-size: 22px; color: var(--c-primary-dk); }
.help-tip { font-size: 16px; line-height: 1.6; margin: 14px 4px 18px; }
.panel-help .btn-primary { margin: 0 auto; }
.stack { display: flex; flex-direction: column; gap: 14px; align-items: center; }
.stack > * { width: min(320px, 100%); }
.panel-result { width: min(760px, 94vw); }
.result-head { font-family: var(--font-title); font-size: 52px; color: var(--c-primary); -webkit-text-stroke: 3px var(--c-ink); paint-order: stroke fill; }
.result-sub { font-size: 18px; margin: 6px 0 10px; }
.stars { font-size: 46px; letter-spacing: 6px; color: #d8cfe0; min-height: 52px; }
.stars .on { color: var(--c-accent); -webkit-text-stroke: 2px var(--c-ink); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 14px 0 22px; }
.stat { background: #fff; border: 3px solid var(--c-ink); border-radius: 18px; padding: 10px 6px; }
.stat b { display: block; font-size: 30px; font-family: var(--font-body); }
.stat span { font-size: 15px; opacity: .8; }
.actions { display: flex; flex-wrap: wrap; gap: 14px; justify-content: center; }
body.fail-layout #screen-result { justify-content: flex-end; padding-right: max(4vw, var(--safe-r)); box-sizing: border-box; background: rgba(43,29,58,.25); }
body.fail-layout .panel-result { width: min(560px, 92vw); }

/* ---------- HUD ---------- */
#hud { pointer-events: none; z-index: 5; }
#hud button { pointer-events: auto; }
.hud-top { position: absolute; top: calc(12px + var(--safe-t)); left: calc(14px + var(--safe-l)); right: calc(14px + var(--safe-r)); display: flex; align-items: center; gap: 16px; }
.progress { position: relative; flex: 1; height: 20px; max-width: 560px; margin: 0 auto; background: var(--c-paper); border: 4px solid var(--c-ink); border-radius: 999px; overflow: visible; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--lv-b), var(--lv-a)); border-radius: 999px; }
.progress .flag { position: absolute; right: -14px; top: -14px; width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--c-secondary); border: 3px solid var(--c-ink); font-family: var(--font-title); font-size: 18px; color: #fff; }
.hud-btns { display: flex; gap: 10px; }
.meter-chase { position: absolute; left: calc(18px + var(--safe-l)); top: 50%; transform: translateY(-50%); width: 26px; height: min(42vh, 360px);
  background: var(--c-paper); border: 4px solid var(--c-ink); border-radius: 999px; overflow: hidden; }
.chase-fill { position: absolute; left: 0; right: 0; bottom: 0; height: 50%; background: linear-gradient(0deg, var(--c-danger), #FF9E7A); }
.chase-label { position: absolute; left: 50%; top: -2px; transform: translateX(-50%); font-size: 12px; writing-mode: vertical-rl; color: var(--c-ink); font-weight: 700; }
.meter-chase.danger { animation: blink 0.4s steps(2) infinite; }
@keyframes blink { 50% { border-color: var(--c-danger); } }
.warn-chip { position: absolute; left: 50%; top: calc(80px + var(--safe-t)); transform: translateX(-50%); padding: 8px 20px; border-radius: 999px;
  background: var(--c-accent); border: 4px solid var(--c-ink); font-family: var(--font-title); font-size: 26px; box-shadow: 0 4px 0 var(--c-ink); white-space: nowrap; }
.banner { position: absolute; left: 50%; top: 32%; transform: translate(-50%, -50%); font-family: var(--font-title); font-size: clamp(36px, 7vw, 80px);
  color: var(--lv-b); -webkit-text-stroke: 5px var(--c-ink); paint-order: stroke fill; text-shadow: 0 6px 0 var(--c-ink); white-space: nowrap; animation: pop-in 260ms var(--ease-pop); }
.hud-bottom { position: absolute; left: 50%; bottom: calc(16px + var(--safe-b)); transform: translateX(-50%); display: flex; align-items: center; gap: 16px; width: min(640px, calc(100% - 140px)); }
.meter-power { position: relative; flex: 1; height: 30px; background: var(--c-paper); border: 4px solid var(--c-ink); border-radius: 999px; overflow: hidden; }
.power-fill { height: 100%; width: 0; background: linear-gradient(90deg, #FFE27A, var(--c-accent)); }
.meter-power span { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 700; }
.btn-power { display: flex; flex-direction: column; align-items: center; justify-content: center; width: 84px; height: 84px; border-radius: 50%;
  background: var(--c-paper); border: 4px solid var(--c-ink); box-shadow: 0 5px 0 var(--c-ink); font-family: var(--font-title); font-size: 15px; }
.btn-power[disabled] { filter: grayscale(.85); opacity: .8; }
.btn-power.ready { background: var(--c-accent); animation: pulse 0.9s ease-in-out infinite; }
.power-ico { width: 46px; height: 40px; background: center/contain no-repeat; font-size: 30px; line-height: 40px; text-align: center; }
@keyframes pulse { 50% { transform: scale(1.08); } }
.touch-hint { position: absolute; left: 50%; bottom: calc(130px + var(--safe-b)); transform: translateX(-50%); background: rgba(255,246,229,.95);
  border: 4px solid var(--c-ink); border-radius: 22px; padding: 12px 20px; font-size: 17px; line-height: 1.6; text-align: center; box-shadow: 0 5px 0 var(--c-ink); width: min(560px, 86vw); box-sizing: border-box; }
.vignette { position: absolute; inset: 0; pointer-events: none; opacity: 0; transition: opacity 200ms;
  background: radial-gradient(ellipse at center, transparent 55%, rgba(230,57,70,.55)); }
#screen-countdown { display: flex; align-items: center; justify-content: center; pointer-events: none; z-index: 6; }
#countdown-num { font-family: var(--font-title); font-size: 140px; color: var(--c-accent); -webkit-text-stroke: 7px var(--c-ink); paint-order: stroke fill; text-shadow: 0 8px 0 var(--c-ink); }

/* ---------- 玩法反馈（批次 2） ---------- */
.warn-chip[data-kind="jump"] { background: var(--c-accent); }
.warn-chip[data-kind="crouch"] { background: #8EC5FF; }
.warn-chip[data-kind="dodge"] { background: #FF8A8A; }
.hud-plate.bump { animation: bump 260ms var(--ease-pop); }
@keyframes bump { 40% { transform: scale(1.14); } }
.meter-power.active .power-fill { background: linear-gradient(90deg, var(--lv-b), var(--lv-a)); }
.meter-power.active span { color: #fff; text-shadow: 0 2px 0 var(--c-ink); }
.meter-power.ending { animation: blink 0.3s steps(2) infinite; }
.meter-power.shake { animation: shake 300ms; }
@keyframes shake { 20% { transform: translateX(-6px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }
.btn-power.active { background: var(--lv-b); }
.float-text { position: absolute; transform: translate(-50%, -50%); font-family: var(--font-title); font-size: 34px; color: var(--c-accent);
  -webkit-text-stroke: 4px var(--c-ink); paint-order: stroke fill; pointer-events: none; animation: float-up 750ms ease-out forwards; white-space: nowrap; }
.float-text.bad { color: #FF8A8A; }
@keyframes float-up { from { opacity: 1; transform: translate(-50%, -50%) scale(.7); } 30% { transform: translate(-50%, -80%) scale(1.1); } to { opacity: 0; transform: translate(-50%, -160%) scale(1); } }
.bubble { position: absolute; transform: translate(-50%, -100%); background: #fff; border: 4px solid var(--c-ink); border-radius: 22px; padding: 8px 18px;
  font-family: var(--font-title); font-size: 26px; box-shadow: 0 4px 0 var(--c-ink); white-space: nowrap; pointer-events: none; animation: pop-in 220ms var(--ease-pop); }
.bubble::after { content: ''; position: absolute; left: 40%; bottom: -16px; border: 9px solid transparent; border-top: 12px solid var(--c-ink); }
body.reduced-motion .float-text, body.reduced-motion .banner, body.reduced-motion .bubble { animation-duration: 1ms; }
body.reduced-motion .btn-power.ready, body.reduced-motion .meter-chase.danger { animation: none; }

/* ---------- 批次 3：界面外壳九宫格（border-image，中心 fill，文字在内容层） ----------
   源图切片按工具实测的内框安全区：panel 989×964 内框 129/120/124/129；
   主按钮 1526×601 内框 179/87/181/111；HUD 牌 1505×619 内框 154/90/154/101；关卡卡 950×1525 内框 105/205/103/202。 */
.panel {
  background: none; border-radius: 0; box-shadow: none;
  border-style: solid; border-color: transparent; border-width: 50px 48px 50px 50px;
  border-image: url('assets/ui_panel_dialog.webp') 132 124 128 132 fill / 50px 48px 50px 50px / 0 stretch;
  padding: 6px 14px 10px; filter: drop-shadow(0 8px 0 rgba(43,29,58,.55));
}
.panel .close { top: -8px; right: -8px; width: 46px; height: 46px; }
.btn-primary {
  background: none; border-radius: 0; box-shadow: none;
  border-style: solid; border-color: transparent; border-width: 16px 30px;
  border-image: url('assets/ui_btn_primary.webp') 150 270 150 270 fill / 16px 30px / 0 stretch;
  padding: 0 12px; filter: drop-shadow(0 5px 0 var(--c-ink));
}
.btn-primary > span { position: relative; top: -1px; }
.btn-primary:active, .btn-primary.pressed { box-shadow: none; filter: drop-shadow(0 1px 0 var(--c-ink)); }
.btn-primary[disabled] { filter: grayscale(.8) brightness(.9) drop-shadow(0 5px 0 var(--c-ink)); }
.title-actions .btn-primary { border-width: 20px 36px; border-image-width: 20px 36px; }
.hud-plate {
  background: none; border-radius: 0; box-shadow: none; height: 58px;
  border-style: solid; border-color: transparent; border-width: 11px 18px;
  border-image: url('assets/ui_hud_plate.webp') 120 170 120 170 fill / 11px 18px / 0 stretch;
  padding: 0 8px 0 2px; filter: drop-shadow(0 4px 0 var(--c-ink));
}
.level-card {
  background: none; border-radius: 0; box-shadow: none;
  border-style: solid; border-color: transparent; border-width: 46px 30px;
  border-image: url('assets/ui_level_card.webp') 215 125 215 125 fill / 46px 30px / 0 stretch;
  padding: 0 4px; filter: drop-shadow(0 6px 0 rgba(43,29,58,.6));
}
.level-card[disabled] { filter: grayscale(.9) drop-shadow(0 6px 0 rgba(43,29,58,.6)); }
.level-card .lock { inset: -8px -4px; border-radius: 18px; }

/* ---------- 竖屏 / 小屏 ---------- */
@media (orientation: portrait) {
  .level-list { grid-template-columns: 1fr; }
  .level-card { flex-direction: row; gap: 12px; text-align: left; align-items: center; }
  .level-card .thumb { width: 42%; flex: none; }
  .level-card { border-width: 26px 20px; border-image-width: 26px 20px; padding: 0 2px; }
  .panel { border-width: 38px 36px 38px 38px; border-image-width: 38px 36px 38px 38px; padding: 4px 8px 8px; }
  .panel .close { top: -4px; right: -4px; }
  .title-actions { left: 50%; right: auto; transform: translateX(-50%); bottom: calc(14vh + var(--safe-b)); }
  .tagline { top: calc(5vh + var(--safe-t) + 26vw); }
  .hud-bottom { bottom: calc(26px + var(--safe-b)); width: calc(100% - 40px); }
  body.fail-layout #screen-result { justify-content: center; align-items: flex-end; padding: 0 0 calc(16px + var(--safe-b)); }
}
@media (max-height: 480px) {
  .panel { padding: 2px 8px 4px; border-width: 34px 32px 34px 34px; border-image-width: 34px 32px 34px 34px; }
  .level-card { border-width: 30px 22px; border-image-width: 30px 22px; }
  .panel h2 { font-size: 30px; margin-bottom: 8px; }
  .result-head { font-size: 38px; }
  .stars { font-size: 34px; min-height: 38px; }
  .stats { margin: 8px 0 12px; }
  .stat b { font-size: 24px; }
  .title-actions .btn-primary { min-height: 64px; font-size: 30px; }
  .help-row { padding: 6px; font-size: 16px; }
  .btn-power { width: 70px; height: 70px; }
  .meter-chase { height: 40vh; }
}
