@font-face {
  font-family: "Cubic11";
  src: url("fonts/Cubic_11.woff2") format("woff2");
  font-display: swap;
}
:root {
  --ink: #3d1e13;
  --ink2: #6e3b26;
  --paper: #fff4dd;
  --paper2: #f6e2bb;
  --red: #c8372f;
  --redD: #8e2320;
  --green: #2f6b45;
  --greenD: #1f4a30;
  --gold: #f2c94c;
  --goldD: #b8892a;
  --muted: #8a6a52;
  --px: 4px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { scrollbar-gutter: stable; }
body {
  background: #8c5831;
  color: var(--ink);
  font-family: "Cubic11", "PingFang TC", "Noto Sans TC", monospace;
  font-size: 16px;
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: none;
  font-smooth: never;
}
#scene {
  position: fixed; left: 0; top: 0;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  z-index: 0;
  cursor: pointer;
  touch-action: manipulation;
}
#bubbles { position: fixed; inset: 0; pointer-events: none; z-index: 1; }
.bubble {
  position: fixed; z-index: 1; display: none; pointer-events: none;
  background: #fffaf0; color: var(--ink);
  padding: 6px 10px; font-size: 12px; line-height: 1.5;
  max-width: 200px; width: max-content;
  box-shadow: 0 -2px 0 0 var(--ink), 0 2px 0 0 var(--ink), -2px 0 0 0 var(--ink), 2px 0 0 0 var(--ink), 0 6px 0 0 rgba(0,0,0,.25);
}
.bubble b { display: block; color: var(--green); font-weight: normal; }
.bubble.raised { z-index: 6; }
.bubble.below::after { bottom: auto; top: -8px; box-shadow: 0 -2px 0 0 var(--ink), -2px 0 0 0 var(--ink), 2px 0 0 0 var(--ink); }
.bubble::after {
  content: ""; position: absolute; left: var(--ax, 50%); bottom: -8px; width: 6px; height: 6px; margin-left: -3px;
  background: #fffaf0; box-shadow: 0 2px 0 0 var(--ink), -2px 0 0 0 var(--ink), 2px 0 0 0 var(--ink);
}

#stage {
  position: relative; z-index: 2;
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: flex-start; justify-content: center;
  padding: max(76px, 8vh) 16px 120px;
  pointer-events: none;
}
.win {
  pointer-events: auto;
  width: 100%; max-width: 540px;
  background: var(--paper);
  padding: 22px 22px 20px;
  margin: 4px;
  box-shadow:
    0 calc(-1 * var(--px)) 0 0 var(--ink),
    0 var(--px) 0 0 var(--ink),
    calc(-1 * var(--px)) 0 0 0 var(--ink),
    var(--px) 0 0 0 var(--ink),
    inset 0 -4px 0 0 var(--paper2),
    inset 4px 4px 0 0 #fffbf0,
    0 12px 0 0 rgba(20,6,4,.35);
}
.win.enter { animation: pop .25s steps(4); }
@keyframes pop { from { transform: scale(.94); opacity: .3; } to { transform: none; opacity: 1; } }

h1, h2, h3 { font-weight: normal; margin: 0 0 .4em; line-height: 1.3; }
h1 { font-size: 24px; color: var(--red); letter-spacing: 1px; }
h2 { font-size: 24px; }
h3 { font-size: 16px; color: var(--ink2); }
p { margin: .4em 0 .8em; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.title-row h1, .title-row h2 { margin: 0; }
.deco { color: var(--goldD); letter-spacing: 2px; font-size: 12px; }

/* ---------- 按鈕 ---------- */
.btn {
  font: inherit; font-size: 16px; color: #fff;
  background: var(--red); border: 0; cursor: pointer;
  padding: 10px 18px; margin: 6px 4px;
  box-shadow:
    0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink),
    inset -3px -3px 0 0 var(--redD), inset 3px 3px 0 0 #e8655b;
  position: relative; top: 0;
  text-shadow: 1px 1px 0 var(--redD);
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { top: 2px; box-shadow:
    0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink),
    inset 3px 3px 0 0 var(--redD); }
.btn.green { background: var(--green); text-shadow: 1px 1px 0 var(--greenD);
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink),
    inset -3px -3px 0 0 var(--greenD), inset 3px 3px 0 0 #4f9a68; }
.btn.gold { background: var(--gold); color: var(--ink); text-shadow: none;
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink),
    inset -3px -3px 0 0 var(--goldD), inset 3px 3px 0 0 #fbe49a; }
.btn.ghost { background: var(--paper2); color: var(--ink); text-shadow: none;
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink),
    inset -3px -3px 0 0 #dcc394; }
.btn.small { font-size: 12px; padding: 4px 10px; }
.btn[disabled] { background: #bba58b; color: #ede1cc; text-shadow: none; cursor: not-allowed; filter: none;
  box-shadow: 0 -3px 0 0 #7d6552, 0 3px 0 0 #7d6552, -3px 0 0 0 #7d6552, 3px 0 0 0 #7d6552; top: 0; }
.btn.block { display: block; width: calc(100% - 8px); }
.actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px; margin-top: 12px; }
.actions.stack { flex-direction: column; align-items: stretch; }
.linkbtn { font: inherit; font-size: 12px; background: none; border: 0; color: var(--muted); text-decoration: underline; cursor: pointer; padding: 4px; }

#toolbar {
  position: fixed; right: 12px; top: 12px; z-index: 5;
  display: flex; gap: 12px;
}
.tool {
  font: inherit; font-size: 16px; color: var(--ink);
  height: 44px; min-width: 44px; padding: 0 12px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--paper); border: 0; cursor: pointer;
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink),
    inset -3px -3px 0 0 var(--paper2), 0 7px 0 0 rgba(20,6,4,.35);
  position: relative; top: 0;
  -webkit-tap-highlight-color: transparent;
}
.tool:active { top: 2px; }
.tool.icon-only { padding: 0; width: 44px; }
.tool.off { color: #b29a80; }
.px-ico { width: 20px; height: 20px; flex: none; image-rendering: pixelated; }
.btn .px-ico { width: 20px; height: 20px; vertical-align: -4px; margin-right: 8px; }
/* 看客廳模式：面板收起，按鈕移到畫面下方正中央、變大變金色 */
body.peek #stage { display: none; }
body.peek #peek {
  position: fixed; left: 50%; top: auto; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  height: 52px; padding: 0 22px; font-size: 16px;
  background: var(--gold);
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink),
    inset -3px -3px 0 0 var(--goldD), inset 3px 3px 0 0 #fbe49a, 0 8px 0 0 rgba(20,6,4,.4);
  animation: bob 1.2s steps(2) infinite;
}
@keyframes bob { 50% { transform: translate(-50%, -3px); } }

/* ---------- 表單 ---------- */
label { display: block; font-size: 12px; color: var(--ink2); margin: 10px 0 4px; }
input, textarea {
  font: inherit; font-size: 16px; color: var(--ink);
  width: 100%; padding: 8px 10px; border: 0; background: #fffdf6;
  box-shadow: inset 3px 3px 0 0 #e6d2ab, 0 -3px 0 0 var(--ink2), 0 3px 0 0 var(--ink2), -3px 0 0 0 var(--ink2), 3px 0 0 0 var(--ink2);
  margin: 3px 0;
  outline: none;
  border-radius: 0;
}
input:focus, textarea:focus { background: #fff; box-shadow: inset 3px 3px 0 0 #e6d2ab, 0 -3px 0 0 var(--red), 0 3px 0 0 var(--red), -3px 0 0 0 var(--red), 3px 0 0 0 var(--red); }
textarea { resize: vertical; min-height: 54px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
@media (max-width: 420px) { .grid2 { grid-template-columns: 1fr; } }
.req { color: var(--red); }

.pin-input { letter-spacing: 16px; text-align: center; font-size: 24px; max-width: 200px; margin: 6px auto; display: block; }

/* ---------- 玩家選單 ---------- */
.players { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin: 14px 4px; }
.player {
  font: inherit; color: var(--ink); background: var(--paper2); border: 0; cursor: pointer;
  padding: 14px 8px 12px; text-align: center;
  box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink), inset -3px -3px 0 0 #dcc394;
}
.player:hover { background: #ffe9be; }
.player .nm { font-size: 24px; display: block; }
.player .st { font-size: 12px; color: var(--muted); }
.sock { display: inline-block; width: 18px; height: 24px; margin-bottom: 4px; image-rendering: pixelated; }

/* ---------- 進度表 ---------- */
.board { width: 100%; border-collapse: collapse; margin: 10px 0 6px; font-size: 16px; }
.board th { font-weight: normal; font-size: 12px; color: var(--muted); text-align: left; padding: 2px 6px; }
.board td { padding: 8px 6px; border-top: 2px dashed #e3cb9e; }
.board tr.me td { background: #fff9e8; }
.dots { letter-spacing: 2px; }
.dot { display: inline-block; width: 10px; height: 10px; margin-right: 3px; background: #e3cb9e; vertical-align: middle; }
.dot.on { background: var(--red); box-shadow: inset -2px -2px 0 0 var(--redD); }
.ok { color: var(--green); }
.wait { color: var(--muted); }

.phase {
  background: #fdeccb; padding: 10px 12px; margin: 12px 0; font-size: 16px;
  box-shadow: 0 -2px 0 0 var(--goldD), 0 2px 0 0 var(--goldD), -2px 0 0 0 var(--goldD), 2px 0 0 0 var(--goldD);
}
.phase .k { color: var(--red); }

/* ---------- 心願卡 ---------- */
.wish-edit { margin: 18px 4px; padding: 14px 14px 10px; background: #fffaf0; position: relative;
  box-shadow: 0 -3px 0 0 var(--ink2), 0 3px 0 0 var(--ink2), -3px 0 0 0 var(--ink2), 3px 0 0 0 var(--ink2); }
.wish-edit .no { position: absolute; top: -14px; left: 10px; background: var(--red); color: #fff; padding: 0 8px; font-size: 12px;
  box-shadow: 0 -2px 0 0 var(--ink), 0 2px 0 0 var(--ink), -2px 0 0 0 var(--ink), 2px 0 0 0 var(--ink); }

.card-row { display: flex; justify-content: center; gap: 18px; margin: 22px 0 10px; flex-wrap: wrap; perspective: 600px; }
.card {
  width: 140px; min-height: 196px; position: relative; cursor: pointer;
  transform-style: preserve-3d; transition: transform .5s steps(6);
  border: 0; padding: 0; background: none; font: inherit; color: inherit;
}
.card.big { width: 240px; min-height: 280px; cursor: default; }
.card.flipped { transform: rotateY(180deg); }
.card .face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  box-shadow: 0 -4px 0 0 var(--ink), 0 4px 0 0 var(--ink), -4px 0 0 0 var(--ink), 4px 0 0 0 var(--ink), 0 10px 0 0 rgba(20,6,4,.35);
}
.card .back {
  background:
    linear-gradient(var(--gold), var(--gold)) center / 12px 100% no-repeat,
    linear-gradient(var(--gold), var(--gold)) center / 100% 12px no-repeat,
    repeating-linear-gradient(45deg, var(--red) 0 8px, var(--redD) 8px 16px);
  display: flex; align-items: center; justify-content: center;
}
.card .back .q { font-size: 48px; color: #fff; text-shadow: 3px 3px 0 var(--ink); position: relative; background: var(--gold); width: 64px; height: 64px; line-height: 64px; text-align: center; color: var(--red); box-shadow: 0 -3px 0 0 var(--ink), 0 3px 0 0 var(--ink), -3px 0 0 0 var(--ink), 3px 0 0 0 var(--ink); }
.card:not(.flipped):not(.big):hover { transform: translateY(-6px); }
.card .front { transform: rotateY(180deg); background: var(--paper); display: flex; flex-direction: column; text-align: left; overflow: hidden; }
.card.static .front { transform: none; position: relative; }
.card.static { cursor: default; min-height: 0; }
.card.static .face { position: relative; }
.card .front .hd { background: var(--green); color: #fff; padding: 6px 10px; font-size: 12px; display: flex; justify-content: space-between; }
.card .front .bd { padding: 12px 12px 14px; flex: 1; }
.card .front .tt { font-size: 24px; line-height: 1.3; color: var(--red); word-break: break-word; margin-bottom: 8px; }
.card:not(.big):not(.static) .front .tt { font-size: 16px; }
.card .front .fl { font-size: 12px; color: var(--muted); margin-top: 6px; }
.card .front .fv { font-size: 16px; word-break: break-word; }
.card:not(.big):not(.static) .front .fv { font-size: 12px; }
.card .front .ft { font-size: 12px; color: var(--goldD); text-align: center; padding-bottom: 6px; letter-spacing: 3px; }

.mini-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 16px; margin: 14px 4px; }
.mini-cards .card .front .tt { font-size: 16px; }
.mini-cards .card .front .fv { font-size: 12px; }
.mini-cards .card { width: auto; }

.reveal-who {
  text-align: center; margin: 16px 0 6px; font-size: 16px;
}
.reveal-who .big { font-size: 24px; color: var(--red); }
.step { text-align: center; font-size: 12px; color: var(--muted); letter-spacing: 2px; }
.secret { background: var(--ink); color: var(--gold); padding: 8px 12px; text-align: center; margin: 10px 0; font-size: 12px; }

#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 10;
  background: var(--ink); color: #fff4dd; padding: 10px 16px; font-size: 16px;
  box-shadow: 0 -3px 0 0 var(--gold), 0 3px 0 0 var(--gold), -3px 0 0 0 var(--gold), 3px 0 0 0 var(--gold);
  display: none; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { display: block; animation: pop .2s steps(3); }

.hr { height: 4px; margin: 16px 0; background: repeating-linear-gradient(90deg, var(--ink2) 0 8px, transparent 8px 16px); opacity: .4; }
.foot { text-align: center; margin-top: 10px; }

@media (max-width: 480px) {
  .win { padding: 18px 14px 16px; }
  .card { width: 96px; min-height: 140px; }
  .card-row { gap: 12px; }
  .card .back .q { width: 44px; height: 44px; line-height: 44px; font-size: 32px; }
  .card.big { width: 100%; max-width: 280px; }
}
.btn.small .px-ico { width: 14px; height: 14px; margin-right: 4px; vertical-align: -2px; }

/* ---------- 三龜派對 ---------- */
body.partying #stage { opacity: 0; visibility: hidden; transition: opacity .3s steps(3), visibility 0s .3s; pointer-events: none; }
#party-banner {
  position: fixed; left: 50%; top: 22%; z-index: 6; pointer-events: none;
  transform: translate(-50%, -50%) scale(0); text-align: center; white-space: nowrap;
}
#party-banner.show { animation: bannerIn 9s steps(1) forwards; }
@keyframes bannerIn {
  0% { transform: translate(-50%, -50%) scale(0); }
  3% { transform: translate(-50%, -50%) scale(.6); }
  6% { transform: translate(-50%, -50%) scale(1.25); }
  9% { transform: translate(-50%, -50%) scale(1); }
  92% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  96% { transform: translate(-50%, -50%) scale(.5); opacity: .6; }
  100% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
}
.pb-main {
  font-size: clamp(36px, 11vw, 96px); line-height: 1;
  color: #fff; letter-spacing: 2px;
  text-shadow: 4px 0 0 #3d1e13, -4px 0 0 #3d1e13, 0 4px 0 #3d1e13, 0 -4px 0 #3d1e13, 6px 8px 0 rgba(0,0,0,.35);
  animation: rainbow .4s steps(1) infinite, wobble .3s steps(2) infinite;
}
.pb-sub {
  display: inline-block; margin-top: 14px; font-size: clamp(18px, 5vw, 32px);
  background: #f2c94c; color: #3d1e13; padding: 6px 16px;
  box-shadow: 0 -4px 0 0 #3d1e13, 0 4px 0 0 #3d1e13, -4px 0 0 0 #3d1e13, 4px 0 0 0 #3d1e13;
  animation: wobble .3s steps(2) infinite reverse;
}
@keyframes rainbow {
  0% { color: #ff4d4d; } 14% { color: #ffb340; } 28% { color: #ffe94d; } 42% { color: #5ee06a; }
  57% { color: #4dc3ff; } 71% { color: #8c6bff; } 85% { color: #ff6bd6; }
}
@keyframes wobble { 0% { transform: rotate(-3deg); } 100% { transform: rotate(3deg); } }

/* ---------- 結果總覽 ---------- */
.results { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 18px 16px; margin: 12px 4px; }
.result .who { font-size: 16px; margin-bottom: 10px; line-height: 1.8; }
.result .who .arrow { color: var(--muted); font-size: 12px; margin: 0 2px; }
.result .who .to { color: var(--red); font-weight: normal; }
.result .card .front .tt { font-size: 16px; }
.result .card .front .fv { font-size: 12px; }
.result .sock, .results + .hr + h3 .sock { width: 14px; height: 18px; vertical-align: -3px; margin: 0; }
.result .card { width: auto; min-height: 0; }
@media (max-width: 480px) { .results { grid-template-columns: 1fr 1fr; gap: 16px 12px; } .result .who { font-size: 12px; } }

/* 卡片內容太長時可以捲動（翻開的抽卡、公布卡） */
.card.big { height: min(56vh, 440px); }
.card.big.static { height: auto; }
.card .front .bd { min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; scrollbar-width: thin; scrollbar-color: var(--ink2) transparent; }
.card.static .front .bd { overflow: visible; }
.card .front .bd::-webkit-scrollbar { width: 6px; }
.card .front .bd::-webkit-scrollbar-thumb { background: var(--ink2); }
.card .front a { color: var(--green); text-decoration: underline; text-underline-offset: 3px; word-break: break-all; }
.card .front a:hover { color: var(--red); }
.card .ft-more { display: none; color: var(--red); letter-spacing: 1px; animation: blink 1s steps(2) infinite; }
.card.more .ft-x { display: none; }
.card.more .ft-more { display: inline; }
.card.more .front .bd { box-shadow: inset 0 -14px 10px -10px rgba(61,30,19,.25); }
@keyframes blink { 50% { opacity: .35; } }
