/* =========================================================
   디베잇 - 스타일 (흑백)
   찬성 = O · 검정 채움 / 반대 = X · 흰 바탕 + 검정 테두리
   ========================================================= */

:root {
  --ink: #111111;
  --paper: #ffffff;
  --gray-50: #fafafa;
  --gray-100: #f2f2f2;
  --gray-200: #e5e5e5;
  --gray-400: #a3a3a3;
  --gray-600: #6b6b6b;

  --radius: 8px;
  --font: "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  min-height: 100vh;
  line-height: 1.6;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; line-height: 1.35; letter-spacing: -0.03em; }

button { font-family: inherit; }

.hidden { display: none !important; }

/* ---------- 아이콘 ---------- */
.icon {
  width: 1.15em;
  height: 1.15em;
  flex-shrink: 0;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.2em;
}

.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- 버튼 ---------- */
.btn-primary,
.btn-secondary,
.btn-join,
.btn-text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn-primary {
  background: var(--ink);
  color: var(--paper);
  border: 1px solid var(--ink);
  padding: 12px 20px;
}
.btn-primary:hover:not(:disabled) { background: #333; }

.btn-secondary {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--gray-200);
  padding: 8px 14px;
}
.btn-secondary:hover:not(:disabled) { border-color: var(--ink); }

.btn-join {
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--ink);
  padding: 7px 14px;
  font-size: 0.875rem;
}
.btn-join:hover { background: var(--ink); color: var(--paper); }

.btn-text {
  background: none;
  border: none;
  color: var(--gray-600);
  padding: 6px 4px;
}
.btn-text:hover { color: var(--ink); }

.btn-large { padding: 15px 30px; font-size: 1.05rem; }

button:disabled { opacity: 0.3; cursor: not-allowed; }
button:focus-visible,
input:focus-visible,
textarea:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ---------- 상단 내비게이션 ---------- */
.navbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 24px;
  background: rgba(255, 255, 255, 0.95);
  border-bottom: 1px solid var(--gray-200);
}

.logo { display: flex; align-items: center; }

/* 디베잇 로고 (index.html의 #logo-full / #logo-mark) */
.brand-logo,
.brand-mark {
  display: block;
  fill: currentColor;
  fill-rule: evenodd;
}
.brand-logo { height: 26px; width: calc(26px * 1225 / 335); }

.user-info { display: flex; align-items: center; gap: 12px; }

.badge {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  padding: 2px 8px;
  border: 1px solid var(--ink);
  border-radius: 4px;
}

.points { font-weight: 700; font-variant-numeric: tabular-nums; }
.points.bump { animation: bump 0.6s ease; }
@keyframes bump {
  0%, 100% { transform: scale(1); }
  40% { transform: scale(1.15); }
}

/* ---------- 공통 레이아웃 ---------- */
.container {
  max-width: 880px;
  margin: 0 auto;
  padding: 40px 24px 72px;
}

section + section { margin-top: 48px; }

section > h2 { font-size: 1.25rem; margin-bottom: 16px; }

/* ---------- 1. 메인: 주제 생성 ---------- */
.create-topic-card {
  padding: 28px;
  border: 1px solid var(--ink);
  border-radius: var(--radius);
}
.create-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.create-desc { margin: 4px 0 0; font-size: 0.9rem; color: var(--gray-600); }

.char-hint { margin: 8px 2px 0; font-size: 0.8rem; color: var(--gray-400); }

/* ---------- 1. 메인: 주제 목록 ---------- */
.topic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}

.topic-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 20px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  transition: border-color 0.15s;
}
.topic-card:hover { border-color: var(--ink); }

.topic-card .category {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gray-600);
}
.topic-card.mine .category { color: var(--ink); }

.topic-card h3 {
  font-size: 1.05rem;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.topic-card .author { margin: 0; font-size: 0.85rem; color: var(--gray-600); }

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
  padding-top: 14px;
}

.status { font-size: 0.8rem; color: var(--gray-600); font-variant-numeric: tabular-nums; }

.empty-msg {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--gray-600);
  padding: 48px 0;
  border: 1px dashed var(--gray-200);
  border-radius: var(--radius);
}

/* ---------- 2. 대기방 ---------- */
.waiting-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  margin-bottom: 32px;
}
.waiting-header .btn-text { align-self: flex-start; }
.waiting-header h2 {
  font-size: 1.6rem;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.waiting-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--gray-600);
}
.waiting-badge.ready { color: var(--ink); }

.waiting-content {
  padding: 40px 24px;
  border: 1px solid var(--ink);
  border-radius: var(--radius);
}

.player-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 28px;
}

.player {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 200px;
  padding: 28px 12px;
  border: 1px dashed var(--gray-400);
  border-radius: var(--radius);
  transition: border-color 0.3s;
}
.player.joined { border: 1px solid var(--ink); }
.player p { margin: 0; font-weight: 700; text-align: center; }

.avatar { width: 44px; height: 44px; stroke-width: 1.6; transition: opacity 0.3s; }
.opacity-50 { opacity: 0.25; }
.avatar.searching { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { opacity: 0.15; }
  50% { opacity: 0.45; }
}

.role-tag { font-size: 0.8rem; color: var(--gray-600); }

.vs {
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: -0.04em;
}

.waiting-actions { margin-top: 32px; text-align: center; }

.waiting-hint { margin: 12px 0 0; font-size: 0.85rem; color: var(--gray-600); }

/* ---------- 진영 추첨 카드 ---------- */
.shuffle-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.96);
}

/* ---------- 주제 룰렛 (위에서 아래로 굴러 내려옴) ---------- */
.topic-reel {
  width: min(92vw, 520px);
  text-align: center;
}
.reel-label {
  margin: 0 0 12px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--gray-600);
}
.reel-window {
  position: relative;
  height: calc(56px * 3);
  overflow: hidden;
  border-top: 1px solid var(--gray-200);
  border-bottom: 1px solid var(--gray-200);
  /* 위아래 줄은 흐리게, 가운데 줄만 또렷하게 */
  -webkit-mask-image: linear-gradient(to bottom, transparent, #000 35%, #000 65%, transparent);
  mask-image: linear-gradient(to bottom, transparent, #000 35%, #000 65%, transparent);
}
.reel-window::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 56px;
  height: 56px;
  border-top: 2px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  pointer-events: none;
}
.reel-strip { will-change: transform; }
.reel-item {
  height: 56px; /* script.js의 REEL_ITEM_HEIGHT와 같아야 한다 */
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topic-reel.landed .reel-item.target {
  background: var(--ink);
  color: var(--paper);
  animation: reel-pop 0.35s ease-out;
}
@keyframes reel-pop {
  0% { transform: scale(1); }
  50% { transform: scale(1.06); }
  100% { transform: scale(1); }
}

.card-stage { perspective: 1000px; }

.single-card {
  position: relative;
  width: 170px;
  height: 240px;
  transform-style: preserve-3d;
}
.single-card.spin { animation: cardSpin 2.4s cubic-bezier(0.2, 0.7, 0.2, 1) forwards; }
@keyframes cardSpin {
  0%   { transform: rotateY(0deg) scale(0.7); }
  30%  { transform: rotateY(720deg) scale(1.05); }
  100% { transform: rotateY(1980deg) scale(1); }
}

.card-face {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border-radius: 12px;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  font-size: 1.5rem;
  font-weight: 800;
}

.card-front {
  color: var(--paper);
  background: var(--ink);
  box-shadow: inset 0 0 0 8px var(--ink), inset 0 0 0 9px rgba(255, 255, 255, 0.4);
}
.card-front .brand-mark { width: 112px; height: calc(112px * 335 / 495); }

.card-back {
  transform: rotateY(180deg);
  border: 2px solid var(--ink);
}
.card-back .icon { width: 72px; height: 72px; }
.card-back.role-pro { background: var(--ink); color: var(--paper); }
.card-back.role-con { background: var(--paper); color: var(--ink); }

/* ---------- 3. 토론방 ---------- */
.debate-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-bottom: 16px;
}
.debate-header h2 {
  flex: 1 1 100%;
  font-size: 1.4rem;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.step-badge { font-weight: 700; font-size: 0.95rem; }

.timer-box {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1px solid var(--ink);
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
}
.timer-box.idle { border-color: var(--gray-200); color: var(--gray-400); }
.timer-box.warning { background: var(--ink); color: var(--paper); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { background: var(--paper); color: var(--ink); } }

.debate-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }

.btn-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border: 1.5px solid var(--ink);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, opacity 0.15s;
}
.btn-item:hover:not(:disabled) { background: var(--ink); color: var(--paper); }
.btn-item #itemCount { font-variant-numeric: tabular-nums; }

.progress-steps {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-bottom: 16px;
}
.progress-steps span {
  padding-top: 8px;
  font-size: 0.78rem;
  color: var(--gray-400);
  border-top: 3px solid var(--gray-200);
}
.progress-steps span.done { color: var(--gray-600); border-color: var(--gray-600); }
.progress-steps span.current { color: var(--ink); font-weight: 700; border-color: var(--ink); }

.debate-board {
  display: flex;
  flex-direction: column;
  gap: 16px;
  height: 52vh;
  min-height: 300px;
  overflow-y: auto;
  padding: 20px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
}

.system-msg {
  align-self: center;
  max-width: 90%;
  text-align: center;
  font-size: 0.8rem;
  color: var(--gray-600);
}
.system-msg.strong { color: var(--ink); font-weight: 700; }

.msg {
  display: flex;
  flex-direction: column;
  max-width: 78%;
  animation: msg-in 0.2s ease-out;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.msg.me { align-self: flex-end; align-items: flex-end; }
.msg.opponent { align-self: flex-start; }

.msg-meta {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  color: var(--gray-600);
  margin: 0 2px 4px;
}
.msg-meta .icon { width: 0.95em; height: 0.95em; color: var(--ink); }

.msg-bubble {
  padding: 12px 16px;
  border-radius: 12px;
  white-space: pre-wrap;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
.msg.role-pro .msg-bubble { background: var(--ink); color: var(--paper); }
.msg.role-con .msg-bubble { background: var(--paper); color: var(--ink); border: 1.5px solid var(--ink); }
.msg.me .msg-bubble { border-bottom-right-radius: 2px; }
.msg.opponent .msg-bubble { border-bottom-left-radius: 2px; }

/* 아이템: 예언 결과 */
.prediction-msg {
  align-self: center;
  width: min(100%, 520px);
  padding: 12px 16px;
  border: 1.5px dashed var(--ink);
  border-radius: 12px;
  background: var(--paper);
  font-size: 0.875rem;
  text-align: center;
}
.prediction-msg.hit { background: var(--ink); color: var(--paper); border-style: solid; }
.prediction-head { display: inline-flex; align-items: center; gap: 6px; font-weight: 800; }
.prediction-text { margin-top: 4px; overflow-wrap: anywhere; }
.prediction-reason { margin-top: 4px; font-size: 0.8rem; opacity: 0.75; }

/* 판정 다시 요청 등 글자 버튼 */
.original-toggle {
  padding: 0;
  background: none;
  border: none;
  font: inherit;
  color: inherit;
  text-decoration: underline;
  cursor: pointer;
}

.typing-dots { display: inline-flex; gap: 4px; padding: 4px 0; }
.typing-dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: dot 1.2s infinite;
}
.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot {
  0%, 60%, 100% { opacity: 0.25; }
  30% { opacity: 1; }
}

.debate-input-area {
  display: flex;
  align-items: stretch;
  gap: 6px;
  margin-top: 12px;
  padding: 4px;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  transition: border-color 0.2s;
}
.debate-input-area.my-turn { border-color: var(--ink); }
.debate-input-area.locked { background: var(--gray-50); }

.my-role-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 12px;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 700;
  white-space: nowrap;
  border: 1.5px solid var(--ink);
}
.my-role-badge.role-pro { background: var(--ink); color: var(--paper); }
.my-role-badge.role-con { background: var(--paper); color: var(--ink); }

.debate-input-area textarea {
  flex: 1;
  min-width: 0;
  height: 36px;
  resize: none;
  padding: 8px 10px;
  font-size: 0.95rem;
  line-height: 1.25;
  font-family: inherit;
  color: var(--ink);
  background: transparent;
  border: none;
}
.debate-input-area textarea:focus { outline: none; }
.debate-input-area .btn-primary { padding: 0 16px; }
.debate-input-area textarea::placeholder { color: var(--gray-400); }

.input-hint { margin: 6px 2px 0; font-size: 0.78rem; color: var(--gray-400); text-align: right; }

/* ---------- 모달 (결과 / 프로필) ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.4);
  animation: fade-in 0.15s ease-out;
}
@keyframes fade-in { from { opacity: 0; } }

.modal {
  width: 100%;
  max-width: 440px;
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 32px 28px 24px;
  background: var(--paper);
  border: 1px solid var(--ink);
  border-radius: 12px;
  animation: pop-in 0.2s ease-out;
}
@keyframes pop-in { from { transform: translateY(8px); opacity: 0; } }

.modal h2 {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 1.7rem;
}
.modal h2 .icon { width: 30px; height: 30px; }
.modal .sub { text-align: center; color: var(--gray-600); margin: 4px 0 24px; font-size: 0.875rem; }

.score-total {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  margin-bottom: 24px;
  text-align: center;
}
.score-total strong { display: block; font-size: 2.4rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.score-total small { color: var(--gray-600); }
.score-total .vs { font-size: 1rem; color: var(--gray-400); }

.score-row { margin-bottom: 14px; }
.score-row .label {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 5px;
}
.score-row .label span:last-child { color: var(--gray-600); font-variant-numeric: tabular-nums; }
.bar {
  height: 6px;
  background: var(--gray-100);
  overflow: hidden;
  margin-bottom: 3px;
}
.bar > span { display: block; height: 100%; transition: width 0.8s ease-out; }
.bar.me > span { background: var(--ink); }
.bar.opp > span { background: var(--gray-400); }

.judge-comment {
  margin: 20px 0 16px;
  padding: 14px 16px;
  border-left: 3px solid var(--ink);
  background: var(--gray-50);
  font-size: 0.9rem;
}
.judge-comment b { display: block; font-size: 0.78rem; margin-bottom: 2px; }
.judge-comment .judge-tip-label { margin-top: 10px; }

.point-change { text-align: center; font-size: 1.2rem; font-weight: 800; margin: 12px 0 4px; font-variant-numeric: tabular-nums; }

.mock-note { text-align: center; font-size: 0.75rem; color: var(--gray-400); margin: 0 0 20px; }

.modal-input {
  display: block;
  width: 100%;
  margin-bottom: 16px;
  padding: 12px 14px;
  font-size: 1rem;
  font-family: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
}
.modal-input:focus { border-color: var(--ink); outline: none; }
.modal-textarea { min-height: 96px; margin-bottom: 4px; resize: none; line-height: 1.5; }
.modal .char-hint { margin: 0 2px 16px; text-align: right; }

.item-rules {
  margin: 0 0 16px;
  padding: 12px 16px 12px 32px;
  background: var(--gray-50);
  border-radius: var(--radius);
  font-size: 0.85rem;
  color: var(--gray-600);
}
.item-rules li + li { margin-top: 4px; }

.modal-actions { display: flex; gap: 8px; }
.modal-actions button { flex: 1; padding: 12px; }

.profile-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 16px 0 24px;
  text-align: center;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
}
.profile-stats div { padding: 14px 4px; }
.profile-stats div + div { border-left: 1px solid var(--gray-200); }
.profile-stats strong { display: block; font-size: 1.5rem; }
.profile-stats small { color: var(--gray-600); }

.tier-progress { margin-bottom: 24px; font-size: 0.85rem; color: var(--gray-600); }
.tier-progress .bar { margin-top: 6px; }
.tier-progress .bar > span { background: var(--ink); }

/* ---------- 토스트 ---------- */
.toast-container {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 400;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  padding: 10px 18px;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--paper);
  font-weight: 500;
  font-size: 0.9rem;
  white-space: nowrap;
  animation: toast-in 0.2s ease-out;
}
.toast.out { opacity: 0; transform: translateY(6px); transition: 0.3s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* ---------- 모바일 ---------- */
@media (max-width: 640px) {
  .navbar { padding: 12px 16px; }
  .brand-logo { height: 22px; width: calc(22px * 1225 / 335); }
  .user-info { gap: 8px; }
  .user-info .btn-secondary { padding: 6px 10px; font-size: 0.85rem; }
  .points { font-size: 0.85rem; }

  .container { padding: 24px 16px 56px; }

  .create-topic-card { padding: 20px; }
  .create-row { flex-direction: column; align-items: stretch; }
  .reel-item { font-size: 0.95rem; }

  .waiting-content { padding: 28px 16px; }
  .player-box { gap: 10px; }
  .player { width: auto; flex: 1; padding: 20px 8px; }
  .avatar { width: 36px; height: 36px; }
  .vs { font-size: 1.1rem; }
  .btn-large { width: 100%; padding: 14px; font-size: 1rem; }

  .debate-board { height: 48vh; padding: 14px; }
  .msg { max-width: 88%; }

  .my-role-badge { padding: 0 8px; }
  .debate-input-area .btn-primary { padding: 0 12px; }
}

@media (max-width: 380px) {
  .user-info .badge { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
