/* ====== common.css — 반응형 토대 + 모여팝 디자인 토큰 ====== */
@import url("https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700;800&family=Plus+Jakarta+Sans:wght@500;600;700;800&family=Nanum+Gothic:wght@400;700;800&display=swap");

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* 모여팝 브랜드 팔레트 (라이트 기본) */
  --purple: #7047ef;
  --lime: #d5ff58;
  --cream: #fbfaf6;
  --ink: #10132b;
  --dark: #0b0d1d;

  --primary: #7047ef;
  --primary-dark: #5b39c7;
  --primary-soft: #ebe7ff;
  --accent: var(--primary);
  --secondary: #d5ff58;
  --success: #12a66f;
  --danger: #e5484d;
  --warn: #f5a524;
  --bg: #fbfaf6;
  --bg-1: #ffffff;
  --bg-2: #ffffff;
  --bg-3: #f1eefb;
  --bg-4: #d9d4ec;
  --text: #10132b;
  --text-dim: #686d85;
  --border: #e8e6ec;
  --on-primary: #ffffff;
  --hover-tint: rgba(16, 19, 43, 0.05);
  --shadow-card: 0 10px 30px rgba(34, 33, 62, 0.08);
  --radius: 14px;
  --radius-lg: 22px;
  --font: "DM Sans", "Nanum Gothic", "Apple SD Gothic Neo", "Pretendard", "Malgun Gothic", sans-serif;
  --font-display: "Plus Jakarta Sans", "DM Sans", "Nanum Gothic", sans-serif;

  /* 반응형 단위 */
  --space-xs: 0.25rem;
  --space-sm: 0.5rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  height: 100%;
  font-family: var(--font);
  word-break: keep-all;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  font-size: 16px;
  line-height: 1.5;
}
html, body { overflow-x: hidden; }
img, video, audio { max-width: 100%; }

@media (max-width: 600px) {
  html, body { font-size: 15px; }
}

/* 표가 좁은 화면에서 가로 스크롤되도록 — 자동 적용을 위해 .table-wrap 헬퍼 */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap table { min-width: 480px; }

/* 폼 컨트롤은 부모 폭 안에 들어가도록 */
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
textarea, select { max-width: 100%; }

::selection { background: var(--lime); color: var(--ink); }
h1, h2, h3, h4 { font-family: var(--font-display); letter-spacing: -0.03em; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── 버튼 ─── */
button {
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  padding: 0.55rem 1.2rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
  min-height: 38px;
}
button .icon { flex-shrink: 0; }
button:hover { background: var(--bg-3); }
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary  { background: var(--primary); border-color: var(--primary); color: var(--on-primary); box-shadow: 0 6px 16px rgba(112,71,239,0.25); }
button.primary:hover  { background: var(--primary-dark); }
button.success  { background: var(--success); border-color: var(--success); color: white; }
button.danger   { background: var(--danger); border-color: var(--danger); color: white; }
button.secondary{ background: var(--secondary); border-color: var(--secondary); color: var(--ink); }
button.ghost    { background: transparent; border-color: var(--border); }
button.sm       { font-size: 0.8rem; padding: 0.3rem 0.65rem; min-height: 32px; gap: 0.25rem; max-width: 100%; }
button.sm > .icon { width: 12px; height: 12px; }
button.lg       { font-size: 1.1rem; padding: 0.85rem 1.6rem; min-height: 50px; }
button.icon-only{ padding: 0.5rem; min-width: 38px; justify-content: center; }

/* ─── 입력 ─── */
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
textarea, select {
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.55rem 0.75rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text);
  outline: none;
  width: 100%;
  min-height: 40px;
}
input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):focus,
textarea:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(112,71,239,0.22);
}
textarea { resize: vertical; min-height: 80px; }

/* 체크박스/라디오 — 어떤 우선순위에도 16px 강제 */
input[type="checkbox"], input[type="radio"],
input[type="checkbox"]:focus, input[type="radio"]:focus {
  width: 16px !important;
  height: 16px !important;
  min-width: 16px !important;
  min-height: 16px !important;
  max-width: 16px !important;
  max-height: 16px !important;
  padding: 0 !important;
  margin: 0 !important;
  flex-shrink: 0 !important;
  display: inline-block !important;
  appearance: auto !important;
  -webkit-appearance: auto !important;
  accent-color: var(--primary);
  cursor: pointer;
  vertical-align: middle;
  box-shadow: none !important;
}

/* 동의 체크박스 행 — 한 줄에 [☐][설명...] 깔끔히 */
.consent-row {
  display: flex !important;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.45rem 0.25rem;
  cursor: pointer;
  border-radius: 6px;
  line-height: 1.5;
  width: 100%;
}
.consent-row:hover { background: var(--hover-tint); }
.consent-row > input[type="checkbox"] {
  margin-top: 0.25rem !important;
}
.consent-row > span { flex: 1 1 auto; min-width: 0; }

/* 소스 토글 체크박스 — 한 줄에 [☐ 라벨] 가로 배열 */
.source-toggle {
  display: inline-flex !important;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.6rem;
  cursor: pointer;
  border-radius: 6px;
  white-space: nowrap;
}
.source-toggle:hover { background: var(--hover-tint); }

/* ─── 표 ─── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
th, td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
}
th { color: var(--text-dim); font-size: 0.82rem; font-weight: 600; }

/* ─── 카드 ─── */
.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  box-shadow: var(--shadow-card);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  background: var(--bg-3);
  color: var(--text);
}
.badge.warn { background: var(--warn); color: var(--ink); }
.badge.danger { background: var(--danger); color: white; }
.badge.success { background: var(--success); color: white; }

/* ─── 레이아웃 유틸 ─── */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }
.gap-3 { gap: 1.5rem; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.flex-1 { flex: 1; min-width: 0; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-dim { color: var(--text-dim); }
.text-sm { font-size: 0.85rem; }
.text-lg { font-size: 1.1rem; }
.text-xl { font-size: 1.4rem; }
.text-2xl { font-size: 1.8rem; }
.text-3xl { font-size: 2.4rem; }
.font-bold { font-weight: 700; }
.font-mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }
.mt-1 { margin-top: 0.5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.5rem; }
.ml-1 { margin-left: 0.5rem; } .ml-2 { margin-left: 1rem; }
.p-1 { padding: 0.5rem; } .p-2 { padding: 1rem; } .p-3 { padding: 1.5rem; }
.scroll-y { overflow-y: auto; }
.hidden { display: none !important; }
.relative { position: relative; }

/* ─── 색상 ─── */
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warn { color: var(--warn); }

/* ─── 폼 행 ─── */
.field { margin-bottom: 1rem; }
.field label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.85rem;
  color: var(--text-dim);
}

/* 좁은 화면에서 인라인 width:120/140/160px 등이 화면보다 작아지도록 자동 축소 */
@media (max-width: 480px) {
  .field[style*="width:120px"],
  .field[style*="width:140px"],
  .field[style*="width:160px"],
  .field[style*="width:200px"] {
    width: 100% !important;
  }
}

/* ─── 토스트 ─── */
.toast {
  position: fixed;
  /* 탭바(z-index:20) 위에 떠있어야 하므로 bottom 여유 확보 */
  bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  padding: 0.7rem 1.4rem;
  background: var(--ink);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.22);
  border-radius: 999px;
  z-index: 9999;
  animation: toastIn 0.2s ease-out;
  max-width: min(90vw, 400px);
  text-align: center;
  box-shadow: 0 0 0 1px rgba(16,19,43,0.5), 0 10px 28px rgba(16,19,43,0.35);
  font-size: 0.93rem;
  line-height: 1.4;
  pointer-events: none;    /* 토스트가 버튼 탭을 막지 않도록 */
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ─── 모달 ─── */
.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(16,19,43,0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
  overflow-y: auto;
}
.modal {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.4rem;
  min-width: 320px;
  width: 100%;
  max-width: 540px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 24px 60px rgba(16,19,43,0.3);
}
.modal h3 { margin-bottom: 1rem; font-size: 1.2rem; }

@media (max-width: 600px) {
  .modal {
    min-width: 0;
    max-width: 100%;
    padding: 1rem;
    border-radius: var(--radius);
  }
  /* stretch 대신 flex-start — 내용이 짧으면 화면 중앙 정렬 유지 */
  .modal-bg { padding: 0.75rem; align-items: flex-start; padding-top: 5vh; }
}

/* ─── 팀 색상 ─── */
/* 팀 색상 — 라이트 배경용 (play/display 의 다크 화면은 자체 CSS 에서 밝은 톤으로 재정의) */
:root {
  --team-1: #e5484d; --team-2: #2f6fe4; --team-3: #12a66f; --team-4: #d98a00;
  --team-5: #7047ef; --team-6: #e0407f; --team-7: #e8680c; --team-8: #0f9d94;
}
.team-1 { color: var(--team-1); }
.team-2 { color: var(--team-2); }
.team-3 { color: var(--team-3); }
.team-4 { color: var(--team-4); }
.team-5 { color: var(--team-5); }
.team-6 { color: var(--team-6); }
.team-7 { color: var(--team-7); }
.team-8 { color: var(--team-8); }
.bg-team-1 { background: var(--team-1); } .bg-team-2 { background: var(--team-2); }
.bg-team-3 { background: var(--team-3); } .bg-team-4 { background: var(--team-4); }
.bg-team-5 { background: var(--team-5); } .bg-team-6 { background: var(--team-6); }

/* ─── SVG 아이콘 ─── */
.icon { display: inline-block; vertical-align: middle; flex-shrink: 0; }

/* ─── 타일 공개 (drawing) ─── */
.tile-reveal-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: 0;
}
.tile-reveal-wrap img {
  display: block;
  max-width: 100%;
  height: auto;
}
.tile-reveal-grid {
  position: absolute;
  inset: 0;
  display: grid;
  pointer-events: none;
}
.tile-reveal-grid > div {
  background: var(--ink);
  transition: opacity 0.4s, transform 0.4s;
}
.tile-reveal-grid > div.opened {
  opacity: 0;
  transform: scale(0.85);
}
.blur-reveal {
  filter: blur(40px) grayscale(80%);
  transition: filter 0.8s ease;
  max-width: 100%;
  max-height: 70vh;
}
.blur-reveal[data-stage="0"] { filter: blur(40px) grayscale(80%); }
.blur-reveal[data-stage="1"] { filter: blur(28px) grayscale(60%); }
.blur-reveal[data-stage="2"] { filter: blur(16px) grayscale(30%); }
.blur-reveal[data-stage="3"] { filter: blur(6px) grayscale(0%); }
.blur-reveal[data-stage="4"] { filter: blur(0) grayscale(0%); }

/* ─── 스크롤바 ─── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 4px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #b6aedd; background-clip: content-box; }

/* ─── 포커스 링 (키보드 내비게이션 접근성) ─── */
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
/* 마우스 클릭 시엔 outline 제거 */
button:focus:not(:focus-visible),
input:focus:not(:focus-visible) {
  outline: none;
}
