/* 3인 4목 — mobile-first */

:root {
  --bg: #0f1220;
  --panel: #1a1f35;
  --panel-2: #232a4a;
  --text: #f2f4ff;
  --muted: #9aa3c7;
  --primary: #5b6cff;
  --primary-hover: #4a5af0;
  --red: #ff5d5d;
  --yellow: #ffce3a;
  --blue: #4aa8ff;
  --board: #2a3158;
  --cell: #1c2242;
  --line: #4a5280;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo",
    "Noto Sans KR", "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

h1 { font-size: 1.5rem; margin: 0.5em 0; }
h2 { font-size: 1.1rem; }
.muted { color: var(--muted); font-size: 0.9rem; }

.flash {
  padding: 10px 16px;
  text-align: center;
  font-size: 0.9rem;
}
.flash-alert { background: #4a2030; color: #ffb4c0; }

/* buttons */
.btn {
  display: inline-block;
  border: 0;
  border-radius: var(--radius);
  padding: 12px 20px;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  background: var(--panel-2);
  color: var(--text);
  transition: transform 0.05s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn-primary { background: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-lg { padding: 16px 28px; font-size: 1.1rem; }
.btn-sm { padding: 8px 14px; font-size: 0.85rem; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-google { background: #fff; color: #1a1a1a; }
.btn-link {
  background: none; border: 0; color: var(--muted);
  text-decoration: underline; cursor: pointer; font-size: inherit; padding: 0;
}
.inline-form { display: inline; }

/* home */
.hero { text-align: center; margin-top: 12vh; }
.hero .logo { font-size: 2.2rem; letter-spacing: 4px; margin-bottom: 0; }
.hero h1 { font-size: 2.2rem; margin: 0.2em 0; }
.tagline { color: var(--muted); margin-bottom: 2em; line-height: 1.6; }
.how-to {
  margin-top: 4em; text-align: left;
  background: var(--panel); border-radius: var(--radius); padding: 8px 24px 16px;
}
.how-to ol { padding-left: 1.2em; line-height: 1.9; color: var(--muted); }

/* auth */
.auth { text-align: center; margin-top: 16vh; }
.dev-login { margin-top: 2.5em; }

/* profile */
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  object-fit: cover; flex-shrink: 0;
}
.avatar-lg { width: 56px; height: 56px; }
.avatar-sm { width: 24px; height: 24px; }
.avatar-fallback {
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary), #8b5bff);
  color: #fff; font-weight: 800; font-size: 1.2rem;
}
.avatar-sm.avatar-fallback { font-size: 0.7rem; }

.profile-card {
  margin: 28px auto 0;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid #2b3363;
  border-radius: var(--radius);
  padding: 18px 20px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  align-items: center;
  text-align: left;
}
.profile-info { min-width: 0; }
.profile-name { font-weight: 800; font-size: 1.05rem; }
.profile-email {
  color: var(--muted); font-size: 0.8rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.profile-record {
  grid-column: 1 / -1;
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 10px; padding-top: 12px;
  border-top: 1px solid #2b3363;
}
.record-line { display: flex; gap: 6px; }
.record-chip {
  background: var(--panel-2); border-radius: 8px;
  padding: 4px 8px; font-size: 0.8rem; font-weight: 700;
}
.record-win { color: #7dd87d; }
.record-draw { color: var(--yellow); }
.record-loss { color: var(--red); }
.record-rate { font-size: 0.85rem; color: var(--muted); font-weight: 700; }
.profile-record { flex-direction: column; align-items: stretch; gap: 8px; }
.record-row { display: flex; align-items: center; gap: 8px; }
.record-row .record-line { flex: 1; }
.record-mode {
  width: 42px; text-align: center; font-size: 0.75rem; font-weight: 800;
  color: var(--muted); background: var(--panel-2); border-radius: 6px; padding: 3px 0;
}
.record-mode-rank { color: var(--yellow); background: #3d3416; }

/* ranking */
.ranking { display: flex; flex-direction: column; gap: 12px; }
.ranking-list { list-style: none; padding: 0; margin: 16px 0 0; text-align: left; }
.ranking-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--panel-2); border-radius: 10px;
  padding: 10px 14px; margin: 8px 0; font-size: 0.9rem;
}
.ranking-row.top-1 { border: 1px solid var(--yellow); }
.rank-no { width: 26px; text-align: center; font-weight: 800; }
.rank-name { flex: 1; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-record { color: var(--muted); font-size: 0.82rem; }
.rank-rate { font-weight: 800; width: 44px; text-align: right; }
.profile-logout { grid-column: 1 / -1; justify-self: end; font-size: 0.8rem; margin-top: 6px; }

.room-header-right { display: flex; align-items: center; gap: 10px; }
.header-user {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--muted); font-size: 0.85rem; font-weight: 600;
}

/* room */
.room { display: flex; flex-direction: column; gap: 12px; flex: 1; }
.room-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 0;
}
.room-logo { color: var(--text); text-decoration: none; font-weight: 800; }
.room-code {
  font-family: ui-monospace, monospace; color: var(--muted);
  background: var(--panel); padding: 4px 10px; border-radius: 8px;
}

.panel {
  background: var(--panel); border-radius: var(--radius);
  padding: 20px; text-align: center;
}

/* mode selection */
.create-form { display: flex; flex-direction: column; gap: 16px; max-width: 380px; margin: 0 auto; }
.mode-group { background: var(--panel); border-radius: var(--radius); padding: 14px 16px; text-align: left; }
.mode-group-label { display: block; font-size: 0.8rem; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.mode-options { display: flex; gap: 8px; }
.mode-chip { flex: 1; }
.mode-chip input { position: absolute; opacity: 0; }
.mode-chip span {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 6px; border-radius: 10px; font-weight: 700; font-size: 0.95rem;
  background: var(--panel-2); border: 2px solid transparent; cursor: pointer;
}
.mode-chip small { color: var(--muted); font-weight: 500; }
.mode-chip input:checked + span { border-color: var(--primary); background: #2b3363; }
.mode-hint { color: var(--muted); font-size: 0.78rem; margin: 10px 0 0; }
.ranking-link { margin-top: 14px; }
.ranking-link a { color: var(--muted); }

/* badges */
.mode-badges { display: flex; gap: 6px; justify-content: center; margin-bottom: 4px; }
.badge {
  display: inline-block; background: var(--panel-2); color: var(--muted);
  border-radius: 8px; padding: 4px 10px; font-size: 0.78rem; font-weight: 700;
}
.badge-rank { background: #3d3416; color: var(--yellow); }

/* lobby */
.player-count { color: var(--primary); }
.ready-badge { float: right; font-size: 0.78rem; color: var(--muted); font-weight: 500; }
.ready-badge.on { color: #7dd87d; font-weight: 700; }
.start-area { margin: 16px 0 6px; }
.lobby-players { list-style: none; padding: 0; margin: 16px 0; }
.lobby-players li {
  background: var(--panel-2); border-radius: 10px;
  padding: 12px; margin: 8px 0; font-weight: 600;
}
.lobby-players .empty-slot { color: var(--muted); font-weight: 400; border: 1px dashed #39406b; background: transparent; }
.lobby-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 12px; }
.join-form { display: flex; flex-direction: column; gap: 12px; max-width: 300px; margin: 0 auto; }
.join-form input[type="text"] {
  border: 1px solid #39406b; background: var(--cell); color: var(--text);
  border-radius: 10px; padding: 12px; font-size: 1rem; text-align: center;
}
.me-badge {
  background: var(--primary); color: #fff; font-size: 0.7rem;
  border-radius: 6px; padding: 2px 6px; margin-left: 6px; vertical-align: middle;
}

/* players bar */
.players-bar {
  list-style: none; padding: 0; margin: 0;
  display: flex; gap: 6px;
}
.player-chip {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 4px;
  background: var(--panel); border-radius: 10px; padding: 8px 4px;
  font-size: 0.85rem; font-weight: 600;
  border: 2px solid transparent;
  min-width: 0;
}
.chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-chip.current { border-color: var(--primary); background: var(--panel-2); }
.player-chip.resigned { opacity: 0.4; }
.player-chip.resigned .chip-name { text-decoration: line-through; }
.resigned-badge { font-size: 0.7rem; color: var(--red); }

/* turn status */
.turn-status {
  text-align: center; padding: 10px; border-radius: 10px;
  background: var(--panel); font-weight: 700;
}
.turn-status.my-turn { background: var(--primary); }
.countdown { font-variant-numeric: tabular-nums; margin-left: 6px; }
.countdown.urgent, .urgent { color: var(--yellow); animation: pulse 0.6s infinite alternate; }
@keyframes pulse { from { opacity: 1; } to { opacity: 0.5; } }

.pause-banner {
  text-align: center; padding: 12px; border-radius: 10px;
  background: #3d3416; color: var(--yellow); font-size: 0.95rem;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
}

/* board — 바둑판처럼 선 교차점 위에 착수 */
.board {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  gap: 0;
  background: var(--board);
  border-radius: var(--radius);
  padding: 10px;
  aspect-ratio: 1;
  touch-action: manipulation;
}
.cell {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  background: transparent;
  border: 0;
  padding: 0;
}
/* 각 칸의 중심을 지나는 가로/세로 선 → 이어지면 격자 */
.cell::before {
  content: ""; position: absolute;
  left: 0; right: 0; top: 50%; height: 2px;
  background: var(--line);
  transform: translateY(-50%);
}
.cell::after {
  content: ""; position: absolute;
  top: 0; bottom: 0; left: 50%; width: 2px;
  background: var(--line);
  transform: translateX(-50%);
}
/* 가장자리는 반만 그려서 테두리 밖으로 선이 안 나가게 */
.cell.edge-left::before { left: 50%; }
.cell.edge-right::before { right: 50%; }
.cell.edge-top::after { top: 50%; }
.cell.edge-bottom::after { bottom: 50%; }

.hoshi {
  position: absolute; z-index: 1;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--line);
}
.point {
  position: absolute; inset: 0; z-index: 2;
  background: transparent; border: 0; padding: 0;
  cursor: pointer;
}
.board-active .point:hover::before,
.point.cell-pending::before {
  content: ""; position: absolute; inset: 12%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
}
.stone {
  position: relative; z-index: 2;
  width: 82%; height: 82%; border-radius: 50%;
  box-shadow: inset 0 -3px 4px rgba(0,0,0,0.35), 0 1px 3px rgba(0,0,0,0.4);
}
.stone-red { background: var(--red); }
.stone-yellow { background: var(--yellow); }
.stone-blue { background: var(--blue); }
.stone-last { outline: 2px solid #fff; outline-offset: 1px; }

/* game misc */
.game { display: flex; flex-direction: column; gap: 12px; }
.game-actions { display: flex; justify-content: space-between; gap: 8px; }
.result-panel h1 { font-size: 1.6rem; }
.result-stats { color: var(--muted); }
.rematch { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; align-items: center; }

@media (min-width: 700px) {
  .container { padding-top: 40px; }
}
