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

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: #0a1929;
  color: #e8f4f8;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  padding: 12px 30px;
  background: rgba(0, 0, 0, 0.5);
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 10;
}

header h1 { font-size: 22px; margin-bottom: 2px; }
header p { font-size: 12px; opacity: 0.7; }

.online-counter {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px;
  background: rgba(77, 171, 247, 0.15);
  border: 1px solid rgba(77, 171, 247, 0.3);
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}

.online-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #4dabf7;
  box-shadow: 0 0 8px #4dabf7;
  animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 380px;
  height: calc(100vh - 70px);
  overflow: hidden;
  min-height: 0;
}

#graph-container {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(circle at 30% 20%, rgba(100, 150, 220, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 70% 80%, rgba(255, 100, 150, 0.08) 0%, transparent 50%),
    linear-gradient(180deg, #0d2038 0%, #1a3a5c 100%);
}

#graph {
  width: 100%;
  height: 100%;
  display: block;
}

/* Узлы (пингвины) */
.node-group { cursor: pointer; }
.node-group:hover .node-circle { filter: url(#glow); }
.node-group:hover .node-emoji { transform: scale(1.15); }

.node-circle {
  fill: rgba(30, 60, 100, 0.85);
  stroke: #4dabf7;
  stroke-width: 2;
  transition: all 0.3s;
}

.node-group.active .node-circle {
  fill: rgba(255, 140, 66, 0.3);
  stroke: #ff8c42;
  stroke-width: 3;
  filter: url(#glow);
}

.node-emoji {
  font-size: 30px;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  transition: transform 0.3s;
}

.node-name {
  fill: #fff;
  font-size: 11px;
  font-weight: 700;
  text-anchor: middle;
  pointer-events: none;
  text-shadow: 0 1px 3px rgba(0,0,0,0.9);
}

.node-age {
  fill: rgba(255, 255, 255, 0.55);
  font-size: 9px;
  text-anchor: middle;
  pointer-events: none;
}

.node-mood-icon {
  font-size: 11px;
  text-anchor: middle;
  pointer-events: none;
}

/* Рёбра */
.edge {
  fill: none;
  stroke-width: 1.8;
  opacity: 0.55;
  transition: all 0.3s;
}

.edge:hover { opacity: 1; stroke-width: 3; }
.edge-love { stroke: #ff4d7d; }
.edge-friend { stroke: #4dabf7; }
.edge-enemy { stroke: #6c757d; stroke-dasharray: 6,4; }

.edge-secret {
  stroke-dasharray: 3,3;
  opacity: 0.4;
}

/* Легенда */
.chart-legend {
  position: absolute;
  bottom: 16px;
  left: 16px;
  display: flex;
  gap: 16px;
  padding: 10px 16px;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  backdrop-filter: blur(10px);
  font-size: 12px;
}

.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-line { width: 20px; height: 2px; display: inline-block; }
.legend-line.love { background: #ff4d7d; }
.legend-line.friend { background: #4dabf7; }
.legend-line.enemy { background: #6c757d; border-top: 1px dashed; }

/* Сайдбар */
#sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding: 16px;
  background: rgba(0, 0, 0, 0.4);
  border-left: 1px solid rgba(255, 255, 255, 0.1);
  min-height: 0;
  max-height: calc(100vh - 70px);
  scrollbar-width: thin;
  scrollbar-color: rgba(77, 171, 247, 0.5) transparent;
}

#sidebar::-webkit-scrollbar { width: 6px; }
#sidebar::-webkit-scrollbar-track { background: transparent; }
#sidebar::-webkit-scrollbar-thumb { background: rgba(77, 171, 247, 0.4); border-radius: 3px; }

#sidebar section {
  background: rgba(0, 0, 0, 0.3);
  border-radius: 12px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

#sidebar h2 { font-size: 13px; margin-bottom: 8px; opacity: 0.9; }

.event-item {
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
  line-height: 1.4;
}
.event-item:last-child { border-bottom: none; }
.event-item .time { font-size: 10px; opacity: 0.5; margin-top: 4px; }

.penguin-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px;
  font-size: 12px;
  cursor: pointer;
  border-radius: 6px;
  transition: background 0.2s;
}
.penguin-item:hover { background: rgba(255, 255, 255, 0.05); }

.penguin-avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: #2a5a8a;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}

.penguin-donate-btn {
  margin-left: auto;
  padding: 3px 8px;
  background: #ff8c42;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 11px;
  cursor: pointer;
}
.penguin-donate-btn:hover { background: #ff6b1a; }

.leader-row {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 0;
  font-size: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.leader-row:last-child { border-bottom: none; }
.leader-rank { font-weight: 700; min-width: 22px; }
.leader-rank.gold { color: #ffd700; }
.leader-rank.silver { color: #c0c0c0; }
.leader-rank.bronze { color: #cd7f32; }
.leader-name { flex: 1; }
.leader-amount { font-weight: 700; color: #ff8c42; }

.relation-row {
  display: flex; align-items: center; gap: 6px;
  padding: 5px 0;
  font-size: 11px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.relation-row:last-child { border-bottom: none; }
.relation-strength { color: #4dabf7; font-weight: 600; }

.donation-item {
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
}
.donation-item:last-child { border-bottom: none; }
.donation-item .donor { font-weight: 600; color: #ff8c42; }

.toast {
  position: absolute;
  top: 20px; left: 50%;
  transform: translateX(-50%);
  padding: 12px 20px;
  background: rgba(13, 40, 71, 0.95);
  border: 1px solid rgba(255, 140, 66, 0.5);
  border-radius: 12px;
  color: #fff;
  font-size: 13px;
  max-width: 500px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 200;
  backdrop-filter: blur(10px);
}
.toast.hidden { display: none; }
.toast-title { font-weight: 700; color: #ff8c42; margin-bottom: 4px; }

.modal {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(5px);
}
.modal.hidden { display: none; }

.modal-content {
  background: linear-gradient(135deg, #1a3a5c, #0d2847);
  border-radius: 16px;
  padding: 28px;
  max-width: 420px;
  width: 90%;
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.15);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  max-height: 90vh;
  overflow-y: auto;
}

.close-btn {
  position: absolute;
  top: 8px; right: 14px;
  font-size: 26px;
  cursor: pointer;
  opacity: 0.7;
}
.close-btn:hover { opacity: 1; }

.modal-content h2 { font-size: 20px; margin-bottom: 6px; text-align: center; }
#modal-penguin { text-align: center; opacity: 0.7; margin-bottom: 16px; font-size: 13px; }

.amount-buttons {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.amount-btn {
  padding: 10px;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}
.amount-btn:hover { background: rgba(255, 140, 66, 0.3); border-color: #ff8c42; }
.amount-btn.selected { background: #ff8c42; border-color: #ff8c42; }

.modal-content input,
.modal-content textarea {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 10px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  color: #fff;
  font-family: inherit;
  font-size: 13px;
}
.modal-content input:focus,
.modal-content textarea:focus { outline: none; border-color: #ff8c42; }

#donate-submit {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, #ff8c42, #ff6b1a);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}

#donate-status {
  margin-top: 10px;
  text-align: center;
  font-size: 12px;
  min-height: 16px;
}
#donate-status.success { color: #4dabf7; }
#donate-status.error { color: #ff4d6d; }

.profile-modal-content { max-width: 480px; }
.profile-header {
  display: flex; align-items: center; gap: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  margin-bottom: 14px;
}
.profile-avatar {
  width: 56px; height: 56px;
  border-radius: 50%;
  background: #4a90c2;
  display: flex; align-items: center; justify-content: center;
  font-size: 30px;
}
.profile-header h2 { font-size: 20px; margin-bottom: 2px; text-align: left; }
.profile-header p { font-size: 12px; opacity: 0.7; }

.profile-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.profile-stats .stat {
  background: rgba(0, 0, 0, 0.3);
  padding: 10px;
  border-radius: 10px;
  text-align: center;
}
.profile-stats .stat-value { font-size: 16px; font-weight: 700; color: #ff8c42; }
.profile-stats .stat-label { font-size: 10px; opacity: 0.7; margin-top: 4px; }

.profile-section { margin-bottom: 14px; }
.profile-section h3 { font-size: 13px; margin-bottom: 6px; opacity: 0.9; }

.profile-relation-row {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 0;
  font-size: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
.profile-relation-row .strength-bar {
  flex: 1;
  height: 6px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
  overflow: hidden;
}
.profile-relation-row .strength-fill {
  height: 100%;
  background: linear-gradient(90deg, #4dabf7, #ff4d6d);
}

.profile-donate-btn {
  width: 100%;
  padding: 12px;
  background: linear-gradient(135deg, #ff8c42, #ff6b1a);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 6px;
}

.loading { opacity: 0.5; font-size: 11px; }

/* ФИКС: hover не должен «вылетать» */
.node-emoji,
.node-circle,
.node-group {
  transform-box: fill-box;
  transform-origin: center;
}

/* ФИКС: SVG растягивается на весь контейнер */
#graph {
  width: 100%;
  height: 100%;
  min-height: 0;
}

#graph-container {
  min-height: 0;
}

/* Уменьшаем узлы, чтобы не наслаивались */
.node-circle { r: 26; }
.node-emoji { font-size: 24px; }
.node-name { font-size: 10px; }
.node-age { font-size: 8px; }
.node-mood-icon { font-size: 9px; }

/* SVG занимает всё пространство контейнера */
#graph {
  width: 100%;
  height: 100%;
  display: block;
}

/* Drag&drop стили */
.node-group { cursor: grab; }
.node-group:active { cursor: grabbing; }
.node-group:hover .node-circle {
  stroke: #ff8c42;
  stroke-width: 3;
}
.node-group:hover .node-emoji {
  filter: drop-shadow(0 0 8px rgba(255, 140, 66, 0.8));
}

#reset-positions {
  position: absolute;
  top: 16px;
  right: 16px;
  padding: 8px 14px;
  background: rgba(0, 0, 0, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  backdrop-filter: blur(10px);
  z-index: 5;
}
#reset-positions:hover {
  background: rgba(255, 140, 66, 0.3);
  border-color: #ff8c42;
}

/* Панель фильтров */
.chart-controls {
  position: absolute;
  bottom: 16px;
  left: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px;
  background: rgba(10, 25, 41, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  backdrop-filter: blur(10px);
  font-size: 12px;
  z-index: 5;
}

.controls-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.filter-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.2s;
  user-select: none;
}

.filter-toggle:hover { background: rgba(255, 255, 255, 0.05); }
.filter-toggle input { display: none; }
.filter-toggle .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  opacity: 0.3;
  transition: opacity 0.2s;
}
.filter-toggle input:checked ~ .dot { opacity: 1; }
.filter-toggle input:checked ~ span:not(.dot) { opacity: 1; }
.filter-toggle span:not(.dot) { opacity: 0.4; transition: opacity 0.2s; }

.dot.love { background: #ff4d7d; }
.dot.friend { background: #4dabf7; }
.dot.enemy { background: #6c757d; }

.strength-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  opacity: 0.85;
}

#strength-slider {
  width: 120px;
  accent-color: #ff8c42;
}

#strength-value {
  font-weight: 700;
  color: #ff8c42;
  min-width: 22px;
  text-align: center;
}

/* Убираем старую легенду, если она осталась */
.chart-legend { display: none; }
