/* ===== 星陨守望 · Starfall Vanguard ===== */
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --ink: #0d0d14;
  --bg: #1a1c2c;
  --bg2: #29366f;
  --line: #566c86;
  --hi: #94b0c2;
  --txt: #f4f4f4;
  --gold: #ffcd75;
  --red: #b13e53;
  --blue: #3b5dc9;
  --cyan: #41a6f6;
  --green: #a7f070;
}

html, body { height: 100%; }
body {
  background: var(--ink);
  background-image: radial-gradient(circle at 20% 10%, rgba(59,93,201,.10), transparent 45%),
                    radial-gradient(circle at 85% 85%, rgba(93,39,93,.14), transparent 45%);
  color: var(--txt);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  font-weight: 700;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

#app { height: 100dvh; display: flex; flex-direction: column; max-width: 1100px; margin: 0 auto; }

/* ---------- top bar ---------- */
#topbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 6px 10px;
  background: var(--bg);
  border-bottom: 3px solid var(--ink);
  box-shadow: 0 3px 0 rgba(148,176,194,.15);
  font-size: 13px;
  z-index: 5;
}
#chapterLabel { color: var(--gold); letter-spacing: 1px; white-space: nowrap; }
#turnLabel { color: var(--cyan); white-space: nowrap; }
#objLabel { color: var(--hi); font-size: 12px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tb-btns { display: flex; gap: 6px; margin-left: auto; }

/* ---------- stage / canvas ---------- */
#stage {
  position: relative; flex: 1; min-height: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 8px; overflow: hidden;
}
#stage::after {  /* scanlines */
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,.14) 0 1px, transparent 1px 3px);
  opacity: .5; z-index: 3;
}
#game {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: var(--ink);
  box-shadow: 0 0 0 3px var(--ink), 0 0 0 5px var(--line), 0 10px 30px rgba(0,0,0,.6);
  touch-action: none;
  cursor: pointer;
}

/* ---------- turn banner ---------- */
#banner {
  position: absolute; left: 0; right: 0; top: 42%;
  text-align: center; padding: 12px 0;
  font-size: clamp(20px, 4.5vw, 34px); letter-spacing: 6px;
  color: var(--txt);
  background: linear-gradient(90deg, transparent, rgba(13,13,20,.92) 18%, rgba(13,13,20,.92) 82%, transparent);
  border-top: 2px solid var(--hi); border-bottom: 2px solid var(--hi);
  z-index: 6; pointer-events: none;
  animation: bannerIn .95s ease both;
}
#banner.player { color: var(--cyan); }
#banner.enemy  { color: #ef7d57; }
#banner.win    { color: var(--gold); }
#banner.lose   { color: var(--red); }
#banner.obj    { color: var(--green); letter-spacing: 2px; font-size: clamp(15px, 3vw, 22px); }
@keyframes bannerIn {
  0%   { opacity: 0; transform: translateX(-30px); }
  15%  { opacity: 1; transform: none; }
  80%  { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateX(30px); }
}

/* ---------- dialog ---------- */
#dialog {
  position: absolute; left: 10px; right: 10px; bottom: 10px;
  background: rgba(13,13,20,.94);
  border: 3px solid var(--hi);
  box-shadow: 0 0 0 3px var(--ink), inset 0 0 0 2px var(--ink);
  padding: 10px 14px 8px;
  min-height: 92px;
  z-index: 7; cursor: pointer;
}
#dlgName { color: var(--gold); font-size: 14px; margin-bottom: 6px; letter-spacing: 2px; }
#dlgText { font-size: 15px; line-height: 1.65; min-height: 3.2em; color: var(--txt); }
#dlgHint { text-align: right; color: var(--hi); font-size: 12px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- 行动菜单（贴在角色旁）---------- */
#cmdMenu {
  position: absolute; z-index: 5;
  display: flex; flex-direction: column; gap: 5px;
  background: rgba(13,13,20,.93);
  border: 2px solid var(--hi);
  box-shadow: 0 0 0 2px var(--ink), 5px 5px 0 rgba(13,13,20,.55);
  padding: 6px;
  min-width: 112px;
  animation: menuIn .1s steps(2) both;
}
#cmdMenu .pbtn { font-size: 13px; padding: 8px 12px; min-height: 38px; text-align: left; }
@keyframes menuIn { from { transform: translateX(-4px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { #cmdMenu { animation: none; } }

/* 选择目标时的底部提示（不拦截点击，目标永远可点）*/
#cmdHint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  z-index: 5; pointer-events: none;
  background: rgba(13,13,20,.88);
  border: 2px solid var(--line);
  box-shadow: 0 0 0 2px var(--ink);
  color: var(--hi); font-size: 12px; letter-spacing: 1px;
  padding: 7px 14px; white-space: nowrap; max-width: 92%;
  overflow: hidden; text-overflow: ellipsis;
}

/* ---------- full screen overlays (title / result / help) ---------- */
#screen {
  position: absolute; inset: 0; z-index: 8;
  display: flex; align-items: center; justify-content: center;
  background: rgba(13,13,20,.68);
  overflow-y: auto; padding: 16px;
}
.menu { text-align: center; display: flex; flex-direction: column; gap: 12px; align-items: center; max-width: 560px; width: 100%; }
.menu.narrow { max-width: 400px; }
.logo {
  font-size: clamp(34px, 9vw, 64px); letter-spacing: 10px; color: var(--gold);
  text-shadow: 4px 4px 0 var(--red), 8px 8px 0 var(--ink);
  margin-bottom: 2px;
}
.menu .sub { color: var(--hi); letter-spacing: 4px; font-size: 13px; margin-bottom: 6px; }
.menu .tiny { color: var(--line); font-size: 12px; margin-top: 4px; }
/* 菜单窗：把零散的按钮收进一个像素窗口 */
.mframe {
  width: 100%;
  display: flex; flex-direction: column; gap: 10px;
  background: var(--bg);
  border: 3px solid var(--line);
  box-shadow: 0 0 0 3px var(--ink), 8px 8px 0 rgba(13,13,20,.5);
  padding: 18px 20px;
}
.mframe .pbtn.big { width: 100%; }
.mdiv { display: flex; align-items: center; gap: 10px; color: var(--hi); font-size: 12px; letter-spacing: 3px; margin-top: 4px; }
.mdiv::before, .mdiv::after { content: ""; flex: 1; height: 2px; background: var(--line); opacity: .55; }
.chrow { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.btnrow { display: flex; gap: 8px; }
.btnrow .pbtn { flex: 1; }
.clearline { color: var(--gold); font-size: 13px; letter-spacing: 2px; }
.helpbox {
  text-align: left; background: var(--bg); border: 3px solid var(--line);
  box-shadow: 0 0 0 3px var(--ink);
  padding: 14px 16px; font-size: 14px; line-height: 1.8; font-weight: 400;
  max-height: 60dvh; overflow-y: auto; width: 100%;
}
.helpbox b { color: var(--gold); }
.helpbox li { margin-left: 1.2em; margin-bottom: 4px; }
.ending p { font-size: 15px; line-height: 2; color: var(--txt); margin-bottom: 10px; font-weight: 400; }
.ending .fin { color: var(--gold); font-size: 20px; letter-spacing: 6px; margin: 14px 0; font-weight: 700; }
.lvline { color: var(--hi); font-size: 13px; }

/* ---------- bottom panel（战斗信息栏，仅战斗中显示）---------- */
#panel {
  display: flex; align-items: center;
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 3px solid var(--ink);
  box-shadow: 0 -3px 0 rgba(148,176,194,.15);
  height: calc(102px + env(safe-area-inset-bottom));
  max-height: 30dvh; overflow-y: auto;
  z-index: 5;
}
#unitCard {
  flex: 1 1 auto; min-width: 0;
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; color: var(--hi);
}
#unitCard canvas { image-rendering: pixelated; flex: none; background: rgba(13,13,20,.5); box-shadow: 0 0 0 2px var(--ink), 0 0 0 3px var(--line); }
#unitCard .uc-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
#unitCard .uc-name { color: var(--txt); font-size: 14px; line-height: 20px; }
#unitCard .uc-name .job { color: var(--cyan); font-size: 12px; margin-left: 6px; }
#unitCard .uc-name .lv { color: var(--gold); font-size: 12px; margin-left: 6px; }
#unitCard .uc-stats { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; line-height: 17px; }
#unitCard .uc-stats span b { color: var(--txt); }
.hpbar { width: 130px; height: 10px; background: var(--ink); box-shadow: 0 0 0 2px var(--ink); position: relative; }
.hpbar i { display: block; height: 100%; background: var(--green); transition: width .25s; }
.hpbar.low i { background: var(--gold); }
.hpbar.crit i { background: var(--red); }
.hpnum { color: var(--txt); font-size: 11px; margin-left: 6px; }
.terraintag { color: var(--green); font-size: 12px; }
.skilltag { color: #c77dff; font-size: 12px; }

/* ---------- pixel buttons ---------- */
.pbtn {
  font-family: inherit; font-weight: 700; font-size: 14px;
  color: var(--txt); background: var(--bg2);
  border: 0; padding: 10px 16px; min-height: 42px; min-width: 42px;
  cursor: pointer; letter-spacing: 1px;
  box-shadow: 0 0 0 2px var(--ink), inset 2px 2px 0 0 rgba(115,239,247,.35), inset -2px -2px 0 0 rgba(13,13,20,.6);
}
.pbtn:hover { filter: brightness(1.15); }
.pbtn:active { transform: translate(1px, 1px); }
.pbtn:disabled { opacity: .4; cursor: not-allowed; transform: none; }
.pbtn.warn { background: var(--red); }
.pbtn.skill { background: #5d275d; }
.pbtn.ghost { background: #333c57; }
.pbtn.big { font-size: 17px; padding: 13px 34px; letter-spacing: 3px; }
.pbtn.small { font-size: 12px; padding: 6px 10px; min-height: 32px; }
.pbtn.chbtn { min-width: 46px; padding: 8px 0; }
.pbtn.gold { background: #8a6b1f; color: var(--gold); }

.hidden { display: none !important; }

/* ---------- responsive ---------- */
@media (max-width: 620px) {
  #topbar { font-size: 11px; gap: 6px; padding: 5px 6px; }
  #objLabel { display: none; }
  #stage { padding: 4px; }
  #dialog { left: 4px; right: 4px; bottom: 4px; min-height: 80px; }
  #dlgText { font-size: 14px; }
  #panel { padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); height: calc(98px + env(safe-area-inset-bottom)); }
  .hpbar { width: 90px; }
  .mframe { padding: 12px 12px; }
}
@media (max-height: 460px) {  /* phone landscape */
  #topbar { font-size: 11px; padding: 3px 8px; }
  .pbtn.small { min-height: 26px; padding: 3px 8px; }
  #panel { height: 92px; max-height: none; padding: 4px 8px; }
  #unitCard canvas { display: none; }
  #cmdMenu { min-width: 96px; padding: 4px; gap: 4px; }
  #cmdMenu .pbtn { min-height: 28px; padding: 4px 8px; font-size: 12px; }
  .menu { gap: 8px; }
  .mframe { padding: 10px 12px; gap: 7px; }
  .logo { font-size: 30px; }
}
