/* 美美下班開鍋｜戰鬥畫面、HUD、觸控按鈕、暫停與升級面板 */
:root {
  --night: #141024; --panel: #221b3a; --panel2: #2c2449; --cream: #fff3d6; --amber: #ffb84d; --teal: #58e0d0;
  --danger: #ff4d5a; --line: rgba(255, 243, 214, 0.18);
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px); --sar: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body {
  height: 100%; overflow: hidden; background: #0b0915; color: var(--cream);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: none; overscroll-behavior: none;
}
[hidden] { display: none !important; }
#game { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#loading { position: fixed; inset: 0; display: grid; place-items: center; font-size: 18px; letter-spacing: 0.1em; color: var(--cream); background: var(--night); z-index: 50; }

/* 身分落款：只在主畫面底部顯示（戰鬥、衣櫃、結算時不擋畫面） */
#credit { display: none; position: fixed; left: 0; right: 0; bottom: 0; padding: 16px 8px calc(6px + var(--sab)); background: linear-gradient(rgba(10, 7, 22, 0), rgba(10, 7, 22, 0.92) 55%); z-index: 31; text-align: center; font-size: 11px; letter-spacing: 0.04em; color: rgba(255, 243, 214, 0.62); pointer-events: none; text-shadow: 0 1px 2px #000; }
#screens.sc-on-title .sc-wrap { padding-bottom: calc(34px + var(--sab)); }

/* ---------- HUD ---------- */
#hud { position: fixed; left: 0; right: 0; top: 0; z-index: 5; pointer-events: none;
  padding: calc(8px + var(--sat)) calc(10px + var(--sar)) 0 calc(10px + var(--sal)); font-weight: 700; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8); }
.hud-row { display: flex; align-items: center; gap: 10px; }
.bar { position: relative; height: 14px; border-radius: 8px; background: rgba(0, 0, 0, 0.55); border: 1.5px solid var(--line); overflow: hidden; }
.bar > i { position: absolute; left: 0; top: 0; bottom: 0; width: 100%; border-radius: 6px; }
.hpwrap { flex: 1 1 0; min-width: 0; max-width: 300px; display: flex; align-items: center; gap: 6px; }
#hpBar { flex: 1; }
#hpFill { background: linear-gradient(#ff8f8f, #e8455a); }
#hpFill.low { animation: lowhp 0.5s steps(2) infinite; }
@keyframes lowhp { 50% { filter: brightness(1.7); } }
.hpwrap { position: relative; }
#hpBar { height: 18px; }
#hpText { position: absolute; left: 0; right: 0; top: 0; line-height: 18px; text-align: center; font-size: 11px; font-variant-numeric: tabular-nums; pointer-events: none; }
#timer { flex: 0 0 auto; font-size: 17px; font-variant-numeric: tabular-nums; background: rgba(0, 0, 0, 0.45); padding: 3px 10px; border-radius: 10px; border: 1px solid var(--line); }
.hud-right { flex: 1 1 0; display: flex; justify-content: flex-end; align-items: center; gap: 8px; font-size: 13px; }
.hud-right button { pointer-events: auto; width: 40px; height: 40px; border-radius: 12px; border: 1.5px solid var(--line); background: rgba(20, 16, 36, 0.8); color: var(--cream); font-size: 16px; font-weight: 800; cursor: pointer; }
#btnMute.off { color: rgba(255, 243, 214, 0.35); text-decoration: line-through; }
.xpwrap { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 12px; }
#xpBar { flex: 1; height: 8px; }
#xpFill { background: linear-gradient(90deg, #7be0ff, #8dffb0); width: 0; }
#modeChip { font-size: 11px; padding: 2px 8px; border-radius: 8px; background: rgba(0, 0, 0, 0.45); border: 1px solid var(--line); }
#arenaName { font-size: 11px; color: #e1ffbe; white-space: nowrap; text-shadow: 0 1px 3px #243329; }
#bossBar { margin: 8px auto 0; max-width: 520px; text-align: center; font-size: 13px; color: #ffd0d0; }
#bossBar .bar { height: 12px; margin-top: 3px; border-color: rgba(255, 120, 120, 0.6); }
#bossFill { background: linear-gradient(#ffb199, #ff4d5a); }
#chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; padding: 2px 8px 2px 3px; border-radius: 10px; background: rgba(0, 0, 0, 0.45); border: 1px solid var(--line); font-weight: 600; }
.chip img { width: 20px; height: 20px; object-fit: contain; }
#banner { margin: 10px auto 0; width: fit-content; max-width: 92%; padding: 8px 18px; border-radius: 12px; font-size: 17px; text-align: center; background: rgba(20, 16, 36, 0.88); border: 2px solid var(--amber); color: var(--cream); }
#banner.danger { border-color: var(--danger); color: #fff; background: rgba(120, 10, 30, 0.9); animation: bannerblink 0.5s steps(2) infinite; }
@keyframes bannerblink { 50% { background: rgba(200, 30, 50, 0.95); } }
#timer::after { content: " / " attr(data-total); font-size: 11px; opacity: 0.7; }
#timer.short-clock::after { content: " 實玩"; }
.run-progress { width: min(600px, 100%); margin: 6px auto 0; }
.run-route { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); list-style: none; gap: 4px; }
.run-route li { position: relative; display: flex; align-items: center; justify-content: center; gap: 4px; padding: 3px 2px; border-radius: 7px; color: rgba(255, 243, 214, 0.62); background: rgba(13, 20, 23, 0.7); font-size: 11px; white-space: nowrap; border: 1px solid rgba(255, 243, 214, 0.16); }
.run-route i { display: grid; place-items: center; width: 15px; height: 15px; flex: none; border-radius: 50%; border: 1px solid currentColor; font-size: 9px; font-style: normal; }
.run-route li.current { color: #fff6d6; background: #704016; border-color: var(--amber); box-shadow: 0 0 0 1px rgba(255, 184, 77, 0.16); }
.run-route li.done { color: #bff7e1; border-color: rgba(88, 224, 208, 0.5); }
.run-phase { min-height: 17px; text-align: center; margin-top: 3px; font-size: 11px; line-height: 1.4; color: #ffe5ad; }
#bossBar.miniboss { color: #ffedb5; }
#bossBar.miniboss .bar { border-color: #e9ba70; }
#bossBar.miniboss #bossFill { background: linear-gradient(#ffe7a8, #de954d); }
#hud:has(.run-progress:not([hidden])) #streak { top: calc(188px + var(--sat)); }
#streak { position: absolute; right: calc(12px + var(--sar)); top: calc(156px + var(--sat)); font-size: 20px; font-weight: 900; color: var(--amber); text-shadow: 0 2px 0 #5a2d0c, 0 0 10px rgba(0, 0, 0, 0.8); font-variant-numeric: tabular-nums; transform-origin: right center; white-space: nowrap; }
#streak.pop { animation: streakpop 0.16s ease-out; }
@keyframes streakpop { 0% { transform: scale(1.45); } 100% { transform: scale(1); } }
body.debug #modeChip::after { content: "・DEBUG"; color: var(--amber); }
#kills { white-space: nowrap; }

/* ---------- 觸控／按鈕 ---------- */
#controls { position: fixed; inset: 0; z-index: 4; pointer-events: none;
  /* 依畫面短邊控制比例，避免窄手機與橫向畫面仍吃下固定 108px。 */
  --touch-a-size: clamp(80px, 22vmin, 96px); --touch-b-size: calc(var(--touch-a-size) * 0.82); }
#stickZone { position: absolute; left: 0; top: 22%; bottom: 0; width: 55%; pointer-events: auto; touch-action: none; }
body:not(.touch) #stickZone { display: none; }
#stick { position: fixed; width: 124px; height: 124px; margin: -62px 0 0 -62px; border-radius: 50%; border: 2px solid rgba(255, 243, 214, 0.75); background: rgba(20, 40, 35, 0.35); display: none; pointer-events: none; }
#stick.on { display: block; }
#stickKnob { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px 0 0 -28px; border-radius: 50%; background: rgba(255, 243, 214, 0.55); border: 2px solid rgba(255, 255, 255, 0.8); }
body.touch #controls::before { content: "搖桿"; position: absolute; left: calc(46px + var(--sal)); bottom: calc(64px + var(--sab)); width: 96px; height: 96px; border-radius: 50%; border: 2px dashed rgba(30, 51, 40, 0.55); background: rgba(20, 32, 38, 0.14); display: grid; place-items: center; font-size: 12px; font-weight: 700; color: #fff6d6; text-shadow: 0 1px 4px #182c23; }
#btnA, #btnB { position: absolute; pointer-events: auto; touch-action: none; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.75); color: #1b1230; font-weight: 900; cursor: pointer; overflow: hidden;
  display: grid; place-items: center; box-shadow: 0 6px 0 rgba(0, 0, 0, 0.35); transition: transform 0.04s; font-family: inherit; }
#btnA { right: calc(18px + var(--sar)); bottom: calc(clamp(78px, 20vmin, 86px) + var(--sab)); width: var(--touch-a-size); height: var(--touch-a-size); background: radial-gradient(circle at 35% 30%, #ffe2a8, var(--amber)); }
/* B 放在右手側的較低位置；320px 寬時也不越進左側 55% 搖桿區。 */
#btnB { right: calc(18px + var(--touch-a-size) * 0.75 + var(--sar)); bottom: calc(24px + var(--sab)); width: var(--touch-b-size); height: var(--touch-b-size); background: radial-gradient(circle at 35% 30%, #c9fff7, var(--teal)); }
#btnA b, #btnB b { font-size: 34px; line-height: 1; position: relative; z-index: 2; }
#btnA small, #btnB small { position: absolute; bottom: 9px; left: 0; right: 0; text-align: center; font-size: 11px; opacity: 0.6; z-index: 2; }
body.touch #btnA small, body.touch #btnB small { display: none; }
#btnA.down, #btnB.down { transform: translateY(4px) scale(0.96); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.35); filter: brightness(1.15); }
#btnB .cd { position: absolute; inset: 0; border-radius: 50%; z-index: 1; background: conic-gradient(rgba(10, 8, 24, 0.78) calc(var(--cd, 0) * 1turn), transparent 0); }
#btnB em { position: absolute; inset: 0; display: grid; place-items: center; z-index: 3; font-style: normal; font-size: 22px; color: #fff; text-shadow: 0 1px 3px #000; font-variant-numeric: tabular-nums; }
#btnB.cooling b { opacity: 0.25; }
#btnB.cooling { border-color: rgba(255, 255, 255, 0.3); }
body:not(.touch) #btnA { width: 72px; height: 72px; right: 22px; bottom: 26px; }
body:not(.touch) #btnB { width: 72px; height: 72px; right: 106px; bottom: 26px; }
body:not(.touch) #btnA b, body:not(.touch) #btnB b { font-size: 24px; margin-top: -8px; }
body:not(.touch) #btnB em { font-size: 17px; }
@media (orientation: landscape) {
  /* 對齊 input.js 的橫向 32~42px 行程，搖桿帽到外圈內緣就是全速。 */
  body.touch #stick { --stick-half: calc(clamp(32px, 10vmin, 42px) + 26px);
    width: calc(var(--stick-half) * 2); height: calc(var(--stick-half) * 2); margin: calc(0px - var(--stick-half)) 0 0 calc(0px - var(--stick-half)); }
  body.touch #stickKnob { width: 48px; height: 48px; margin: -24px 0 0 -24px; }
}

/* ---------- 面板（暫停／升級） ---------- */
.overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: rgba(8, 6, 18, 0.72); padding: calc(14px + var(--sat)) calc(14px + var(--sar)) calc(14px + var(--sab)) calc(14px + var(--sal)); overflow: auto; touch-action: manipulation; }
.panel { width: min(440px, 100%); background: var(--panel); border: 2px solid var(--line); border-radius: 20px; padding: 22px 20px; text-align: center; box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5); }
.panel h1 { font-size: 26px; margin-bottom: 8px; color: var(--amber); }
.panel h2 { font-size: 22px; margin-bottom: 10px; color: var(--amber); }
.hint { font-size: 13px; line-height: 1.7; color: rgba(255, 243, 214, 0.8); margin-bottom: 14px; }
.btn { display: block; width: 100%; margin-top: 10px; padding: 13px 16px; min-height: 48px; border-radius: 14px; border: 2px solid var(--line); background: var(--panel2); color: var(--cream); font-size: 16px; font-weight: 800; cursor: pointer; font-family: inherit; touch-action: manipulation; }
.btn.primary { background: var(--amber); color: #1b1230; border-color: #ffe2a8; }
.btn:active { transform: translateY(2px); filter: brightness(1.1); }
.btn:focus-visible, .card:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }


.build { margin-bottom: 12px; display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; }
.build .hint { flex-basis: 100%; }
.build .chip { padding: 3px 10px; font-size: 12px; }
.build .chip.kA { border-color: var(--amber); }
.build .chip.kB { border-color: var(--teal); }
.build .chip.kW { border-color: #c8f08a; }
#resume { z-index: 40; }
#pause { z-index: 24; }
.resume-profile { padding: 6px 10px; margin-bottom: 8px; color: #d6fff3; font-weight: 800; border-radius: 10px; background: rgba(88,224,208,.12); }
/* 小店是獨立安全房間；捲動由面板自己負責，不讓背後搖桿接到手勢。 */
.rest-shop { z-index: 22; display: flex; justify-content: center; align-items: flex-start; touch-action: pan-y; background: radial-gradient(ellipse at 30% 10%, rgba(55, 89, 74, .92), rgba(15, 12, 31, .97) 75%); }
.rest-wrap { width: min(820px, 100%); margin: auto 0; padding: 22px 24px 18px; border-radius: 24px; border: 2px solid #9ec8a5; background: linear-gradient(145deg, #233c36, #222037 80%); box-shadow: 0 18px 55px rgba(0,0,0,.4); text-align: center; }
.rest-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.rest-eyebrow { font-size: 12px; font-weight: 800; color: #bce8cf; }
.rest-pause { min-height: 38px; padding: 6px 11px; border-radius: 10px; border: 1px solid #759a84; background: #23342f; color: var(--cream); font-family: inherit; font-size: 12px; font-weight: 700; cursor: pointer; touch-action: manipulation; }
.rest-hosts { display: flex; justify-content: center; align-items: center; gap: 28px; margin: 10px 0 6px; font-size: 44px; line-height: 1; }
.rest-hosts > span { position: relative; display: inline-block; }
.rest-hosts i { position: absolute; bottom: -4px; right: -13px; font-size: 28px; font-style: normal; }
.rest-hosts .rest-steam { color: #ffde99; font-size: 28px; }
.rest-wrap h2 { color: #ffe4a2; font-size: clamp(23px, 4vw, 30px); line-height: 1.3; }
.rest-sub { margin-top: 5px; font-size: 13px; line-height: 1.5; color: #dbeddc; }
.rest-safe { display: inline-block; margin: 9px 0 12px; padding: 4px 12px; border-radius: 99px; background: rgba(88,224,208,.15); color: #c5ffe9; font-size: 12px; font-weight: 700; }
.rest-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.rest-card { display: flex; flex-direction: column; align-items: center; gap: 7px; min-width: 0; min-height: 200px; padding: 15px 12px; color: var(--cream); background: #294038; border: 2px solid #85baa0; border-radius: 17px; font-family: inherit; cursor: pointer; touch-action: manipulation; }
.rest-card b { font-size: 23px; line-height: 1.2; }
.rest-card > span:not(.rest-tag) { font-size: 13px; line-height: 1.6; }
.rest-card strong { margin-top: auto; padding: 6px 9px; border-radius: 8px; background: rgba(0,0,0,.25); font-size: 16px; font-variant-numeric: tabular-nums; color: #fff1ca; }
.rest-card small { font-size: 11px; line-height: 1.5; color: #e7e7d8; }
.rest-tag { padding: 2px 9px; border-radius: 99px; font-size: 11px; background: rgba(255,255,255,.1); }
.rest-spicy { background: #55342f; border-color: #ef987b; }
.rest-plain { background: #323342; border-color: #a8aec5; }
.rest-card:active { transform: translateY(2px); }
.rest-card:focus-visible, .rest-pause:focus-visible { outline: 3px solid var(--amber); outline-offset: 3px; }
.rest-foot { margin-top: 12px; color: #cdd9d1; font-size: 11px; line-height: 1.6; }
@media (max-width: 620px) and (orientation: portrait) {
  .rest-wrap { padding: 15px 14px; }
  .rest-cards { grid-template-columns: 1fr; gap: 9px; }
  .rest-card { display: grid; grid-template-columns: 1fr auto; align-items: center; text-align: left; gap: 3px 10px; padding: 11px 13px; min-height: 0; }
  .rest-card b { font-size: 21px; grid-column: 1; }
  .rest-tag { justify-self: start; grid-column: 1; }
  .rest-card > span:not(.rest-tag) { grid-column: 1; font-size: 12px; }
  .rest-card strong { grid-column: 2; grid-row: 1 / 4; margin: 0; font-size: 14px; }
  .rest-card small { grid-column: 1 / -1; }
  .rest-hosts { font-size: 36px; margin-top: 10px; }
  .rest-sub { font-size: 12px; }
}
#levelup .lv-wrap { width: min(760px, 100%); text-align: center; }
#levelup h2 { font-size: 24px; color: var(--amber); margin-bottom: 4px; }
#levelup .sub { font-size: 13px; color: rgba(255, 243, 214, 0.75); margin-bottom: 14px; }
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.card { background: var(--panel); border: 2px solid var(--line); border-radius: 18px; padding: 16px 12px; color: var(--cream); cursor: pointer; text-align: center; font-family: inherit; min-height: 150px; display: flex; flex-direction: column; align-items: center; gap: 6px; touch-action: manipulation; }
/* 保持卡片命中區固定，游標停在底緣時也能穩定選牌。 */
.card:hover { border-color: var(--amber); }
.card .tag { font-size: 11px; font-weight: 800; padding: 2px 10px; border-radius: 10px; background: rgba(255, 255, 255, 0.12); }
.card.kA .tag { background: var(--amber); color: #1b1230; }
.card.kB .tag { background: var(--teal); color: #1b1230; }
.card.kW .tag { background: #c8f08a; color: #1b1230; }
.card .name { font-size: 18px; font-weight: 900; }
.card .desc { font-size: 13px; line-height: 1.55; color: rgba(255, 243, 214, 0.85); }
.card .key { margin-top: auto; font-size: 11px; opacity: 0.55; }
body.touch .card .key { display: none; }
@media (max-width: 620px) and (orientation: portrait) {
  /* 直向時面板靠上：矮螢幕上第三張卡才不會壓到 A 鍵的位置被連點誤選 */
  #levelup { align-items: start; padding-top: calc(56px + var(--sat)); }
  .cards { grid-template-columns: 1fr; }
  .card { min-height: 0; flex-direction: row; flex-wrap: wrap; text-align: left; padding: 12px 14px; }
  .card .desc { flex-basis: 100%; }
}
#chips { transition: opacity 0.6s; }
#chips.dim { opacity: 0.4; }
/* 窄螢幕：把位置讓給血條，擊倒數留到結算再看 */
@media (max-width: 480px) {
  #kills { display: none; } .hud-right { flex: 0 0 auto; }
  #banner:not([hidden]) ~ #streak { visibility: hidden; }   /* 橫幅出現的那幾秒先讓位，字才不會疊在一起 */
  .run-route li { gap: 3px; font-size: 10px; }
  .run-route i { width: 12px; height: 12px; font-size: 8px; }
}
@media (max-height: 430px) {
  #btnA { bottom: calc(34px + var(--sab)); }
  #btnB { right: calc(30px + var(--touch-a-size) + var(--sar)); bottom: calc(12px + var(--sab)); }
  #chips { display: none; }
  #streak { top: calc(84px + var(--sat)); font-size: 17px; }
  /* 橫向高度很矮：Boss 血條與橫幅收小，別蓋到畫面正中的主角 */
  #bossBar { margin-top: 3px; font-size: 11px; }
  #bossBar .bar { height: 8px; margin-top: 1px; }
  #banner { margin-top: 4px; padding: 4px 14px; font-size: 14px; }
  #levelup { align-items: start; }   /* 面板貼上緣，第三張卡才不會壓到 A 鍵 */
  .card { min-height: 0; padding: 10px; }
  .panel { padding: 14px 16px; }
  .hint { margin-bottom: 6px; line-height: 1.5; }
  .run-progress { margin-top: 3px; max-width: 550px; }
  .run-route li { padding: 2px; font-size: 10px; }
  .run-phase { margin-top: 1px; min-height: 14px; font-size: 10px; }
  #hud:has(.run-progress:not([hidden])) #streak { top: calc(122px + var(--sat)); font-size: 16px; }
  .rest-wrap { padding: 10px 14px; }
  .rest-hosts, .rest-sub { display: none; }
  .rest-wrap h2 { font-size: 22px; margin-top: 3px; }
  .rest-safe { margin: 4px 0 8px; padding: 2px 10px; }
  .rest-card { min-height: 162px; padding: 10px; gap: 4px; }
  .rest-card b { font-size: 21px; }
  .rest-foot { margin-top: 6px; }
}
@media (prefers-reduced-motion: reduce) { #banner.danger, #hpFill.low, #streak.pop { animation: none; } }
