/* [claude code] 2026-08-27 建案:版面與樣式(零框架,純手寫) */

:root {
  --bg: #0b1026;
  --bg2: #131a3d;
  --card: #182150;
  --line: #2b3670;
  --fg: #e8ecff;
  --muted: #9aa6d8;
  --accent: #ffd76e;
  --good: #3ddc84;
  --bad: #ff6b6b;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: radial-gradient(1200px 700px at 50% -10%, var(--bg2), var(--bg));
  color: var(--fg);
  font-family: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
  /* 🔴 手機上不要讓整頁跟著手指晃 —— 玩到一半畫面自己捲走是最惱人的事 */
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}

.app {
  max-width: 1080px;
  margin: 0 auto;
  padding: 10px 12px calc(12px + env(safe-area-inset-bottom));
}

/* ---------- 頁首 ---------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.top h1 {
  font-size: 19px;
  margin: 0;
  letter-spacing: 1px;
  font-weight: 500;
  color: var(--muted);
}
.top h1 b { color: var(--fg); font-weight: 700; }
.who { display: flex; gap: 6px; }

/* ---------- 版面 ---------- */
.main {
  display: grid;
  grid-template-columns: minmax(0, 420px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.stage-col { display: flex; flex-direction: column; gap: 8px; }

/* ---------- HUD ---------- */
.hud {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: #05081c;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 7px 10px;
}
.hud-hp { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hud-label { font-size: 12px; color: var(--accent); white-space: nowrap; }
.bar { display: flex; gap: 2px; }
/* 🔴 生命力用格子不是百分比長條:剩三格與剩兩格要一眼看得出差別 */
.bar i {
  width: 9px; height: 14px;
  background: #223;
  border-radius: 2px;
  display: block;
  transition: background .12s;
}
.bar i.on { background: var(--good); }
.bar i.on.low { background: var(--bad); }
.hud-floor {
  font-variant-numeric: tabular-nums;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 1px;
  white-space: nowrap;
}

/* ---------- 舞台 ---------- */
.stage {
  position: relative;
  /* 420 : 620 —— 跟 server 給的 playW / playH 對齊。改那邊要一起改這裡。 */
  aspect-ratio: 420 / 620;
  width: 100%;
  /* 🔴 高度的上限要寫成**寬度**的上限(用比例換算),不要直接寫 max-height:
     aspect-ratio + max-height 會讓瀏覽器壓扁高度而**保留寬度** → 畫面比例跑掉,
     下緣那條「掉出去就結束」的線就被畫到螢幕外面了(玩家會覺得自己在畫面上就死了)。
     實測 791×733 的視窗:寫 max-height:74vh 時畫布變成 416×538(邏輯高只剩 543)。 */
  max-width: calc(74vh * 420 / 620);
  margin: 0 auto;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #06091d;
}
#cv { display: block; width: 100%; height: 100%; touch-action: none; }

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(4, 7, 22, .78);
  backdrop-filter: blur(2px);
  text-align: center;
  padding: 16px;
}
.overlay[hidden] { display: none; }
.ov h2 { margin: 0 0 8px; font-size: 26px; }
.ov p { margin: 4px 0; color: var(--muted); line-height: 1.6; }
.ov .why { color: var(--fg); }
.ov .rank { font-size: 20px; color: var(--fg); margin-top: 10px; }
.ov .rank b { color: var(--accent); font-size: 26px; }
.ov .best { color: var(--good); font-weight: 700; }

/* ---------- 按鈕 ---------- */
button {
  font: inherit;
  color: var(--fg);
  background: #2a367e;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 14px;
  cursor: pointer;
}
button:hover { background: #35439a; }
button:active { transform: translateY(1px); }
button.ghost { background: transparent; color: var(--muted); }
button.ghost:hover { background: #1b2350; color: var(--fg); }
button.big {
  margin-top: 12px;
  padding: 12px 26px;
  font-size: 18px;
  font-weight: 700;
  background: var(--accent);
  color: #2a2100;
  border-color: transparent;
}
button.big:hover { background: #ffe89a; }
.nick {
  background: #1b2350;
  border-style: dashed;
  max-width: 46vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- 觸控操作(搖桿 / 三顆鍵,可切換)---------- */
.controls { position: relative; }
/* 🔴 一次只顯示一套 —— 兩套同時在畫面上,手機的直版高度會被吃掉一大塊 */
.controls[data-scheme="stick"] .pad { display: none; }
.controls[data-scheme="pad"] .stick { display: none; }

.scheme {
  position: absolute;
  right: 0;
  top: -30px;
  padding: 3px 10px;
  font-size: 11px;
  background: transparent;
  color: var(--muted);
  border-style: dashed;
}

/* 虛擬搖桿:圓形底座 + 圓形搖桿頭(手機遊戲最常見的那種)。
   浮動式 —— 手指按在哪裡,底座就浮到哪裡。 */
.stick {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 132px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #10173a;
  overflow: hidden;
  /* 🔴 touch-action: none —— 少了它,手指一滑就變成整頁捲動,搖桿等於失靈 */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.stick.is-active { background: #17205a; border-color: var(--accent); }

/* 底座:正圓。預設停在正中間,按下去時 JS 會把它移到手指那一點。 */
.stick-base {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 112px;
  height: 112px;
  margin: -56px 0 0 -56px;
  border-radius: 50%;
  background: radial-gradient(circle at 50% 38%, #182a63, #0a1030 72%);
  border: 2px solid var(--line);
  display: grid;
  place-items: center;
  /* 放開時滑回中間;按著的時候 JS 會關掉這個過渡(不然底座會追著手指跑) */
  transition: left .18s ease, top .18s ease;
}
.stick.is-active .stick-base { transition: none; border-color: var(--accent); }

/* 左右提示:圓環上的兩個小三角,一眼看出「這是左右用的」 */
.stick-base::before,
.stick-base::after {
  content: '';
  position: absolute;
  top: 50%;
  margin-top: -6px;
  border-top: 6px solid transparent;
  border-bottom: 6px solid transparent;
  opacity: .5;
}
.stick-base::before { left: 8px; border-right: 9px solid var(--muted); }
.stick-base::after { right: 8px; border-left: 9px solid var(--muted); }

.stick-knob {
  display: block;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: linear-gradient(180deg, #5567d8, #2a367e);
  border: 2px solid #8b9bf0;
  box-shadow: 0 3px 8px rgba(0, 0, 0, .45);
  /* transform 由 JS 設 —— 不加 transition,加了會跟手指有延遲(手感很差) */
}
.stick.is-active .stick-knob {
  background: linear-gradient(180deg, #ffe89a, #e0b23c);
  border-color: #fff3c4;
}
.stick-hint {
  position: absolute;
  bottom: 6px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  pointer-events: none;
}

.pad {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.pad-btn {
  padding: 16px 0;
  font-size: 20px;
  background: #1b2350;
  /* 🔴 touch-action: none + user-select: none —— 少了這兩行,
     手機上連按會選到文字、長按會跳出選單,而且會觸發頁面縮放 */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.pad-btn.is-down { background: #3a49aa; }
.pad-btn--jump { color: var(--accent); font-weight: 700; }

/* ---------- 側欄 ---------- */
.side { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.card {
  background: linear-gradient(180deg, var(--card), #141c46);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}
.card h2 {
  margin: 0 0 10px;
  font-size: 15px;
  color: var(--accent);
  letter-spacing: 1px;
}

.mode {
  display: block;
  width: 100%;
  text-align: left;
  margin-bottom: 8px;
  background: #141c46;
  padding: 10px 12px;
}
.mode.is-on { border-color: var(--accent); background: #23306f; }
.mode b { display: block; font-size: 16px; margin-bottom: 2px; }
.mode span { font-size: 12px; color: var(--muted); line-height: 1.5; }

/* ---------- 排行榜 ---------- */
.tabrow { display: flex; gap: 6px; margin-bottom: 8px; flex-wrap: wrap; }
.tab {
  padding: 6px 12px;
  font-size: 13px;
  background: #141c46;
  border-radius: 999px;
}
.tab.is-on { background: var(--accent); color: #2a2100; border-color: transparent; font-weight: 700; }
.tab--sm { padding: 4px 10px; font-size: 12px; }

.board-head, .row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) 48px 78px;
  gap: 6px;
  align-items: center;
  padding: 5px 6px;
  font-size: 13px;
}
.board-head { color: var(--muted); font-size: 11px; border-bottom: 1px solid var(--line); }
.board-list { max-height: 340px; overflow-y: auto; }
.row { border-bottom: 1px solid rgba(43, 54, 112, .5); }
.row.is-me { background: rgba(255, 215, 110, .12); border-radius: 8px; }
.row .rk { text-align: center; }
.row .nk { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .fl { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.row .tm { text-align: right; font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.row .tm i { display: block; font-style: normal; opacity: .7; font-size: 10px; }
.empty { padding: 22px 8px; text-align: center; color: var(--muted); line-height: 1.8; }
.board-me {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  flex-wrap: wrap;
}
.board-me b { color: var(--accent); font-size: 15px; }

/* ---------- 說明 ---------- */
.keys { font-size: 12px; color: var(--muted); margin: 0 0 10px; line-height: 2; }
kbd {
  background: #0a1030;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
  font-size: 11px;
}
.legend { list-style: none; margin: 0; padding: 0; font-size: 12px; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: 8px; padding: 3px 0; line-height: 1.5; }
.lg { width: 26px; height: 9px; border-radius: 2px; flex: none; }
.lg-normal { background: #bcd6f5; }
.lg-spring { background: repeating-linear-gradient(90deg, #3ddc84 0 4px, #0b5 4px 8px); }
.lg-conv { background: linear-gradient(90deg, #bcd6f5 40%, #5b83c6 40%); }
.lg-mover { background: #bcd6f5; border-bottom: 3px solid #5b83c6; }
.lg-fake { background: #bcd6f5; opacity: .45; }
.lg-spike { background: #e8edf5; clip-path: polygon(0 100%, 12% 0, 25% 100%, 37% 0, 50% 100%, 62% 0, 75% 100%, 87% 0, 100% 100%); }

/* ---------- 彈窗 / 提示 ---------- */
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(2, 4, 14, .72);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 50;
}
.modal-back[hidden] { display: none; }
.modal {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  width: min(420px, 100%);
  max-height: 86vh;
  overflow-y: auto;
}
.modal h3 { margin: 0 0 10px; font-size: 18px; }
.modal p { line-height: 1.7; margin: 6px 0; }
.modal label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.modal input {
  width: 100%;
  padding: 10px;
  font: inherit;
  color: var(--fg);
  background: #0c1234;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.modal a { color: var(--accent); }
.row-btn { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
button.danger { background: #7a2230; border-color: #a83a4a; }
button.danger:hover { background: #97303f; }
button.ghost.danger { background: transparent; color: #ff9d9d; border-color: #7a2230; }
.check { display: flex; align-items: flex-start; gap: 8px; margin: 12px 0; font-size: 13px; color: var(--fg); }
.check input { width: auto; margin-top: 3px; }
.code {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  font-size: 26px;
  letter-spacing: 5px;
  text-align: center;
  background: #0c1234;
  border: 1px dashed var(--accent);
  border-radius: 10px;
  padding: 14px;
  color: var(--accent);
  user-select: all;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: #0c1234;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 14px;
  z-index: 60;
  max-width: 90vw;
  text-align: center;
}
.toast[hidden] { display: none; }
.toast--warn { border-color: var(--bad); color: #ffd7d7; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.foot {
  margin-top: 14px;
  text-align: center;
  font-size: 11px;
  color: #5a67a8;
}
.foot a { color: #7f8fe8; }

/* ==========================================================================
   窄螢幕(手機直版)—— 🔴 這一段**一定要放在檔案最後面**。
   CSS 同權重時後面的贏:原本它寫在「版面」那一段(檔案前半),
   而 `.stage` / `.stick` 的本體定義在它後面 → 媒體查詢裡的值**整段被蓋掉、完全沒生效**,
   而且畫面看起來還是好的(因為桌機那組數字剛好也塞得下)。
   2026-08-27 實測抓到:`stage.max-width` 拿到的是桌機的 407px,不是這裡算的 379px。
   ========================================================================== */
@media (max-width: 780px) {
  .main { grid-template-columns: 1fr; }
  .app { padding: 6px 8px calc(8px + env(safe-area-inset-bottom)); }
  .top h1 { font-size: 15px; }
  /* 🔴 手機要用 dvh 不是 vh:vh 算的是「網址列收起來時」的高度,
     而網址列一出現,畫面就會被推出可視範圍(玩到一半底下的按鍵不見了)。
     扣掉的那些是 HUD + 操作區 + 頁首的高度。 */
  .stage { max-width: min(100%, calc((100dvh - 252px) * 420 / 620)); }
  .stick { height: 124px; }
  .pad-btn { padding: 14px 0; }
}
