/* Modern glass look, better contrast, and playful comment bubbles */
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap");

:root {
  --bg-1: #071421;
  --bg-2: #0f2933;
  --glass: rgba(255, 255, 255, 0.04);
  --muted: rgba(255, 255, 255, 0.55);
  --accent: #5eead4;
  --danger: #ff6b6b;
}

* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  background: linear-gradient(135deg, var(--bg-1), #0b2230 60%, #06212a);
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto,
    "Helvetica Neue", Arial;
  color: #eaf6f6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden; /* Prevent horizontal scroll on body */
}

.app {
  max-width: 1200px;
  margin: 20px auto;
  padding: 18px;
  border-radius: 12px;
}

/* Topbar */
.topbar {
  padding: 10px 4px 18px 4px;
  text-align: center;
}
.topbar h1 {
  font-size: 22px;
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.2px;
}
#toggle-admin {
  margin-top: 8px;
}

/* Grid layout */
.main-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  align-items: start;
}

/* Card */
.card {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.01));
  padding: 16px;
  border-radius: 12px;
  box-shadow: 0 8px 28px rgba(2, 6, 23, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.03);
}

/* Admin panel dropdown */
.admin-panel {
  display: none;
  margin: 10px auto;
  max-width: 600px;
}
.admin-panel.show { display: block; }
.admin-panel .admin-header h2 { margin: 0; font-size: 18px; }
.admin-login-row { display: flex; gap: 8px; margin-top: 10px; }
.admin-login-row input {
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.04);
  background: transparent;
  color: inherit;
}
.admin-login-row .btn { padding: 10px 12px; }
.admin-actions { margin-top: 12px; opacity: 1; transition: opacity 300ms ease; }
.hidden { display: none; }

/* Buttons & Inputs */
input, textarea, button { font-family: inherit; }
input, textarea {
  background: rgba(255, 255, 255, 0.02);
  color: inherit;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.03);
}
textarea { min-height: 88px; resize: vertical; }
.btn {
  background: var(--accent);
  color: #042027;
  padding: 10px 14px;
  border-radius: 9px;
  border: 0;
  font-weight: 700;
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease;
}
.btn.small { padding: 8px 10px; }
.btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.45);
}
.btn.danger,
.btn.danger:hover {
  background: var(--danger);
  color: white;
}

/* Voting panel specifics */
.voting-panel .user-row { display: flex; gap: 8px; margin-bottom: 12px; }
.voting-panel .user-row input { flex: 1; }
.section-title {
  margin: 8px 0 6px 0;
  font-size: 16px;
  color: var(--muted);
  font-weight: 600;
}

/* Question area */
.question-box {
  padding: 12px;
  border-radius: 10px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.015), rgba(255, 255, 255, 0.01));
  border: 1px solid rgba(255, 255, 255, 0.02);
}
.question-text { font-size: 20px; margin-bottom: 12px; color: #e9f8fb; }

/* Choice buttons */
.choices { display: flex; flex-direction: column; gap: 10px; }
.choice-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.02);
  cursor: pointer;
  color: #eaf6f6;
  transition: transform 180ms cubic-bezier(0.2, 0.9, 0.3, 1),
    box-shadow 200ms ease, background 200ms ease;
}
.choice-btn:hover {
  transform: translateY(-6px);
  box-shadow: 0 18px 30px rgba(0, 0, 0, 0.45);
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.03));
}
.choice-btn .label { font-weight: 600; letter-spacing: 0.2px; }
.choice-btn .count {
  background: rgba(255, 255, 255, 0.03);
  padding: 6px 10px;
  border-radius: 999px;
  min-width: 44px;
  text-align: center;
  font-weight: 700;
}

/* Results */
.results-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.result-item {
  position: relative;
  overflow: hidden;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  border-radius: 8px;
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.01), rgba(255, 255, 255, 0.02));
  border: 1px solid rgba(255, 255, 255, 0.02);
}
.result-bar {
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), rgba(94,234,212,0.4));
  border-radius: 8px;
  opacity: 0.35;
  transition: width 620ms cubic-bezier(.34,1.56,.64,1);
  z-index: 0;
}
.result-label, .result-count { position: relative; z-index: 1; }

/* Chat */
.chat-input { display: flex; gap: 8px; margin-bottom: 12px; }
.chat-input input { flex: 1; }
.comment-stream { position: relative; min-height: 140px; overflow: visible; }
.comment-bubble {
  position: absolute;
  bottom: 10px;
  max-width: 240px;
  padding: 10px 12px;
  border-radius: 12px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), rgba(255, 255, 255, 0.01));
  color: #eaf6f6;
  box-shadow: 0 8px 28px rgba(2,6,23,0.7), 0 2px 12px rgba(0,0,0,0.45);
  opacity: 0;
  transform-origin: 100% 100%;
  border-left: 6px solid rgba(255, 255, 255, 0.08);
  overflow-wrap: anywhere;
  font-size: 14px;
  pointer-events: none;
}

/* Animations */
@keyframes popfade {
  0% { opacity: 0; transform: translateY(28px) scale(0.92) rotate(var(--rot, 0deg)); }
  8% { opacity: 1; transform: translateY(0px) scale(1.12) rotate(calc(var(--rot, 0deg) * 0.6)); }
  18% { transform: translateY(-4px) scale(0.98) rotate(calc(var(--rot, 0deg) * 0.8)); }
  60% { transform: translateY(0px) scale(1) rotate(var(--rot, 0deg)); opacity: 1; }
  100% { opacity: 0; transform: translateY(40px) scale(0.9) rotate(calc(var(--rot, 0deg) * 1.1)); }
}

/* ------------------------------------------------ */
/* MIND MAP STYLES (UPDATED FOR PAN/ZOOM)           */
/* ------------------------------------------------ */

.mindmap-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mindmap-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.mindmap-controls {
  display: flex;
  gap: 8px;
}

.mindmap-container {
  position: relative;
  height: 600px; /* Increased Height */
  width: 100%;
  /* Radial gradient gives a sense of depth */
  background: radial-gradient(circle at center, #1a2c38 0%, #0b1a24 100%);
  border-radius: 12px;
  overflow: hidden; /* Important: Hides nodes that fly "off camera" */
  border: 1px solid rgba(255, 255, 255, 0.05);

  /* Cursor logic for Panning */
  cursor: grab;
  touch-action: none; /* Prevents browser scroll on mobile */
  user-select: none;
}

.mindmap-container:active {
  cursor: grabbing;
}

/* The SVG layer for lines (sits behind nodes) */
#mindmap-svg {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none; /* Let clicks pass through to nodes */
  z-index: 0;
  /* SVG needs to be huge so we don't clip lines when zooming? 
     Actually, we just redraw coordinates. But let's ensure it covers. */
}

/* The Line Style */
.mindmap-link {
  stroke: rgba(94, 234, 212, 0.3); /* Accent color, low opacity */
  stroke-width: 2px;
  transition: stroke 0.3s;
}

/* The Node (Word) Style */
.mm-node {
  position: absolute;
  /* Removed 'transform: translate(-50%, -50%)' because JS handles full matrix now */
  top: 0; left: 0; 
  padding: 8px 16px;
  background: linear-gradient(135deg, rgba(255,255,255,0.1), rgba(255,255,255,0.05));
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 20px;
  color: #eaf6f6;
  font-size: 14px;
  font-weight: 600;

  cursor: grab;
  user-select: none;
  z-index: 1;

  /* Performance optimization for 60FPS physics */
  will-change: transform;
  /* Only animate colors/shadows, NOT position (JS handles position) */
  transition: background 0.2s, box-shadow 0.2s;

  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.mm-node:hover {
  background: rgba(255,255,255,0.15);
  z-index: 10;
}

.mm-node.dragging {
  cursor: grabbing;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 100;
  background: var(--accent);
  color: #042027;
}

/* Feedback when you drag over another node (Potential Parent) */
.mm-node.hover-target {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(94, 234, 212, 0.2);
}

.mindmap-instructions {
  position: absolute;
  bottom: 10px;
  left: 0; right: 0;
  text-align: center;
  color: rgba(255,255,255,0.3);
  pointer-events: none;
  z-index: 0;
}

/* Custom Confirmation Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}
.modal-box {
  background: linear-gradient(180deg, #1e293b, #0f172a);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 24px;
  border-radius: 16px;
  width: 320px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.5);
  transform: translateY(20px);
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.modal-overlay.active .modal-box {
  transform: translateY(0);
}
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 8px; color: #fff; }
.modal-desc { font-size: 14px; color: rgba(255,255,255,0.6); margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }


/* Mind Map Lock Overlay */
.mindmap-locked {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(7, 20, 33, 0.85); /* Dark matching background */
  backdrop-filter: blur(8px);
  z-index: 999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: rgba(255, 255, 255, 0.8);
  transition: opacity 0.4s ease, backdrop-filter 0.4s ease;
}

.mindmap-locked.hidden {
  opacity: 0;
  pointer-events: none;
  backdrop-filter: blur(0px);
}

/* Responsive */
@media (max-width: 880px) {
  .main-grid { grid-template-columns: 1fr; padding: 12px; }
  .comment-bubble { max-width: 260px; }
}