:root {
  --font-sans: "Be Vietnam Pro", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  /* Bảng màu tối giản, ấm áp và sang trọng */
  --bg: #111317;
  --bg-elevated: #1a1d24;
  --border-subtle: rgba(255, 255, 255, 0.09);

  --text-light: #f4f4f6;
  --text-dim: #8e95a5;

  /* Mặt lưng bài: Đen than & Vàng Champagne */
  --back-bg: #181b22;
  --champagne: #d6b887;
  --champagne-soft: rgba(214, 184, 135, 0.28);

  /* Mặt trước bài: Giấy kem mịn & Chữ mực đen sâu */
  --paper: #faf8f5;
  --ink: #17181c;
  --ink-muted: #6c707d;
  --paper-border: rgba(23, 24, 28, 0.08);

  /* Điểm nhấn tinh tế theo 4 loại bài */
  --accent-truth: #0f766e;
  --accent-truth-bg: rgba(15, 118, 110, 0.1);

  --accent-dare: #b45309;
  --accent-dare-bg: rgba(180, 83, 9, 0.1);

  --accent-spicy: #be123c;
  --accent-spicy-bg: rgba(190, 18, 60, 0.1);

  --accent-trans: #4f46e5;
  --accent-trans-bg: rgba(79, 70, 229, 0.1);

  --card-w: min(84vw, 336px);
  --card-h: min(53dvh, 444px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100dvh;
  overflow: hidden;
  background-color: var(--bg);
  background-image: radial-gradient(circle at 50% 35%, #1c2029 0%, #111317 70%);
  color: var(--text-light);
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

.app {
  max-width: 440px;
  height: 100dvh;
  margin: 0 auto;
  padding: max(env(safe-area-inset-top), 16px) 20px max(env(safe-area-inset-bottom), 20px);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

/* ================= HEADER TỐI GIẢN ================= */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-left {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.app-title {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-light);
}

.deck-count {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-dim);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-light);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease;
}

.icon-btn:active {
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.08);
}

.turn-indicator {
  text-align: center;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--champagne);
  margin-top: 6px;
}

.turn-indicator.hidden {
  display: none;
}

/* ================= SÂN KHẤU BÀI 3D ================= */
.stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  perspective: 1400px;
}

.deck-stack {
  position: relative;
  width: var(--card-w);
  height: var(--card-h);
}

/* Các lớp bài xếp dưới tạo chiều sâu gọn gàng */
.stack-card {
  position: absolute;
  inset: 0;
  border-radius: 22px;
  background: var(--back-bg);
  border: 1px solid rgba(214, 184, 135, 0.18);
  box-shadow: 0 14px 32px rgba(0, 0, 0, 0.45);
  pointer-events: none;
  transition: transform 0.35s ease, opacity 0.3s ease;
}

.stack-card-2 {
  transform: translateY(10px) scale(0.94);
  opacity: 0.5;
}

.stack-card-1 {
  transform: translateY(5px) scale(0.97);
  opacity: 0.8;
}

/* Hiệu ứng Xào Bài mượt */
.deck-stack.shuffling .stack-card-1 {
  animation: shuffleLeft 0.52s cubic-bezier(0.22, 1, 0.36, 1);
}

.deck-stack.shuffling .stack-card-2 {
  animation: shuffleRight 0.52s cubic-bezier(0.22, 1, 0.36, 1);
}

.deck-stack.shuffling .card-slot {
  animation: shuffleTop 0.52s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes shuffleLeft {
  0%, 100% { transform: translateY(5px) scale(0.97); }
  45% { transform: translateX(-44px) rotate(-7deg) scale(0.97); }
}

@keyframes shuffleRight {
  0%, 100% { transform: translateY(10px) scale(0.94); }
  45% { transform: translateX(44px) rotate(7deg) scale(0.94); }
}

@keyframes shuffleTop {
  0%, 100% { transform: translateY(0); }
  45% { transform: translateY(-8px) scale(1.02); }
}

/* Lá bài chính */
.card-slot {
  position: relative;
  width: 100%;
  height: 100%;
  z-index: 4;
  cursor: pointer;
  transform-style: preserve-3d;
  touch-action: pan-y;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform 0.68s cubic-bezier(0.2, 0.85, 0.28, 1.08);
}

.card-inner.is-flipped {
  transform: rotateY(180deg);
}

/* Hiệu ứng nhấc bài từ cọc lên rồi lật mở */
.card-slot.drawing-anim {
  animation: liftCard 0.68s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes liftCard {
  0% {
    transform: translateY(10px) scale(0.96);
  }
  40% {
    transform: translateY(-22px) scale(1.035);
  }
  100% {
    transform: translateY(0) scale(1);
  }
}

/* Hiệu ứng vuốt bỏ lá cũ */
.card-slot.discard-left {
  animation: throwOutLeft 0.28s ease-in forwards;
}

.card-slot.discard-right {
  animation: throwOutRight 0.28s ease-in forwards;
}

@keyframes throwOutLeft {
  to {
    transform: translateX(-125%) rotate(-14deg);
    opacity: 0;
  }
}

@keyframes throwOutRight {
  to {
    transform: translateX(125%) rotate(14deg);
    opacity: 0;
  }
}

.card-face {
  position: absolute;
  inset: 0;
  border-radius: 22px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  overflow: hidden;
}

/* ================= MẶT LƯNG BÀI (SANG TRỌNG, TỐI GIẢN) ================= */
.card-back {
  background: linear-gradient(165deg, #1d212b 0%, #14171e 100%);
  border: 1px solid rgba(214, 184, 135, 0.35);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.55);
  padding: 16px;
}

.card-back-border {
  width: 100%;
  height: 100%;
  border-radius: 14px;
  border: 1px solid var(--champagne-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 24px 16px;
}

.back-meta {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  color: rgba(214, 184, 135, 0.65);
}

.back-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
}

.back-diamond {
  width: 54px;
  height: 54px;
  border: 1px solid var(--champagne);
  transform: rotate(45deg);
  display: grid;
  place-items: center;
}

.back-diamond-inner {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(214, 184, 135, 0.45);
}

.back-title {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--champagne);
}

.back-hint {
  font-size: 0.8rem;
  font-weight: 400;
  color: var(--text-dim);
}

/* ================= MẶT TRƯỚC BÀI (GIẤY KEM SẠCH SẼ, ĐỒNG BỘ FONT) ================= */
.card-front {
  transform: rotateY(180deg);
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 26px 54px rgba(0, 0, 0, 0.6);
  padding: 26px 26px 22px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

/* Ánh sáng lướt nhẹ khi lật bài */
.card-glare {
  position: absolute;
  inset: -50%;
  background: linear-gradient(
    115deg,
    transparent 40%,
    rgba(255, 255, 255, 0.65) 50%,
    transparent 60%
  );
  transform: translateX(-100%) rotate(12deg);
  pointer-events: none;
}

.card-inner.is-flipped .card-glare {
  animation: sweepGlare 0.75s 0.16s ease-out forwards;
}

@keyframes sweepGlare {
  to {
    transform: translateX(100%) rotate(12deg);
  }
}

/* Màu nhấn tinh tế theo từng loại lá bài */
.card-front[data-type="truth"] {
  --card-accent: var(--accent-truth);
  --card-accent-bg: var(--accent-truth-bg);
}

.card-front[data-type="dare"] {
  --card-accent: var(--accent-dare);
  --card-accent-bg: var(--accent-dare-bg);
}

.card-front[data-type="spicy"] {
  --card-accent: var(--accent-spicy);
  --card-accent-bg: var(--accent-spicy-bg);
}

.card-front[data-type="transition"] {
  --card-accent: var(--accent-trans);
  --card-accent-bg: var(--accent-trans-bg);
}

.card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--card-accent-bg);
  color: var(--card-accent);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.card-badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--card-accent);
}

.card-index {
  font-size: 0.8rem;
  font-weight: 500;
  color: #a1a6b3;
  font-variant-numeric: tabular-nums;
}

/* Nội dung câu hỏi đặt đúng trọng tâm với nhiều khoảng thở */
.card-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  padding: 12px 0;
  overflow-y: auto;
}

.card-text {
  font-size: clamp(1.08rem, 4.4vw, 1.26rem);
  font-weight: 600;
  line-height: 1.55;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.timer-wrap {
  display: none;
}

.timer-wrap.visible {
  display: flex;
}

.timer-pill {
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid rgba(23, 24, 28, 0.14);
  background: #ffffff;
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.timer-pill.running {
  background: var(--ink);
  color: #ffffff;
  border-color: var(--ink);
}

.card-bottom {
  border-top: 1px solid var(--paper-border);
  padding-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.penalty-label {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--ink-muted);
  flex-shrink: 0;
}

.penalty-value {
  font-size: 0.79rem;
  font-weight: 600;
  line-height: 1.35;
  color: var(--card-accent);
  text-align: right;
}

/* ================= CỤM ĐIỀU KHIỂN DƯỚI CÙNG ================= */
.controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.progress-line {
  width: 100%;
  height: 3px;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 2px;
}

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--champagne);
  border-radius: 999px;
  transition: width 0.35s ease;
}

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

.btn-choice {
  height: 46px;
  border-radius: 13px;
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-light);
  font-size: 0.88rem;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: transform 0.14s ease, background 0.2s ease, border-color 0.2s ease;
}

.btn-choice:active {
  transform: scale(0.96);
  background: rgba(255, 255, 255, 0.09);
}

.btn-choice .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.choice-truth .dot {
  background: #14b8a6;
}

.choice-dare .dot {
  background: #f59e0b;
}

.action-row {
  display: flex;
  gap: 10px;
}

.btn-secondary {
  width: 50px;
  height: 50px;
  border-radius: 14px;
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-light);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  cursor: pointer;
  transition: transform 0.14s ease, background 0.2s ease;
}

.btn-secondary:active {
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.08);
}

.btn-primary {
  flex: 1;
  height: 50px;
  border-radius: 14px;
  border: none;
  background: var(--paper);
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  transition: transform 0.14s ease, opacity 0.2s ease;
}

.btn-primary:active {
  transform: scale(0.97);
  opacity: 0.92;
}

/* Thông báo nhỏ gọn khi hết loại bài */
.toast {
  position: fixed;
  bottom: 140px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: rgba(24, 27, 34, 0.95);
  border: 1px solid var(--border-subtle);
  color: var(--text-light);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 500;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 60;
  white-space: nowrap;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ================= MODAL TÙY CHỌN & LỊCH SỬ ================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  z-index: 40;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.modal-backdrop.open {
  display: flex;
}

.modal-sheet {
  width: 100%;
  max-width: 440px;
  max-height: 82dvh;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border-subtle);
  border-radius: 22px 22px 0 0;
  padding: 20px 20px max(env(safe-area-inset-bottom), 24px);
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: sheetUp 0.24s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes sheetUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head h2 {
  font-size: 1rem;
  font-weight: 600;
}

.close-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  padding: 4px 6px;
}

.modal-body {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.field-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field-title {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--text-light);
}

.field-sub {
  font-size: 0.76rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.segmented-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.seg-btn {
  padding: 9px 13px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-dim);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.18s ease;
}

.seg-btn.active {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--paper);
  font-weight: 600;
}

.field-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
}

.switch-input {
  width: 20px;
  height: 20px;
  accent-color: var(--champagne);
  cursor: pointer;
}

.text-input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--border-subtle);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text-light);
  font-size: 0.86rem;
  outline: none;
}

.text-input:focus {
  border-color: var(--champagne);
}

.btn-reset {
  width: 100%;
  height: 46px;
  border-radius: 12px;
  border: 1px solid rgba(244, 63, 94, 0.3);
  background: rgba(244, 63, 94, 0.1);
  color: #fda4af;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  padding: 12px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--champagne);
}

.history-text {
  font-size: 0.84rem;
  line-height: 1.45;
  color: var(--text-light);
}

@media (max-height: 680px) {
  :root {
    --card-h: 54dvh;
  }
  .card-front {
    padding: 20px 20px 16px;
  }
  .card-text {
    font-size: 1rem;
  }
}
