/* 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; }
.flash-notice { background: #1c3a2a; color: #a4e8bc; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}

/* 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-md { width: 36px; height: 36px; }
.avatar-sm { width: 24px; height: 24px; }
.avatar-xl { width: 96px; height: 96px; font-size: 2.4rem; }
.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; }
.rank-tier { font-weight: 800; font-size: 0.85rem; white-space: nowrap; }
.tier-diamond { color: #7de3ff; }
.tier-gold { color: var(--yellow); }
.tier-silver { color: #cdd4ea; }
.tier-bronze { color: #d99a6c; }
.tier-stone { color: var(--muted); }
.tier-legend { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }

/* 티어/랭크 점수 표시 */
.profile-tier { display: flex; align-items: center; gap: 8px; }
.profile-tier-value { font-size: 0.95rem; }
.result-rank-delta { font-size: 1rem; }
.delta-up { color: #7dd87d; }
.delta-down { color: var(--red); }
.profile-logout { grid-column: 1 / -1; justify-self: end; font-size: 0.8rem; margin-top: 6px; }
.profile-links {
  grid-column: 1 / -1; display: flex; gap: 14px; justify-content: flex-end;
  font-size: 0.8rem; margin-top: 6px;
}

/* 프로필 수정 */
.profile-form { display: flex; flex-direction: column; gap: 12px; max-width: 320px; margin: 16px auto 0; }
.profile-form-avatar { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.avatar-upload-label { cursor: pointer; }
.profile-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;
}
.form-errors { background: #4a2030; color: #ffb4c0; border-radius: 10px; padding: 10px 14px; font-size: 0.85rem; }
.form-errors p { margin: 2px 0; }

/* lobby player rows */
.lobby-player { display: flex; align-items: center; gap: 10px; text-align: left; }
.lobby-player-name { flex: 1; }
.lobby-player .ready-badge { float: none; }

.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); }
.login-cta { margin-top: 28px; display: flex; flex-direction: column; gap: 10px; align-items: center; }

/* 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); }
.badge-quick { background: #1c3a4a; color: var(--blue); }

/* 참여 중인 방 배너 */
.current-room-banner {
  max-width: 380px; margin: 0 auto 16px;
  background: var(--panel); border: 1px solid var(--primary);
  border-radius: var(--radius); padding: 14px 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.current-room-info { display: flex; flex-direction: column; gap: 4px; align-items: center; }
.current-room-state { font-weight: 800; color: var(--yellow); }
.current-room-state.playing { color: #7dd87d; }
.current-room-desc { color: var(--muted); font-size: 0.85rem; }
.current-room-actions { display: flex; gap: 8px; justify-content: center; align-items: center; }
.entry-buttons { display: flex; gap: 10px; }
.entry-buttons .btn { flex: 1; }

/* 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;
}
.host-badge {
  background: #3d3416; color: var(--yellow); font-size: 0.7rem; font-weight: 800;
  border-radius: 6px; padding: 2px 6px; margin-left: 6px; vertical-align: middle;
}
.btn-kick {
  background: transparent; border: 1px solid var(--red); color: var(--red);
  border-radius: 8px; padding: 4px 8px; font-size: 0.72rem; font-weight: 700; cursor: pointer;
}
.btn-kick:hover { background: #4a2030; }
.rematch-members {
  list-style: none; padding: 0; margin: 4px 0 0; width: 100%; max-width: 300px;
}
.rematch-members li {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel-2); border-radius: 8px;
  padding: 6px 10px; margin: 6px 0; font-size: 0.85rem;
}
.rematch-member-name { flex: 1; text-align: left; font-weight: 600; }

/* 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;
}
.draw-offer-banner {
  text-align: center; padding: 12px; border-radius: 10px;
  background: #1c3a4a; color: var(--text); font-size: 0.95rem;
  display: flex; flex-direction: column; gap: 8px; align-items: center;
  border: 1px solid var(--blue);
}
.draw-offer-actions { display: flex; gap: 8px; }
.game-actions { flex-wrap: wrap; justify-content: center; }

/* board — 바둑판처럼 선 교차점 위에 착수 */
.board-wrap { position: relative; }
.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;
}
.point-over-stone { z-index: 3; }
.board-active .point:hover::before,
.point.cell-pending::before {
  content: ""; position: absolute; inset: 12%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
}
.board-pinging .point:hover::before {
  content: ""; position: absolute; inset: 18%;
  border-radius: 50%;
  border: 2px dashed rgba(255, 255, 255, 0.4);
}
.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-stats { color: var(--muted); }
.rematch { margin-top: 12px; display: flex; flex-direction: column; gap: 10px; align-items: center; }

/* 훈수(핑) */
.ping-bar {
  display: flex; gap: 6px; align-items: center; justify-content: center; flex-wrap: wrap;
  background: var(--panel); border-radius: var(--radius); padding: 8px 10px;
}
.ping-kind {
  border: 2px solid transparent; border-radius: 10px;
  background: var(--panel-2); color: var(--text);
  font-size: 0.85rem; font-weight: 700; padding: 7px 12px; cursor: pointer;
}
.ping-kind.active { border-color: var(--primary); background: #2b3363; }
.ping-hint { color: var(--muted); font-size: 0.72rem; width: 100%; text-align: center; }

.pings-layer {
  position: absolute; inset: 10px;
  pointer-events: none; z-index: 5;
}
.ping-marker {
  position: absolute;
  transform: translate(-50%, -100%);
  display: flex; flex-direction: column; align-items: center;
  animation: ping-pop 4s ease forwards;
}
.ping-icon { font-size: 1.6rem; line-height: 1; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.6)); }
.ping-label {
  background: rgba(15, 18, 32, 0.92); border: 1.5px solid var(--muted);
  border-radius: 8px; padding: 2px 7px;
  font-size: 0.68rem; font-weight: 700; white-space: nowrap;
}
.ping-color-red .ping-label { border-color: var(--red); }
.ping-color-yellow .ping-label { border-color: var(--yellow); }
.ping-color-blue .ping-label { border-color: var(--blue); }
@keyframes ping-pop {
  0% { opacity: 0; transform: translate(-50%, -100%) scale(0.4); }
  8% { opacity: 1; transform: translate(-50%, -100%) scale(1.25); }
  16% { transform: translate(-50%, -100%) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -100%) scale(0.9); }
}

/* 감정표현 */
.reaction-bar {
  display: flex; gap: 4px; justify-content: center; flex-wrap: wrap;
  background: var(--panel); border-radius: var(--radius); padding: 8px;
  transition: opacity 0.2s;
}
.reaction-bar.cooling { opacity: 0.4; pointer-events: none; }
.reaction-btn {
  flex: 1; background: transparent; border: 0; border-radius: 8px;
  font-size: 1.4rem; padding: 6px 0; cursor: pointer;
  transition: transform 0.1s;
}
.reaction-btn:hover { background: var(--panel-2); }
.reaction-btn:active { transform: scale(1.3); }

.reactions-overlay {
  position: fixed; top: 0; left: 0; right: 0; height: 0;
  z-index: 100; pointer-events: none;
}
.reaction-bubble {
  position: absolute; top: 130px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: rgba(26, 31, 53, 0.92);
  border: 2px solid var(--panel-2);
  border-radius: 14px; padding: 8px 14px;
  animation: reaction-float 2.8s ease-out forwards;
}
.reaction-color-red { border-color: var(--red); }
.reaction-color-yellow { border-color: var(--yellow); }
.reaction-color-blue { border-color: var(--blue); }
.reaction-bubble-emoji { font-size: 2rem; line-height: 1; }
.reaction-bubble-name { font-size: 0.7rem; color: var(--muted); font-weight: 700; }
@keyframes reaction-float {
  0% { opacity: 0; transform: translateX(-50%) translateY(20px) scale(0.5); }
  12% { opacity: 1; transform: translateX(-50%) translateY(0) scale(1.1); }
  20% { transform: translateX(-50%) translateY(0) scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: translateX(-50%) translateY(-70px) scale(0.9); }
}

/* 게임 종료 연출 */
.result-panel { animation: result-pop 0.45s cubic-bezier(0.18, 1.4, 0.4, 1); }
@keyframes result-pop {
  from { opacity: 0; transform: scale(0.75) translateY(16px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.result-banner {
  color: var(--muted); font-size: 0.8rem; font-weight: 800; letter-spacing: 2px;
}
.result-hero-emoji {
  font-size: 3.4rem; line-height: 1.2; margin-top: 8px;
  animation: result-bounce 0.9s ease 0.2s 2;
}
@keyframes result-bounce {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(-14px); }
  70% { transform: translateY(4px); }
}
.result-title { font-size: 2.2rem; margin: 0.1em 0 0.3em; }
.result-title-win { color: var(--yellow); }
.result-title-lose { color: var(--muted); }
.result-win {
  border: 2px solid var(--yellow);
  box-shadow: 0 0 24px rgba(255, 206, 58, 0.25);
}
.result-winner-line { font-size: 1.05rem; }
.stone-mini {
  display: inline-block; width: 14px; height: 14px; border-radius: 50%;
  vertical-align: -1px; margin: 0 2px;
}
.chip-crown { font-size: 0.9rem; }

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