:root {
  --bg: #f7efdc;
  --card: #fffaf0;
  --text: #3a2a1a;
  --mute: #7a6650;
  --line: #e8d5b0;
  --brown: #8a5a2b;
  --ok: #2f9e57;
  --warn: #d9a400;
  --bad: #d63939;
  --gray: #9a9288;
}
* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0 auto;
  width: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, "Noto Sans TC", "PingFang TC", sans-serif;
  font-size: 16px;
  line-height: 1.4;
}
#app { max-width: 1280px; margin: 0 auto; padding: 12px 16px 16px; }
section { margin-top: 24px; }
h2 { margin: 0 0 12px; font-size: 18px; font-weight: 700; }
h3 { margin: 0 0 4px; font-size: 16px; font-weight: 700; color: var(--brown); }
p { margin: 0; }
img { image-rendering: pixelated; }
.ok { --c: var(--ok); }
.warn { --c: var(--warn); }
.bad { --c: var(--bad); }
.gray { --c: var(--gray); }
[hidden] { display: none !important; }
button, input { font: inherit; }
button { min-width: 44px; min-height: 44px; cursor: pointer; border: 0; color: inherit; background: transparent; padding: 0; }
:focus-visible { outline: 3px solid var(--brown); outline-offset: 3px; }

/* 上方：頭像列＋錢袋 */
header { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px; }
.tools { order: -1; width: 100%; display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
/* overflow-x:auto 會連帶裁切上下：頭像外圈 box-shadow 3px 要留 4px 內距，不然手機上圓框上緣被切 */
.town { flex: 1 1 100%; min-width: 0; display: flex; gap: 4px; overflow-x: auto; overflow-y: hidden; padding: 4px 4px 4px; }
.house {
  flex: none; width: 84px; min-height: 76px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 4px;
}
.house .av { width: 44px; height: 44px; object-fit: contain; border-radius: 50%; background: var(--card); box-shadow: 0 0 0 3px var(--c); }
.house.gray .av { filter: grayscale(1); opacity: .7; }
.house span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.house.bad span { color: var(--bad); }
.logout {
  flex: none; width: 44px; height: 44px; border-radius: 22px;
  display: flex; align-items: center; justify-content: center;
  color: var(--mute); background: var(--card); border: 2px solid var(--line);
}
.logout svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.purse {
  display: flex; align-items: center; gap: 6px; padding: 0 14px 0 8px;
  background: #fff6df; border: 2px solid var(--brown); border-radius: 22px;
}
.purse .coin { width: 32px; height: 32px; object-fit: contain; }
.purse .amt { font-weight: 800; font-variant-numeric: tabular-nums; }

/* 道具說明框：滑鼠移上去、鍵盤聚焦或點一下（.open）顯示 */
.hasTip { position: relative; }
.tip {
  display: none; position: absolute; top: calc(100% + 6px); left: 0; z-index: 10;
  min-width: 220px; max-width: min(320px, calc(100vw - 32px));
  background: #1d2540; color: #fff; border: 2px solid #f0cf7a; border-radius: 8px; padding: 10px 12px;
  text-align: left; box-shadow: 0 4px 12px rgba(0, 0, 0, .3);
}
.hasTip.right .tip { left: auto; right: 0; }
.hasTip.open .tip { display: block; }
.hasTip:has(:focus-visible) .tip { display: block; }
@media (hover: hover) {
  .hasTip:hover .tip { display: block; }
}
.tip p { margin-bottom: 4px; }
.tip p:last-child { margin-bottom: 0; }
.tip .title { font-weight: 700; color: #f0cf7a; }
.tip .sub { color: #c8d0e8; }

/* Claude／Codex 角色與 MP 條 */
.party { display: grid; gap: 10px; }
.mpbox { background: var(--card); border: 2px solid var(--line); border-radius: 18px; padding: 12px 14px; display: grid; gap: 8px; align-content: end; }
.crew { display: flex; align-items: flex-end; gap: 10px; min-height: 76px; }
.crew .hasTip { min-width: 0; }
.char { width: 64px; height: 64px; object-fit: contain; flex: none; }
.bubble {
  position: relative; min-height: 44px; padding: 8px 14px; border-radius: 16px; text-align: left;
  background: #fff; border: 2px solid var(--brown); font-weight: 600; overflow-wrap: anywhere;
}
.bubble::before {
  content: ""; position: absolute; left: -9px; bottom: 14px; width: 14px; height: 14px;
  background: #fff; border-left: 2px solid var(--brown); border-bottom: 2px solid var(--brown); transform: rotate(45deg);
}
.bubble.idle { display: flex; align-items: center; color: var(--mute); font-weight: 400; border-color: var(--line); }
.bubble.idle::before { border-color: var(--line); }
.mp { width: 100%; min-height: 44px; display: grid; grid-template-columns: 64px 1fr; align-items: center; gap: 8px; text-align: left; }
.mp .name { font-weight: 700; }
.track { position: relative; height: 18px; border-radius: 9px; background: #2b3550; }
.track i { position: absolute; inset: 0 auto 0 0; border-radius: 9px; background: #e5383b; }
.track b { position: absolute; top: -4px; bottom: -4px; width: 3px; background: #f4e7c0; box-shadow: 0 0 0 1px var(--text); }
.mp.red .name { color: var(--bad); }
.mp.gray .track i { background: var(--gray); }

/* 監控卡片 */
/* 卡片大圖：點一下跳出 NPC 對話框（只在 .open 時顯示，不靠滑過） */
.npcbtn { flex: none; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.npcsay .tip { display: none; width: max-content; min-width: 200px; max-width: min(300px, calc(100vw - 48px)); background: #fffdf4; color: var(--text); border: 3px solid var(--brown); border-radius: 10px; padding: 12px 14px; font-weight: 600; }
.npcsay.open .tip, .npcsay:has(:focus-visible) .tip { display: block; }
@media (hover: hover) {
  .npcsay:not(.open):hover .tip { display: none; }
}
.cards { display: grid; gap: 10px; }
.card {
  min-height: 44px; display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: 12px; align-items: start;
  background: var(--card); border: 2px solid var(--line); border-radius: 18px; padding: 12px 14px;
}
.card.bad { border-color: var(--bad); background: #fdf1ee; }
.card .av { width: 56px; height: 56px; object-fit: contain; border-radius: 50%; background: #fff; box-shadow: 0 0 0 3px var(--c); }
.card.gray .av { filter: grayscale(1); opacity: .7; }
.card .head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.card .name { font-size: 18px; font-weight: 700; }
.card .ago { color: var(--mute); flex: none; }
.card .state { color: var(--c); font-weight: 600; }
.card .scan { display: flex; justify-content: space-between; gap: 8px; margin-top: 2px; }
.card .scan span { min-width: 0; overflow-wrap: anywhere; }
.card .scan time, .card .every { color: var(--mute); flex: none; }
.card .every { margin-top: 2px; }

/* 任務視窗與 NPC 對話視窗 */
.quests { display: flex; gap: 10px; align-items: flex-start; }
.leaf { width: 32px; height: 32px; flex: none; margin-top: 8px; }
.window { flex: 1; min-width: 0; background: #fff6df; border: 3px solid var(--brown); border-radius: 14px; padding: 10px 14px; }
.quests .window { display: grid; gap: 10px; }
.zone ul { margin: 0; padding: 0; list-style: none; }
.quest { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.tiny { width: 32px; height: 32px; object-fit: contain; flex: none; }
.qtext { flex: 1; min-width: 0; display: flex; flex-direction: column; overflow-wrap: anywhere; }
.qtext span, .quest time { color: var(--mute); }
.quest time { flex: none; }
.tags { display: flex; flex-wrap: wrap; gap: 4px 6px; }
.tags em { font-style: normal; }
.tags .flag { color: #fff; background: var(--bad); border-radius: 6px; padding: 0 6px; }
.none { color: var(--mute); }
.say time { flex: none; color: var(--mute); font-variant-numeric: tabular-nums; }
.say { display: flex; align-items: center; gap: 8px; min-height: 44px; overflow-wrap: anywhere; }
.say span { min-width: 0; }
.say.bad span { color: var(--bad); }
.facts { margin: 10px 4px 0; color: var(--mute); }
@media (prefers-reduced-motion: no-preference) {
  .say { opacity: 0; animation: pop .4s ease forwards; animation-delay: calc(var(--i) * .25s); }
}
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.credit { padding: 8px 16px 24px; text-align: center; color: var(--mute); }
#app.stale section, #app.stale #town { opacity: .45; }

/* 登入 */
#login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
#login-form { width: 100%; max-width: 360px; display: grid; gap: 12px; }
#login-form input[type="password"] { min-height: 48px; padding: 0 14px; border: 1px solid var(--gray); border-radius: 10px; }
#login-form button { border-radius: 10px; background: var(--text); color: white; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; }
.check input { width: 24px; height: 24px; }
#msg { margin: 0; min-height: 1.4em; color: var(--bad); }

@media (min-width: 700px) {
  .party { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .quests .window { grid-template-columns: 1fr 1fr; }
  header { flex-wrap: nowrap; }
  .tools { order: 0; width: auto; }
  .town { flex: 1; }
}
@media (min-width: 1100px) {
  .cards { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
