/* ── Reset & Base ─────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #1a1a2e;
  --bg2:       #16213e;
  --bg3:       #0f3460;
  --accent:    #e94560;
  --gold:      #f5a623;
  --text:      #eaeaea;
  --text-dim:  #888;
  --board-bg:  #dcb468;
  --board-line:#8B6914;
  --radius:    8px;
  --shadow:    0 4px 20px rgba(0,0,0,0.4);
}

body {
  font-family: 'Noto Sans KR', 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Header ───────────────────────────────────── */
header {
  background: var(--bg2);
  border-bottom: 2px solid var(--bg3);
  padding: 12px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}
h1 { font-size: 1.4rem; color: var(--gold); white-space: nowrap; }

nav { display: flex; gap: 8px; flex: 1; }
.nav-btn {
  background: transparent;
  border: 1px solid var(--bg3);
  color: var(--text-dim);
  padding: 6px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  transition: all .2s;
}
.nav-btn:hover, .nav-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

#my-country {
  font-size: 0.85rem;
  color: var(--text-dim);
  white-space: nowrap;
}
#my-country span { color: var(--gold); font-weight: bold; }


/* ── Main ─────────────────────────────────────── */
main {
  flex: 1;
  max-width: 1200px;
  margin: 20px auto;
  padding: 0 16px;
  width: 100%;
}

/* ── Games Page ───────────────────────────────── */
.games-layout {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.games-list {
  width: 180px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  position: sticky;
  top: 80px;
}

.game-item {
  background: var(--bg2);
  border: 1px solid var(--bg3);
  border-radius: var(--radius);
  padding: 8px 10px;
  cursor: pointer;
  transition: border-color .2s;
}
.game-item:hover { border-color: var(--accent); }
.game-item.selected { border-color: var(--gold); background: var(--bg3); }

.game-item-matchup {
  font-size: 0.85rem;
  font-weight: bold;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 3px;
}
.game-item-matchup .vs { color: var(--text-dim); font-size: 0.8rem; margin: 0 3px; }

.game-item-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-dim);
}

/* ── Detailed Game View ───────────────────────── */
#game-detail {
  margin-top: 24px;
  display: none;
}
#game-detail.visible { display: block; }

.detail-layout {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: start;
}

.board-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

#go-board {
  border-radius: 4px;
  box-shadow: 0 0 30px rgba(0,0,0,0.6);
  cursor: crosshair;
  max-width: 100%;
}

.timer-bar {
  width: 100%;
  max-width: 540px;
  background: var(--bg3);
  border-radius: var(--radius);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.9rem;
}
.timer-bar .countdown { font-size: 1.3rem; font-weight: bold; color: var(--gold); font-variant-numeric: tabular-nums; }
.timer-bar .countdown.divine-waiting { color: #a855f7; font-size: 1rem; }
.turn-info { color: var(--text-dim); }
.turn-info span { color: var(--text); font-weight: bold; }

/* ── 신의 한수 펄스 애니메이션 ── */
@keyframes divine-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.4; }
}

/* ── Sidebar ──────────────────────────────────── */
.sidebar {
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel {
  background: var(--bg2);
  border: 1px solid var(--bg3);
  border-radius: var(--radius);
  padding: 14px;
}
.panel h3 {
  font-size: 0.85rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--bg3);
  padding-bottom: 6px;
}

/* 포로/집 정보 */
.score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  font-size: 0.9rem;
}
.stone-black { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #111; border: 1px solid #555; margin-right: 4px; }
.stone-white { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #fff; border: 1px solid #aaa; margin-right: 4px; }

/* 투표 현황 */
.vote-list { display: flex; flex-direction: column; gap: 6px; }
.vote-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
}
.vote-coord { font-family: monospace; color: var(--gold); min-width: 32px; }
.vote-bar-wrap { flex: 1; background: var(--bg3); border-radius: 4px; height: 8px; overflow: hidden; }
.vote-bar { height: 100%; background: var(--accent); border-radius: 4px; transition: width .3s; }
.vote-count { color: var(--text-dim); min-width: 28px; text-align: right; }

/* 상대전적 */
.h2h-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 0.9rem;
}
.h2h-score { font-size: 1.1rem; font-weight: bold; color: var(--gold); }

/* 투표 버튼 */
.vote-actions { display: flex; gap: 8px; margin-top: 8px; }
.btn-pass {
  width: 100%;
  padding: 8px;
  background: var(--bg3);
  border: 1px solid var(--text-dim);
  color: var(--text);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all .2s;
}
.btn-pass:hover { background: var(--accent); border-color: var(--accent); }

.my-vote-info {
  font-size: 0.8rem;
  color: var(--gold);
  text-align: center;
  min-height: 18px;
}

/* ── Standings ────────────────────────────────── */
.standings-wrap, .h2h-wrap { max-width: 700px; margin: 0 auto; }
.standings-table, .h2h-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg2);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.standings-table th, .h2h-table th {
  background: var(--bg3);
  padding: 12px 16px;
  text-align: left;
  font-size: 0.85rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.standings-table td, .h2h-table td {
  padding: 12px 16px;
  border-top: 1px solid var(--bg3);
  font-size: 0.95rem;
}
.standings-table tr:hover td, .h2h-table tr:hover td { background: rgba(255,255,255,0.03); }
.rank { font-weight: bold; color: var(--gold); }
.elo-val { font-weight: bold; color: var(--accent); }

/* ── History ──────────────────────────────────── */
.history-list { display: flex; flex-direction: column; gap: 12px; }
.history-item {
  background: var(--bg2);
  border: 1px solid var(--bg3);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}
.history-matchup { font-size: 1rem; }
.history-winner { color: var(--gold); font-weight: bold; }
.history-date { font-size: 0.8rem; color: var(--text-dim); }
.btn-sgf {
  background: transparent;
  border: 1px solid var(--bg3);
  color: var(--text-dim);
  padding: 4px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.8rem;
  transition: all .2s;
}
.btn-sgf:hover { border-color: var(--accent); color: var(--accent); }

/* ── 규칙 버튼 ───────────────────────────────── */
.btn-rules {
  border-color: var(--gold) !important;
  color: var(--gold) !important;
}
.btn-rules:hover {
  background: var(--gold) !important;
  color: #1a1a2e !important;
}

/* ── 규칙 모달 ───────────────────────────────── */
.rules-modal-bg {
  position: fixed;
  inset: 0;
  z-index: 9000;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}
.rules-modal-bg.show {
  opacity: 1;
  pointer-events: auto;
}
.rules-modal {
  background: var(--bg2);
  border: 1px solid var(--bg3);
  border-radius: 12px;
  padding: 28px 32px;
  max-width: 560px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  position: relative;
  transform: translateY(20px);
  transition: transform .25s;
}
.rules-modal-bg.show .rules-modal {
  transform: translateY(0);
}
.rules-close {
  position: absolute;
  top: 12px; right: 16px;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.6rem;
  cursor: pointer;
  line-height: 1;
}
.rules-close:hover { color: var(--text); }
#rules-content h2 {
  color: var(--gold);
  font-size: 1.2rem;
  margin: 0 0 16px;
}
#rules-content h3 {
  color: var(--accent);
  font-size: 0.95rem;
  margin: 18px 0 6px;
}
#rules-content p, #rules-content li {
  color: var(--text-dim);
  font-size: 0.88rem;
  line-height: 1.7;
  margin: 0;
}
#rules-content ul {
  padding-left: 18px;
  margin: 4px 0;
}
#rules-content .rules-badge {
  display: inline-block;
  background: var(--bg3);
  border-radius: 4px;
  padding: 1px 7px;
  font-size: 0.82rem;
  margin-right: 4px;
}

/* ── WIN / LOSE / DRAW 오버레이 ───────────────── */
#result-overlay {
  position: fixed;
  inset: 0;
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity .4s;
}
#result-overlay.show { opacity: 1; pointer-events: auto; }

#confetti-canvas {
  position: fixed;
  inset: 0;
  z-index: 9997;
  pointer-events: none;
}

.result-bg {
  position: absolute;
  inset: 0;
  transition: opacity .4s;
}
.result-bg.win  { background: radial-gradient(ellipse at center, rgba(10,20,40,0.92) 0%, rgba(0,0,0,0.97) 100%); }
.result-bg.lose { background: radial-gradient(ellipse at center, rgba(60,0,0,0.93) 0%, rgba(0,0,0,0.97) 100%); }
.result-bg.draw { background: radial-gradient(ellipse at center, rgba(20,20,50,0.92) 0%, rgba(0,0,0,0.97) 100%); }

.result-inner {
  position: relative;
  text-align: center;
  z-index: 1;
  transform: scale(0.6);
  transition: transform .5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
#result-overlay.show .result-inner { transform: scale(1); }

.result-flag {
  font-size: 7rem;
  line-height: 1;
  margin-bottom: 20px;
  filter: drop-shadow(0 0 30px rgba(255,255,255,0.4));
  animation: flagFloat 2s ease-in-out infinite;
}
@keyframes flagFloat {
  0%, 100% { transform: translateY(0) rotate(-2deg); }
  50%       { transform: translateY(-12px) rotate(2deg); }
}

.result-text {
  font-size: 6rem;
  font-weight: 900;
  letter-spacing: .08em;
  line-height: 1;
  margin-bottom: 16px;
  text-transform: uppercase;
}
.result-text.win {
  color: #FFD700;
  text-shadow:
    0 0 20px #FFD700,
    0 0 60px #FFA500,
    0 0 100px #FF8C00,
    4px 4px 0 #8B6914;
  animation: winPulse 1.5s ease-in-out infinite;
}
@keyframes winPulse {
  0%, 100% { text-shadow: 0 0 20px #FFD700, 0 0 60px #FFA500, 0 0 100px #FF8C00, 4px 4px 0 #8B6914; }
  50%       { text-shadow: 0 0 40px #FFD700, 0 0 100px #FFA500, 0 0 160px #FF8C00, 4px 4px 0 #8B6914; }
}
.result-text.lose {
  color: #ff4444;
  text-shadow: 0 0 20px #ff0000, 4px 4px 0 #6b0000;
  animation: loseDim .8s ease-in-out infinite alternate;
}
@keyframes loseDim {
  from { opacity: 1; }
  to   { opacity: 0.6; }
}
.result-text.draw {
  color: #aabbff;
  text-shadow: 0 0 20px #6688ff, 4px 4px 0 #223388;
}

.result-sub {
  font-size: 1.6rem;
  color: rgba(255,255,255,0.8);
  margin-bottom: 12px;
  letter-spacing: .05em;
}
.result-score {
  font-size: 1.1rem;
  color: rgba(255,255,255,0.5);
  margin-bottom: 28px;
}

.result-close {
  background: rgba(255,255,255,0.1);
  border: 2px solid rgba(255,255,255,0.3);
  color: #fff;
  padding: 12px 40px;
  border-radius: 30px;
  font-size: 1rem;
  cursor: pointer;
  transition: all .2s;
  letter-spacing: .05em;
}
.result-close:hover {
  background: rgba(255,255,255,0.2);
  border-color: rgba(255,255,255,0.6);
  transform: scale(1.05);
}

/* 화면 흔들림 (LOSE) */
@keyframes screenShake {
  0%,100% { transform: translateX(0); }
  10%      { transform: translateX(-8px) rotate(-0.5deg); }
  20%      { transform: translateX(8px) rotate(0.5deg); }
  30%      { transform: translateX(-6px); }
  40%      { transform: translateX(6px); }
  50%      { transform: translateX(-4px); }
  60%      { transform: translateX(4px); }
  70%      { transform: translateX(-2px); }
  80%      { transform: translateX(2px); }
}
body.shake { animation: screenShake .6s ease-out; }

/* ── Toast ────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg3);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 0.9rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity .3s;
  z-index: 9999;
  border: 1px solid var(--accent);
}
#toast.show { opacity: 1; }

/* ── Footer ───────────────────────────────────── */
footer {
  text-align: center;
  padding: 16px;
  color: var(--text-dim);
  font-size: 0.8rem;
  background: var(--bg2);
  border-top: 1px solid var(--bg3);
}

/* ── Responsive ───────────────────────────────── */
@media (max-width: 768px) {
  .games-layout { flex-direction: column; }
  .games-list { width: 100%; flex-direction: row; flex-wrap: wrap; position: static; }
  .game-item { flex: 1; min-width: 130px; }
  .detail-layout { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; }
  .sidebar .panel { flex: 1; min-width: 160px; }
  #go-board { width: 100% !important; height: auto !important; }
}
