:root {
  --ink: #3a372f;
  --muted: #7b7566;
  --green: #5f9e46;
  --red: #e0524f;
  --yellow: #f2c14e;
  --panel: rgba(255, 250, 240, 0.93);
  --shadow: 0 4px 16px rgba(40, 40, 20, 0.2);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: #b3dc93; color: var(--ink);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Heiti TC", sans-serif;
  user-select: none; -webkit-user-select: none;
}
canvas#game { display: block; position: fixed; inset: 0; }
.hidden { display: none !important; }

/* ── 遊戲中的介面 ── */
.panel {
  position: fixed; background: var(--panel); border-radius: 14px;
  box-shadow: var(--shadow); padding: 10px 14px; font-size: 15px;
  transition: background .4s, color .4s;
}
.small { font-size: 12px; color: var(--muted); }
body.night .panel { background: rgba(30, 34, 68, 0.9); color: #eef0ff; }
body.night .small { color: #a9afd8; }

#hud-phase { top: 14px; left: 14px; min-width: 190px; }
#hud-day { font-weight: 800; font-size: 17px; margin-bottom: 6px; }
.bar { height: 8px; background: rgba(0, 0, 0, 0.12); border-radius: 99px; overflow: hidden; }
body.night .bar { background: rgba(255, 255, 255, 0.15); }
.fill { height: 100%; width: 50%; background: var(--green); border-radius: 99px; }
body.night #hud-time { background: #8f9cf0; }

#hud-flock { top: 14px; left: 50%; transform: translateX(-50%); text-align: center; min-width: 210px; }
#hud-flock-mode { font-weight: 800; font-size: 20px; margin: 2px 0 6px; }
.sync {
  display: inline-block; padding: 2px 12px; border-radius: 99px; font-size: 13px; font-weight: 700;
  background: #dcefd0; color: #3b7a26;
}
.sync.bad { background: #fde0dc; color: #c0392b; animation: pulse .55s infinite alternate; }

#hud-status { top: 14px; right: 14px; line-height: 1.75; }
.pips i {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-left: 3px; vertical-align: middle; background: var(--yellow);
}
.pips i.off { background: rgba(0, 0, 0, 0.13); }
body.night .pips i.off { background: rgba(255, 255, 255, 0.18); }

#hud-hunger-box { bottom: 14px; left: 14px; width: 230px; }
.bar.hunger { height: 12px; margin: 5px 0; }
#hud-hunger { transition: width .3s; }
#hud-hunger[data-stage="0"] { background: #8bc26b; }
#hud-hunger[data-stage="1"] { background: #f2b33d; }
#hud-hunger[data-stage="2"] { background: var(--red); }
#hud-hunger-stage { font-size: 13px; }
.tag {
  display: inline-block; margin-top: 6px; background: var(--red); color: #fff;
  font-weight: 800; font-size: 13px; padding: 2px 10px; border-radius: 99px;
  animation: pulse .7s infinite alternate;
}

#hud-hint {
  position: fixed; bottom: 62px; left: 50%; transform: translateX(-50%);
  background: rgba(40, 38, 30, 0.8); color: #fff; padding: 8px 20px; border-radius: 99px;
  font-size: 16px; max-width: calc(100vw - 32px); text-align: center;
}
#hud-hint:empty { display: none; }
#hud-keys {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  font-size: 12px; color: #fff; text-shadow: 0 1px 3px rgba(0, 0, 0, .6); white-space: nowrap;
}
@media (max-width: 900px) { #hud-keys { display: none; } #hud-hint { bottom: 130px; } }

/* ── 公告 ── */
#announce {
  position: fixed; top: 21%; left: 50%; transform: translateX(-50%);
  text-align: center; pointer-events: none; opacity: 0; width: min(720px, 92vw);
}
#announce.show { animation: announce var(--dur, 2.4s) ease forwards; }
#announce .a-title { font-size: 30px; font-weight: 900; color: #fff; text-shadow: 0 2px 8px rgba(0, 0, 0, .55); }
#announce .a-sub { font-size: 17px; color: #fff; text-shadow: 0 1px 5px rgba(0, 0, 0, .65); margin-top: 6px; }
@keyframes announce {
  0% { opacity: 0; transform: translate(-50%, 12px); }
  10% { opacity: 1; transform: translate(-50%, 0); }
  80% { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes pulse { to { transform: scale(1.07); } }
#hud-flock .sync.bad { animation-name: pulse; }
@keyframes blink { 50% { opacity: .35; } }

/* ── 黑幕 ── */
#fade {
  position: fixed; inset: 0; background: #12142a; opacity: 0; pointer-events: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: #fff; text-align: center; padding: 20px;
}
#fade > div { opacity: 0; transition: opacity .3s; }
#fade.text-on > div { opacity: 1; }
#fade-title { font-size: 36px; font-weight: 900; margin-bottom: 16px; letter-spacing: 2px; }
#fade-sub { font-size: 18px; line-height: 1.9; white-space: pre-line; color: #e3e1ff; max-width: 640px; }
#fade-skip { margin-top: 28px; font-size: 13px; color: rgba(255, 255, 255, .45) !important; }

#pause {
  position: fixed; inset: 0; background: rgba(15, 18, 40, .55); color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-size: 36px; font-weight: 900;
}
#pause small { font-size: 15px; font-weight: 400; margin-top: 8px; }

#error-box {
  position: fixed; top: 10px; left: 10px; right: 10px; max-height: 50vh; overflow: auto;
  background: #fff1f0; color: #a3221c; border: 2px solid #e0524f; border-radius: 10px;
  padding: 12px; font-size: 12px; white-space: pre-wrap; z-index: 99; user-select: text;
}

/* 按 F 顯示的幀率（檢查卡頓用） */
#fps {
  position: fixed; right: 10px; bottom: 8px; z-index: 60; pointer-events: none;
  background: rgba(0, 0, 0, 0.55); color: #fff; padding: 3px 8px; border-radius: 6px;
  font: 12px/1.4 Consolas, monospace;
}
#fps.bad { background: rgba(190, 40, 30, 0.8); }

/* ── 投票面板 ── */
#vote-panel {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  width: min(680px, calc(100vw - 32px)); background: var(--panel); border-radius: 18px;
  padding: 14px 20px; box-shadow: var(--shadow); font-size: 15px;
}
.vp-title { font-size: 21px; font-weight: 900; }
.vp-title.bad { color: var(--red); }
.vp-sub { color: var(--muted); margin: 2px 0 8px; font-size: 14px; }
.vp-row { margin: 5px 0; }
.vp-target { font-size: 19px; color: #b5862a; }
.vp-warn { color: var(--red); font-weight: 700; }
.vp-ok { color: var(--green); font-weight: 700; }
.vp-keys { margin-top: 10px; font-size: 13px; color: var(--muted); }
.vp-list {
  list-style: none; margin: 6px 0 0; padding: 0; max-height: 32vh; overflow: auto;
  font-size: 14px; line-height: 1.75; columns: 2; column-gap: 24px;
}
@media (max-width: 640px) { .vp-list { columns: 1; } }
.vp-list li { break-inside: avoid; }
.vp-list li.me { color: var(--red); }
.vp-list li.abstain { opacity: 0.55; }
#hud-need { opacity: 0.7; font-size: 12px; }

/* ── 各個畫面 ── */
.screen {
  position: fixed; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; padding: 16px;
  background: rgba(30, 45, 20, 0.28);
}
.press { margin-top: 18px; font-weight: 800; color: var(--green); animation: blink 1.2s infinite; }
.tiny { font-size: 12px; color: var(--muted); }

.title-box {
  text-align: center; background: var(--panel); padding: 34px 52px;
  border-radius: 26px; box-shadow: var(--shadow); max-width: calc(100vw - 32px);
}
.title-box h1 { font-size: 66px; margin: 0; letter-spacing: 8px; }
.title-box .en { color: var(--muted); letter-spacing: 3px; }
.tagline { font-size: 18px; margin: 18px 0 4px; }
#title-art { display: block; max-width: 440px; width: 100%; border-radius: 14px; margin: 0 auto 14px; }

#screen-card { background: rgba(14, 16, 36, 0.86); color: #fff; }
.card { width: 240px; height: 320px; perspective: 1000px; }
.card-inner {
  position: relative; width: 100%; height: 100%; transform-style: preserve-3d;
  transition: transform 1s cubic-bezier(.3, 1.35, .5, 1);
}
.card.flipped .card-inner { transform: rotateY(180deg); }
.card-face {
  position: absolute; inset: 0; border-radius: 18px; backface-visibility: hidden;
  -webkit-backface-visibility: hidden; display: flex; flex-direction: column;
  align-items: center; justify-content: center; box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
}
.card-back {
  background: repeating-linear-gradient(45deg, #f6efe0 0 14px, #ece2cc 14px 28px);
  color: #b9a985; font-size: 110px; font-weight: 900; border: 6px solid #fff;
}
.card-front { transform: rotateY(180deg); background: #2a2f55; border: 6px solid var(--yellow); }
.role-name { font-size: 56px; font-weight: 900; color: var(--yellow); line-height: 1.1; }
.role-line { color: #cfd3f5; }
.card-text { text-align: center; margin-top: 24px; max-width: 520px; line-height: 1.7; }
.card-text .big { font-size: 24px; margin-bottom: 4px; }
.card-text b { color: var(--yellow); }
.card-text .tiny { color: #9aa0c8; }

.help-box {
  background: var(--panel); border-radius: 22px; padding: 22px 30px;
  max-width: 940px; width: 100%; max-height: calc(100vh - 32px); overflow: auto; box-shadow: var(--shadow);
}
.help-box h2 { margin: 0 0 12px; }
.help-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 760px) { .help-cols { grid-template-columns: 1fr; } }
.help-col { border-radius: 14px; padding: 10px 18px; }
.help-col.night { background: #262b52; color: #eef0ff; }
.help-col.day { background: #e8f4dc; }
.help-col h3 { margin: 6px 0 4px; }
.help-col ol { padding-left: 20px; line-height: 1.75; margin: 4px 0 10px; }
.help-box .press { text-align: center; }
kbd {
  display: inline-block; padding: 0 6px; border-radius: 5px; background: #fff; color: #333;
  border: 1px solid #bbb; border-bottom-width: 2px; font-family: inherit; font-size: 13px; line-height: 1.5;
}
.q, .x {
  display: inline-block; width: 20px; height: 20px; border-radius: 50%; text-align: center;
  line-height: 16px; font-weight: 900; background: #fff; border: 2px solid;
}
.q { color: #e0a526; border-color: #e0a526; }
.x { color: var(--red); border-color: var(--red); }

.end-box {
  background: var(--panel); border-radius: 24px; padding: 28px 40px; text-align: center;
  width: min(560px, 100%); box-shadow: var(--shadow); max-height: calc(100vh - 32px); overflow: auto;
}
#end-side { display: inline-block; padding: 3px 16px; border-radius: 99px; font-weight: 900; color: #fff; }
.win #end-side { background: #3b4a8a; }
.lose #end-side { background: #8a8270; }
#end-title { font-size: 34px; margin: 12px 0 6px; }
#end-desc { font-size: 17px; margin: 0 0 8px; }
.end-reasons-title { font-weight: 800; margin-top: 12px; }
.end-reasons { text-align: left; display: inline-block; margin: 6px 0; line-height: 1.7; }
#end-stats { display: flex; gap: 22px; justify-content: center; margin-top: 16px; font-size: 13px; color: var(--muted); }
.stat b { display: block; font-size: 28px; color: var(--ink); }
