/* ====== common.css — 반응형 토대 ====== */

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

:root {
  --primary: #4f46e5;
  --primary-dark: #3730a3;
  --secondary: #f59e0b;
  --success: #10b981;
  --danger: #ef4444;
  --warn: #f59e0b;
  --bg: #0f172a;
  --bg-2: #1e293b;
  --bg-3: #334155;
  --bg-4: #475569;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --border: #475569;
  --radius: 10px;
  --radius-lg: 16px;

  /* 반응형 단위 */
  --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: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo",
               "Pretendard", "Malgun Gothic", sans-serif;
  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%; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── 버튼 ─── */
button {
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius);
  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: white; }
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: black; }
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: 8px;
  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(79,70,229,0.2);
}
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: rgba(255,255,255,0.04); }
.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: rgba(255,255,255,0.04); }

/* ─── 표 ─── */
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);
  padding: var(--space-md);
}

.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: black; }
.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;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.7rem 1.4rem;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  z-index: 9999;
  animation: toastIn 0.2s ease-out;
  max-width: 90vw;
  text-align: center;
  box-shadow: 0 6px 16px rgba(0,0,0,0.35);
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ─── 모달 ─── */
.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  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 20px 50px rgba(0,0,0,0.5);
}
.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);
  }
  .modal-bg { padding: 0.5rem; align-items: stretch; }
}

/* ─── 팀 색상 ─── */
.team-1 { color: #f87171; }
.team-2 { color: #60a5fa; }
.team-3 { color: #34d399; }
.team-4 { color: #fbbf24; }
.team-5 { color: #c084fc; }
.team-6 { color: #f472b6; }
.team-7 { color: #fb923c; }
.team-8 { color: #2dd4bf; }
.bg-team-1 { background: #f87171; } .bg-team-2 { background: #60a5fa; }
.bg-team-3 { background: #34d399; } .bg-team-4 { background: #fbbf24; }
.bg-team-5 { background: #c084fc; } .bg-team-6 { background: #f472b6; }

/* ─── 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: #1e293b;
  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: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--bg-4); }
