/* [claude code] 2026-11-14 修檔頭註解:插在多行註解中間的獨立註解行把註解提早關掉、吞掉 :root 色票 */
/* [Codex] 2026-10-28 v0.22: round-two polish and verification. */
/* [Codex] 2026-10-26 v0.21: mobile controls, readable feedback, challenges and privacy. */
/* [claude code] 2026-08-30 建案:貪蛇競技場 —— 零美術,全部用色塊與文字
 * [claude code] 2026-11-10 index hash mismatch
 *
 * 🔴 深色底不是風格選擇,是**可讀性**:場上的蛇與食物都是高飽和的色相,
 *    放在白底上會糊成一片;深底能讓每一條蛇的顏色自己跳出來。
 *    (參考畫面是淺底的,但那是有美術貼圖的版本 —— 零美術的話深底才分得開。)
 */

:root {
  --bg: #0e1524;
  --grid: #182338;
  --panel: #16203a;
  --panel2: #1e2b4d;
  --line: #2b3c63;
  --fg: #e8eefc;
  --dim: #93a3c4;
  --accent: #34c5f0;
  --gain: #ff5a5a;   /* 🔴 台灣紅賺綠賠:紅 = 好事 / 得分 */
  --loss: #37d67a;   /*     綠 = 壞事 / 失分 */
  --warn: #ffb020;
  --danger: #ff4d4d;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--fg);
  font-family: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
  -webkit-user-select: none; user-select: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#cv { display: block; width: 100%; height: 100%; touch-action: none; }

.hidden { display: none !important; }

/* ── HUD ───────────────────────────────────────────────────── */

#hud { position: fixed; inset: 0; pointer-events: none; }

#hudTop {
  position: absolute; top: max(8px, env(safe-area-inset-top)); left: 50%;
  transform: translateX(-50%); display: flex; gap: 10px; width: max-content; max-width: calc(100vw - 16px);
}
#hudTop .stat {
  background: rgba(14,21,36,.72); border: 1px solid var(--line);
  border-radius: 10px; padding: 4px 12px; text-align: center; min-width: 70px;
  backdrop-filter: blur(4px);
}
#hudTop .lab { display: block; font-size: 11px; color: var(--dim); line-height: 1.2; }
#hudTop b { font-size: 20px; font-variant-numeric: tabular-nums; }

/* 限時道具 —— 只有拿到才出現(沒有就不佔位置) */
#buffBar {
  position: absolute; top: max(8px, env(safe-area-inset-top)); right: 8px;
  display: flex; flex-direction: column; gap: 6px; align-items: flex-end;
}
.buffChip {
  display: flex; align-items: center; gap: 6px;
  background: rgba(14,21,36,.8); border: 1px solid currentColor;
  border-radius: 999px; padding: 3px 10px 3px 6px; font-size: 12px;
}
.buffChip .ic { font-size: 15px; }
.buffChip .nm { color: var(--fg); }
.buffChip .tm { font-variant-numeric: tabular-nums; opacity: .85; }

/* 房內即時榜(參考畫面左上) */
#board {
  position: absolute; top: max(8px, env(safe-area-inset-top)); left: 8px;
  background: rgba(14,21,36,.72); border: 1px solid var(--line);
  border-radius: 10px; padding: 6px 8px; min-width: 148px; font-size: 12px;
  backdrop-filter: blur(4px);
}
.bTitle { color: var(--warn); font-weight: 700; margin-bottom: 3px; font-size: 12px; }
#bList { list-style: none; margin: 0; padding: 0; }
#bList li { display: flex; gap: 5px; line-height: 1.55; white-space: nowrap; }
#bList .rk { color: var(--dim); width: 15px; text-align: right; }
#bList .nk { flex: 1; overflow: hidden; text-overflow: ellipsis; max-width: 96px; }
#bList .sc { color: var(--accent); font-variant-numeric: tabular-nums; }
#bList li.me { color: var(--warn); font-weight: 700; }
#bList li.me .nk { color: var(--warn); }
.bFoot { color: var(--dim); font-size: 11px; margin-top: 3px; }

/* 擊殺播報 */
#feed {
  position: absolute; left: 50%; transform: translateX(-50%);
  top: 62px; display: flex; flex-direction: column; gap: 3px; align-items: center;
}
.feedRow {
  background: rgba(14,21,36,.7); border-radius: 999px; padding: 2px 12px;
  font-size: 12px; animation: fadeUp .3s ease;
}
.feedRow .k { color: var(--gain); font-weight: 700; }
.feedRow .v { color: var(--dim); }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

#toast {
  position: absolute; left: 50%; top: 38%; transform: translateX(-50%);
  font-size: 22px; font-weight: 800; text-align: center; text-shadow: 0 2px 8px #000;
  pointer-events: none; opacity: 0; transition: opacity .2s;
}
#toast.on { opacity: 1; }
#toast small { display: block; font-size: 13px; font-weight: 400; opacity: .85; }

/* 手機控制 */
.touchOnly { display: none; }
body.touch .touchOnly { display: block; }

#stick {
  position: absolute; left: 22px; bottom: max(26px, env(safe-area-inset-bottom));
  width: 118px; height: 118px; border-radius: 50%;
  background: rgba(255,255,255,.07); border: 2px solid rgba(255,255,255,.16);
  pointer-events: auto; touch-action: none;
}
#stick i {
  position: absolute; left: 50%; top: 50%; width: 48px; height: 48px;
  margin: -24px 0 0 -24px; border-radius: 50%;
  background: rgba(52,197,240,.5); border: 2px solid rgba(255,255,255,.35);
}
#boostBtn {
  position: absolute; right: 24px; bottom: max(30px, env(safe-area-inset-bottom));
  width: 92px; height: 92px; border-radius: 50%; font-size: 34px;
  background: rgba(255,176,32,.22); border: 2px solid rgba(255,176,32,.55);
  color: var(--warn); pointer-events: auto; touch-action: none;
}
#boostBtn.on { background: rgba(255,176,32,.5); }

/* ── 疊層畫面 ───────────────────────────────────────────────── */

.screen {
  position: fixed; inset: 0; display: flex; align-items: flex-start; justify-content: center;
  background: rgba(8,12,22,.94);
  padding: 16px; overflow-y: auto; z-index: 10;
}
.panel {
  margin: auto 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 22px; width: 100%; max-width: 400px; text-align: center;
  box-shadow: 0 18px 60px rgba(0,0,0,.5);
}
.panel.wide { max-width: 480px; }
.panel h1 {
  margin: 0 0 6px; font-size: 30px; letter-spacing: 2px;
  background: linear-gradient(90deg, #34c5f0, #a86bff);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.panel h2 { margin: 0 0 8px; font-size: 22px; }
.sub { color: var(--dim); font-size: 13px; margin: 0 0 16px; line-height: 1.6; }
.sub b { color: var(--accent); }

.nickRow { text-align: left; margin-bottom: 14px; }
.nickRow label { font-size: 12px; color: var(--dim); display: block; margin-bottom: 4px; }
.nickIn { display: flex; gap: 6px; }
input {
  flex: 1; background: var(--panel2); border: 1px solid var(--line); color: var(--fg);
  border-radius: 9px; padding: 10px 12px; font-size: 15px; font-family: inherit; width: 100%;
}
input:focus { outline: none; border-color: var(--accent); }
button {
  background: var(--panel2); border: 1px solid var(--line); color: var(--fg);
  border-radius: 9px; padding: 10px 14px; font-size: 14px; cursor: pointer;
  font-family: inherit;
}
button:hover { border-color: var(--accent); }
button.big {
  display: block; width: 100%; margin: 14px 0 10px; padding: 14px;
  font-size: 18px; font-weight: 700; border: none;
  background: linear-gradient(90deg, #2aa7d8, #7b4ff0); color: #fff;
}
button.link { background: none; border: none; color: var(--dim); font-size: 13px; }
button.link:hover { color: var(--accent); }
button.link.danger { color: #c96; }

.myStats { color: var(--dim); font-size: 12px; margin-bottom: 12px; line-height: 1.7; }
.myStats b { color: var(--fg); }

.tips { text-align: left; border-top: 1px solid var(--line); padding-top: 12px; }
.tip { display: flex; gap: 8px; font-size: 12px; color: var(--dim); line-height: 1.65; margin-bottom: 3px; }
.tip b:first-child {
  color: var(--accent); min-width: 52px; flex-shrink: 0;
}
.tip span b { color: var(--warn); }

.startFoot {
  display: flex; align-items: center; gap: 10px; justify-content: center;
  margin-top: 12px; border-top: 1px solid var(--line); padding-top: 10px;
}
.online { color: var(--dim); font-size: 12px; margin-left: auto; }
.verline { position: static; margin-top: 14px; color: #7283a8; font-size: 11px; text-align: right; }

.dBy { color: var(--dim); font-size: 13px; margin-bottom: 14px; min-height: 18px; }
.dBy b { color: var(--gain); }
.dGrid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px; }
.dGrid div { background: var(--panel2); border-radius: 10px; padding: 8px 4px; }
.dGrid span { display: block; font-size: 11px; color: var(--dim); }
.dGrid b { font-size: 19px; font-variant-numeric: tabular-nums; }
.dRank { font-size: 13px; color: var(--dim); min-height: 20px; margin-bottom: 4px; }
.dRank .best { color: var(--warn); font-weight: 700; }

.tabs { display: flex; gap: 6px; justify-content: center; margin-bottom: 10px; }
.tabs.sub2 button { font-size: 12px; padding: 6px 12px; }
.tabs button.on { background: var(--accent); border-color: var(--accent); color: #06121b; font-weight: 700; }

.bt { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 8px; }
.bt th { color: var(--dim); font-weight: 400; font-size: 11px; text-align: left; padding: 4px 6px; }
.bt td { padding: 5px 6px; border-top: 1px solid var(--line); text-align: left; }
.bt td:first-child, .bt th:first-child { width: 30px; color: var(--dim); }
.bt td:nth-child(3), .bt td:nth-child(4) { font-variant-numeric: tabular-nums; }
.bt tr.me td { color: var(--warn); font-weight: 700; }

#accForm { text-align: left; }
#accForm label { font-size: 12px; color: var(--dim); display: block; margin: 8px 0 4px; }
.msg { font-size: 12px; color: var(--warn); min-height: 18px; margin-top: 6px; line-height: 1.5; }
.msg.ok { color: var(--loss); }
.codeBox {
  background: var(--panel2); border: 1px dashed var(--warn); border-radius: 10px;
  padding: 12px; margin: 10px 0; font-size: 13px; line-height: 1.7; text-align: left;
}
.codeBox code { font-size: 17px; color: var(--warn); letter-spacing: 2px; }

#netWarn {
  position: fixed; top: 0; left: 0; right: 0; z-index: 20;
  background: var(--danger); color: #fff; text-align: center;
  font-size: 13px; padding: 6px;
}

/* 手機:面板窄一點、字小一點 */
@media (max-width: 480px) {
  .panel { padding: 18px 15px; }
  .panel h1 { font-size: 25px; }
  #board { min-width: 124px; font-size: 11px; }
  #bList .nk { max-width: 74px; }
  #hudTop b { font-size: 17px; }
}
/* 矮螢幕(手機橫放):榜縮短,不要蓋住半個畫面 */
@media (max-height: 460px) {
  #board { max-height: 46vh; overflow: hidden; }
}

/* [Codex] 2026-10-26 v0.16: compact portrait HUD. */
@media (max-width: 600px) {
  #board { top: calc(max(8px, env(safe-area-inset-top)) + 76px); max-width: 155px; min-width: 130px; }
  #bList li:nth-child(n+4) { display: none; }
  #buffBar { top: calc(max(8px, env(safe-area-inset-top)) + 76px); }
  #feed { top: 170px; width: 100%; }
}
body.touch #board { top: calc(max(8px, env(safe-area-inset-top)) + 76px); }
body.touch #bList li:nth-child(n+4) { display: none; }
body.touch #buffBar { top: calc(max(8px, env(safe-area-inset-top)) + 76px); }

/* [Codex] 2026-10-26 v0.17: the joystick follows the initial left-side touch. */
body.touch #stick { bottom: auto; transform: translate(-50%, -50%); pointer-events: none; opacity: 0; transition: opacity .15s; }
body.touch #stick.active { opacity: 1; }
.tips summary { cursor: pointer; color: var(--accent); font-size: 12px; padding: 5px 0; }
#grace { position: absolute; top: 55px; left: 50%; transform: translateX(-50%); color: var(--warn); font-size: 12px; white-space: nowrap; }
@media (max-width: 600px) { #grace { top: 170px; } }
body.touch #grace { top: 170px; }

/* [Codex] 2026-10-26 v0.18: readable feedback, static overlays and spectator controls. */
#toast { top: 25%; width: 90%; }
#toast[data-level="1"] { font-size: 18px; }
#toast[data-level="2"] { font-size: 28px; }
#toast[data-level="3"] { font-size: 32px; }
#watchBar { position: fixed; bottom: max(20px,env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); display:flex; gap:12px; align-items:center; background:var(--panel); padding:10px; border-radius:12px; white-space:nowrap; }
.startFoot { flex-wrap: wrap; }

/* [Codex] 2026-10-26 v0.19: portrait announcements and kill feed use separate bands. */
@media (max-width: 600px) {
  #feed { top:auto;bottom:calc(max(30px,env(safe-area-inset-bottom)) + 112px); }
  .feedRow { max-width:calc(100vw - 16px);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:11px; }
}
@media (orientation:portrait) {
  body.touch #feed { top:auto;bottom:calc(max(30px,env(safe-area-inset-bottom)) + 112px); }
}
/* [Codex] 2026-10-26 v0.20: challenge progress and cosmetic selectors. */
.retention { text-align:left;margin:12px 0;font-size:12px; }
.retention summary { cursor:pointer;color:var(--accent);margin-bottom:8px; }
.retention small { color:var(--dim); }
.challengeRow { display:flex;justify-content:space-between;gap:8px;padding:5px 0;border-bottom:1px solid var(--line); }
.challengeRow.done { color:var(--warn); }
.lookRow { display:flex;gap:5px;flex-wrap:wrap;align-items:center;margin-top:8px; }
.lookRow small { width:100%; }
.lookRow button { padding:6px 8px;min-height:36px;font-size:12px; }
.lookRow button:disabled { opacity:.45;cursor:default; }
.lookRow button.selected { outline:2px solid var(--accent); }
#personalGoal { position:absolute;left:50%;transform:translateX(-50%);top:calc(max(8px,env(safe-area-inset-top)) + 52px);color:var(--dim);font-size:10px;line-height:14px;white-space:nowrap; }
/* [Codex] 2026-10-26 v0.21: readable standalone privacy page. */
.privacyPage { position:static;height:auto;overflow:auto;padding:20px 12px; }
.privacyPage .panel { margin:0 auto;text-align:left;max-width:650px; }
.privacyPage h1 { font-size:24px;letter-spacing:0; }
.privacyPage h2 { margin-top:24px;font-size:18px; }
.privacyPage p { line-height:1.8;font-size:14px;color:var(--dim); }

/* [Codex] 2026-10-27 v0.22: touch targets and unobtrusive arena board. */
body.touch button, body.touch .link { min-width:44px;min-height:44px; }
body.touch a.link { display:inline-flex;align-items:center;justify-content:center; }
body.touch #board { background:rgba(14,21,36,.45);backdrop-filter:none;pointer-events:auto;cursor:pointer;min-height:44px; }
#board { pointer-events:auto;cursor:pointer; }
#board.mini .bTitle, #board.mini #bList { display:none; }
#board .bFoot { display:flex;flex-wrap:wrap;gap:4px; }
#bMine { color:var(--accent); }
.dTip { color:var(--accent);font-size:13px;line-height:1.6;margin:8px 0; }
.dChal { color:var(--warn);font-size:12px;line-height:1.6;margin:8px 0; }
/* [Codex] 2026-10-29 v0.24: separate progression rows and a readable decay label. */
.progressLine { display:block;white-space:nowrap; }
#hDecay { display:inline-block;margin-left:4px;vertical-align:middle;font-size:10px;line-height:1.4;color:var(--warn);white-space:nowrap; }
.retention summary { position:relative;list-style:none;padding-left:14px; }
.retention summary::-webkit-details-marker { display:none; }
.retention summary::before { content:'▸';position:absolute;left:0;top:0; }
.retention[open] summary::before { content:'▾'; }
body.touch .retention summary::before { top:10px; }
a { color:var(--accent); }

body.touch .retention summary { min-height:44px;line-height:1.6;padding:10px 0 10px 14px; }

/* [Codex] 2026-10-28 v0.23: protection ending and one disclosure arrow. */
#grace.ending { color:#ff946b;font-weight:800; }
.dTip { white-space:pre-line; }
.tips summary { list-style:none; }
.tips summary::-webkit-details-marker { display:none; }
.tips summary::before { content:"▸";display:inline-block;margin-right:6px;transition:transform .15s; }
.tips details[open] summary::before { transform:rotate(90deg); }

/* [Codex] 2026-10-30 v0.25: wrap the three daily tasks and nearest progress on phones. */
.challengeDetail, .challengeClosest { display:block;white-space:normal;overflow-wrap:anywhere;text-align:center; }
.challengeClosest { margin-top:4px;color:var(--accent); }
