:root {
  --bg: #05080f;
  --panel: #0c1521;
  --panel2: #111d2c;
  --line: rgba(70, 220, 205, .20);
  --ink: #d7ecf7;
  --dim: #7e94a8;
  --acc: #3ee0c8;
  --warn: #ffb454;
  --bad: #ff5f72;
  --hp: #ff5b6e;
  --void: #6d5dff;
}

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

html, body {
  margin: 0; padding: 0; height: 100%;
  background: radial-gradient(120% 80% at 50% 0%, #0d1b2b 0%, #05080f 55%, #020407 100%);
  color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  overscroll-behavior: none;
  user-select: none;
}

body { display: flex; justify-content: center; align-items: center; }

#app {
  width: 100%; max-width: 430px;
  min-height: 100dvh;
  display: flex; flex-direction: column; justify-content: center;
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  gap: 8px;
}

@media (max-height: 700px) {
  body { align-items: flex-start; }
  #app { justify-content: flex-start; }
}

/* ---------- 機身 ---------- */

#device {
  display: flex; flex-direction: column; gap: 8px;
  background: linear-gradient(180deg, #0c1725 0%, #070e18 100%);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 10px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .5), 0 18px 50px -20px rgba(62, 224, 200, .35), inset 0 1px 0 rgba(255, 255, 255, .04);
}

#hud {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12.5px; letter-spacing: .04em;
  padding: 2px 4px;
}
.hud-l, .hud-r { display: flex; align-items: center; gap: 6px; }
.hud-r { color: var(--dim); }

#vName { font-size: 15px; font-weight: 700; letter-spacing: .06em; }
#vDay { font-variant-numeric: tabular-nums; }

.tag {
  font-size: 10.5px; padding: 1px 7px; border-radius: 999px;
  border: 1px solid currentColor;
  color: var(--acc);
  opacity: .9;
}

/* ---------- 螢幕 ---------- */

#screen {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: #04101a;
  border: 1px solid rgba(62, 224, 200, .18);
  box-shadow: inset 0 0 40px rgba(0, 0, 0, .8), inset 0 0 0 1px rgba(62, 224, 200, .06);
  aspect-ratio: 1 / 1;
}

#cv {
  display: block; width: 100%; height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

#screen::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(180deg, rgba(0, 0, 0, .16) 0 2px, rgba(0, 0, 0, 0) 2px 4px);
  mix-blend-mode: multiply;
}

#call {
  position: absolute; top: 8px; right: 8px;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--warn); color: #24160a;
  font-weight: 900; display: grid; place-items: center;
  animation: blink .8s infinite steps(2);
  box-shadow: 0 0 14px rgba(255, 180, 84, .8);
}
@keyframes blink { 50% { opacity: .2; } }

/* ---------- 計量條 ---------- */

#meters { display: flex; flex-direction: column; gap: 5px; padding: 0 2px; }

.meter { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--dim); }
.meter > span { width: 30px; flex: none; letter-spacing: .1em; }
.meter > b { width: 30px; text-align: right; color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

.bar {
  flex: 1; height: 9px; border-radius: 999px;
  background: rgba(255, 255, 255, .07);
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(0, 0, 0, .6);
}
.bar > i {
  display: block; height: 100%; width: 0%;
  border-radius: 999px;
  transition: width .35s ease, background .35s;
  background: linear-gradient(90deg, #1f8f7c, #52f0cf);
}
#mEnergy { background: linear-gradient(90deg, #7a6bff, #b9a8ff); }
#mMood { background: linear-gradient(90deg, #b76a1f, #ffc96b); }

#goal {
  font-size: 11.5px; letter-spacing: .02em;
  color: var(--dim);
  padding: 0 4px;
  min-height: 16px;
  display: flex; align-items: center; gap: 6px;
  white-space: nowrap; overflow: hidden;
}
#goal b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
#goal.ready { color: #6ff0b4; }
#goal.warn { color: #ff9aa6; }
#goal.done { color: var(--warn); }

/* ---------- 按鈕 ---------- */

#pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

#pad button, .btn {
  appearance: none; border: 1px solid rgba(90, 220, 255, .16);
  background: linear-gradient(180deg, #16253a, #101a29);
  color: var(--ink);
  border-radius: 13px;
  min-height: 56px;
  font-size: 15px; font-family: inherit; letter-spacing: .08em;
  cursor: pointer;
  transition: transform .06s, filter .15s, box-shadow .15s;
  box-shadow: 0 3px 0 rgba(0, 0, 0, .35), inset 0 1px 0 rgba(255, 255, 255, .05);
}

#pad button {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: 6px 2px 7px;
}
#pad button .ico {
  width: 26px; height: 26px;
  image-rendering: pixelated;
  display: block;
  filter: drop-shadow(0 0 6px rgba(90, 220, 255, .18));
}
#pad button span { font-size: 12px; letter-spacing: .1em; line-height: 1; }

#pad button:active, .btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, .35); filter: brightness(1.25); }
#pad button:disabled { opacity: .35; }

#pad button.hot { border-color: rgba(255, 180, 84, .5); color: #ffd9a3; }
#pad button.prime { background: linear-gradient(180deg, #1b3b3a, #11282a); border-color: rgba(62, 224, 200, .45); color: #b9fff2; }

/* ---------- 覆蓋層 ---------- */

#overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(2, 5, 10, .78);
  backdrop-filter: blur(7px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .16s ease;
}
@keyframes fade { from { opacity: 0; } }

#panel {
  width: 100%; max-width: 430px;
  max-height: 92dvh; overflow-y: auto;
  background: linear-gradient(180deg, #0e1927, #0a131e);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: 18px 18px 0 0;
  padding: 16px 14px calc(18px + env(safe-area-inset-bottom));
  box-shadow: 0 -20px 60px rgba(0, 0, 0, .7);
  animation: slideup .22s cubic-bezier(.2, .9, .3, 1);
  overscroll-behavior: contain;
}
@keyframes slideup { from { transform: translateY(40px); opacity: .4; } }

.hidden { display: none !important; }

.phead {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px; padding-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, .07);
}
.phead h2 { margin: 0; font-size: 17px; letter-spacing: .1em; font-weight: 700; }
.phead .close {
  width: 34px; height: 34px; border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, .12);
  background: rgba(255, 255, 255, .04);
  color: var(--ink); font-size: 17px; cursor: pointer;
}

.row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 12px; margin-bottom: 8px;
  background: var(--panel2);
  border: 1px solid rgba(255, 255, 255, .06);
  border-radius: 12px;
  font-size: 13.5px;
}
.row .grow { flex: 1; min-width: 0; }
.row small { color: var(--dim); font-size: 11.5px; display: block; margin-top: 2px; line-height: 1.5; }
.row .val { font-variant-numeric: tabular-nums; color: var(--acc); font-weight: 700; }

.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.btn-row .btn { flex: 1; min-height: 46px; }

.btn.ghost { background: rgba(255, 255, 255, .03); }
.btn.danger { color: #ffb3bd; border-color: rgba(255, 95, 114, .4); }
.btn.ok { color: #b9fff2; border-color: rgba(62, 224, 200, .45); }

/* 圖鑑 */
.dexgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.dexcell {
  background: var(--panel2); border-radius: 10px; padding: 6px 4px 8px;
  text-align: center; border: 1px solid rgba(255, 255, 255, .05);
}
.dexcell img { width: 100%; max-width: 62px; image-rendering: pixelated; display: block; margin: 0 auto 2px; }
.dexcell span { font-size: 10.5px; color: var(--ink); display: block; line-height: 1.25; }
.dexcell.locked img { filter: brightness(0) opacity(.28); }
.dexcell.locked span { color: #46566a; }

/* 進化圖 */
.evoblock { margin-bottom: 10px; }
.evoblock h3 { font-size: 12px; color: var(--dim); font-weight: 600; letter-spacing: .12em; margin: 0 0 6px; }
.evoopt {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 12px; margin-bottom: 6px;
  background: var(--panel2); border: 1px solid rgba(255, 255, 255, .05);
}
.evoopt img { width: 42px; height: 42px; image-rendering: pixelated; flex: none; }
.evoopt .grow { flex: 1; min-width: 0; }
.evoopt .nm { font-size: 13.5px; font-weight: 600; }
.evoopt .rq { font-size: 11px; color: var(--dim); margin-top: 3px; line-height: 1.5; }
.evoopt .rq .ok { color: #7dffb0; }
.evoopt .rq .no { color: #ff8d9c; }
.evoopt.ready { border-color: rgba(62, 224, 200, .45); box-shadow: 0 0 0 1px rgba(62, 224, 200, .12) inset; }

/* 升級 */
.upg { display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-bottom: 8px; border-radius: 12px; background: var(--panel2); border: 1px solid rgba(255, 255, 255, .05); }
.upg .grow { flex: 1; min-width: 0; }
.upg b { font-size: 13.5px; font-weight: 600; }
.upg b em { font-style: normal; color: var(--dim); font-weight: 500; font-size: 11.5px; margin-left: 6px; }
.upg small { display: block; color: var(--dim); font-size: 11.5px; margin-top: 4px; line-height: 1.5; }
.upg .pips { display: flex; gap: 3px; margin-top: 6px; }
.upg .pips i { width: 12px; height: 5px; border-radius: 3px; background: rgba(255, 255, 255, .12); }
.upg .pips i.on { background: var(--acc); }
.upg button { flex: none; }

.logline { font-size: 12px; color: var(--dim); padding: 6px 2px; border-bottom: 1px dashed rgba(255, 255, 255, .06); line-height: 1.5; }
.logline b { color: var(--ink); font-weight: 500; margin-right: 6px; font-size: 11px; }

/* 提示 */
#toast {
  position: fixed; left: 50%; bottom: 26%; transform: translateX(-50%);
  background: rgba(10, 20, 30, .96);
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 9px 16px; border-radius: 999px;
  font-size: 13px; letter-spacing: .04em;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
  z-index: 40; white-space: nowrap; max-width: 88vw; overflow: hidden; text-overflow: ellipsis;
}
#toast.on { opacity: 1; transform: translateX(-50%) translateY(-6px); }

/* 散步／訓練面板 */
.fullscreen-panel { text-align: center; }
.bigbtn {
  width: 100%; min-height: 96px; border-radius: 16px;
  font-size: 19px; letter-spacing: .16em; font-weight: 700;
  background: linear-gradient(180deg, #1b3b3a, #0f2630);
  border: 1px solid rgba(62, 224, 200, .45);
  color: #c6fff5;
}
.bigbtn:active { filter: brightness(1.3); }
.hint { font-size: 12px; color: var(--dim); line-height: 1.7; margin: 10px 2px; }
