/* 사진 빙고 공통 스타일 (모바일 우선) */
:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece4;
  --text: #1f1d1a;
  --muted: #6b665d;
  --border: #ddd8cc;
  --accent: #ff6b35;
  --accent-ink: #ffffff;
  --line: #f5b700;
  --line-soft: #fff4cc;
  --ok: #2e9e5b;
  --danger: #e03131;
  --danger-soft: #ffe3e3;
  --grid: #cfc8b9;
  --grid-outer: #1f1d1a;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161513;
    --surface: #211f1c;
    --surface-2: #2b2925;
    --text: #f2efe9;
    --muted: #a39d92;
    --border: #3a3732;
    --line-soft: #3d3418;
    --danger-soft: #3d1c1c;
    --grid: #4a463f;
    --grid-outer: #d8d3c8;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { margin: 0 0 0.5em; line-height: 1.25; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* ---------- 폼/버튼 ---------- */
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  width: 100%;
  padding: 0.7em 0.8em;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; font-weight: 600; margin: 0.9em 0 0.35em; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4em;
  padding: 0.7em 1.1em;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { filter: brightness(0.96); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; }
.btn-lg { padding: 0.9em 1.3em; font-size: 1.05rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}

/* ---------- 상단 바 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar .title { font-weight: 800; font-size: 1.05rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 800;
  font-size: 1.35rem;
  padding: 2px 10px;
  border-radius: 8px;
  background: var(--surface-2);
}
.timer.urgent { background: var(--danger); color: #fff; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.65; } }

.conn { font-size: 0.8rem; text-align: center; }
.conn.offline { background: var(--danger); color: #fff; padding: 4px; }

.pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  background: var(--surface-2); font-size: 0.85rem; font-weight: 700;
}
.pill-accent { background: var(--line); color: #1f1d1a; }

/* ---------- 빙고판 ---------- */
.board {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  /* 칸 사이 간격 없이 하나의 사각형 표: 바깥 굵은 테두리 + 안쪽 격자선 */
  border: 3px solid var(--grid-outer);
  background: var(--surface);
}
.cell {
  position: relative;
  aspect-ratio: 1;
  padding: 4px;
  border: 0;
  border-right: 1px solid var(--grid);
  border-bottom: 1px solid var(--grid);
  border-radius: 0;
  background: var(--surface);
  overflow: hidden;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.cell:nth-child(5n) { border-right: 0; }
.cell:nth-child(n + 21) { border-bottom: 0; }
.cell:hover { background: var(--surface-2); }
/* 줄 완성/경고 테두리는 사진 위에 보이도록 별도 레이어 */
.cell .frame { position: absolute; inset: 0; z-index: 2; pointer-events: none; }
.cell.in-line .frame { box-shadow: inset 0 0 0 3px var(--line); }
.cell.warned .frame { box-shadow: inset 0 0 0 3px var(--danger); }
.cell .topic {
  position: relative; z-index: 1;
  font-size: clamp(0.6rem, 2.6vw, 0.85rem);
  font-weight: 700;
  text-align: center;
  word-break: keep-all;
  overflow-wrap: anywhere;
  line-height: 1.2;
}
.cell img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cell.filled .topic {
  position: absolute; left: 0; right: 0; bottom: 0;
  padding: 2px 3px;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: clamp(0.5rem, 2vw, 0.7rem);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cell.in-line:not(.filled) { background: var(--line-soft); }
.cell.warned::after {
  content: ''; position: absolute; inset: 0; background: rgba(224, 49, 49, 0.35); z-index: 0;
}
.warn-badge {
  position: absolute; top: 3px; right: 3px; z-index: 3;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--danger); color: #fff; font-weight: 900; font-size: 0.8rem;
  display: flex; align-items: center; justify-content: center;
}
.cell .spinner { display: none; }
.cell.uploading .spinner {
  display: block; position: absolute; z-index: 3;
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.6); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
.cell.uploading::before { content: ''; position: absolute; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 2; }
@keyframes spin { to { transform: rotate(360deg); } }

.board-small { border-width: 2px; }
.board-small .cell { padding: 1px; }
.board-small .cell.in-line .frame { box-shadow: inset 0 0 0 2px var(--line); }
.board-small .cell.warned .frame { box-shadow: inset 0 0 0 2px var(--danger); }
.board-small .cell .topic { font-size: 0.5rem; }
.board-small .cell.filled .topic { display: none; }
.board-small .warn-badge { width: 12px; height: 12px; font-size: 0.55rem; top: 1px; right: 1px; }
.board-small .cell.warned { box-shadow: 0 0 0 2px var(--danger) inset; }

/* ---------- 모달/오버레이 ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal {
  width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto;
  background: var(--surface); border-radius: var(--radius); padding: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}
.modal-wide { max-width: 1100px; }
.modal img.preview { width: 100%; max-height: 60vh; object-fit: contain; border-radius: 10px; background: #000; }
.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; margin-top: 14px; }

.end-screen { text-align: center; }
.end-screen .big { font-size: 3rem; }
.end-screen h2 { font-size: 1.5rem; }

/* ---------- 토스트 ---------- */
#toasts {
  position: fixed; z-index: 100; left: 50%; top: 14px; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px; width: min(92vw, 420px); pointer-events: none;
}
.toast {
  padding: 12px 16px; border-radius: 12px; font-weight: 700;
  background: #1f1d1a; color: #fff; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  opacity: 0; transform: translateY(-10px); transition: 0.25s;
  white-space: pre-line;
}
.toast.show { opacity: 1; transform: none; }
.toast-error { background: var(--danger); }
.toast-ok { background: var(--ok); }

/* ---------- 결과 ---------- */
.result-title { text-align: center; font-size: 1.6rem; }
.winners { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.winner h3 { text-align: center; }
.ranking { list-style: none; padding: 0; margin: 16px 0 0; }
.ranking li {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.ranking .rank { width: 2em; font-weight: 800; text-align: center; }
.ranking .name { flex: 1; font-weight: 700; }
.ranking li.win { background: var(--line-soft); border-radius: 8px; }
.reveal { animation: reveal 0.6s ease-out; }
@keyframes reveal { from { transform: scale(0.85); opacity: 0; } }

.wrap { width: 100%; max-width: 640px; margin: 0 auto; padding: 16px; }
