:root {
  --bg1: #fff4e8; --bg2: #fde7f1; --bg3: #e6f0ff;
  --ink: #3a2e4f; --ink-soft: #6b5d80;
  --card: #ffffff; --line: #eadff2;
  --pink: #d63a72; --pink-soft: #ffe1ec;
  --blue: #2563d9; --blue-soft: #e0ebff;
  --green: #138a5a; --green-soft: #dcf7ea;
  --red: #c93434; --red-soft: #ffe3e3;
  --gold: #f6b21a;
  --p0: #2563d9; --p1: #d63a72;
  --radius: 22px;
  --shadow: 0 6px 0 rgba(58, 46, 79, .10), 0 10px 24px rgba(58, 46, 79, .10);
  --safe-t: env(safe-area-inset-top, 0px); --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; position: fixed; inset: 0; overflow: hidden;
  font-family: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  color: var(--ink); background: linear-gradient(160deg, var(--bg1), var(--bg2) 55%, var(--bg3));
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation;
}
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; touch-action: manipulation; }
input { font: inherit; }
#app { position: absolute; inset: 0; padding: calc(var(--safe-t) + 12px) 16px calc(var(--safe-b) + 12px); display: flex; flex-direction: column; }

/* ---------- 通用按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  min-height: 60px; padding: 0 26px; border-radius: 999px; font-size: 22px; font-weight: 800;
  background: var(--card); color: var(--ink); box-shadow: var(--shadow); transition: transform .12s, box-shadow .12s, opacity .2s;
}
.btn:active { transform: translateY(4px) scale(.98); box-shadow: 0 2px 0 rgba(58, 46, 79, .12); }
.btn[disabled] { opacity: .45; pointer-events: none; }
.btn.pink { background: var(--pink); color: #fff; }
.btn.blue { background: var(--blue); color: #fff; }
.btn.green { background: var(--green); color: #fff; }
.btn.red { background: var(--red); color: #fff; }
.btn.big { min-height: 84px; font-size: 28px; padding: 0 40px; }
.btn.small { min-height: 48px; font-size: 18px; padding: 0 18px; }
.icon-btn { width: 56px; height: 56px; border-radius: 50%; background: var(--card); box-shadow: var(--shadow); font-size: 26px; display: grid; place-items: center; }
.icon-btn:active { transform: translateY(3px); }

/* ---------- 首页 ---------- */
.home { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 22px; text-align: center; overflow-y: auto; }
.title { font-size: clamp(40px, 7vw, 72px); font-weight: 900; margin: 0; letter-spacing: 2px; color: var(--pink); text-shadow: 0 4px 0 #fff, 0 7px 0 rgba(214, 58, 114, .18); }
.parade { font-size: clamp(36px, 6vw, 56px); display: flex; gap: 10px; justify-content: center; }
.parade span { display: inline-block; animation: hop 1.6s ease-in-out infinite; }
@keyframes hop { 0%, 100% { transform: translateY(0) } 40% { transform: translateY(-14px) rotate(-6deg) } 60% { transform: translateY(0) } }
.row { display: flex; gap: 16px; flex-wrap: wrap; justify-content: center; }
.link { font-size: 18px; color: var(--ink-soft); text-decoration: underline; padding: 8px; }

/* ---------- 建房 ---------- */
.page { flex: 1; display: flex; flex-direction: column; gap: 16px; overflow-y: auto; align-items: center; padding-bottom: 12px; }
.page h2 { font-size: 30px; margin: 4px 0 0; }
.themes { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 12px; width: 100%; max-width: 940px; }
.theme { background: #fff; border-radius: var(--radius); padding: 10px 6px; box-shadow: var(--shadow); border: 4px solid transparent; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.theme .ti { font-size: 40px; line-height: 1.15; }
.theme b { font-size: 19px; }
.theme small { font-size: 13px; color: var(--ink-soft); }
.theme.on { border-color: var(--pink); background: var(--pink-soft); }

.page { gap: 20px; }
.pick-sec { width: 100%; max-width: 980px; background: rgba(255, 255, 255, .55); border-radius: 28px; padding: 16px 18px 20px; }
.pick-sec h3 { margin: 0 0 14px 4px; font-size: 22px; font-weight: 900; color: var(--ink); }
/* 数量：分段胶囊按钮，和主题卡片区分开 */
.sizes { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; background: #fff; border-radius: 999px; padding: 6px; box-shadow: var(--shadow); width: fit-content; max-width: 100%; margin: 0 auto; }
.size { display: flex; align-items: baseline; gap: 6px; border-radius: 999px; padding: 10px 22px; border: 3px solid transparent; }
.size b { font-size: 24px; }
.size small { font-size: 15px; color: var(--ink-soft); }
.size.on { border-color: var(--blue); background: var(--blue-soft); }
.modal .pick-sec { background: #fff3ea; margin-top: 12px; }

.page-actions { position: sticky; bottom: 0; padding-block: 8px 4px; }
.page h2 { margin: 0; }

/* ---------- 加入：数字键盘 ---------- */
.code-display { display: flex; gap: 12px; }
.code-display span { width: 74px; height: 92px; border-radius: 20px; background: #fff; box-shadow: var(--shadow); font-size: 56px; font-weight: 900; display: grid; place-items: center; color: var(--blue); }
.keypad { display: grid; grid-template-columns: repeat(3, 96px); gap: 14px; }
.keypad button { height: 84px; border-radius: 24px; background: #fff; box-shadow: var(--shadow); font-size: 38px; font-weight: 800; }
.keypad button:active { transform: translateY(4px); box-shadow: none; }

/* ---------- 游戏页 ---------- */
.topbar { display: flex; align-items: center; gap: 12px; min-height: 72px; }
.player { display: flex; align-items: center; gap: 10px; background: rgba(255,255,255,.9); border-radius: 999px; padding: 6px 18px 6px 6px; box-shadow: var(--shadow); min-width: 0; border: 4px solid transparent; transition: border-color .3s; }
.player .av { font-size: 38px; width: 54px; height: 54px; display: grid; place-items: center; border-radius: 50%; background: #fff; flex: none; position: relative; }
.player .dot { position: absolute; right: 0; bottom: 2px; width: 14px; height: 14px; border-radius: 50%; background: #22c55e; border: 2px solid #fff; }
.player .dot.off { background: #b9b0c6; }
.player .nm { font-size: 20px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 9em; }
.player .rm { font-size: 15px; color: var(--ink-soft); white-space: nowrap; }
.player.active { border-color: var(--pc); }
.status { flex: 1; text-align: center; font-size: clamp(18px, 2.6vw, 26px); font-weight: 900; padding: 10px 16px; border-radius: 999px; background: var(--pc, #fff); color: #fff; box-shadow: var(--shadow); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; transition: background .3s; }
.status.neutral { background: #fff; color: var(--ink); }
.pulse { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.03); } }

.board-wrap { flex: 1; min-height: 0; margin: 12px 0; display: flex; gap: 16px; }
.board-area { flex: 1; min-width: 0; min-height: 0; position: relative; }
.board.readonly .card { cursor: default; }
/* 出题人：一直显示的大秘密卡 */
.side { flex: 0 0 clamp(200px, 26%, 300px); background: #fff; border-radius: 28px; border: 5px solid var(--pink-soft); box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 16px; text-align: center; }
.side small { font-size: 18px; font-weight: 800; color: var(--ink-soft); }
.side .e { font-size: clamp(90px, 12vw, 160px); line-height: 1.1; }
.side .e svg { width: 100%; max-width: 220px; height: auto; aspect-ratio: 1; display: block; }
.side b { font-size: 30px; }
@media (orientation: portrait) {
  .board-wrap { flex-direction: column; }
  .side { flex: 0 0 auto; flex-direction: row; gap: 18px; padding: 10px 24px; }
  .side .e { font-size: 72px; }
  .side .e svg { width: 100px; }
}
.version { font-size: 14px; color: var(--ink-soft); margin-top: 8px; }
.board { position: absolute; inset: 0; display: grid; justify-content: center; align-content: center; gap: var(--gap, 10px); }
.card { width: var(--cw); height: var(--ch); perspective: 900px; position: relative; padding: 0; }
.card .inner { position: absolute; inset: 0; transition: transform .5s cubic-bezier(.3, 1.4, .5, 1); transform-style: preserve-3d; }
.card.covered .inner { transform: rotateY(180deg); }
.card .front, .card .back { position: absolute; inset: 0; border-radius: calc(var(--cw) * .14); backface-visibility: hidden; -webkit-backface-visibility: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; overflow: hidden; }
.card .front { background: #fff; box-shadow: 0 5px 0 rgba(58, 46, 79, .10), 0 8px 18px rgba(58, 46, 79, .10); border: 3px solid #fff; }
.card .back { transform: rotateY(180deg); background: repeating-linear-gradient(45deg, #c7b8e8 0 12px, #d6caf0 12px 24px); border: 3px solid #fff; box-shadow: 0 3px 0 rgba(58,46,79,.08); }
.card .back .ghost { font-size: calc(var(--cw) * .32); opacity: .35; filter: grayscale(1); line-height: 1; }
.card .back .ghost svg { width: calc(var(--cw) * .38); height: calc(var(--cw) * .38); }
.card .emo { font-size: calc(var(--cw) * .5); line-height: 1.15; }
.card .pic { width: 86%; aspect-ratio: 1; display: grid; place-items: center; }
.card .pic svg { width: 100%; height: 100%; }
.card .nm { font-size: max(13px, calc(var(--cw) * .13)); font-weight: 800; margin-top: 2px; white-space: nowrap; max-width: 94%; overflow: hidden; text-overflow: ellipsis; }
.card.sel .front { border-color: var(--pink); box-shadow: 0 0 0 5px var(--pink-soft), 0 8px 18px rgba(214, 58, 114, .3); transform: scale(1.04); }
.card.mine .front::after { content: '🤫'; position: absolute; top: 4px; right: 6px; font-size: max(16px, calc(var(--cw) * .16)); }
.board.guessing .card:not(.covered) .front { animation: wiggle 1.2s ease-in-out infinite; border-color: var(--gold); }
@keyframes wiggle { 0%, 100% { transform: rotate(-1.5deg) } 50% { transform: rotate(1.5deg) } }
.card.pop .inner { animation: pop .35s; }
@keyframes pop { 50% { transform: scale(1.1) } }

.bottombar { display: flex; align-items: center; gap: 14px; min-height: 84px; }
.bottombar .grow { flex: 1; display: flex; gap: 14px; justify-content: flex-end; flex-wrap: wrap; align-items: center; }
.hint { font-size: 20px; font-weight: 800; color: var(--ink-soft); flex: 1; text-align: center; }

/* 等待加入 */
.lobby { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; text-align: center; }
.lobby .bigcode { display: flex; gap: 14px; }
.lobby .bigcode span { width: 96px; height: 120px; border-radius: 24px; background: #fff; box-shadow: var(--shadow); font-size: 76px; font-weight: 900; color: var(--pink); display: grid; place-items: center; }
.lobby p { font-size: 22px; margin: 0; color: var(--ink-soft); font-weight: 700; }
.dots span { display: inline-block; animation: hop 1.2s infinite; font-size: 40px; }
.dots span:nth-child(2) { animation-delay: .15s } .dots span:nth-child(3) { animation-delay: .3s }

/* ---------- 弹层 ---------- */
#overlay { position: fixed; inset: 0; background: rgba(58, 46, 79, .45); display: flex; align-items: center; justify-content: center; padding: calc(var(--safe-t) + 16px) 16px calc(var(--safe-b) + 16px); z-index: 10; animation: fade .2s; }
@keyframes fade { from { opacity: 0 } }
.modal { background: #fffaf5; border-radius: 32px; padding: 24px; max-width: 920px; width: 100%; max-height: 100%; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.25); text-align: center; animation: rise .3s cubic-bezier(.3, 1.4, .5, 1); }
@keyframes rise { from { transform: translateY(40px) scale(.95); opacity: 0 } }
.modal h2 { margin: 0 0 14px; font-size: 30px; }
.modal p { font-size: 20px; color: var(--ink-soft); margin: 8px 0; }
.modal .row { margin-top: 18px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.modal-head h2 { margin: 0; text-align: left; }

.secret-show { display: inline-flex; flex-direction: column; align-items: center; background: #fff; border-radius: 28px; padding: 14px 30px; box-shadow: var(--shadow); margin: 6px 0; border: 5px solid var(--pink-soft); }
.secret-show .e { font-size: 110px; line-height: 1.1; }
.secret-show .e svg { width: 150px; height: 150px; }
.secret-show b { font-size: 26px; }
.secret-show small { font-size: 16px; color: var(--ink-soft); font-weight: 700; }
.setting { display: flex; justify-content: space-between; align-items: center; background: #fff; border-radius: 18px; padding: 10px 16px; font-size: 20px; font-weight: 800; margin-bottom: 10px; }
.toggle { width: 74px; height: 42px; border-radius: 999px; background: #d8d0e3; position: relative; transition: background .2s; }
.toggle::after { content: ''; position: absolute; top: 4px; left: 4px; width: 34px; height: 34px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 2px 4px rgba(0,0,0,.15); }
.toggle.on { background: var(--green); }
.toggle.on::after { transform: translateX(32px); }
.rules { text-align: left; font-size: 19px; line-height: 1.7; }
.rules li { margin-bottom: 4px; }

#toast { position: fixed; left: 50%; top: calc(var(--safe-t) + 96px); transform: translateX(-50%); background: var(--ink); color: #fff; padding: 14px 26px; border-radius: 999px; font-size: 22px; font-weight: 800; z-index: 20; box-shadow: 0 10px 30px rgba(0,0,0,.25); animation: rise .25s; max-width: 90vw; text-align: center; }
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 30; overflow: hidden; }
#confetti span { position: absolute; top: -60px; font-size: 40px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(115vh) rotate(720deg); } }
.shake { animation: shake .5s; }
@keyframes shake { 20%, 60% { transform: translateX(-10px) } 40%, 80% { transform: translateX(10px) } }

@media (max-width: 700px) {
  .btn { min-height: 52px; font-size: 19px; padding: 0 18px; }
  .btn.big { min-height: 68px; font-size: 22px; }
  .player .nm { max-width: 4em; font-size: 16px; }
  .player .av { width: 44px; height: 44px; font-size: 30px; }
  .status { font-size: 16px; padding: 8px 10px; }
  .topbar { flex-wrap: wrap; }
  .status { order: 3; flex-basis: 100%; }
  .lobby .bigcode span { width: 70px; height: 90px; font-size: 54px; }
  .keypad { grid-template-columns: repeat(3, 80px); }
  .secret-show .e { font-size: 80px; }
}

/* emoji 一律优先用彩色 emoji 字体（iPad 上是 Apple Color Emoji），避免回退成黑白线稿 */
.emo, .ghost, .secret-show .e, .side .e, .av, .ti, .parade, .dots {
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", system-ui, sans-serif;
}
