/* =========================================================
   BALLSY — UI
   参考语言：Game Boy 卡带面板 / 8-bit 像素字体 / 双层描边
   ========================================================= */

@font-face {
  font-family: 'PressStart';
  src: url('fonts/PressStart2P.woff2') format('woff2'),
       url('fonts/PressStart2P.ttf') format('truetype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg:      #050408;
  --panel:   #08070b;
  --line:    #b8b2a4;
  --line-2:  #3a3644;
  --text:    #f2ede2;
  --muted:   #8a8396;
  --red:     #d63b2f;
  --red-hi:  #e8564a;
  --yellow:  #f0c040;
  --pink:    #f0a0a0;
  --px: 'PressStart', ui-monospace, monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--px);
  overscroll-behavior: none;
  -webkit-font-smoothing: none;
  font-smooth: never;
}

body::before {
  content: "";
  position: fixed; inset: 0;
  background:
    radial-gradient(80% 45% at 50% 0%, rgba(107, 79, 160, .10), transparent 70%),
    radial-gradient(70% 40% at 50% 110%, rgba(214, 59, 47, .07), transparent 70%);
  pointer-events: none;
}

/* ---------- 卡带面板 ---------- */
#app {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 430px;
  height: min(calc(100dvh - 12px), 920px);
  margin: 6px auto;
  padding: 10px;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 7px;
  box-shadow:
    0 0 0 2px #050408,
    0 0 0 3px var(--line-2),
    0 24px 70px -30px #000;
  overflow: hidden;
}

/* ---------- HUD ---------- */
#hud { flex: 0 0 auto; }

.hud__top {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 2px 8px;
}
.hud__name {
  font-size: 13px;
  letter-spacing: .02em;
  color: var(--text);
}
.hud__heart {
  width: 16px; height: 14px;
  image-rendering: pixelated;
  margin-top: -1px;
}
.hud__count {
  margin-left: auto;
  font-size: 11px;
  color: var(--yellow);
  letter-spacing: .04em;
}

.hud__bar {
  display: flex;
  align-items: center;
  gap: 8px;
}
.hud__label {
  font-size: 9px;
  color: var(--text);
  letter-spacing: .06em;
}
.meter {
  flex: 1;
  height: 15px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #14121a;
  padding: 2px;
  overflow: hidden;
  position: relative;
}
.meter i {
  display: block;
  height: 100%;
  width: 60%;
  border-radius: 5px;
  background: linear-gradient(180deg, var(--red-hi) 0 40%, var(--red) 40% 100%);
  transition: width .45s cubic-bezier(.2, .9, .2, 1), background .3s;
}
.meter i::after {
  content: "";
  display: block;
  height: 1px;
  margin-top: 1px;
  background: rgba(255, 255, 255, .3);
}

#helpBtn {
  width: 24px; height: 24px;
  flex: 0 0 24px;
  display: grid; place-items: center;
  font-family: var(--px);
  font-size: 10px;
  color: var(--muted);
  background: #14121a;
  border: 2px solid var(--line-2);
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
}
#helpBtn:active { color: var(--text); border-color: var(--line); }

#wearBtn {
  height: 24px;
  flex: 0 0 auto;
  display: grid; place-items: center;
  font-family: var(--px);
  font-size: 8px;
  letter-spacing: 0;
  color: var(--muted);
  background: #14121a;
  border: 2px solid var(--line-2);
  border-radius: 4px;
  cursor: pointer;
  padding: 0 5px;
}
#wearBtn:active { color: var(--yellow); border-color: var(--yellow); }

/* ---------- 游戏画面 ---------- */
#frame {
  position: relative;
  flex: 1 1 auto;
  min-height: 140px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0d0b10;
  border: 2px solid var(--line-2);
  border-radius: 3px;
  overflow: hidden;
}
#frame canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

/* ---------- 开场 ---------- */
.hidden { display: none !important; }
#tapHint {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  font-size: 8px;
  letter-spacing: 3px;
  color: var(--amber, #f0c040);
  text-shadow: 0 0 6px rgba(240, 192, 64, .5);
  pointer-events: none;
  z-index: 3;
  animation: tapBlink 1.2s steps(1, end) infinite;
}
@keyframes tapBlink {
  0%, 60% { opacity: 1; }
  61%, 100% { opacity: .2; }
}
#skipIntro {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 40;
  font-family: inherit;
  font-size: 8px;
  letter-spacing: 1px;
  color: #8a8396;
  background: rgba(12, 10, 16, .8);
  border: 2px solid #2e2740;
  padding: 6px 9px;
  cursor: pointer;
}
body.intro #hud { opacity: 0; pointer-events: none; }

/* ---------- 对话框 ---------- */
#dialogue {
  flex: 0 0 auto;
  height: 108px;
  padding: 8px 10px 9px;
  border: 2px solid var(--line);
  border-radius: 4px;
  background: #0e0c12;
  box-shadow: inset 0 0 0 2px #050408;
  overflow: hidden;
}
.dlg__head {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 9px;
  letter-spacing: .06em;
  color: var(--text);
  margin-bottom: 7px;
}
.dlg__dot {
  width: 6px; height: 6px;
  background: var(--yellow);
  flex: 0 0 6px;
}
.dlg__body {
  margin: 0;
  font-size: 10px;
  line-height: 1.85;
  letter-spacing: .01em;
  color: var(--text);
  opacity: 0;
  transition: opacity .18s;
}
.dlg__body.in { opacity: 1; }

/* ---------- 弹层 ---------- */
#sheet {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(4, 3, 7, .86);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
  z-index: 20;
}
#sheet.hidden { display: none; }

/* 衣橱模式：贴底、不模糊，换装时能看见他 */
#sheet.wardrobe {
  place-items: end center;
  padding: 0 10px 10px;
  background: rgba(4, 3, 7, .38);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}
#sheet.wardrobe .sheet__inner {
  width: min(94vw, 400px);
  max-height: 62vh;
  overflow: auto;
  padding: 10px;
}
#sheet.wardrobe .sheet__q { margin: 0 0 8px; font-size: 9px; }
#sheet.wardrobe .opts {
  flex-direction: row;
  overflow-x: auto;
  gap: 6px;
  padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
}
#sheet.wardrobe .opts button {
  flex: 0 0 auto;
  padding: 8px 10px;
  font-size: 9px;
  white-space: nowrap;
}
#sheet.wardrobe .keys { margin: 8px 0 6px; font-size: 8px; }
#sheet.wardrobe .close { padding: 11px; margin-top: 2px; }

.sheet__inner {
  width: min(94vw, 400px);
  padding: 16px;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 0 0 2px #050408, 0 0 0 3px var(--line-2);
}
.sheet__q {
  margin: 0 0 14px;
  font-size: 11px;
  line-height: 1.9;
  color: var(--text);
}
.opts { display: flex; flex-direction: column; gap: 7px; }
.opts button {
  font-family: var(--px);
  font-size: 10px;
  text-align: left;
  padding: 12px 12px;
  color: var(--text);
  background: #14121a;
  border: 2px solid var(--line-2);
  border-radius: 4px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.opts button:active { border-color: var(--yellow); background: #1b1726; }
.opts button.worn { color: var(--yellow); border-color: var(--yellow); background: #1b1726; }

.keys {
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
  font-size: 9px;
  line-height: 2.1;
  color: var(--muted);
}
.keys b { color: var(--yellow); font-weight: 400; }

.close {
  width: 100%;
  font-family: var(--px);
  font-size: 10px;
  letter-spacing: .08em;
  padding: 12px;
  color: #08070b;
  background: var(--line);
  border: 0;
  border-radius: 4px;
  cursor: pointer;
}

/* ---------- 小屏微调 ---------- */
@media (max-height: 680px) {
  #app { gap: 6px; padding: 8px; }
  .dlg__body { font-size: 9px; line-height: 1.85; min-height: 3.7em; }
  #dialogue { min-height: 82px; padding: 6px 8px 7px; }
  .hud__name { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
