/* 前端由 shironchen/meowvillage 部署（2026-10-21） */
/* 像素村莊 — 配色與共用元件在 /static/base.css（頁面用 <link> 帶版本，不要在這裡 @import）。 */

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;   /* iOS Safari：網址列伸縮不再讓版面跳動 */
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  overflow: hidden;
}

body {
  display: grid;
  grid-template-columns: 1fr 320px;
  grid-template-rows: 52px 1fr;
  grid-template-areas:
    "top top"
    "stage side";
}

/* ── 頂欄 ───────────────────────────────────────── */
#topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand { font-weight: 900; letter-spacing: 2px; color: var(--brand); }
.sub { font-size: 11px; letter-spacing: 4px; color: var(--muted); }
.clock {
  margin-left: auto;
  padding: 3px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 700;
  font-size: 12px;
}
.status { font-size: 11px; color: var(--muted); min-width: 84px; text-align: right; }
.online {
  font-size: 12px;
  font-weight: 700;
  color: var(--brand);
  background: var(--brand-soft);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
}
.status.live { color: var(--ok); }
.status.paused { color: var(--muted); }
.status.error { color: var(--alert); }

/* ── 右上角：單一頭像＋個人選單 ─────────────────── */
#account { position: relative; }

#avatarBtn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 2px solid var(--brand);
  border-radius: 50%;
  background: var(--brand-soft);
  overflow: hidden;
  cursor: pointer;
}

#avatarBtn:hover { box-shadow: 0 0 0 3px var(--brand-soft); }

#avatarImg { width: 100%; height: 100%; object-fit: cover; }

#avatarFallback {
  color: var(--brand);
  font-weight: 900;
  font-size: 14px;
  font-family: var(--sans);
}

#accountMenu {
  position: absolute;
  top: 42px;
  right: 0;
  z-index: 60;
  min-width: 230px;
  padding: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

#menuEmail {
  margin: 4px 8px 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.menu-item {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 10px;
  background: none;
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.menu-item:hover { background: var(--brand-soft); color: var(--brand); }

/* ── 舞台 ───────────────────────────────────────── */
#stage-wrap {
  grid-area: stage;
  display: grid;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* 地圖貼齊舞台四邊，不留空隙（Gary 2026-08-07）——畫布的 bitmap 由 JS 算成
   跟舞台同比例，所以撐滿不會變形。告警的紅框改用 inset 陰影，不能用 border：
   border 會佔掉版面，反而生出一圈縫。 */
#stage {
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  background: var(--bg);
}
/* 換空間（2026-10-15）：走進門框，舊畫面（#stageFade 拍下的那張）疊在上面
   慢慢變透明、新地圖在底下浮出——交疊淡換；中央飄出半透明空間名稱，左上角常駐小標。
   這幾層都不吃滑鼠，不擋走路。 */
#stage-wrap { position: relative; }
#stageFade {
  position: absolute; inset: 0; width: 100%; height: 100%; z-index: 2;
  image-rendering: pixelated; pointer-events: none; opacity: 1;
}
#stageFade.fading { opacity: 0; transition: opacity .9s ease; }
#zoneTag {
  position: absolute; top: 10px; left: 12px; z-index: 3; pointer-events: none;
  padding: 3px 10px; border-radius: 999px;
  font: 600 12px/1.6 "Noto Sans TC", sans-serif;
  background: rgba(251, 250, 247, .55); color: #5f4a38;
  backdrop-filter: blur(2px);
  transition: background .5s, color .5s;
}
#zoneTag[data-space="tvbs"] {
  background: rgba(11, 18, 32, .55); color: #3fe0ff;
  font-family: ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .08em;
}
#zoneTitle {
  position: absolute; left: 50%; top: 36%; z-index: 3; pointer-events: none;
  transform: translate(-50%, -50%); white-space: nowrap; opacity: 0;
  font: 800 44px/1 "Noto Sans TC", sans-serif; letter-spacing: .18em;
  color: #5f4a38;
}
#zoneTitle[data-space="tvbs"] {
  color: #3fe0ff; font-family: ui-monospace, "SF Mono", Menlo, monospace;
  text-shadow: 0 0 18px rgba(63, 224, 255, .8);
}
#zoneTitle.show { animation: zone-in 2.4s ease forwards; }
@keyframes zone-in {
  0%   { opacity: 0;  transform: translate(-50%, -38%); }
  20%  { opacity: .5; transform: translate(-50%, -50%); }
  70%  { opacity: .5; transform: translate(-50%, -50%); }
  100% { opacity: 0;  transform: translate(-50%, -56%); }
}
#zoneTag[data-space="meowbox"], #zoneTitle[data-space="meowbox"] { color: #9b785c; }
#zoneTag[data-space="gamestudio"] { background: rgba(43, 31, 72, .55); color: #ffd166; }
#zoneTitle[data-space="gamestudio"] {
  color: #ffd166; text-shadow: 3px 3px 0 #ff6b9a, -2px -2px 0 #4ecdc4;
}
@media (max-width: 860px) { #zoneTitle { font-size: 30px; } }

body.alert #stage { box-shadow: inset 0 0 0 3px var(--alert), inset 0 0 24px #b03a2e55; }

/* ── 側欄：標題固定、動態捲動、指令框釘在底部 ─────── */
#sidebar {
  grid-area: side;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-left: 1px solid var(--line);
  padding: 12px;
  overflow: hidden;
  min-height: 0;
}

#tabs {
  flex: 0 0 auto;
  display: flex;
  gap: 6px;
  margin: 0 0 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.tab {
  padding: 5px 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  cursor: pointer;
}

.tab.active {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

#sheetHandle { display: none; }

#feed, #chatlog {
  list-style: none;
  margin: 0;
  padding: 0 2px 8px 0;
  flex: 1 1 auto;
  overflow-y: auto;
  min-height: 0;
}

#chatlog li {
  padding: 8px 12px;
  margin-bottom: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 12.5px;
  line-height: 1.6;
}

#chatlog li.mine { background: var(--brand-soft); }
#chatlog li.empty { color: var(--muted); text-align: center; }
#chatlog .who { color: var(--brand); font-weight: 700; margin-right: 6px; }
#chatlog .when { color: var(--muted); font-size: 10.5px; float: right; }

#feed li {
  padding: 9px 12px;
  margin-bottom: 8px;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--brand);
  border-radius: 12px;
  font-size: 12.5px;
  line-height: 1.6;
}

#feed li.empty { color: var(--muted); border-left-color: var(--line); text-align: center; }
/* 具體那行（只有主人拿得到 detail）——次要、可換行，不跟敘事搶視線 */
#feed .what {
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.5;
  margin-top: 3px;
  overflow-wrap: anywhere;
}
#feed .who { color: var(--brand); font-weight: 700; margin-right: 6px; }
#feed .when { color: var(--muted); font-size: 10.5px; float: right; }
#feed li.alert { border-left-color: var(--alert); }

/* ── 指令框（flex 尾端固定，不再蓋住動態）──────────── */
#cmdbox {
  flex: 0 0 auto;
  margin-top: 4px;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

#cmdbox label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--brand);
  margin-bottom: 6px;
}

.cmd-row { display: flex; gap: 8px; position: relative; }

/* ── 手機搭話鈕（2026-08-06）───────────────────────── */
/* 互動選單：桌機浮在玩家頭頂、手機貼抽屜上緣（座標一律由 JS 給） */
#talkMenu {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 190px;               /* 動態值由 JS 依抽屜高度覆寫 */
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

/* 桌機小顆（浮在貓頭上，太大就把村子蓋住了，2026-08-06 Gary）；
   手機是拇指要按的東西，下面 media query 再放大回去。 */
.talk-opt {
  padding: 7px 13px;
  background: var(--card);
  border: 1.5px solid var(--brand);
  border-radius: 999px;
  box-shadow: var(--shadow);
  color: var(--brand);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
  cursor: pointer;
}

a.talk-opt { text-decoration: none; display: inline-block; }

/* 桌機：三顆直排疊起來比貓還高好幾倍（2026-12-02 Gary）——改成一排小膠囊，
   只蓋住頭頂一條。手機維持直排大顆（拇指要按）。 */
@media (min-width: 861px) {
  #talkMenu { flex-direction: row; flex-wrap: wrap; justify-content: center;
              gap: 4px; max-width: 420px; }
  .talk-opt { padding: 3px 10px; font-size: 12px; border-width: 1px; }
}
.talk-opt:hover { background: var(--brand-soft); }

/* 放左上（2026-12-02）：原本在左下，蓋住 TVBS 門；手機版還跟底部的
   「登入後可以跟貓互動」疊在一起。開始走路就自動收掉。 */
.move-hint {
  position: fixed;
  left: 16px;
  top: 100px;
  z-index: 45;
  width: min(320px, calc(100vw - 32px));
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.move-hint p { margin: 0 0 8px; font-size: 13px; line-height: 1.6; }
#moveHintTitle { color: var(--brand); font-weight: 800; }
.move-hint .hint-touch { display: none; }
@media (pointer: coarse) {
  .move-hint .hint-touch { display: block; }
  .move-hint .hint-mouse { display: none; }
}
.move-hint button {
  border: none;
  border-radius: 999px;
  padding: 6px 14px;
  background: var(--brand);
  color: #fff;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
}

/* ── @ 提及自動補完 ─────────────────────────────── */
#mentionMenu {
  /* fixed 浮在整頁之上——放在 sidebar 裡會被 overflow:hidden 裁切（手機抽屜實測）。
     位置由 JS 依輸入框即時對齊。 */
  position: fixed;
  z-index: 80;
  min-width: 180px;
  max-height: 42vh;
  overflow-y: auto;
  padding: 5px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

.mention-opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
}

.mention-opt:hover, .mention-opt.sel { background: var(--brand-soft); color: var(--brand); }

.mention-opt .tag {
  font-size: 10px;
  font-weight: 700;
  color: var(--brand);
  border: 1px solid var(--brand);
  border-radius: 999px;
  padding: 0 6px;
}

.mention { color: var(--brand); font-weight: 700; }

/* ── 角色管理（打扮自己的貓）───────────────────────── */
#avatarPanel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 90;
  width: min(360px, calc(100vw - 32px));
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.avatar-body { display: flex; gap: 14px; align-items: flex-start; }

#avatarPreview {
  width: 108px;
  height: 126px;
  image-rendering: pixelated;
  background: #d4e4bc;
  border: 1px solid var(--line);
  border-radius: 10px;
  flex: 0 0 auto;
}

#avatarSwatches { flex: 1; min-width: 0; }
#avatarSwatches h4 { margin: 4px 0 4px; font-size: 11.5px; color: var(--muted); }

.swatch-row { display: flex; flex-wrap: wrap; gap: 6px; }

.swatch {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 2px solid var(--line);
  cursor: pointer;
  padding: 0;
}

.swatch.none {
  background: var(--card);
  color: var(--muted);
  font-size: 10px;
  line-height: 1;
}

.swatch.sel { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }

.avatar-name { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.avatar-name span { font-size: 12px; font-weight: 700; color: var(--brand); flex: 0 0 auto; }
.avatar-name input {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
}
.avatar-name input:focus { border-color: var(--brand); }

.avatar-actions { display: flex; gap: 8px; margin-top: 12px; }

.avatar-actions button {
  flex: 1;
  padding: 9px 0;
  border: none;
  border-radius: 999px;
  background: var(--brand);
  color: #fff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.avatar-actions button.ghost {
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--muted);
}

/* ── 村公所白板（Claude 額度）───────────────────────── */
#usageBoard, #jobBoard, #logBoard, #catBoard, #musicBox,
#gameBoard, #gamePick, #gameInvite {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 90;
  min-width: 260px;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.usage-title {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  color: var(--brand);
  border-bottom: 1px solid var(--line);
  padding: 0 28px 8px 0;
}

.float-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.float-close:hover { color: var(--ink); background: var(--brand-soft); }

.usage-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-size: 14px;
  margin: 6px 0;
}

.usage-row b { color: var(--brand); width: 26px; }
#usageBoard .note { color: var(--muted); font-size: 11px; margin: 6px 0 0; }

/* 額度過期：數字淡掉、底下明講隔了多久。只寫 HH:MM 的話，昨天同一時刻的
   舊資料看起來跟剛回報的一樣新（Gary 2026-08-08 抓到）。 */
#usageBoard .usage-row.stale { opacity: .45; }
#usageBoard p { margin: 4px 0; font-size: 13px; }

#cmd {
  flex: 1;
  min-width: 0;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
}

#cmd::placeholder { color: #b0a89c; }
#cmd:focus { border-color: var(--brand); }

#cmdbox button[type="submit"] {
  padding: 8px 18px;
  background: var(--brand);
  border: none;
  border-radius: 999px;
  color: #fff;
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}

#cmdbox button[type="submit"]:hover { filter: brightness(1.08); }
#cmdbox button[type="submit"]:disabled { opacity: .5; cursor: default; }

.hint:empty { display: none; }

.hint { margin: 8px 0 0; font-size: 11px; color: var(--muted); line-height: 1.5; }
.hint.ok { color: var(--ok); }
.hint.err { color: var(--alert); }

/* ── 手機（iPhone 15 Pro 基準）：相機跟隨＋三段直向版面 ──
   頂欄避開動態島（safe-area-top）、地圖吃剩餘高度（canvas 由 JS 設成
   視窗大小、鏡頭跟玩家）、底部面板 46dvh 含聊天與輸入框（貼底、
   留 home bar 安全區）。輸入字級 16px 防 iOS 聚焦自動縮放。 */
@media (max-width: 860px) {
  /* 卡片是浮層不佔版面：地圖永遠滿版、構圖不動（meowbox 地圖同款） */
  body {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
    grid-template-areas: "top" "stage";
  }

  #topbar {
    padding-top: calc(6px + env(safe-area-inset-top));
    padding-bottom: 6px;
    gap: 10px;
  }
  .sub { display: none; }
  .move-hint { top: calc(96px + env(safe-area-inset-top)); left: 12px; }
  .clock { font-size: 11px; padding: 2px 10px; }
  .status { min-width: 0; }

  .talk-opt { padding: 11px 20px; font-size: 16px; }


  #sidebar {
    border-left: none;
    border-top: 1px solid var(--line);
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  }

  /* 指頭尺寸 */
  .tab { padding: 8px 18px; font-size: 13px; }
  #avatarBtn { width: 38px; height: 38px; }
  .mention-opt { padding: 10px 12px; font-size: 15px; }

  /* meowbox 地圖式三檔位：hidden（全縮）／browse(44dvh)／full(80dvh)
     高度是唯一動畫屬性：拖拉時 .dragging 關過渡跟手，鬆手吸附檔位回彈。 */
  #sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    border-top: none;
    border-left: none;
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, .10);
    padding-top: 0;
    height: 44dvh;
    transition: height .32s cubic-bezier(.2, .8, .2, 1);
    will-change: height;
    background: var(--card);
  }

  #sidebar.dragging { transition: none; }

  #sheetHandle {
    display: grid;
    place-items: center;
    width: 100%;
    padding: 10px 0 6px;
    border: none;
    background: none;
    cursor: grab;
    touch-action: none;   /* 把手拖拉自己接手，不給頁面捲動 */
  }

  #sheetHandle span {
    width: 44px;
    height: 5px;
    border-radius: 999px;
    background: #d9d0c2;
  }

  /* hidden＝地圖幾乎全螢幕，但仍露出卡片上緣一小段（2026-08-06 Gary 指定）——
     全透明的話只剩一條浮在草地上的把手，看不出那是可以拉上來的面板。 */
  body[data-sheet="hidden"] #sidebar {
    height: calc(34px + env(safe-area-inset-bottom));
  }
  body[data-sheet="hidden"] #tabs,
  body[data-sheet="hidden"] #cmdbox,
  body[data-sheet="hidden"] #feed,
  body[data-sheet="hidden"] #chatlog { display: none; }

  body[data-sheet="browse"] #sidebar { height: 44dvh; }
  /* 全開＝整個畫面（Gary 裁決）：直角、避開瀏海 */
  body[data-sheet="full"] #sidebar {
    height: 100dvh;
    border-radius: 0;
    padding-top: env(safe-area-inset-top);
  }

  /* 底部面板改通訊軟體式（2026-08-05）：
     輸入列＝一條圓角輸入框＋圓形送出鈕，無標題無卡片框；
     說明文字平常隱藏，只在回饋（ok/err）時浮現一行。 */
  #tabs { margin-bottom: 8px; padding-bottom: 6px; }

  #feed li, #chatlog li {
    padding: 8px 11px;
    margin-bottom: 6px;
    font-size: 13px;
    border-radius: 12px;
  }

  #cmdbox {
    padding: 8px 0 0;
    background: transparent;
    border: none;
    border-top: 1px solid var(--line);
    border-radius: 0;
    box-shadow: none;
  }

  #cmdbox label { display: none; }

  .cmd-row { gap: 8px; align-items: center; }

  #cmd {
    font-size: 16px;
    padding: 11px 16px;
    background: var(--card);
    border: 1px solid var(--line);
  }

  #cmdbox button[type="submit"] {
    flex: 0 0 auto;
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
    font-size: 14px;
  }

  .hint { display: none; margin: 6px 2px 0; font-size: 11px; }
  .hint.ok, .hint.err { display: block; }
}

/* ── 角色面板：走到帶 panel 的村民面前浮出 ───────────── */
#panelOverlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(11, 11, 11, .45);
}

#panelOverlay[hidden] { display: none; }

#panelBox {
  display: flex;
  flex-direction: column;
  width: min(960px, 100%);
  height: min(720px, 100%);
  overflow: hidden;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

#panelBar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--brand-soft);
  border-bottom: 1px solid var(--line);
  font-weight: 700;
  font-size: 13px;
}

#panelClose {
  padding: 2px 10px;
  background: none;
  border: none;
  color: var(--muted);
  font-family: inherit;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

#panelClose:hover { color: var(--ink); }

#panelFrame {
  flex: 1;
  width: 100%;
  border: none;
  background: var(--bg);
}

@media (max-width: 860px) {
  #panelOverlay { padding: 0; }
  #panelBox { border-radius: 0; border: none; height: 100%; }

  /* 手機把面板左右內距讓給棋盤：格子愈大愈按得準。實測 390px 寬的機器上
     四子棋 41→47px、黑白棋 39→43px（iOS 建議 44）；五子棋 9×9 再怎麼讓
     也到不了 44，靠「按住預覽、放開才下」補（見 games.js 的 pointerdown）。 */
  #gameBoard { padding: 12px 8px; }
  #gameGrid.gomoku, #gameGrid.connect4, #gameGrid.othello {
    width: calc(100vw - 24px);
  }
}

/* ── 委託板：差事佇列（2026-08-06 二改：一行一卡、點開看全文）── */
#jobBoard, #catBoard {
  width: min(440px, calc(100vw - 32px));
  max-height: 72dvh;
  overflow-y: auto;
}

.job-row {
  margin-bottom: 6px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  border-radius: 10px;
  font-size: 12.5px;
  line-height: 1.55;
}

.job-row summary {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 9px 10px;
  cursor: pointer;
  list-style: none;               /* 不要瀏覽器預設三角形 */
}
.job-row summary::-webkit-details-marker { display: none; }

.job-row .dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--line); }
.job-row.wait .dot { background: #d8a13a; }
.job-row.run  .dot { background: var(--ok); }
.job-row.fail .dot { background: var(--alert); }

.job-row.wait { border-left-color: #d8a13a; }
.job-row.run  { border-left-color: var(--ok); }
.job-row.fail { border-left-color: var(--alert); }
.job-row.done { opacity: .72; }
.job-row[open] { opacity: 1; }

.job-row b { flex: none; color: var(--brand); }

.job-what {                        /* 合上時差事只給一行 */
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: var(--ink);
}

.job-when { flex: none; font-size: 11px; color: var(--muted); }
.job-row.wait .job-when { color: #b07d1e; font-weight: 700; }
.job-row.run  .job-when { color: var(--ok); font-weight: 700; }

.job-detail {
  padding: 2px 12px 10px 25px;
  font-size: 12px;
  color: var(--muted);
}
.job-row[open] .job-what { white-space: normal; }   /* 展開＝同一行文字放開換行 */
.job-result {
  display: block;
  margin-top: 6px;
  padding: 8px 10px;
  background: var(--brand-soft);
  border-radius: 8px;
  color: var(--ink);
  white-space: pre-wrap;
}

/* 執行規劃：多行的步驟表，跟結果摘要同一種紙，但留白多一點好讀 */
.todo-plan {
  margin: 4px 0 8px;
  padding: 10px 12px;
  background: var(--brand-soft);
  border-radius: 8px;
  color: var(--ink);
  line-height: 1.6;
  white-space: pre-wrap;
}

.job-divider {
  margin: 12px 2px 6px;
  font-size: 11px;
  color: var(--muted);
  border-bottom: 1px solid var(--line);
  padding-bottom: 4px;
}

/* ── 每日紀錄板（2026-08-06）：按日分組、可篩單一隻貓 ── */
#logBoard {
  width: min(460px, calc(100vw - 32px));
  max-height: 72dvh;
  overflow-y: auto;
}

.log-filter {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  font-size: 12px;
  color: var(--muted);
}

.log-filter select {
  flex: 1;
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  font-family: inherit;
  font-size: 12.5px;
}

.log-day {
  margin: 12px 0 6px;
  font-size: 12px;
  font-weight: 700;
  color: var(--brand);
  border-bottom: 1px dashed var(--line);
  padding-bottom: 4px;
}
.log-day:first-child { margin-top: 0; }

.log-row {
  display: flex;
  gap: 8px;
  padding: 6px 2px;
  font-size: 12.5px;
  line-height: 1.55;
  border-bottom: 1px solid var(--brand-soft);
}

.log-row .log-time { flex: none; color: var(--muted); font-variant-numeric: tabular-nums; }
.log-row .log-who { flex: none; color: var(--brand); font-weight: 700; }
.log-row .log-what { min-width: 0; word-break: break-word; }

/* ── 玩遊戲（2026-08-06 圈圈叉叉；2026-08-07 抽成共用面板＋五子棋）──── */
/* 棋盤格數由各遊戲設 --cols／gridClass，面板本體兩款共用 */
#gameGrid {
  display: grid;
  grid-template-columns: repeat(var(--cols, 3), 1fr);
  margin: 0 auto;
  /* 按住拖曳是在瞄準落點，不該順便把頁面捲走（手機實測 2026-08-08） */
  touch-action: none;
}

#gameGrid.ttt { gap: 6px; width: min(264px, calc(100vw - 80px)); }
#gameGrid.gomoku { gap: 2px; width: min(342px, calc(100vw - 48px)); }

/* 黑白棋：整塊綠檯面、格子是檯面上的凹槽，跟四子棋的「板子＋圓孔」同一個
   做法但不畫耳朵——8×8 已經夠滿，再加裝飾會糊掉（2026-08-08）。 */
#gameGrid.othello {
  gap: 2px;
  width: min(336px, calc(100vw - 48px));
  padding: 5px;
  background: #8fb08a;
  border-radius: 12px;
}

#gameGrid.othello .game-cell {
  border-radius: 50%;
  border-color: #7a9a76;
  background: #9dbd98;
  font-size: 20px;
}

#gameGrid.othello .game-cell.filled { background: #9dbd98; }
/* 空格的星位點：比肉球再淡一階，8×8 全鋪才不會吵 */
#gameGrid.othello .paw { fill: #6f8f6b; opacity: .5; }
/* 會被翻掉的子：瞄準時淡亮（.lane 在這裡的意思是「這些會變成我的」） */
#gameGrid.othello .game-cell.lane { background: #b9d3b4; }
/* 四子棋：一塊有貓耳的板子，格子是圓孔——一眼看得出是「投進去」
   不是「點格子」（Gary 2026-08-07：版面不夠可愛，要有貓咪元素）。
   耳朵用 ::before/::after 貼同一張 SVG，右耳左右翻。 */
#gameGrid.connect4 {
  position: relative;
  gap: 4px;
  width: min(322px, calc(100vw - 48px));
  margin-top: 22px;
  padding: 5px;
  background: var(--brand-soft);
  border-radius: 14px;
}

#gameGrid.connect4::before,
#gameGrid.connect4::after {
  content: '';
  position: absolute;
  top: -19px;
  width: 42px;
  height: 30px;
  background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 42 30"><path d="M1 29 L14 2 Q19.5 -5 26.5 2 L41 29 Z" fill="%23f0ece5" stroke="%23ddd4c6" stroke-width="2" stroke-linejoin="round"/><path d="M11.5 26 L19 11 Q20.5 8 23 11 L30 26 Z" fill="%23f2cfc2"/></svg>') no-repeat center / contain;
}

#gameGrid.connect4::before { left: 14px; }
#gameGrid.connect4::after { right: 14px; transform: scaleX(-1); }

.game-cell {
  position: relative;   /* .aim-ghost 疊在格子上 */
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  padding: 0;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--brand);
  font-family: inherit;
  font-size: 30px;
  font-weight: 900;
  cursor: pointer;
}

/* 9×9 一格只有三十幾 px，圓角與字級要跟著縮，不然整片看起來糊成一塊 */
#gameGrid.gomoku .game-cell {
  border-radius: 5px;
  font-size: 20px;
  line-height: 1;
}

#gameGrid.connect4 .game-cell {
  border-radius: 50%;
  padding: 0;
}

/* 已經有子的格子不再 hover，但整欄都投得進去——空格照樣要有回饋 */
#gameGrid.connect4 .game-cell.filled { background: var(--card); }

/* 棋子是貓頭、空格是肉球印（SVG 由 connect4.js 產） */
.game-cell svg { width: 78%; height: 78%; display: block; }
.game-cell .paw { fill: var(--brand); opacity: .22; }

/* 落子動畫：一般棋是彈出來，四子棋是從那一欄上方掉下來再彈兩下。
   --fall 由 games.js 給（在第幾列），一列＝格高 100% 加一道 4px 縫。 */
@keyframes game-pop {
  from { transform: scale(.5); opacity: .3; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes game-drop {
  0% { transform: translateY(calc(var(--fall) * -100% - var(--fall) * 4px)); }
  62% { transform: translateY(0); }
  76% { transform: translateY(-16%); }
  88% { transform: translateY(0); }
  95% { transform: translateY(-5%); }
  100% { transform: translateY(0); }
}

.game-cell.just { animation: game-pop .2s ease-out; }

#gameGrid.connect4 .game-cell.just {
  animation: game-drop .46s cubic-bezier(.45, 0, .8, 1);
  z-index: 1;   /* 掉落途中要蓋在上方那些空洞前面 */
}

@media (prefers-reduced-motion: reduce) {
  .game-cell.just, #gameGrid.connect4 .game-cell.just { animation: none; }
}

.game-cell:hover:not(.filled) { background: var(--brand-soft); }
.game-cell.filled { cursor: default; opacity: 1; }

/* 「你是哪一色」：標題下一行小字，帶一顆真的棋子——照著找就好，不必先把
   顏色名翻譯成畫面上哪一顆（2026-08-08）。 */
.game-mine {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--muted);
}
.game-mine b { color: var(--brand); }
.mine-chip {
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
}
.mine-chip svg { width: 100%; height: 100%; display: block; }

/* ── 音樂盒（2026-08-08）：曲子現場合成，見 music.js ── */
#musicBox { width: min(300px, calc(100vw - 32px)); }

.music-row { display: flex; justify-content: center; margin-bottom: 10px; }

#musicToggle {
  padding: 8px 22px;
  border: 1.5px solid var(--brand);
  border-radius: 999px;
  background: var(--card);
  color: var(--brand);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
#musicToggle.on { background: var(--brand); color: #fff; }

.music-tracks { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }

.music-track {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.music-track.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); }

.music-slider {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--muted);
}
.music-slider span { flex: none; width: 32px; }
.music-slider input { flex: 1 1 auto; accent-color: var(--brand); }
.music-slider b { flex: none; width: 42px; text-align: right; color: var(--brand); }

.music-check {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 10px 0 2px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}
.music-check input { accent-color: var(--brand); }

/* 右上角的迷你開關：不用走到廣場也能開關音樂 */
#musicMini {
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--brand-soft);
  font-size: 13px;
  line-height: 1.2;
  cursor: pointer;
}
#musicMini.on { background: var(--brand); border-color: var(--brand); }

/* 外面的歌：有版權的音樂不進 repo，這裡只嵌官方播放器 */
#musicExt { margin-top: 10px; }
#musicExt > summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  color: var(--brand);
  padding: 4px 0;
}
.music-add { display: flex; gap: 5px; margin: 8px 0 4px; }
.music-add input {
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: inherit;
  font-size: 12px;
}
#musicUrl { flex: 1 1 auto; }
.music-add button {
  flex: none;
  padding: 6px 10px;
  border: 1px solid var(--brand);
  border-radius: 8px;
  background: var(--card);
  color: var(--brand);
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.ext-row { display: flex; gap: 5px; align-items: stretch; }
.ext-row .music-track { flex: 1 1 auto; text-align: left; }
.ext-del {
  flex: none;
  width: 30px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--muted);
  font-family: inherit;
  cursor: pointer;
}
.ext-del:hover { color: var(--alert); border-color: var(--alert); }
#musicPlayer:not(:empty) { margin-top: 8px; border-radius: 10px; overflow: hidden; }
#musicPlayer iframe { display: block; border-radius: 10px; }

/* 瞄準：滑過哪一欄整欄淡亮（.lane），真正會落下的那格再深一點（.aim）並
   疊一顆半透明的貓頭。四子棋是投整欄，只亮滑鼠底下那格會讓人以為子會停
   在那裡（Gary 2026-08-07）。單格 :hover 在這裡會跟整欄打架，蓋掉。 */
#gameGrid.connect4 .game-cell:hover:not(.filled) { background: var(--bg); }
#gameGrid.connect4 .game-cell.lane:not(.filled) { background: var(--brand-soft); }
.game-cell.aim:not(.filled) {
  background: var(--brand-soft);
  box-shadow: inset 0 0 0 2px var(--brand);
}

.aim-ghost {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  opacity: .38;
  pointer-events: none;   /* 疊在格子上，但點擊要穿透回按鈕本身 */
}
.aim-ghost svg { width: 78%; height: 78%; }

.game-status {
  margin: 12px 0 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  text-align: center;
}

.game-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 12px;
}

.game-actions button {
  padding: 8px 18px;
  background: var(--brand);
  border: 1px solid var(--brand);
  border-radius: 999px;
  color: #fff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.game-actions button.ghost {
  background: var(--card);
  color: var(--brand);
}

/* 選遊戲：一款一列，跟走近村民的互動選單同一種手感 */
#gamePick { z-index: 95; min-width: 200px; text-align: center; }

#gamePickList { display: flex; flex-direction: column; gap: 8px; }

/* 沿用 .talk-opt 那顆藥丸鈕（含手機放大），這裡只調整版面上的差別 */
.game-choice { padding: 10px 18px; font-size: 14px; }

/* 對手棋力：星星分等級上色，一眼分得出找誰好欺負 */
.game-skill {
  display: block;
  margin: 2px 0 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .3px;
  color: var(--muted);
}

#gamePickSkill { margin: -4px 0 10px; text-align: center; }

.game-skill.lv-perfect { color: #b03a2e; }
.game-skill.lv-good { color: #b07d1e; }
.game-skill.lv-casual { color: #6b8f6b; }
.game-skill.lv-random { color: var(--muted); }

/* 邀請提示：比棋盤更上層，才不會被自己的等待視窗蓋住 */
#gameInvite {
  z-index: 96;
  top: 90px;
  transform: translate(-50%, 0);
  text-align: center;
}

#gameInvite p { margin: 0; font-size: 14px; font-weight: 700; color: var(--ink); }

/* 預排列（委託板）：沿用 .job-what／.job-when，等確認的用板上既有的琥珀色 */
.plan-row { display: flex; gap: 7px; align-items: center; padding: 6px 10px;
  border-bottom: 1px dashed var(--line); font-size: 12.5px; }
.plan-row b { flex: none; color: var(--brand); }
.plan-row.wait { background: rgba(216,161,58,.14); border-radius: 6px; }
.plan-row.wait .job-when { color: #b07d1e; font-weight: 700; }
.plan-actions button { margin-left: .3em; padding: .15em .6em; cursor: pointer; }

/* 分享鈕：在差事卡展開處，長得像連結而不是主要動作 */
.job-share {
  margin-top: 6px;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--brand);
  font-family: inherit;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.job-share:hover { background: var(--brand-soft); border-color: var(--brand); }
.job-share:disabled { opacity: .7; cursor: default; }

/* ── 單件差事的公開頁（/village/share/…）──────────────
   刻意跟村莊長得不一樣：它不是地圖，是一張可以貼給別人的紀錄卡。 */
body.share-page {
  display: block;
  overflow: auto;
  padding: 24px 16px;
  background: var(--bg);
}

.share-card {
  max-width: 620px;
  margin: 0 auto;
  padding: 26px 24px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.share-brand { margin: 0 0 4px; font-size: 12px; letter-spacing: 1px; color: var(--muted); }
.share-who { margin: 0 0 18px; font-size: 22px; color: var(--brand); }
.share-block { margin-bottom: 16px; }
.share-label {
  margin: 0 0 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--muted);
}
.share-what, .share-result {
  margin: 0;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}
.share-result { border-left: 3px solid var(--ok); }
.share-foot {
  margin: 18px 0 6px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}
.share-page .note { margin: 0; font-size: 11px; color: var(--muted); }


/* ── 導覽模式（?demo=1）：嵌在履歷頁裡自己演 ──────────
   給的是「30 秒看懂這是什麼」，不是給人操作的介面。 */
body.demo #sidebar, body.demo #topbar, body.demo #talkMenu { display: none; }
body.demo { grid-template-columns: 1fr; grid-template-rows: 1fr; }
body.demo #stage-wrap { grid-area: auto; }

#demoBar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(transparent, rgba(0, 0, 0, .72) 38%);
  color: #fff;
}

#demoCaption {
  flex: 1;
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.6;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .6);
}

#demoEnter {
  flex: none;
  padding: 8px 16px;
  border-radius: 999px;
  background: var(--card);
  color: var(--brand);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
}

@media (max-width: 860px) {
  #demoBar { flex-direction: column; align-items: stretch; gap: 8px; }
  #demoCaption { font-size: 13px; }
  #demoEnter { text-align: center; }
}

/* 合併的動態（同日同事件 ×N）：點開才看每一次的細節 */
#feed details > summary { list-style: none; cursor: pointer; }
#feed details > summary::-webkit-details-marker { display: none; }
#feed .times {
  display: inline-block; margin-left: 6px; padding: 0 7px;
  border-radius: 999px; background: var(--brand-soft); color: var(--brand);
  font-size: 11px; font-weight: 700; line-height: 1.6;
}
#feed details[open] .times { background: var(--brand); color: #fff; }
#feed .what .at { color: var(--muted); font-size: 10.5px; margin-right: 6px; }

/* 小地圖：舞台右下角，半透明框，點了走過去 */
#miniMap {
  position: absolute; right: 12px; bottom: 12px; z-index: 3;
  width: 180px; height: 108px;
  border: 2px solid #5c4030; border-radius: 8px;
  background: #d4e4bc; box-shadow: var(--shadow);
  opacity: .92; cursor: pointer;
}
#miniMap:hover { opacity: 1; }
body.demo #miniMap { display: none; }
