/* ============================================
   Color Link Connect — Styles
   ============================================ */

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

[hidden] { display: none !important; }

:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-card2: #273347;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #3b82f6;
  --radius: 12px;
  --cell-gap: 3px;
}

/* body는 .game-shell-body (공유 CSS)에서 100dvh flex column 처리 */
body {
  font-family: 'Noto Sans KR', sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---- Screens ---- */
.screen {
  flex: 1 1 0;
  min-height: 0;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  padding: 0.75rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  animation: fadeIn 0.2s ease;
  overflow-y: auto;
  scrollbar-width: thin;
}

#screen-map {
  padding-top: 3.5rem; /* back-pill 공간 */
}

#screen-game {
  overflow-y: hidden;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Typography ---- */
h1 { font-size: 2rem; font-weight: 900; text-align: center; }
h2 { font-size: 1.4rem; font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 600; }

.subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s, transform 0.1s;
  text-decoration: none;
}

.btn:active { transform: scale(0.97); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  width: 100%;
  padding: 1rem;
  font-size: 1.1rem;
}

.btn-primary:hover { filter: brightness(1.1); }

.btn-secondary {
  background: var(--bg-card2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { filter: brightness(1.15); }

.btn-icon {
  background: var(--bg-card2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 0.5rem 0.9rem;
  font-size: 1.1rem;
}

.btn-icon:hover { color: var(--text); }

/* ---- Stage Map ---- */
.stage-map {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 100%;
}

.stage-map-meta {
  color: var(--text-muted);
  font-size: 0.8rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

/* ---- 크기 탭 (세그먼트 컨트롤) ---- */
.size-tabs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
}

.size-tab {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  min-width: 4.2rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-card);
  color: var(--text-muted);
  font-family: inherit;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s, transform 0.1s;
}

.size-tab .tab-size { font-size: 0.95rem; font-weight: 900; line-height: 1.1; }
.size-tab .tab-progress { font-size: 0.68rem; font-weight: 600; opacity: 0.85; }

.size-tab:hover { color: var(--text); border-color: var(--accent); }
.size-tab:active { transform: scale(0.96); }

.size-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 3px 10px rgba(59, 130, 246, 0.35);
}

.size-tab.done:not(.active) { border-color: #22c55e; color: #4ade80; }

.stage-map-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.55rem;
  width: 100%;
}

.stage-btn {
  aspect-ratio: 1;
  min-width: 0;
  background: linear-gradient(135deg, #e8f4fd, #d4eaf7);
  border: 2px solid rgba(255,255,255,0.5);
  border-radius: 16px;
  color: #5a7a9a;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, filter 0.15s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  position: relative;
  padding: 0.35rem 0.35rem 0.3rem;
  box-shadow: 0 4px 10px rgba(79, 156, 219, 0.25), inset 0 1px 2px rgba(255,255,255,0.6);
}

/* ---- 스테이지 미니 미리보기 (엔드포인트 점 배치) ---- */
.stage-preview-wrap {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stage-preview {
  width: 100%;
  height: 100%;
  display: block;
}

.stage-preview .preview-grid {
  stroke: rgba(0, 0, 0, 0.13);
  stroke-width: 0.03;
}

.stage-preview circle {
  stroke: rgba(0, 0, 0, 0.22);
  stroke-width: 0.05;
  paint-order: stroke;
}

/* 티어별 메인 컬러 (기본 + 클리어 상태 모두 포함) */
/* 5x5 — 주황 */
.stage-btn[data-size="5"]         { background: linear-gradient(135deg, #fff0e0, #ffd4a0); color: #c05a00; box-shadow: 0 4px 10px rgba(192,90,0,0.22), inset 0 1px 2px rgba(255,255,255,0.6); }
.stage-btn[data-size="5"].cleared { background: linear-gradient(135deg, #ffe8c0, #ffcc80); color: #a04800; box-shadow: 0 4px 12px rgba(192,90,0,0.3),  inset 0 1px 2px rgba(255,255,255,0.6); }
/* 6x6 — 노랑 */
.stage-btn[data-size="6"]         { background: linear-gradient(135deg, #fffde0, #fff6a0); color: #8a7200; box-shadow: 0 4px 10px rgba(138,114,0,0.22), inset 0 1px 2px rgba(255,255,255,0.6); }
.stage-btn[data-size="6"].cleared { background: linear-gradient(135deg, #fff9c0, #fff080); color: #6a5600; box-shadow: 0 4px 12px rgba(138,114,0,0.3),  inset 0 1px 2px rgba(255,255,255,0.6); }
/* 7x7 — 하늘 */
.stage-btn[data-size="7"]         { background: linear-gradient(135deg, #e0f4ff, #a8dcff); color: #0060a0; box-shadow: 0 4px 10px rgba(0,96,160,0.22),   inset 0 1px 2px rgba(255,255,255,0.6); }
.stage-btn[data-size="7"].cleared { background: linear-gradient(135deg, #c8eaff, #88ccff); color: #004880; box-shadow: 0 4px 12px rgba(0,96,160,0.3),    inset 0 1px 2px rgba(255,255,255,0.6); }
/* 8x8 — 분홍 */
.stage-btn[data-size="8"]         { background: linear-gradient(135deg, #ffe0f0, #ffb0d8); color: #b0006a; box-shadow: 0 4px 10px rgba(176,0,106,0.22),  inset 0 1px 2px rgba(255,255,255,0.6); }
.stage-btn[data-size="8"].cleared { background: linear-gradient(135deg, #ffc8e8, #ff90c8); color: #900050; box-shadow: 0 4px 12px rgba(176,0,106,0.3),   inset 0 1px 2px rgba(255,255,255,0.6); }
/* 9x9 — 민트 */
.stage-btn[data-size="9"]         { background: linear-gradient(135deg, #e0fff6, #a0f5dc); color: #007858; box-shadow: 0 4px 10px rgba(0,120,88,0.22),   inset 0 1px 2px rgba(255,255,255,0.6); }
.stage-btn[data-size="9"].cleared { background: linear-gradient(135deg, #c0faea, #70eeca); color: #005840; box-shadow: 0 4px 12px rgba(0,120,88,0.3),    inset 0 1px 2px rgba(255,255,255,0.6); }
/* 10x10 — 보라 */
.stage-btn[data-size="10"]         { background: linear-gradient(135deg, #efe6ff, #d2b8ff); color: #5a18b8; box-shadow: 0 4px 10px rgba(90,24,184,0.22), inset 0 1px 2px rgba(255,255,255,0.6); }
.stage-btn[data-size="10"].cleared { background: linear-gradient(135deg, #e2d0ff, #c0a0ff); color: #44108c; box-shadow: 0 4px 12px rgba(90,24,184,0.3),  inset 0 1px 2px rgba(255,255,255,0.6); }

.stage-btn .stage-num {
  flex: 0 0 auto;
  font-size: 0.9rem;
  font-weight: 900;
  line-height: 1;
}

.stage-btn .stage-star {
  position: absolute;
  top: 3px;
  right: 4px;
  font-size: 0.7rem;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.25));
}

.stage-btn.cleared {
  border-color: rgba(34, 197, 94, 0.7);
}

.stage-btn:hover:not(.locked) {
  transform: translateY(-5px) scale(1.06);
  box-shadow: 0 9px 20px rgba(79, 156, 219, 0.35), inset 0 1px 2px rgba(255,255,255,0.6);
  filter: brightness(1.04);
}

.stage-btn.locked {
  cursor: not-allowed;
  filter: saturate(0.45) brightness(0.9);
}

/* 잠긴 스테이지는 미리보기를 흐리게 + 잠금 아이콘 오버레이 */
.stage-btn.locked .stage-preview-wrap { filter: blur(1.5px); opacity: 0.5; }
.stage-btn.locked .stage-num { visibility: hidden; }

.stage-btn .stage-lock {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
}

.stage-btn .stage-lock svg {
  width: 1.5rem;
  height: 1.5rem;
}

/* ---- Game Screen ---- */
.game-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  padding-left: 6rem; /* back-pill 공간 */
  flex-shrink: 0;
}

#game-stage-label {
  font-size: 1.1rem;
  font-weight: 800;
  text-align: center;
}

.board-wrap {
  flex: 1 1 0;
  min-height: 0;
  align-items: center;
}

.game-controls {
  flex-shrink: 0;
}

.game-info {
  display: flex;
  gap: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.game-info-item strong {
  color: var(--text);
  font-size: 1rem;
}

/* ---- Board ---- */
.board-wrap {
  position: relative; /* anchors .game-hint */
  width: 100%;
  display: flex;
  justify-content: center;
  touch-action: none;
  user-select: none;
}

.game-rule-note {
  color: var(--text-muted);
  font-size: 0.82rem;
  text-align: center;
  line-height: 1.45;
}

.game-fill-label {
  margin-left: 0.75rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: rgba(59, 158, 235, 0.15);
  color: #74c2f0;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
}

.game-fill-label.full {
  background: rgba(0, 200, 150, 0.18);
  color: #00c896;
}

.game-hint {
  position: absolute;
  left: 50%;
  bottom: 0.75rem;
  transform: translateX(-50%);
  max-width: min(92%, 480px);
  padding: 0.6rem 1rem;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid rgba(59, 158, 235, 0.55);
  color: #e2e8f0;
  font-size: 0.88rem;
  line-height: 1.45;
  text-align: center;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  z-index: 5;
  animation: hintIn 0.25s ease-out;
  pointer-events: none;
}

@keyframes hintIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* 빈 칸 알림 펄스 — 힌트가 뜰 때 채워야 할 칸을 가리킨다 */
.cell.hint-empty {
  animation: emptyPulse 0.8s ease-in-out 2;
}

@keyframes emptyPulse {
  0%, 100% { box-shadow: none; }
  50% { box-shadow: inset 0 0 0 3px rgba(245, 230, 66, 0.85); }
}

.board {
  display: grid;
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: var(--cell-gap);
  gap: var(--cell-gap);
  touch-action: none;
}

/* ---- Cell ---- */
.cell {
  position: relative;
  background: var(--bg);
  border-radius: 4px;
  cursor: crosshair;
  overflow: visible;
}

/* Arms — pipe segments from cell center to edge */
.arm {
  position: absolute;
  background: var(--c);
  display: none;
  border-radius: 2px;
}

.arm-top    { top: 0;    left: 35%; width: 30%; height: 52%; }
.arm-bottom { bottom: 0; left: 35%; width: 30%; height: 52%; }
.arm-left   { left: 0;   top: 35%; height: 30%; width: 52%; }
.arm-right  { right: 0;  top: 35%; height: 30%; width: 52%; }

.arm.on { display: block; }

/* Center dot — shown for all colored cells */
.dot {
  position: absolute;
  top: 35%; left: 35%;
  width: 30%; height: 30%;
  border-radius: 50%;
  background: var(--c);
}

/* Number label inside endpoint dot */
.dot-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1em;
  font-weight: 800;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 2px rgba(0,0,0,0.5);
  line-height: 1;
  pointer-events: none;
  user-select: none;
}

/* Endpoint — larger filled circle */
.cell.endpoint .dot {
  top: 20%; left: 20%;
  width: 60%; height: 60%;
  box-shadow: 0 0 0 3px rgba(255,255,255,0.15);
  transform-origin: center;
}

/* Dragging endpoint pulse */
@keyframes endpointPulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.35); }
}
.cell.endpoint.dragging .dot {
  animation: endpointPulse 0.5s ease-in-out infinite;
}

/* Connected pair bounce */
@keyframes endpointBounce {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.45); }
  65%  { transform: scale(0.88); }
  100% { transform: scale(1); }
}
.cell.endpoint.connected-anim .dot {
  animation: endpointBounce 0.45s ease-out forwards;
}

/* ---- Game Controls ---- */
.game-controls {
  display: flex;
  gap: 0.6rem;
  width: 100%;
  justify-content: center;
}

/* ---- Status bar ---- */
.status-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.pairs-indicator {
  display: flex;
  gap: 0.35rem;
}

.pair-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.3);
  transition: border-color 0.2s;
}

.pair-dot.done {
  border-color: transparent;
}

/* ---- Clear Overlay ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  animation: fadeIn 0.2s ease;
}

.overlay-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 2.5rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 260px;
}

.overlay-icon { font-size: 3rem; }
.overlay-title { font-size: 1.8rem; font-weight: 900; color: #22c55e; }
.overlay-meta { color: var(--text-muted); font-size: 0.9rem; }

.overlay-actions {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 0.5rem;
}

/* ---- Responsive ---- */
@media (max-width: 360px) {
  .stage-map { gap: 0.5rem; }
  .stage-map-grid { gap: 0.4rem; }
  .size-tab { min-width: 3.6rem; padding: 0.35rem 0.45rem; }
  .size-tab .tab-size { font-size: 0.85rem; }
}
