*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  height: 100%;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  background: #0f1115;
  color: #e7e9ee;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans TC", sans-serif;
  -webkit-user-select: none; user-select: none;
  overscroll-behavior: none;
  touch-action: manipulation;
}

button { font: inherit; }
.btn {
  background: #2a2f3a;
  color: #e7e9ee;
  border: 1px solid #3a4150;
  padding: 0.75rem 1.1rem;
  border-radius: 10px;
  font-size: 1rem;
  cursor: pointer;
  min-height: 3rem;
  min-width: 3rem;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: #3a6df0; border-color: #3a6df0; }
.btn-secondary { background: #1a1d24; }
.btn-danger { background: #7a2a2a; border-color: #8a3a3a; }
.btn.big { font-size: 1.25rem; padding: 1rem 1.5rem; }

.hidden { display: none !important; }

/* board page */
.board-page {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100svh;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  background: #171a21;
  border-bottom: 1px solid #2a2f3a;
  position: relative;
}
.turn-indicator {
  display: inline-flex;
  align-items: center;
  padding: 0;
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  font: inherit;
  transition: transform 0.06s;
}
.turn-indicator:active { transform: scale(0.97); }
.turn-indicator-row {
  display: flex; align-items: baseline; gap: 0.75rem;
}
.turn-label {
  font-weight: 700;
  font-size: 1.75rem;
  letter-spacing: 0.05em;
  padding: 0.4rem 1rem;
  border-radius: 8px;
  width: 10rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  box-sizing: border-box;
}
.turn-label-text { display: inline-block; }
.turn-label .pass-arrows { display: inline-block; opacity: 0.9; }
.turn-label.turn-red { background: #b84242; color: #fff; animation: turnPulse 2s ease-in-out infinite; }
.turn-label.turn-blue { background: #3a6df0; color: #fff; animation: turnPulse 2s ease-in-out infinite; }
@keyframes turnPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0.0); }
  50% { box-shadow: 0 0 0 6px rgba(255,255,255,0.08); }
}
.turn-counts { font-size: 1.15rem; font-variant-numeric: tabular-nums; margin-left: 0.5rem; }
.count-red { color: #ff7a7a; font-weight: 600; }
.count-blue { color: #8ab4ff; font-weight: 600; }

.scoreboard {
  flex: 1;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.9rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  min-width: 0;
}
.score-team { display: inline-flex; align-items: baseline; }
.score-num { font-size: 2.1rem; }
.score-sep { font-size: 1.2rem; margin: 0 0.15rem; opacity: 0.55; }
.score-den { font-size: 1.2rem; opacity: 0.7; }
.score-red { color: #ff7a7a; }
.score-blue { color: #8ab4ff; }
.score-divider { color: #4a5060; font-weight: 400; font-size: 1.5rem; }
.starts-label {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.starts-red { color: #ff7a7a; }
.starts-blue { color: #8ab4ff; }
.icon-btn {
  padding: 0.5rem;
  width: 3.25rem; height: 3.25rem;
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 0;
}

.qr-corner {
  display: flex; align-items: center; gap: 0.4rem;
  padding: 0.3rem 0.5rem 0.3rem 0.3rem;
  background: #fff;
  border-radius: 8px;
}
.qr-corner img { display: block; width: 64px; height: 64px; }
.room-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1.1rem; font-weight: 700; letter-spacing: 0.12em;
  color: #1a1a1a;
}

.settings-content { max-width: 26rem; position: relative; text-align: left; }
.settings-content h2 { margin-top: 0; }
.settings-section { margin: 1rem 0 1.25rem; }
.settings-label {
  display: block;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #9aa0ad;
  margin-bottom: 0.5rem;
}
.settings-list { display: grid; gap: 0.75rem; margin: 1.25rem 0 0; }

.modal-close-x {
  position: absolute;
  top: 0.5rem; right: 0.5rem;
  width: 2.25rem; height: 2.25rem;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: #9aa0ad;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.modal-close-x:hover { background: #2a2f3a; color: #fff; }

.segmented {
  display: flex;
  background: #0f1115;
  border: 1px solid #2a2f3a;
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
}
.seg-btn {
  flex: 1;
  background: transparent;
  border: none;
  color: #c8ccd4;
  padding: 0.55rem 0.4rem;
  border-radius: 7px;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
}
.seg-btn.active { background: #3a6df0; color: #fff; font-weight: 600; }
.seg-btn:not(.active):hover { background: #1f232c; }

.board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 0.5rem;
  padding: 0.5rem;
  min-height: 0;
}

.card {
  position: relative;
  border-radius: 12px;
  perspective: 1000px;
  cursor: pointer;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
  transition: transform 0.06s;
  background: #e8dfc4;
  color: #1a1a1a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  text-align: center;
  overflow: hidden;
}
.card.pressing { transform: scale(0.98); }

.card-inner {
  position: relative;
  width: 100%; height: 100%;
  transition: transform 0.5s cubic-bezier(0.4, 0.2, 0.2, 1);
  transform-style: preserve-3d;
  border-radius: inherit;
}
.card.flipped .card-inner { transform: rotateY(180deg); }

.card-face {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  border-radius: inherit;
  background: #e8dfc4;
  color: #1a1a1a;
  overflow: hidden;
  font-weight: 700;
  text-align: center;
}
.card-back { transform: rotateY(180deg); background: #f2e9cf; }

.card-word {
  font-size: clamp(1.1rem, 2.2vw, 2rem);
  letter-spacing: 0.02em;
  padding: 0.2rem 0.4rem;
}
.w-zh { font-size: clamp(1.4rem, 3vw, 2.5rem); font-weight: 400; }

/* language modes (default: en-primary = front EN, back ZH) */
body.lang-en-primary .card-front .w-zh { display: none; }
body.lang-en-primary .card-back  .w-en { display: none; }

body.lang-zh-primary .card-front .w-en { display: none; }
body.lang-zh-primary .card-back  .w-zh { display: none; }

body.lang-bilingual .card-face { flex-direction: column; gap: 0.1rem; }
body.lang-bilingual .w-en { font-size: clamp(0.95rem, 1.8vw, 1.6rem); }
body.lang-bilingual .w-zh { font-size: clamp(1.15rem, 2.2vw, 2rem); }

.press-progress {
  position: absolute; inset: 0;
  background: linear-gradient(
    to top,
    rgba(var(--turn-rgb, 58, 109, 240), 0.6),
    rgba(var(--turn-rgb, 58, 109, 240), 0.25)
  );
  transform-origin: bottom;
  transform: scaleY(var(--p, 0));
  transition: transform 0.05s linear;
  pointer-events: none;
  z-index: 2;
  border-radius: inherit;
}
.board.turn-red { --turn-rgb: 184, 66, 66; }
.board.turn-blue { --turn-rgb: 58, 109, 240; }

.card.revealed { cursor: default; }
.card.revealed .card-face { color: #fff; }
.card.color-red, .card.color-red .card-face { background: #b84242; color: #fff; }
.card.color-blue, .card.color-blue .card-face { background: #3a6df0; color: #fff; }
.card.color-neutral, .card.color-neutral .card-face { background: #9a8f72; color: #fff; }
.card.color-assassin, .card.color-assassin .card-face { background: #1a1a1a; color: #f0f0f0; }
.card.color-assassin .card-face { border: 2px solid #e8dfc4; }

/* spymaster / player board */
.spy-main { display: grid; grid-template-rows: auto 1fr; min-height: 100svh; padding: 0.5rem; gap: 0.5rem; }
.spy-main .spy-board {
  grid-template-rows: repeat(5, minmax(110px, 1fr));
}
body.spymaster-page { height: auto; min-height: 100%; overflow-y: auto; overflow-x: hidden; }
.spy-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.5rem 0.75rem; background: #171a21; border-radius: 10px;
}
.spy-header .turn-label { font-size: 1.25rem; }
.spy-header .timer { font-size: 1.5rem; margin: 0; }

.spy-card, .player-card {
  font-size: clamp(0.85rem, 3.5vw, 1.25rem);
}
.spy-card { touch-action: auto; -webkit-touch-callout: default; }
.spy-card .card-word {
  user-select: text;
  -webkit-user-select: text;
  cursor: text;
}
.fx-layer {
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 200;
  overflow: hidden;
}
.confetti-piece {
  position: absolute;
  border-radius: 2px;
  animation: confettiFly 1.6s cubic-bezier(0.1, 0.6, 0.4, 1) forwards;
  will-change: transform, opacity;
}
@keyframes confettiFly {
  0%   { transform: translate(0, 0) rotate(0); opacity: 1; }
  100% { transform: translate(var(--dx), calc(var(--dy) + 400px)) rotate(var(--rot)); opacity: 0; }
}
.emoji-burst {
  position: absolute;
  transform: translate(-50%, -50%) scale(0.3);
  font-size: 8rem;
  animation: emojiPop 1.3s ease-out forwards;
  will-change: transform, opacity;
  text-shadow: 0 4px 16px rgba(0,0,0,0.6);
}
@keyframes emojiPop {
  0%   { transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
  25%  { transform: translate(-50%, -50%) scale(1.25); opacity: 1; }
  60%  { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  100% { transform: translate(-50%, -60%) scale(0.95); opacity: 0; }
}
.fx-flash {
  position: absolute; inset: 0;
  animation: fxFlash 0.5s ease-out forwards;
}
@keyframes fxFlash {
  0% { opacity: 0; }
  30% { opacity: 1; }
  100% { opacity: 0; }
}
@keyframes fxShake {
  0%, 100% { transform: translateX(0); }
  10%, 30%, 50%, 70%, 90% { transform: translateX(-8px); }
  20%, 40%, 60%, 80% { transform: translateX(8px); }
}
body.fx-shake { animation: fxShake 0.5s ease-in-out; }

.tx-badge {
  position: absolute;
  top: 6px; right: 6px;
  z-index: 4;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.35);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 700;
  line-height: 1;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(2px);
  transition: background 0.15s, transform 0.08s;
}
.tx-badge:hover { background: rgba(0, 0, 0, 0.6); }
.tx-badge:active { transform: scale(0.9); }
.card.revealed .tx-badge { background: rgba(255, 255, 255, 0.28); }

.tx-content { max-width: 22rem; text-align: left; }
.tx-content h3 { margin: 0 0 0.75rem; font-size: 1.5rem; text-align: center; }
.tx-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 0.5rem; }
.tx-list li {
  display: flex; align-items: baseline; gap: 0.6rem;
  padding: 0.5rem 0.75rem;
  background: #0f1115;
  border-radius: 8px;
  border: 1px solid #2a2f3a;
}
.tx-text { font-size: 1.75rem; font-weight: 400; }
.tx-sense { font-size: 0.95rem; color: #9aa0ad; }

.x-overlay {
  position: absolute; inset: 0;
  pointer-events: none;
  display: none;
  z-index: 3;
  border-radius: inherit;
}
.x-overlay svg {
  width: 100%; height: 100%;
  stroke: rgba(255, 255, 255, 0.85);
  stroke-width: 6;
  stroke-linecap: round;
  fill: none;
  filter: drop-shadow(0 0 3px rgba(0,0,0,0.5));
}
.card.revealed .x-overlay { display: block; }

/* modal */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal-content {
  background: #1a1d24;
  border-radius: 16px;
  padding: 1.5rem;
  max-width: 32rem;
  width: 100%;
  text-align: center;
}
.modal-content h2 { margin: 0 0 0.5rem; font-size: 2rem; }
.modal-translation { font-size: 1.5rem; margin-bottom: 1rem; color: #ffce7a; }
.modal-def { margin: 0.5rem 0; line-height: 1.5; color: #c8ccd4; }

.status-banner {
  position: fixed;
  bottom: 1rem; left: 50%;
  transform: translateX(-50%);
  padding: 1rem 2rem;
  border-radius: 12px;
  font-size: 2rem;
  font-weight: 700;
  z-index: 50;
}
.status-banner.winner-red { background: #b84242; color: #fff; }
.status-banner.winner-blue { background: #3a6df0; color: #fff; }

/* join page */
.join-page { display: flex; align-items: center; justify-content: center; min-height: 100svh; padding: 1rem; }
.join-main { max-width: 28rem; width: 100%; text-align: center; }
.join-main h1 { font-size: 2.25rem; margin: 0 0 0.25rem; }
.join-prompt { color: #9aa0ad; margin-bottom: 1.5rem; }
.join-room {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 1rem; color: #9aa0ad; margin: 0 0 1rem;
}
.join-room #join-room-code { color: #e8eaf0; font-weight: 700; letter-spacing: 0.15em; }
.role-buttons { display: grid; gap: 0.75rem; }
.role-btn {
  display: block; padding: 1.25rem;
  border-radius: 14px;
  color: #fff;
  text-decoration: none;
  font-weight: 600;
}
.role-btn-title { font-size: 1.4rem; }
.role-btn-sub { font-size: 0.9rem; opacity: 0.85; margin-top: 0.25rem; font-weight: 400; }
.role-red { background: #b84242; }
.role-blue { background: #3a6df0; }
.role-player { background: #2a2f3a; border: 1px solid #3a4150; }

/* gate */
.gate { min-height: 100svh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.gate-card { max-width: 28rem; width: 100%; text-align: center; background: #171a21; padding: 2rem; border-radius: 16px; }
.gate-card h1 { margin: 0 0 0.5rem; }
.gate-card p { color: #9aa0ad; margin-bottom: 1.5rem; }
.gate-card .btn { display: block; width: 100%; margin-bottom: 0.5rem; text-align: center; text-decoration: none; }
