@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&family=Space+Grotesk:wght@600;700&display=swap');

:root {
  --bg-main: #0c1017;
  --bg-card: rgba(22, 30, 44, 0.85);
  --bg-card-hover: rgba(30, 41, 59, 0.95);
  --border-subtle: rgba(255, 255, 255, 0.1);
  --border-gold: #d4af37;
  --gold-glow: rgba(212, 175, 55, 0.4);
  --accent-cyan: #38bdf8;
  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --wood-light: #e6c99c;
  --wood-dark: #caa370;
  --board-border: #4a3220;
  --cell-size: min(38px, calc((100vw - 40px) / 15), calc((100vh - 310px) / 15));
  --grid-count: 15;
}

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

body {
  font-family: 'Plus Jakarta Sans', sans-serif;
  background-color: var(--bg-main);
  background-image: 
    radial-gradient(circle at 50% 0%, rgba(56, 189, 248, 0.08) 0%, transparent 60%),
    radial-gradient(circle at 80% 100%, rgba(212, 175, 55, 0.05) 0%, transparent 50%);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-x: hidden;
  position: relative;
}

/* Header Bar */
.app-header {
  width: 100%;
  max-width: 1200px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 20px;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, #ffd700, #ff8c00);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  color: #0f141c;
  font-size: 16px;
  box-shadow: 0 2px 10px rgba(255, 215, 0, 0.3);
}

.brand-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, #ffffff 0%, #cbd5e1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-badge {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.15);
  color: var(--accent-cyan);
  border: 1px solid rgba(56, 189, 248, 0.3);
}

.header-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-subtle);
  font-size: 14px;
  font-weight: 600;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #94a3b8;
}

.status-dot.active-turn {
  background: #22c55e;
  box-shadow: 0 0 10px #22c55e;
  animation: pulseDot 1.5s infinite;
}

@keyframes pulseDot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.3); opacity: 0.7; }
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-icon-text {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon-text:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-1px);
}

.spectator-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(148, 163, 184, 0.1);
  border: 1px solid rgba(148, 163, 184, 0.2);
  color: #94a3b8;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
}

/* Match Lobby & Players Status */
.match-arena {
  width: 100%;
  max-width: 1100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 16px 20px 16px;
  gap: 12px;
  flex: 1;
}

.players-bar {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  max-width: 750px;
}

.player-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.player-card.active-turn {
  border-color: var(--border-gold);
  box-shadow: 0 0 15px var(--gold-glow);
  background: rgba(30, 41, 59, 0.9);
}

.player-card.is-you::after {
  content: 'YOU';
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 9px;
  font-weight: 800;
  padding: 1px 5px;
  background: var(--accent-cyan);
  color: #0f172a;
  border-radius: 4px;
  letter-spacing: 0.5px;
}

.player-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.player-avatar.white-stone {
  background: radial-gradient(circle at 35% 35%, #ffffff 0%, #cbd5e1 100%);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.4), inset 0 -2px 4px rgba(0, 0, 0, 0.2);
  color: #0f172a;
  border: 1px solid #94a3b8;
}

.player-avatar.black-stone {
  background: radial-gradient(circle at 35% 35%, #475569 0%, #090d16 100%);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.5), inset 0 2px 3px rgba(255, 255, 255, 0.2);
  color: #ffffff;
  border: 1px solid #334155;
}

.player-meta {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.player-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
}

.player-status-tag {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.player-status-tag.ready {
  color: #22c55e;
}

.btn-join {
  background: linear-gradient(135deg, #d4af37, #b8860b);
  color: #0f141c;
  border: none;
  font-weight: 700;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(212, 175, 55, 0.3);
}

.btn-join:hover {
  transform: scale(1.04);
  box-shadow: 0 4px 12px rgba(212, 175, 55, 0.5);
}

.vs-badge {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 14px;
  font-weight: 800;
  color: #64748b;
  padding: 4px 8px;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.5);
}

/* User Role Banner */
.role-banner {
  width: 100%;
  max-width: 750px;
  text-align: center;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
}

.role-banner.role-player {
  background: rgba(56, 189, 248, 0.1);
  border-color: rgba(56, 189, 248, 0.3);
  color: var(--accent-cyan);
}

.role-banner.role-spectator {
  background: rgba(168, 85, 247, 0.1);
  border-color: rgba(168, 85, 247, 0.3);
  color: #c084fc;
}

/* The Gomoku Board */
.board-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  margin: 4px 0;
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--grid-count), var(--cell-size));
  grid-template-rows: repeat(var(--grid-count), var(--cell-size));
  border: 6px solid var(--board-border);
  border-radius: 4px;
  background: linear-gradient(135deg, var(--wood-light) 0%, var(--wood-dark) 100%);
  box-shadow: 
    0 15px 35px rgba(0, 0, 0, 0.6),
    inset 0 0 10px rgba(0, 0, 0, 0.2);
  user-select: none;
  position: relative;
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  border: 0.5px solid rgba(80, 50, 20, 0.35);
  position: relative;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease;
}

.cell:hover {
  background-color: rgba(255, 255, 255, 0.18);
}

/* Star points (Hoshi markers at standard Gomoku positions) */
.cell.star-point::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: rgba(60, 35, 15, 0.75);
  pointer-events: none;
  z-index: 1;
}

.cell.selected {
  background-color: rgba(250, 204, 21, 0.45) !important;
  box-shadow: inset 0 0 0 2px #eab308;
}

/* 3D Tactile Stones */
.stone {
  position: absolute;
  width: calc(var(--cell-size) * 0.85);
  height: calc(var(--cell-size) * 0.85);
  border-radius: 50%;
  font-family: 'Space Grotesk', sans-serif;
  font-size: calc(var(--cell-size) * 0.45);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  user-select: none;
  z-index: 2;
  animation: stoneDrop 0.22s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes stoneDrop {
  0% { transform: scale(0.3) translateY(-8px); opacity: 0; }
  100% { transform: scale(1) translateY(0); opacity: 1; }
}

.stone.white {
  background: radial-gradient(circle at 35% 35%, #ffffff 0%, #f1f5f9 45%, #cbd5e1 100%);
  color: #0f172a;
  border: 1px solid rgba(148, 163, 184, 0.6);
  box-shadow: 
    0 4px 6px rgba(0, 0, 0, 0.35),
    inset 0 -2px 3px rgba(0, 0, 0, 0.15);
}

.stone.black {
  background: radial-gradient(circle at 35% 35%, #475569 0%, #1e293b 40%, #090d16 100%);
  color: #ffffff;
  border: 1px solid rgba(51, 65, 85, 0.7);
  box-shadow: 
    0 4px 6px rgba(0, 0, 0, 0.5),
    inset 0 2px 2px rgba(255, 255, 255, 0.25);
}

.cell.winning-cell {
  background-color: rgba(250, 204, 21, 0.28) !important;
  box-shadow: inset 0 0 10px rgba(250, 204, 21, 0.6) !important;
  border-color: rgba(234, 179, 8, 0.7) !important;
}

.winning-cell .stone {
  animation: winningPulse 1.1s infinite alternate cubic-bezier(0.4, 0, 0.2, 1) !important;
  box-shadow: 0 0 20px #facc15, 0 0 35px #eab308, inset 0 0 8px #ffffff !important;
  border: 2.5px solid #fffbeb !important;
  z-index: 10;
}

@keyframes winningPulse {
  0% { transform: scale(1); filter: brightness(1); }
  100% { transform: scale(1.18); filter: brightness(1.3); }
}

/* Bottom Player Hand / Tray */
.action-tray {
  width: 100%;
  max-width: 650px;
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 10px 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.tray-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
}

.tray-title {
  font-weight: 700;
  color: var(--text-main);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stone-selector-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 10px;
  width: 100%;
}

.stone-card {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
  position: relative;
}

.stone-card:not(.disabled):not(.locked):hover {
  background: rgba(30, 41, 59, 0.8);
  border-color: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

.stone-card.disabled {
  opacity: 0.35;
  filter: grayscale(1);
  pointer-events: none;
}

.stone-card.locked {
  opacity: 0.45;
  pointer-events: none;
}

.stone-card .lock-badge {
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: 9px;
  background: #334155;
  color: #94a3b8;
  padding: 1px 4px;
  border-radius: 4px;
  font-weight: 700;
}

.stone-preview {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Space Grotesk', sans-serif;
  font-size: 18px;
  font-weight: 700;
}

.stone-card .stock-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
}

.btn-place {
  width: 100%;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 5px 0;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-place:hover {
  background: linear-gradient(135deg, #60a5fa, #3b82f6);
}

/* Non-blocking Victory Celebration Banner */
.victory-banner {
  width: 100%;
  max-width: 750px;
  background: rgba(18, 26, 42, 0.94);
  backdrop-filter: blur(14px);
  border: 1.5px solid var(--border-gold);
  border-radius: 16px;
  padding: 14px 20px;
  box-shadow: 0 12px 35px rgba(0, 0, 0, 0.6), 0 0 25px var(--gold-glow);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  animation: slideUpFade 0.35s ease-out;
  position: relative;
  z-index: 50;
}

.victory-banner.is-minimized {
  padding: 8px 16px;
  border-radius: 999px;
  max-width: 600px;
  background: rgba(15, 23, 42, 0.92);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.6), 0 0 15px rgba(212, 175, 55, 0.3);
}

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

.victory-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.victory-main-info {
  display: flex;
  align-items: center;
  gap: 14px;
}

.victory-trophy-badge {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.25), rgba(255, 140, 0, 0.2));
  border: 1px solid rgba(255, 215, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  box-shadow: 0 0 15px rgba(255, 215, 0, 0.3);
  animation: trophyPop 2s infinite ease-in-out;
  flex-shrink: 0;
}

@keyframes trophyPop {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08) rotate(3deg); }
}

.victory-text-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.victory-title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.victory-title {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 18px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 0.3px;
}

.victory-target-badge {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(234, 179, 8, 0.2);
  color: #facc15;
  border: 1px solid rgba(234, 179, 8, 0.4);
}

.victory-detail-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  flex-wrap: wrap;
}

.victory-line-desc {
  font-weight: 600;
  color: #94a3b8;
}

.victory-formula {
  font-family: 'Space Grotesk', monospace;
  font-weight: 700;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.1);
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid rgba(56, 189, 248, 0.25);
  font-size: 13px;
}

.victory-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-inspect {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: var(--accent-cyan);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-inspect:hover {
  background: rgba(56, 189, 248, 0.22);
  border-color: rgba(56, 189, 248, 0.6);
  transform: translateY(-1px);
}

.btn-play-again {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: linear-gradient(135deg, #d4af37, #b8860b);
  color: #0f141c;
  border: none;
  padding: 8px 18px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(212, 175, 55, 0.4);
}

.btn-play-again:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(212, 175, 55, 0.6);
}

/* Minimized Mode Styling */
.victory-minimized {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 12px;
}

.mini-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.mini-trophy {
  font-size: 16px;
}

.mini-winner {
  font-weight: 700;
  color: #ffffff;
}

.mini-formula {
  font-family: 'Space Grotesk', monospace;
  font-size: 12px;
  font-weight: 700;
  color: #38bdf8;
  background: rgba(56, 189, 248, 0.12);
  padding: 1px 6px;
  border-radius: 4px;
}

.mini-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-inspect-mini {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  padding: 5px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-inspect-mini:hover {
  background: rgba(255, 255, 255, 0.16);
}

.btn-play-again-mini {
  background: linear-gradient(135deg, #d4af37, #b8860b);
  color: #0f141c;
  border: none;
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-play-again-mini:hover {
  transform: translateY(-1px);
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 15, 0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.25s ease-out;
}

.modal-card {
  background: #131c2e;
  border: 1px solid var(--border-gold);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8), 0 0 20px var(--gold-glow);
  border-radius: 16px;
  padding: 28px;
  max-width: 440px;
  width: 90%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  animation: popScale 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-card h2 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 24px;
  font-weight: 700;
}

.modal-card p {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
}

.countdown-number {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 64px;
  font-weight: 800;
  color: #ffd700;
  text-shadow: 0 0 25px rgba(255, 215, 0, 0.6);
  line-height: 1;
}

.btn-primary {
  background: linear-gradient(135deg, #d4af37, #b8860b);
  color: #0f141c;
  border: none;
  font-weight: 700;
  font-size: 14px;
  padding: 10px 24px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 12px rgba(212, 175, 55, 0.4);
}

.btn-primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(212, 175, 55, 0.6);
}

.rule-list {
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 8px 0;
  font-size: 13px;
  color: #cbd5e1;
}

.rule-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

.rule-icon {
  font-size: 16px;
}

.none {
  display: none !important;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes popScale {
  from { transform: scale(0.85); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* Mobile & Small Screen Adaptations */
@media (max-width: 600px) {
  .app-header {
    padding: 8px 12px;
  }
  .brand-title {
    font-size: 17px;
  }
  .brand-badge {
    display: none;
  }
  .btn-icon-text span {
    display: none;
  }
  .players-bar {
    gap: 8px;
  }
  .player-card {
    padding: 8px 10px;
    gap: 8px;
  }
  .player-avatar {
    width: 28px;
    height: 28px;
    font-size: 14px;
  }
  .player-title {
    font-size: 12px;
  }
  .player-status-tag {
    font-size: 10px;
  }
  .stone-selector-grid {
    gap: 6px;
  }
  .stone-preview {
    width: 30px;
    height: 30px;
    font-size: 15px;
  }
  .action-tray {
    padding: 8px 10px;
  }
  .victory-banner {
    padding: 10px 14px;
    border-radius: 12px;
  }
  .victory-title {
    font-size: 15px;
  }
  .victory-trophy-badge {
    width: 36px;
    height: 36px;
    font-size: 20px;
  }
  .victory-formula {
    font-size: 11px;
  }
  .btn-inspect, .btn-play-again {
    padding: 6px 12px;
    font-size: 12px;
  }
}
