:root {
  --bg: #FFF6E5;
  --ink: #2B2340;
  --ink-2: #6B6380;
  --line: #2B2340;
  --card: #FFFFFF;
  --coral: #FF6B6B;
  --coral-d: #E85555;
  --mint: #3CCFB4;
  --mint-l: #D9F7F0;
  --sun: #FFD84D;
  --sun-l: #FFF1B8;
  --grape: #8C7BFF;
  --grape-l: #ECE8FF;
  --pink-l: #FFE1E1;
  --radius: 20px;
  --shadow: 4px 4px 0 var(--line);
  --shadow-s: 3px 3px 0 var(--line);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}
button, input { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------- background ---------- */
#bg-deco { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.blob { position: absolute; border-radius: 50%; filter: blur(2px); opacity: .55; }
.b1 { width: 260px; height: 260px; background: var(--sun-l); top: -80px; right: -70px; }
.b2 { width: 200px; height: 200px; background: var(--mint-l); bottom: 60px; left: -90px; }
.b3 { width: 140px; height: 140px; background: var(--grape-l); bottom: -40px; right: 20px; }

.app {
  position: relative; z-index: 1;
  max-width: 480px; margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 18px calc(28px + env(safe-area-inset-bottom));
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column;
}

/* ---------- boot ---------- */
.boot { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; }
.boot-logo { font-size: 34px; font-weight: 900; letter-spacing: 1px; }
.boot-dots { display: flex; gap: 8px; }
.boot-dots i, .dots i { width: 9px; height: 9px; border-radius: 50%; background: var(--ink); display: inline-block; animation: bounce 1s infinite ease-in-out; }
.boot-dots i:nth-child(2), .dots i:nth-child(2) { animation-delay: .15s; }
.boot-dots i:nth-child(3), .dots i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .35; } 40% { transform: translateY(-7px); opacity: 1; } }
.dots { display: inline-flex; gap: 5px; vertical-align: middle; }
.dots i { width: 6px; height: 6px; }

/* ---------- common ---------- */
.card {
  background: var(--card);
  border: 2.5px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; gap: 10px; align-items: center; }
.grow { flex: 1; }
.center { text-align: center; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.label { font-size: 14px; font-weight: 700; margin-bottom: 8px; display: block; }

.btn {
  appearance: none; border: 2.5px solid var(--line); border-radius: 16px;
  background: var(--card); box-shadow: var(--shadow-s);
  padding: 14px 18px; font-size: 17px; font-weight: 800; cursor: pointer;
  transition: transform .08s, box-shadow .08s, background .2s, opacity .2s;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; user-select: none;
}
.btn:active:not(:disabled) { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--line); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--coral); color: #fff; }
.btn-mint { background: var(--mint); color: var(--ink); }
.btn-sun { background: var(--sun); }
.btn-grape { background: var(--grape); color: #fff; }
.btn-ghost { background: transparent; box-shadow: none; border-style: dashed; font-weight: 700; font-size: 15px; padding: 11px 14px; }
.btn-ghost:active:not(:disabled) { transform: none; }
.btn-sm { padding: 9px 12px; font-size: 14px; border-radius: 12px; width: auto; }
.btn-link { background: none; border: none; box-shadow: none; padding: 6px; font-size: 14px; font-weight: 600; color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px; width: auto; cursor: pointer; }

.input {
  width: 100%; border: 2.5px solid var(--line); border-radius: 14px; background: #fff;
  padding: 13px 14px; font-size: 17px; font-weight: 600; outline: none;
  transition: box-shadow .15s;
}
.input:focus { box-shadow: 0 0 0 4px var(--sun-l); }
.input::placeholder { color: #B5AEC4; font-weight: 500; }

.seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.seg button {
  border: 2.5px solid var(--line); border-radius: 12px; background: #fff; padding: 10px 0;
  font-weight: 800; font-size: 14px; cursor: pointer;
}
.seg button.on { background: var(--sun); box-shadow: var(--shadow-s); }

.tag {
  display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px;
  border: 2px solid var(--line); font-size: 12.5px; font-weight: 800; background: #fff; white-space: nowrap;
}
.tag.mint { background: var(--mint-l); }
.tag.sun { background: var(--sun-l); }
.tag.pink { background: var(--pink-l); }
.tag.grape { background: var(--grape-l); }
.tag.gray { background: #F1EFF5; color: var(--ink-2); border-color: #B5AEC4; }

/* ---------- home ---------- */
.hero { text-align: center; padding: 18px 0 8px; }
.logo { font-size: 44px; font-weight: 900; line-height: 1.05; letter-spacing: 1px; position: relative; display: inline-block; }
.logo .q { color: var(--coral); display: inline-block; animation: wobble 2.4s infinite ease-in-out; transform-origin: 50% 80%; }
@keyframes wobble { 0%, 100% { transform: rotate(0); } 20% { transform: rotate(14deg); } 40% { transform: rotate(-8deg); } 60% { transform: rotate(4deg); } }
.logo-sub { margin-top: 10px; font-size: 15px; color: var(--ink-2); font-weight: 600; }
.bubbles { display: flex; justify-content: center; gap: 10px; margin: 16px 0 4px; }
.bubble {
  border: 2.5px solid var(--line); border-radius: 16px; padding: 8px 14px; font-weight: 900; font-size: 18px; box-shadow: var(--shadow-s);
  position: relative;
}
.bubble.l { background: var(--mint); transform: rotate(-5deg); animation: bumpL 2.6s infinite ease-in-out; }
.bubble.r { background: var(--sun); transform: rotate(5deg); animation: bumpR 2.6s infinite ease-in-out; }
.bubble.m { background: var(--coral); color: #fff; animation: pop 2.6s infinite ease-in-out; }
@keyframes bumpL { 0%, 100% { transform: rotate(-5deg) translateX(0); } 50% { transform: rotate(-5deg) translateX(6px); } }
@keyframes bumpR { 0%, 100% { transform: rotate(5deg) translateX(0); } 50% { transform: rotate(5deg) translateX(-6px); } }
@keyframes pop { 0%, 40%, 100% { transform: scale(1); } 50% { transform: scale(1.15); } }

.rules { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 6px 0 4px; }
.rule { background: #fff; border: 2px solid var(--line); border-radius: 14px; padding: 10px 8px; text-align: center; }
.rule b { display: block; font-size: 22px; margin-bottom: 2px; }
.rule span { font-size: 12.5px; font-weight: 700; line-height: 1.35; display: block; }

.divider { display: flex; align-items: center; gap: 10px; color: var(--ink-2); font-size: 13px; font-weight: 700; }
.divider::before, .divider::after { content: ""; flex: 1; height: 2px; background: repeating-linear-gradient(90deg, #C9C2D6 0 6px, transparent 6px 11px); }

/* ---------- lobby ---------- */
.room-code {
  font-size: 40px; font-weight: 900; letter-spacing: 8px; text-align: center;
  font-family: "SF Mono", ui-monospace, Menlo, monospace; padding: 6px 0 2px;
}
.invite-box {
  border: 2px dashed var(--line); border-radius: 12px; padding: 10px 12px; font-size: 13px; word-break: break-all;
  background: #FFFBF2; color: var(--ink-2); user-select: all; -webkit-user-select: all;
}
.vs { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
.player { text-align: center; }
.avatar {
  width: 72px; height: 72px; margin: 0 auto 8px; border-radius: 50%; border: 2.5px solid var(--line);
  display: flex; align-items: center; justify-content: center; font-size: 30px; font-weight: 900; box-shadow: var(--shadow-s);
}
.avatar.a { background: var(--mint); }
.avatar.b { background: var(--sun); }
.avatar.empty { background: #fff; border-style: dashed; box-shadow: none; color: #B5AEC4; animation: breathe 1.6s infinite ease-in-out; }
@keyframes breathe { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.06); } }
.player .name { font-weight: 800; font-size: 15px; max-width: 130px; margin: 0 auto; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vs-mark { font-weight: 900; font-size: 22px; color: var(--coral); }

/* ---------- play ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.round-badge {
  background: var(--ink); color: #fff; border-radius: 999px; padding: 7px 14px; font-weight: 900; font-size: 15px;
  box-shadow: 3px 3px 0 var(--coral);
}
.timer { position: relative; width: 46px; height: 46px; flex: none; }
.timer svg { width: 46px; height: 46px; transform: rotate(-90deg); }
.timer .t-bg { fill: #fff; stroke: var(--line); stroke-width: 2.5; }
.timer .t-fg { fill: none; stroke: var(--mint); stroke-width: 5; stroke-linecap: round; transition: stroke-dashoffset .25s linear, stroke .3s; }
.timer .t-num { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 15px; }
.timer.warn .t-fg { stroke: var(--coral); }
.timer.warn .t-num { color: var(--coral-d); animation: tick 1s infinite; }
@keyframes tick { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.18); } }

.status-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.pstat {
  background: #fff; border: 2px solid var(--line); border-radius: 14px; padding: 9px 10px; display: flex; align-items: center; gap: 8px; min-width: 0;
}
.pstat .dot { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line); display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 14px; flex: none; }
.pstat .dot.a { background: var(--mint); }
.pstat .dot.b { background: var(--sun); }
.pstat .meta { min-width: 0; }
.pstat .nm { font-weight: 800; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pstat .st { font-size: 12px; font-weight: 700; color: var(--ink-2); margin-top: 1px; }
.pstat .st.ok { color: #13A58A; }
.pstat .st.off { color: var(--coral-d); }

.clue {
  background: var(--grape-l); border: 2.5px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.clue-title { font-size: 13px; font-weight: 800; color: var(--ink-2); margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.clue-words { display: flex; align-items: center; justify-content: center; gap: 10px; }
.clue-word {
  flex: 1; max-width: 44%; background: #fff; border: 2.5px solid var(--line); border-radius: 14px; padding: 12px 8px; text-align: center;
  font-size: 22px; font-weight: 900; word-break: break-all; position: relative;
}
.clue-word small { display: block; font-size: 11.5px; font-weight: 700; color: var(--ink-2); margin-top: 3px; }
.clue-word.empty { color: #B5AEC4; font-size: 16px; }
.clue-plus { font-weight: 900; font-size: 22px; color: var(--grape); }
.clue-hint { text-align: center; margin-top: 10px; font-size: 13.5px; font-weight: 700; }
.first-clue { text-align: center; padding: 6px 0; }
.first-clue .big { font-size: 22px; font-weight: 900; margin-bottom: 4px; }

.history-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; max-height: 210px; overflow-y: auto; }
.h-item { display: grid; grid-template-columns: 38px 1fr 1fr; gap: 8px; align-items: center; font-size: 14px; font-weight: 700; }
.h-item .r { font-size: 12px; color: var(--ink-2); font-weight: 800; }
.h-item .w { background: #fff; border: 2px solid var(--line); border-radius: 10px; padding: 5px 8px; text-align: center; word-break: break-all; }
.h-item .w.empty { color: #B5AEC4; border-color: #B5AEC4; }

.compose .input { font-size: 22px; text-align: center; padding: 16px 14px; font-weight: 800; }
.counter { text-align: right; font-size: 12px; color: var(--ink-2); font-weight: 700; margin-top: 6px; }
.err { color: var(--coral-d); font-size: 13.5px; font-weight: 700; min-height: 18px; margin-top: 4px; text-align: center; }
#h-err:empty, #j-err:empty { display: none; }
a.btn { color: var(--ink); }

.locked { text-align: center; padding: 22px 16px; }
.locked .seal {
  display: inline-block; padding: 12px 22px; border: 2.5px solid var(--line); border-radius: 16px; background: var(--mint);
  font-size: 26px; font-weight: 900; box-shadow: var(--shadow-s); transform: rotate(-2deg); margin: 6px 0 14px; word-break: break-all;
}
.locked .wait { font-weight: 800; font-size: 15px; }

.giveup-wrap { margin-top: auto; padding-top: 18px; text-align: center; }

/* ---------- reveal ---------- */
.reveal-head { text-align: center; margin: 4px 0 18px; }
.reveal-head .t { font-size: 28px; font-weight: 900; }
.reveal-head .s { font-size: 14px; color: var(--ink-2); font-weight: 700; margin-top: 6px; }
.flip-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; perspective: 900px; }
.flip { position: relative; height: 150px; }
.flip-inner { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform .7s cubic-bezier(.3, 1.4, .5, 1); }
.flip.open .flip-inner { transform: rotateY(180deg); }
.flip-face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border: 2.5px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 10px; text-align: center;
}
.flip-front { background: repeating-linear-gradient(45deg, var(--grape) 0 12px, #9D8EFF 12px 24px); color: #fff; font-size: 40px; font-weight: 900; }
.flip-back { transform: rotateY(180deg); background: #fff; }
.flip-back .w { font-size: 28px; font-weight: 900; word-break: break-all; line-height: 1.15; }
.flip-back .w.empty { font-size: 18px; color: #B5AEC4; }
.flip-back .who { margin-top: 10px; font-size: 12.5px; font-weight: 800; padding: 3px 10px; border-radius: 999px; border: 2px solid var(--line); }
.flip.a .flip-back .who { background: var(--mint-l); }
.flip.b .flip-back .who { background: var(--sun-l); }
.flip.hit .flip-back { background: var(--sun); animation: hitpulse .6s .8s both; }
@keyframes hitpulse { 0% { transform: rotateY(180deg) scale(1); } 50% { transform: rotateY(180deg) scale(1.08); } 100% { transform: rotateY(180deg) scale(1); } }

.decide { display: flex; flex-direction: column; gap: 12px; }
.decide-note { text-align: center; font-size: 13.5px; font-weight: 700; color: var(--ink-2); min-height: 20px; }
.decide-note.hl { color: var(--ink); }

.boom { text-align: center; font-size: 40px; font-weight: 900; color: var(--coral); animation: boomIn .5s .9s both cubic-bezier(.3, 1.6, .5, 1); }
@keyframes boomIn { 0% { transform: scale(0) rotate(-20deg); opacity: 0; } 100% { transform: scale(1) rotate(-4deg); opacity: 1; } }

/* ---------- result ---------- */
.result-hero { text-align: center; padding: 10px 0 4px; }
.result-hero .kicker { font-size: 14px; font-weight: 800; color: var(--ink-2); }
.result-hero .num { font-size: 64px; font-weight: 900; line-height: 1; margin: 8px 0 4px; }
.result-hero .num em { font-style: normal; color: var(--coral); }
.result-hero .num small { font-size: 24px; font-weight: 900; }
.result-hero .num em { font-size: 72px; }
.title-badge {
  display: inline-block; margin-top: 10px; padding: 9px 18px; background: var(--sun); border: 2.5px solid var(--line); border-radius: 999px;
  font-size: 20px; font-weight: 900; box-shadow: var(--shadow-s); transform: rotate(-2deg);
}
.result-hero .quote { margin-top: 12px; font-size: 14.5px; font-weight: 700; color: var(--ink-2); }
.pair-names { display: flex; justify-content: center; align-items: center; gap: 8px; margin-top: 12px; font-weight: 800; }

.chain { display: flex; flex-direction: column; gap: 10px; }
.chain-head { display: grid; grid-template-columns: 44px 1fr 1fr; gap: 8px; font-size: 12.5px; font-weight: 800; color: var(--ink-2); text-align: center; }
.chain-item { display: grid; grid-template-columns: 44px 1fr 1fr; gap: 8px; align-items: stretch; }
.chain-item .r {
  display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 900; border-radius: 10px; background: var(--ink); color: #fff;
}
.chain-item .w {
  border: 2px solid var(--line); border-radius: 12px; padding: 9px 6px; text-align: center; font-weight: 800; font-size: 16px; background: #fff; word-break: break-all;
}
.chain-item .w.a { background: var(--mint-l); }
.chain-item .w.b { background: var(--sun-l); }
.chain-item .w.empty { color: #B5AEC4; background: #fff; border-color: #B5AEC4; font-size: 14px; }
.chain-item.hit .w { background: var(--sun); box-shadow: var(--shadow-s); }
.chain-item.hit .r { background: var(--coral); }
.chain-note { font-size: 12px; font-weight: 700; color: var(--ink-2); grid-column: 2 / 4; text-align: center; margin-top: -4px; }

.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- toast / modal ---------- */
.toast-wrap { position: fixed; left: 0; right: 0; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 50; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 14px; font-weight: 800; font-size: 14.5px; max-width: 88vw;
  box-shadow: 3px 3px 0 var(--coral); animation: toastIn .3s cubic-bezier(.3, 1.5, .5, 1);
}
.toast.out { animation: toastOut .3s forwards; }
@keyframes toastIn { from { transform: translateY(20px) scale(.9); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toastOut { to { transform: translateY(14px); opacity: 0; } }

.net-banner {
  position: fixed; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 40;
  background: var(--coral); color: #fff; border: 2px solid var(--line); border-radius: 999px; padding: 7px 16px; font-size: 13px; font-weight: 800;
}

.modal { position: fixed; inset: 0; z-index: 60; background: rgba(43, 35, 64, .45); display: flex; align-items: center; justify-content: center; padding: 20px; animation: fadeIn .2s; }
.modal-card { width: 100%; max-width: 400px; max-height: 90vh; overflow-y: auto; }
.modal-card h3 { margin: 0 0 8px; font-size: 20px; font-weight: 900; }
.modal-card p { margin: 0 0 16px; color: var(--ink-2); font-weight: 600; font-size: 14.5px; line-height: 1.5; }
.share-img { width: 100%; border-radius: 14px; border: 2.5px solid var(--line); display: block; margin-bottom: 12px; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------- confetti ---------- */
.confetti { position: fixed; inset: 0; pointer-events: none; z-index: 45; overflow: hidden; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 14px; border: 1.5px solid var(--line); border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translate3d(var(--dx), 110vh, 0) rotate(var(--rot)); } }

.fade-in { animation: fadeUp .35s ease both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.state-page { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 16px; text-align: center; }
.state-page .emoji { font-size: 56px; }
.state-page h2 { margin: 0; font-size: 24px; font-weight: 900; }
.state-page p { margin: 0; color: var(--ink-2); font-weight: 600; }

@media (max-width: 360px) {
  .logo { font-size: 38px; }
  .room-code { font-size: 32px; letter-spacing: 6px; }
  .flip-back .w { font-size: 22px; }
}
