:root {
  --bg: #111017;
  --bg2: #1b1924;
  --panel: #201e2b;
  --line: #2f2c3d;
  --text: #f5f3fa;
  --muted: #9a96ad;
  --accent: #ff5d8f;
  --c-life: #ff8a3d;
  --c-brain: #9b6bff;
  --c-love: #ff5d8f;
  --c-rich: #2ec27e;
  --c-social: #3fa9ff;
  --c-game: #ffc93c;
  --c-event: #ff4d4d;
  --radius: 28px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Microsoft YaHei", sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
}

button {
  font: inherit;
  color: inherit;
  border: 0;
  background: none;
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.screen {
  display: none;
  min-height: 100%;
  min-height: 100dvh;
  padding: calc(var(--safe-top) + 16px) 18px calc(var(--safe-bottom) + 18px);
  max-width: 520px;
  margin: 0 auto;
}

.screen.active {
  display: flex;
  flex-direction: column;
}

/* ---------- 首页 ---------- */
.hero {
  text-align: center;
  padding: 10px 0 8px;
}

.logo {
  display: inline-block;
  padding: 4px 14px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--c-love), var(--c-brain));
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 4px;
}

.hero h1 {
  margin: 12px 0 6px;
  font-size: 34px;
  font-weight: 900;
  letter-spacing: 2px;
}

.hero .sub {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.hero .i-en {
  font-size: 0.55em;
  letter-spacing: 1px;
}

.hero .sub .i-en {
  font-size: 11px;
  letter-spacing: 0;
  margin-top: 3px;
}

.panel-title .i-zh,
.panel-title .i-en,
.btn .i-zh,
.btn .i-en,
.fine .i-zh,
.fine .i-en {
  display: inline;
}

.panel-title .i-en,
.btn .i-en,
.fine .i-en {
  margin-left: 6px;
}

.panel-title > .hint {
  display: block;
  margin: 3px 0 0;
}

.panel.row .panel-title > .hint {
  display: inline;
  margin-left: 6px;
}

.hint .i-en,
.tap-hint .i-en {
  display: block;
  margin-left: 0;
}

.panel {
  background: var(--panel);
  border-radius: 20px;
  padding: 14px;
  margin-top: 12px;
}

.panel.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-title {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 10px;
}

.panel.row .panel-title {
  margin: 0;
}

.hint {
  font-weight: 400;
  font-size: 12px;
  color: var(--muted);
  margin-left: 6px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  padding: 8px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  color: var(--muted);
  font-size: 14px;
  transition: all 0.15s;
}

.chip.on {
  color: #111;
  border-color: transparent;
  background: var(--cc, var(--accent));
  font-weight: 700;
}

.chip.cat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-align: left;
  line-height: 1.2;
}

.chip-txt small {
  display: block;
  font-size: 10px;
  font-weight: 600;
  opacity: 0.75;
}

.chip .count {
  opacity: 0.7;
  font-size: 12px;
}

.player-form {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.player-form input {
  flex: 1;
  min-width: 0;
  background: var(--bg2);
  border: 1.5px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  color: var(--text);
  font: inherit;
  font-size: 16px;
  outline: none;
  -webkit-user-select: text;
  user-select: text;
}

.player-form input:focus {
  border-color: var(--accent);
}

.btn-small {
  padding: 0 16px;
  border-radius: 14px;
  background: var(--bg2);
  border: 1.5px solid var(--line);
  font-weight: 700;
}

.player-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.player-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 3px 3px 8px;
  border-radius: 12px;
  background: var(--bg2);
}

.seat {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #111;
  font-size: 13px;
  font-weight: 900;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.pname {
  flex: 1;
  min-width: 0;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mini {
  width: 34px;
  height: 32px;
  border-radius: 9px;
  background: var(--panel);
  color: var(--text);
  font-size: 16px;
  font-weight: 800;
  flex-shrink: 0;
}

.mini:disabled {
  opacity: 0.25;
}

.mini.del {
  color: var(--muted);
  font-size: 20px;
}

.hint.block {
  display: block;
  margin: 2px 0 0;
}

.switch {
  position: relative;
  width: 50px;
  height: 30px;
}

.switch input {
  display: none;
}

.switch span {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--line);
  transition: 0.2s;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  transition: 0.2s;
}

.switch input:checked + span {
  background: var(--accent);
}

.switch input:checked + span::after {
  transform: translateX(20px);
}

.setup-actions {
  margin-top: auto;
  padding-top: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.btn {
  height: 56px;
  border-radius: 18px;
  font-size: 18px;
  font-weight: 800;
}

.btn.primary {
  background: linear-gradient(135deg, var(--c-love), var(--c-brain));
  box-shadow: 0 10px 30px -10px rgba(255, 93, 143, 0.7);
}

.btn.ghost {
  border: 1.5px solid var(--line);
}

.btn:active,
.ctrl:active,
.chip:active {
  transform: scale(0.96);
}

.fine {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  margin: 2px 0 0;
}

/* ---------- 抽卡页 ---------- */
#play {
  padding-bottom: calc(var(--safe-bottom) + 14px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  height: 44px;
  flex-shrink: 0;
}

.setup-top .logo {
  margin-left: 2px;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  background: var(--panel);
  display: grid;
  place-items: center;
}

.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: var(--text);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.progress {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.2;
  color: var(--muted);
}

.p-count {
  font-size: 13px;
}

.p-count b {
  color: var(--text);
  font-size: 17px;
}

.p-round {
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* 语言切换 */
.lang-switch {
  display: flex;
  flex-shrink: 0;
  background: var(--panel);
  border-radius: 14px;
  padding: 3px;
  height: 40px;
}

.lang-switch button {
  min-width: 38px;
  padding: 0 9px;
  border-radius: 11px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}

.lang-switch button.on {
  background: var(--text);
  color: #111;
}

/* 双语文案：英文作为第二行小字 */
.i-zh,
.i-en {
  display: block;
}

.i-en {
  font-size: 0.72em;
  font-weight: 600;
  opacity: 0.7;
  margin-top: 1px;
}

.turn {
  margin: 12px auto 0;
  padding: 7px 16px;
  border-radius: 999px;
  background: var(--panel);
  font-size: 15px;
  animation: pop 0.35s ease;
}

.turn b {
  color: var(--accent);
}

.turn .i-en {
  text-align: center;
}

.turn.passed {
  background: #3a1d12;
  box-shadow: 0 0 0 1.5px var(--c-life);
}

.turn.passed b {
  color: var(--c-life);
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  perspective: 1400px;
  padding: 14px 0;
  min-height: 0;
}

.card {
  position: relative;
  width: min(88vw, 420px);
  height: min(66dvh, 600px);
  touch-action: pan-y;
  will-change: transform;
}

.card .inner {
  position: absolute;
  inset: 0;
  transform-style: preserve-3d;
  transition: transform 0.55s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.card.flipped .inner {
  transform: rotateY(180deg);
}

.face {
  position: absolute;
  inset: 0;
  border-radius: var(--radius);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}

.face.back {
  background: var(--cc);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #111;
  box-shadow: 0 24px 60px -24px var(--cc);
}

.face.back::before {
  content: "";
  position: absolute;
  inset: 14px;
  border: 2px dashed rgba(17, 17, 17, 0.25);
  border-radius: calc(var(--radius) - 10px);
}

.back-mark {
  font-size: 92px;
  font-weight: 900;
  line-height: 1;
}

.back-cat {
  margin-top: 18px;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: 2px;
}

.back-cat-en {
  margin-top: 4px;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 3px;
  opacity: 0.65;
}

.back-brand {
  position: absolute;
  bottom: 30px;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 6px;
  opacity: 0.6;
}

.face.front {
  transform: rotateY(180deg);
  background: #fbf9f4;
  color: #17151d;
  padding: 22px 22px 20px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 60px -28px rgba(0, 0, 0, 0.8);
}

.front-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.tag {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--cc);
  color: #111;
  font-weight: 900;
  font-size: 14px;
}

.tag small {
  font-size: 10px;
  letter-spacing: 1px;
  opacity: 0.7;
}

.card-no {
  font-size: 12px;
  color: #a19cae;
  font-weight: 700;
}

.front-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  padding: 10px 0;
}

/* 内容放得下时垂直居中，放不下时从顶部开始滚动（justify-content:center 会裁掉顶部） */
.front-body::before,
.front-body::after {
  content: "";
  margin: auto;
}

.q-zh {
  font-size: clamp(24px, 7.4vw, 32px);
  font-weight: 900;
  line-height: 1.38;
  letter-spacing: 0.5px;
}

.q-zh.long {
  font-size: clamp(18px, 5.2vw, 22px);
  font-weight: 700;
  line-height: 1.6;
}

.q-en {
  margin-top: 12px;
  font-size: 15px;
  line-height: 1.45;
  color: #6e6880;
  font-weight: 500;
}

.lang-en .q-en {
  margin-top: 0;
  font-size: clamp(22px, 6.4vw, 28px);
  color: #17151d;
  font-weight: 800;
  line-height: 1.32;
}

.lang-en .q-en.long {
  font-size: clamp(16px, 4.6vw, 19px);
  font-weight: 600;
}

.game-name {
  font-size: clamp(30px, 9vw, 40px);
  font-weight: 900;
  margin-bottom: 10px;
}

.game-name-en {
  font-size: 14px;
  font-weight: 800;
  color: #a19cae;
  letter-spacing: 1px;
  margin: -6px 0 12px;
}

.subs {
  border-top: 2px dashed #e6e1d8;
  padding-top: 12px;
}

.subs-title {
  font-size: 12px;
  color: #a19cae;
  font-weight: 700;
  margin-bottom: 8px;
}

.subs-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sub-chip {
  padding: 6px 11px;
  border-radius: 10px;
  background: #efebe3;
  color: #4b4659;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.3;
  text-align: left;
}

.sub-chip.on {
  background: var(--cc);
  color: #111;
  font-weight: 800;
  animation: pop 0.4s ease;
}

.sub-chip em {
  display: block;
  font-style: normal;
  font-size: 11px;
  font-weight: 500;
  opacity: 0.7;
}

.sub-banner {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 12px;
  padding: 9px 12px;
  border-radius: 12px;
  background: #17151d;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  animation: pop 0.45s ease;
}

.sub-banner b {
  color: var(--cc);
}

.sub-banner .i-en {
  font-size: 12px;
}

.lang-both .sub-chip {
  padding: 5px 10px;
}

.lang-both .subs-title .i-en {
  font-size: 10px;
}

.sub-restore {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  font-weight: 500;
  opacity: 0.6;
}

.swapped {
  animation: swapIn 0.35s ease;
}

@keyframes swapIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* 事件卡 */
.card.event .face.back {
  background: radial-gradient(circle at 30% 20%, #ffd166, var(--c-event) 70%);
}

.card.event .face.front {
  background: linear-gradient(160deg, #2a0f1a, #17151d);
  color: #fff;
}

.card.event .q-en {
  color: #c9bfd6;
}

.event-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 4px;
  color: #ffd166;
  margin-bottom: 14px;
}

.tap-hint {
  margin: 14px 0 0;
  font-size: 12px;
  color: var(--muted);
  transition: opacity 0.3s;
}

/* 发牌、离场动画 */
.card.enter {
  animation: dealIn 0.42s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

.card.leave-left {
  transition: transform 0.28s ease-in, opacity 0.28s;
  transform: translateX(-120vw) rotate(-18deg) !important;
  opacity: 0;
}

.card.leave-right {
  transition: transform 0.28s ease-in, opacity 0.28s;
  transform: translateX(120vw) rotate(18deg) !important;
  opacity: 0;
}

.card.snap {
  transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.3, 1.3);
}

@keyframes dealIn {
  from {
    transform: translateY(40px) scale(0.9) rotate(-4deg);
    opacity: 0;
  }
  to {
    transform: none;
    opacity: 1;
  }
}

@keyframes pop {
  0% {
    transform: scale(0.85);
    opacity: 0;
  }
  60% {
    transform: scale(1.05);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.ctrl {
  height: 64px;
  padding: 0 12px;
  border-radius: 20px;
  background: var(--panel);
  border: 1.5px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
  font-size: 15px;
  line-height: 1.15;
  text-align: left;
}

.ctrl.event {
  border-color: var(--c-event);
}

.ctrl.main {
  background: var(--text);
  border-color: var(--text);
  color: #111;
  font-size: 18px;
  font-weight: 900;
}

.ctrl-txt {
  min-width: 0;
}

.ctrl-ico {
  font-size: 20px;
  flex-shrink: 0;
}

/* ---------- 弹层 ---------- */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet-mask {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade 0.2s ease;
}

.sheet-body {
  position: relative;
  width: 100%;
  max-width: 520px;
  background: var(--bg2);
  border-radius: 28px 28px 0 0;
  padding: 22px 20px calc(var(--safe-bottom) + 22px);
  text-align: center;
  animation: up 0.3s cubic-bezier(0.2, 0.9, 0.3, 1);
}

.sheet-body h3 {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 900;
}

.sheet-body .muted {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 14px;
}

.sheet-body h3 .i-en {
  font-size: 15px;
  margin-top: 2px;
}

.sheet-body .muted .i-en {
  font-size: 12px;
}

.sheet-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
}

.sheet-actions .btn {
  flex: 1;
  height: 50px;
  font-size: 16px;
}

.penalty-text {
  margin: 14px 0 4px;
  font-size: 24px;
  font-weight: 900;
  line-height: 1.4;
}

.penalty-en {
  color: var(--muted);
  font-size: 14px;
}

.penalty-ico {
  font-size: 56px;
  animation: pop 0.45s ease;
}

/* 甩锅 */
.sheet-ico {
  font-size: 52px;
  line-height: 1.1;
  margin-bottom: 4px;
  animation: pop 0.45s ease;
}

.pass-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 10px;
  margin-top: 4px;
}

.pass-btn {
  min-height: 52px;
  padding: 8px 10px;
  border-radius: 16px;
  background: var(--panel);
  border: 1.5px solid var(--line);
  font-size: 17px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pass-btn:active {
  transform: scale(0.95);
  background: var(--accent);
  color: #111;
}

.sheet-body .muted.small {
  font-size: 12px;
  margin: 12px 0 0;
}

.toast {
  position: fixed;
  left: 50%;
  top: calc(var(--safe-top) + 70px);
  transform: translate(-50%, -20px);
  background: var(--text);
  color: #111;
  padding: 10px 18px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s;
  z-index: 60;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

@keyframes up {
  from {
    transform: translateY(100%);
  }
}

@media (max-height: 640px) {
  .card {
    height: 58dvh;
  }
  .hero {
    padding: 4px 0 6px;
  }
  .hero h1 {
    font-size: 28px;
  }
  .ctrl {
    height: 52px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation: none !important;
    transition: none !important;
  }
}
